diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-07-11 13:25:42 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-07-18 10:50:48 +0000 |
commit | b8e4975c7a274f7bd1dd1fa20016c34c62045a04 (patch) | |
tree | a4883a3ce565b64a318f76a93815720ede0dade6 /tests/auto/quick/qquickanimations | |
parent | dde49f989e6f77a8db87d7fafc2d4ced34113135 (diff) |
[Quick] Make sure an transition instance is stopped when replaced
When a running transition does not finish of natural causes (reached
the end state due to e.g. the timer finishing), it can happen that it
will never be marked as finished. Specifically, when an transition is
running (e.g. an add animation for a ListView), and that transition is
replaced by another transition (a displace transition, because another
item got added to the ListView before the add transition was finished),
the first animation was never marked as stopped. The effect was that
the running property would stay "true" for forever.
Task-number: QTBUG-38099
Change-Id: Icbcc732f787ff23c72d843f1ecaa86a2cc9c75ec
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickanimations')
-rw-r--r-- | tests/auto/quick/qquickanimations/data/replacingTransitions.qml | 51 | ||||
-rw-r--r-- | tests/auto/quick/qquickanimations/tst_qquickanimations.cpp | 37 |
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickanimations/data/replacingTransitions.qml b/tests/auto/quick/qquickanimations/data/replacingTransitions.qml new file mode 100644 index 0000000000..ff7c50cd67 --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/replacingTransitions.qml @@ -0,0 +1,51 @@ +import QtQuick 2.9 + +Rectangle { + id: theRoot + property alias model: theModel + property alias addTimer: addToModel + property alias addTransition: addTrans + property alias displaceTransition: displaceTrans + + width: 400 + height: 400 + + ListModel { + id: theModel + } + Timer { + id: addToModel + interval: 1000 + running: false + repeat: true + onTriggered: { + theModel.insert(0, {"name": "item " + theModel.count}) + if (theModel.count > 2) + stop() + } + } + Component { + id: listDelegate + Text { + text: name + } + } + ListView { + id: listView + + property int animationDuration: 10000 + + anchors.fill: parent + model: theModel + delegate: listDelegate + add: Transition { + id: addTrans + NumberAnimation { properties: "x"; from: 400; duration: listView.animationDuration } + NumberAnimation { properties: "y"; from: 400; duration: listView.animationDuration } + } + addDisplaced: Transition { + id: displaceTrans + NumberAnimation { properties: "x,y"; duration: listView.animationDuration } + } + } +} diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 3cfe03a376..0f095774e8 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -29,6 +29,8 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQuick/qquickview.h> +#include <QtQml/private/qqmltimer_p.h> +#include <QtQml/private/qqmllistmodel_p.h> #include <QtQml/private/qanimationgroupjob_p.h> #include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickitemanimation_p.h> @@ -106,6 +108,7 @@ private slots: void pathLineUnspecifiedXYBug(); void unsetAnimatorProxyJobWindow(); void finished(); + void replacingTransitions(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -1686,6 +1689,40 @@ void tst_qquickanimations::finished() } } +void tst_qquickanimations::replacingTransitions() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("replacingTransitions.qml")); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create())); + if (!c.errors().isEmpty()) + qDebug() << c.errorString(); + QVERIFY(rect); + + QQmlTimer *addTimer = rect->property("addTimer").value<QQmlTimer*>(); + QVERIFY(addTimer); + QCOMPARE(addTimer->isRunning(), false); + + QQuickTransition *addTrans = rect->property("addTransition").value<QQuickTransition*>(); + QVERIFY(addTrans); + QCOMPARE(addTrans->running(), false); + + QQuickTransition *displaceTrans = rect->property("displaceTransition").value<QQuickTransition*>(); + QVERIFY(displaceTrans); + QCOMPARE(displaceTrans->running(), false); + + QQmlListModel *model = rect->property("model").value<QQmlListModel *>(); + QVERIFY(model); + QCOMPARE(model->count(), 0); + + addTimer->start(); + QTest::qWait(1000 + 1000 + 10000); + + QTRY_COMPARE(addTimer->isRunning(), false); + QTRY_COMPARE(addTrans->running(), false); + QTRY_COMPARE(displaceTrans->running(), false); + QCOMPARE(model->count(), 3); +} + QTEST_MAIN(tst_qquickanimations) #include "tst_qquickanimations.moc" |