Ensure bindings on pause work correctly.
authorMichael Brasser <michael.brasser@nokia.com>
Fri, 29 Jul 2011 03:10:25 +0000 (13:10 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 29 Jul 2011 07:39:41 +0000 (09:39 +0200)
Defer the actual pause, in the same way we defer the actual start.

Task-number: QTBUG-19080
Change-Id: I500e5aa6678cbb5321979fda31f60d6d6e19a61e
Reviewed-on: http://codereview.qt.nokia.com/2366
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
src/declarative/util/qdeclarativeanimation.cpp
tests/auto/declarative/qdeclarativeanimations/data/pauseBindingBug.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp

index 213ebe5..56867d8 100644 (file)
@@ -265,6 +265,10 @@ void QDeclarativeAbstractAnimation::setPaused(bool p)
     }
 
     d->paused = p;
+
+    if (!d->componentComplete)
+        return;
+
     if (d->paused)
         qtAnimation()->pause();
     else
@@ -292,6 +296,10 @@ void QDeclarativeAbstractAnimation::componentFinalized()
         d->running = false;
         setRunning(true);
     }
+    if (d->paused) {
+        d->paused = false;
+        setPaused(true);
+    }
 }
 
 /*!
diff --git a/tests/auto/declarative/qdeclarativeanimations/data/pauseBindingBug.qml b/tests/auto/declarative/qdeclarativeanimations/data/pauseBindingBug.qml
new file mode 100644 (file)
index 0000000..359cda1
--- /dev/null
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: rect
+    width: 200
+    height: 200
+
+    property bool animating: false
+    property int value: 0
+
+    NumberAnimation on value {
+        objectName: "animation"
+        paused: !rect.animating
+        to: 100
+        duration: 50
+    }
+}
index 9308aca..6461b69 100644 (file)
@@ -89,6 +89,7 @@ private slots:
     void doubleRegistrationBug();
     void alwaysRunToEndRestartBug();
     void transitionAssignmentBug();
+    void pauseBindingBug();
 };
 
 #define QTIMED_COMPARE(lhs, rhs) do { \
@@ -857,6 +858,20 @@ void tst_qdeclarativeanimations::transitionAssignmentBug()
     QCOMPARE(rect->property("nullObject").toBool(), false);
 }
 
+//QTBUG-19080
+void tst_qdeclarativeanimations::pauseBindingBug()
+{
+    QDeclarativeEngine engine;
+
+    QDeclarativeComponent c(&engine, SRCDIR "/data/pauseBindingBug.qml");
+    QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+    QVERIFY(rect != 0);
+    QDeclarativeAbstractAnimation *anim = rect->findChild<QDeclarativeAbstractAnimation*>("animation");
+    QVERIFY(anim->qtAnimation()->state() == QAbstractAnimation::Paused);
+
+    delete rect;
+}
+
 QTEST_MAIN(tst_qdeclarativeanimations)
 
 #include "tst_qdeclarativeanimations.moc"