diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-02-24 05:06:56 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-02-24 05:06:56 (GMT) |
commit | a2a8cea2835ef24104fe784b6ce0f508cc5637c0 (patch) | |
tree | 80f6ad699172cb436c0d159472f8203fd5430ad4 /tests/auto/declarative | |
parent | 7c76abb0dc4204043bec9b6fa315f9753a7986ae (diff) | |
download | Qt-a2a8cea2835ef24104fe784b6ce0f508cc5637c0.zip Qt-a2a8cea2835ef24104fe784b6ce0f508cc5637c0.tar.gz Qt-a2a8cea2835ef24104fe784b6ce0f508cc5637c0.tar.bz2 |
Automatically connect to a notify signal if the requested signal is
in the "onFooChanged" form, even if the notify signal is not called
"fooChanged".
Task-number: QT-2783
Diffstat (limited to 'tests/auto/declarative')
3 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/autoNotifyConnection.qml b/tests/auto/declarative/qdeclarativelanguage/data/autoNotifyConnection.qml new file mode 100644 index 0000000..640fb54 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/autoNotifyConnection.qml @@ -0,0 +1,6 @@ +import Test 1.0 +MyQmlObject { + property bool receivedNotify : false + onPropertyWithNotifyChanged: { receivedNotify = true; } +} + diff --git a/tests/auto/declarative/qdeclarativelanguage/testtypes.h b/tests/auto/declarative/qdeclarativelanguage/testtypes.h index 21f3e70..fa62eb4 100644 --- a/tests/auto/declarative/qdeclarativelanguage/testtypes.h +++ b/tests/auto/declarative/qdeclarativelanguage/testtypes.h @@ -102,6 +102,7 @@ class MyQmlObject : public QObject, public MyInterface, public QDeclarativeParse Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal); Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType); Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject) + Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) Q_INTERFACES(MyInterface QDeclarativeParserStatus) public: @@ -137,6 +138,9 @@ public: MyCustomVariantType customType() const { return m_custom; } void setCustomType(const MyCustomVariantType &v) { m_custom = v; } + + int propertyWithNotify() const { return m_propertyWithNotify; } + void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); } public slots: void basicSlot() { qWarning("MyQmlObject::basicSlot"); } void basicSlotWithArgs(int v) { qWarning("MyQmlObject::basicSlotWithArgs(%d)", v); } @@ -144,6 +148,7 @@ public slots: signals: void basicSignal(); void basicParameterizedSignal(int parameter); + void oddlyNamedNotifySignal(); private: friend class tst_qmllanguage; @@ -151,6 +156,7 @@ private: MyInterface *m_interface; MyQmlObject *m_qmlobject; MyCustomVariantType m_custom; + int m_propertyWithNotify; }; QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES) QML_DECLARE_TYPE(MyQmlObject); diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index cb59f47..b177636 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -88,6 +88,7 @@ private slots: void rootAsQmlComponent(); void inlineQmlComponents(); void idProperty(); + void autoNotifyConnection(); void assignSignal(); void dynamicProperties(); void dynamicPropertiesNested(); @@ -511,6 +512,22 @@ void tst_qmllanguage::idProperty() QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); } +// Tests automatic connection to notify signals if "onBlahChanged" syntax is used +// even if the notify signal for "blah" is not called "blahChanged" +void tst_qmllanguage::autoNotifyConnection() +{ + QDeclarativeComponent component(&engine, TEST_FILE("autoNotifyConnection.qml")); + VERIFY_ERRORS(0); + MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create()); + QVERIFY(object != 0); + QMetaProperty prop = object->metaObject()->property(object->metaObject()->indexOfProperty("receivedNotify")); + QVERIFY(prop.isValid()); + + QCOMPARE(prop.read(object), QVariant::fromValue(false)); + object->setPropertyWithNotify(1); + QCOMPARE(prop.read(object), QVariant::fromValue(true)); +} + // Tests that signals can be assigned to void tst_qmllanguage::assignSignal() { |