summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativestates
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-02-25 00:38:43 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-02-25 00:38:43 (GMT)
commitd654f87319408e3d9754fa5a8ad376c3eaef4489 (patch)
tree7276a6edf146fb9d1426dfd39714a6b2fbc3c4cf /tests/auto/declarative/qdeclarativestates
parentfcfb08e40264c3417da91f4e187758d85f190a4f (diff)
downloadQt-d654f87319408e3d9754fa5a8ad376c3eaef4489.zip
Qt-d654f87319408e3d9754fa5a8ad376c3eaef4489.tar.gz
Qt-d654f87319408e3d9754fa5a8ad376c3eaef4489.tar.bz2
Automatically connect to signals "onFooChanged" if property is "foo".
This follows on from a2a8cea2835ef24104fe784b6ce0f508cc5637c0 to make it work for PropertyChanges and QDeclarativeMetaProperty as well. Task-number: QT-2783
Diffstat (limited to 'tests/auto/declarative/qdeclarativestates')
-rw-r--r--tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml19
-rw-r--r--tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp67
2 files changed, 69 insertions, 17 deletions
diff --git a/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml b/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml
new file mode 100644
index 0000000..a373cfc
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativestates/data/basicChanges4.qml
@@ -0,0 +1,19 @@
+import Qt.test 1.0
+import Qt 4.6
+
+MyRectangle {
+ id: rect
+ width: 100; height: 100
+ color: "red"
+
+ states: State {
+ name: "aBlueDay"
+ PropertyChanges {
+ target: rect
+ onPropertyWithNotifyChanged: { rect.color = "blue"; }
+ }
+ }
+
+ Component.onCompleted: rect.state = "aBlueDay"
+}
+
diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
index 44fb51f..feac9c2 100644
--- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
+++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp
@@ -46,6 +46,29 @@
#include <private/qdeclarativepropertychanges_p.h>
#include <private/qdeclarativestategroup_p.h>
+
+class MyRect : public QDeclarativeRectangle
+{
+ Q_OBJECT
+ Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
+public:
+ MyRect() {}
+
+ void doSomething() { emit didSomething(); }
+
+ int propertyWithNotify() const { return m_prop; }
+ void setPropertyWithNotify(int i) { m_prop = i; emit oddlyNamedNotifySignal(); }
+Q_SIGNALS:
+ void didSomething();
+ void oddlyNamedNotifySignal();
+
+private:
+ int m_prop;
+};
+
+QML_DECLARE_TYPE(MyRect)
+
+
class tst_qdeclarativestates : public QObject
{
Q_OBJECT
@@ -83,6 +106,11 @@ private slots:
void nonExistantProperty();
};
+void tst_qdeclarativestates::initTestCase()
+{
+ QML_REGISTER_TYPE(Qt.test, 1, 0, MyRectangle,MyRect);
+}
+
QByteArray tst_qdeclarativestates::fullDataPath(const QString &path)
{
return QUrl::fromLocalFile(SRCDIR + path).toString().toUtf8();
@@ -156,6 +184,28 @@ void tst_qdeclarativestates::basicChanges()
QCOMPARE(rect->border()->width(),1);
}
+
+ {
+ // Test basicChanges4.qml can magically connect to propertyWithNotify's notify
+ // signal using 'onPropertyWithNotifyChanged' even though the signal name is
+ // actually 'oddlyNamedNotifySignal'
+
+ QDeclarativeComponent component(&engine, SRCDIR "/data/basicChanges4.qml");
+ QVERIFY(component.isReady());
+
+ MyRect *rect = qobject_cast<MyRect*>(component.create());
+ QVERIFY(rect != 0);
+
+ QMetaProperty prop = rect->metaObject()->property(rect->metaObject()->indexOfProperty("propertyWithNotify"));
+ QVERIFY(prop.hasNotifySignal());
+ QString notifySignal = QByteArray(prop.notifySignal().signature());
+ QVERIFY(!notifySignal.startsWith("propertyWithNotifyChanged("));
+
+ QCOMPARE(rect->color(), QColor(Qt::red));
+
+ rect->setPropertyWithNotify(100);
+ QCOMPARE(rect->color(), QColor(Qt::blue));
+ }
}
void tst_qdeclarativestates::basicExtension()
@@ -335,23 +385,6 @@ void tst_qdeclarativestates::basicBinding()
}
}
-class MyRect : public QDeclarativeRectangle
-{
- Q_OBJECT
-public:
- MyRect() {}
- void doSomething() { emit didSomething(); }
-Q_SIGNALS:
- void didSomething();
-};
-
-QML_DECLARE_TYPE(MyRect)
-
-void tst_qdeclarativestates::initTestCase()
-{
- QML_REGISTER_TYPE(Qt.test, 1, 0, MyRectangle,MyRect);
-}
-
void tst_qdeclarativestates::signalOverride()
{
QDeclarativeEngine engine;