Property changes in Component.onCompleted should trigger Behaviors.
authorMichael Brasser <michael.brasser@nokia.com>
Mon, 7 Nov 2011 22:35:55 +0000 (08:35 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 9 Nov 2011 00:23:33 +0000 (01:23 +0100)
Task-number: QTBUG-22555
Change-Id: Ieffb8037d7289113ea4f629ba3b578a845d2cb28
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/qml/qdeclarativevme.cpp
tests/auto/declarative/qdeclarativebehaviors/data/startOnCompleted.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp

index ad8d80c..52095e3 100644 (file)
@@ -1384,6 +1384,18 @@ QDeclarativeContextData *QDeclarativeVME::complete(const Interrupt &interrupt)
     }
     parserStatus.deallocate();
 
+    for (int ii = 0; ii < finalizeCallbacks.count(); ++ii) {
+        QDeclarativeEnginePrivate::FinalizeCallback callback = finalizeCallbacks.at(ii);
+        QObject *obj = callback.first;
+        if (obj) {
+            void *args[] = { 0 };
+            QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, callback.second, args);
+        }
+        if (watcher.hasRecursed())
+            return 0;
+    }
+    finalizeCallbacks.clear();
+
     while (componentAttached) {
         QDeclarativeComponentAttached *a = componentAttached;
         a->rem();
@@ -1397,18 +1409,6 @@ QDeclarativeContextData *QDeclarativeVME::complete(const Interrupt &interrupt)
             return 0;
     }
 
-    for (int ii = 0; ii < finalizeCallbacks.count(); ++ii) {
-        QDeclarativeEnginePrivate::FinalizeCallback callback = finalizeCallbacks.at(ii);
-        QObject *obj = callback.first;
-        if (obj) {
-            void *args[] = { 0 };
-            QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, callback.second, args);
-        }
-        if (watcher.hasRecursed())
-            return 0;
-    }
-    finalizeCallbacks.clear();
-
     QDeclarativeContextData *rv = rootContext;
 
     reset();
diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/startOnCompleted.qml b/tests/auto/declarative/qdeclarativebehaviors/data/startOnCompleted.qml
new file mode 100644 (file)
index 0000000..fdc3779
--- /dev/null
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+
+Rectangle {
+    width: 400
+    height: 400
+
+    Rectangle {
+        id: innerRect
+        width: 100; height: 100
+        color: "green"
+        Behavior on x { NumberAnimation {} }
+    }
+
+    Component.onCompleted: innerRect.x = 100
+}
index b6e68d6..e84cd58 100644 (file)
@@ -77,6 +77,7 @@ private slots:
     void runningTrue();
     void sameValue();
     void delayedRegistration();
+    void startOnCompleted();
 };
 
 void tst_qdeclarativebehaviors::simpleBehavior()
@@ -432,6 +433,25 @@ void tst_qdeclarativebehaviors::delayedRegistration()
     QTRY_COMPARE(innerRect->property("x").toInt(), int(100));
 }
 
+//QTBUG-22555
+void tst_qdeclarativebehaviors::startOnCompleted()
+{
+    QDeclarativeEngine engine;
+
+    QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("startOnCompleted.qml")));
+    QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+    QVERIFY(rect != 0);
+
+    QQuickItem *innerRect = rect->findChild<QQuickRectangle*>();
+    QVERIFY(innerRect != 0);
+
+    QCOMPARE(innerRect->property("x").toInt(), int(0));
+
+    QTRY_COMPARE(innerRect->property("x").toInt(), int(100));
+
+    delete rect;
+}
+
 QTEST_MAIN(tst_qdeclarativebehaviors)
 
 #include "tst_qdeclarativebehaviors.moc"