From 26ec7d7e407fd1b55f69d63833a3ee8af4479d85 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 8 Nov 2011 08:35:55 +1000 Subject: [PATCH] Property changes in Component.onCompleted should trigger Behaviors. Task-number: QTBUG-22555 Change-Id: Ieffb8037d7289113ea4f629ba3b578a845d2cb28 Reviewed-by: Martin Jones --- src/declarative/qml/qdeclarativevme.cpp | 24 +++++++++++----------- .../data/startOnCompleted.qml | 15 ++++++++++++++ .../tst_qdeclarativebehaviors.cpp | 20 ++++++++++++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/startOnCompleted.qml diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index ad8d80c..52095e3 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -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 index 0000000..fdc3779 --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/startOnCompleted.qml @@ -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 +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index b6e68d6..e84cd58 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -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(c.create()); + QVERIFY(rect != 0); + + QQuickItem *innerRect = rect->findChild(); + 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" -- 2.7.4