Only fast-foward states when there is a transition.
authorMichael Brasser <michael.brasser@nokia.com>
Thu, 8 Sep 2011 05:22:22 +0000 (15:22 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 8 Sep 2011 23:07:55 +0000 (01:07 +0200)
Fast-forwarding is only required when we are animating a state change.

Task-number: QTBUG-16662
Change-Id: I20e1a056cb3268b92b606be34809bcd0e2bfb898
Reviewed-on: http://codereview.qt-project.org/4390
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Charles Yin <charles.yin@nokia.com>

src/declarative/util/qdeclarativetransitionmanager.cpp
tests/auto/declarative/qdeclarativestates/data/avoidFastForward.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp

index 0b549b7..30504cb 100644 (file)
@@ -119,7 +119,7 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
     cancel();
 
     QDeclarativeStateOperation::ActionList applyList = list;
-    // Determine which actions are binding changes.
+    // Determine which actions are binding changes and disable any current bindings
     foreach(const QDeclarativeAction &action, applyList) {
         if (action.toBinding)
             d->bindingsList << action;
@@ -139,8 +139,11 @@ void QDeclarativeTransitionManager::transition(const QList<QDeclarativeAction> &
     //
     // This doesn't catch everything, and it might be a little fragile in
     // some cases - but whatcha going to do?
+    //
+    // Note that we only fast forward if both a transition and bindings are
+    // present, as it is unneccessary (and potentially expensive) otherwise.
 
-    if (!d->bindingsList.isEmpty()) {
+    if (transition && !d->bindingsList.isEmpty()) {
 
         // Apply all the property and binding changes
         for (int ii = 0; ii < applyList.size(); ++ii) {
diff --git a/tests/auto/declarative/qdeclarativestates/data/avoidFastForward.qml b/tests/auto/declarative/qdeclarativestates/data/avoidFastForward.qml
new file mode 100644 (file)
index 0000000..519befc
--- /dev/null
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: rect
+    width: 200
+    height: 200
+
+    property int updateCount: 0
+    onColorChanged: updateCount++
+
+    property color aColor: "green"
+
+    states: State {
+        name: "a"
+        PropertyChanges { target: rect; color: aColor }
+    }
+}
index e13a6c4..165179e 100644 (file)
@@ -149,6 +149,7 @@ private slots:
     void extendsBug();
     void editProperties();
     void QTBUG_14830();
+    void avoidFastForward();
 };
 
 void tst_qdeclarativestates::initTestCase()
@@ -1513,6 +1514,20 @@ void tst_qdeclarativestates::QTBUG_14830()
     QCOMPARE(item->width(), qreal(171));
 }
 
+void tst_qdeclarativestates::avoidFastForward()
+{
+    QDeclarativeEngine engine;
+
+    //shouldn't fast forward if there isn't a transition
+    QDeclarativeComponent c(&engine, SRCDIR "/data/avoidFastForward.qml");
+    QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+    QVERIFY(rect != 0);
+
+    QSGItemPrivate *rectPrivate = QSGItemPrivate::get(rect);
+    rectPrivate->setState("a");
+    QCOMPARE(rect->property("updateCount").toInt(), 1);
+}
+
 QTEST_MAIN(tst_qdeclarativestates)
 
 #include "tst_qdeclarativestates.moc"