From: Michael Brasser Date: Thu, 8 Sep 2011 05:22:22 +0000 (+1000) Subject: Only fast-foward states when there is a transition. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=de868c71b7ec5f463ed9b1a142f3b805d1c3d627;p=konrad%2Fqtdeclarative.git Only fast-foward states when there is a transition. 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 Reviewed-by: Charles Yin --- diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index 0b549b7..30504cb 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -119,7 +119,7 @@ void QDeclarativeTransitionManager::transition(const QList & 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 & // // 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 index 0000000..519befc --- /dev/null +++ b/tests/auto/declarative/qdeclarativestates/data/avoidFastForward.qml @@ -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 } + } +} diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index e13a6c4..165179e 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -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(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"