QtPropertyBrowserとフレンドを組み込んだQt 5では、この質問はもはや関係しません。私はThadeaux's approachの行に沿ってeditingFinished
シグナルをQtLineEditorFactoryに実装し、それを必要としない、あるいはそうしたいと決めた!おそらく私の時間を無駄にする気持ちを和らげるために、誰かが役に立つと思うかもしれない場合に備えて、自分の解決策のコード差分を取ります。
Index: src/qteditorfactory.cpp
===================================================================
--- src/qteditorfactory.cpp (revision 737)
+++ src/qteditorfactory.cpp (working copy)
@@ -1076,7 +1076,6 @@
}
-
/*!
\class QtLineEditFactory
@@ -1094,7 +1093,6 @@
{
d_ptr = new QtLineEditFactoryPrivate();
d_ptr->q_ptr = this;
-
}
/*!
@@ -1121,6 +1119,10 @@
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
connect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
+
+ // c.s. Added 4/12/2017
+ connect(this, SIGNAL(propertyEditingFinished(QtProperty*, const QString&)),
+ manager, SIGNAL(propertyEditingFinished(QtProperty*, const QString&)));
}
/*!
@@ -1131,7 +1133,6 @@
QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager,
QtProperty *property, QWidget *parent)
{
-
QLineEdit *editor = d_ptr->createEditor(property, parent);
editor->setEchoMode((EchoMode)manager->echoMode(property));
editor->setReadOnly(manager->isReadOnly(property));
@@ -1146,9 +1147,49 @@
this, SLOT(slotSetValue(const QString &)));
connect(editor, SIGNAL(destroyed(QObject *)),
this, SLOT(slotEditorDestroyed(QObject *)));
- return editor;
+
+ // c.s. Added 4/12/2017
+ connect(editor, SIGNAL(editingFinished()), SLOT(handleEditingFinished()));
+ return editor;
}
+
+
+// c.s. Added 4/12/2017
+void QtLineEditFactory::handleEditingFinished()
+{
+ auto keys = d_ptr->m_editorToProperty.keys();
+ QLineEdit *le = qobject_cast<QLineEdit*>(sender());
+ if (!le)
+ return;
+
+ disconnect(le, SIGNAL(editingFinished()), this, SLOT(handleEditingFinished()));
+
+ QtProperty *property = 0;
+
+ const QMap<QLineEdit *, QtProperty *>::ConstIterator ecend =
+ d_ptr->m_editorToProperty.constEnd();
+ for (QMap<QLineEdit *, QtProperty *>::ConstIterator itEditor =
+ d_ptr->m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor)
+ {
+ if (itEditor.key() == le)
+ {
+ property = itEditor.value();
+ if (!property)
+ return;
+
+ QtStringPropertyManager *manager = propertyManager(property);
+
+ if (!manager)
+ return;
+
+ QString s = manager->value(property);
+ manager->setValue(property, s); // make sure it has the last value
+ emit propertyEditingFinished(property, s);
+ }
+ }
+}
+
/*!
\internal
@@ -1165,6 +1206,9 @@
disconnect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
this, SLOT(slotReadOnlyChanged(QtProperty *, bool)));
+ // c.s. Added 4/12/2017
+ disconnect(this, SIGNAL(propertyEditingFinished(QtProperty*, const QString&)),
+ manager, SIGNAL(propertyEditingFinished(QtProperty*, const QString&)));
}
// QtDateEditFactory
Index: src/qteditorfactory.h
===================================================================
--- src/qteditorfactory.h (revision 737)
+++ src/qteditorfactory.h (working copy)
@@ -183,6 +183,14 @@
QWidget *createEditor(QtStringPropertyManager *manager, QtProperty *property,
QWidget *parent);
void disconnectPropertyManager(QtStringPropertyManager *manager);
+
+// c.s. Added 4/12/2017
+Q_SIGNALS:
+ void propertyEditingFinished(QtProperty*, const QString&); // signal editing done in line_editor is finished
+
+protected slots:
+ void handleEditingFinished(); // similar to QLineEdit
+
private:
QtLineEditFactoryPrivate *d_ptr;
Q_DECLARE_PRIVATE(QtLineEditFactory)
Index: src/qtpropertymanager.h
===================================================================
--- src/qtpropertymanager.h (revision 737)
+++ src/qtpropertymanager.h (working copy)
@@ -200,6 +200,9 @@
void echoModeChanged(QtProperty *property, const int);
void readOnlyChanged(QtProperty *property, bool);
+ // c.s. Added 4/12/2017
+ void propertyEditingFinished(QtProperty *, const QString &val);
+
protected:
QString valueText(const QtProperty *property) const;
QString displayText(const QtProperty *property) const;
5年後、私はあなたと同じ気分になりました。私は、.NETのものと同じくらい少しでもプロパティグリッドを作るために多くのハッキングを行ってきました。 – Jack