summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-03-27 18:36:11 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-08 11:26:39 +0200
commit5422fb79486a1818d6355d75f019fe63120a43d0 (patch)
treea4b95a12034097d2941983cb216dff64081321f5 /tests/auto/tools
parent0bfbe10ff20f271cff0c0af6ca1fb1894bb48d60 (diff)
Allow declaring QProperty<> based Q_PROPERTYies with a notify signal
This requires mostly making moc a bit more permissive, which has the advantage that it also simplifies the code a little bit. The newly added test case demonstrates how to connect such a property with a change signal. One test case needed to be changed regarding the callback as the publicProperty member now has a (permanent) observer and therefore re-assigning the binding will re-evaluate it as the value might have changed. Change-Id: Ia7edcec432de830bdd4e07d943c5d4550c175ca4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/tools')
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index b701aa05a3..08dae7f6ca 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -4106,19 +4106,23 @@ void tst_Moc::requiredProperties()
class ClassWithQPropertyMembers : public QObject
{
Q_OBJECT
- Q_PROPERTY(int publicProperty)
+ Q_PROPERTY(int publicProperty NOTIFY publicPropertyChanged)
Q_PROPERTY(int privateExposedProperty)
public:
QProperty<int> publicProperty;
QProperty<int> notExposed;
+signals:
+ void publicPropertyChanged();
+
protected:
QProperty<int> protectedProperty;
private:
QProperty<int> privateProperty;
QProperty<int> privateExposedProperty;
+ QPropertyMemberChangeHandler<&ClassWithQPropertyMembers::publicProperty, &ClassWithQPropertyMembers::publicPropertyChanged> connector{this};
};
void tst_Moc::qpropertyMembers()
@@ -4139,12 +4143,15 @@ void tst_Moc::qpropertyMembers()
prop.write(&instance, 42);
QCOMPARE(instance.publicProperty.value(), 42);
+ QSignalSpy publicPropertySpy(&instance, SIGNAL(publicPropertyChanged()));
+
instance.publicProperty.setValue(100);
QCOMPARE(prop.read(&instance).toInt(), 100);
+ QCOMPARE(publicPropertySpy.count(), 1);
QCOMPARE(prop.metaType(), QMetaType(QMetaType::Int));
- QVERIFY(!prop.notifySignal().isValid());
+ QVERIFY(prop.notifySignal().isValid());
}
@@ -4195,7 +4202,6 @@ void tst_Moc::setQPRopertyBinding()
void *argv[] = { &binding };
instance.qt_metacall(QMetaObject::SetQPropertyBinding, prop.propertyIndex(), argv);
}
- QVERIFY(!bindingCalled); // not yet!
QCOMPARE(instance.publicProperty.value(), 42);
QVERIFY(bindingCalled); // but now it should've been called :)