From cf0b965aaab0ea7e777c1f8e8d35de3a73d7d08e Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Wed, 11 Jul 2018 13:25:42 +0200 Subject: [Quick] Make sure an transition instance is stopped when destroyed 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: Id7d7053cb2fc1912127d9f5e71f27eb984ba7435 Reviewed-by: Simon Hausmann --- .../qquickanimations/data/replacingTransitions.qml | 51 ++++++++++++++++++++++ .../qquickanimations/tst_qquickanimations.cpp | 37 ++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/auto/quick/qquickanimations/data/replacingTransitions.qml (limited to 'tests/auto/quick/qquickanimations') 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 de86bb16db..de8e30407b 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -105,6 +107,7 @@ private slots: void pathSvgAnimation(); void pathLineUnspecifiedXYBug(); void unsetAnimatorProxyJobWindow(); + void replacingTransitions(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -1612,6 +1615,40 @@ void tst_qquickanimations::unsetAnimatorProxyJobWindow() QCOMPARE(proxy.job().data(), job); } +void tst_qquickanimations::replacingTransitions() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("replacingTransitions.qml")); + QScopedPointer rect(qobject_cast(c.create())); + if (!c.errors().isEmpty()) + qDebug() << c.errorString(); + QVERIFY(rect); + + QQmlTimer *addTimer = rect->property("addTimer").value(); + QVERIFY(addTimer); + QCOMPARE(addTimer->isRunning(), false); + + QQuickTransition *addTrans = rect->property("addTransition").value(); + QVERIFY(addTrans); + QCOMPARE(addTrans->running(), false); + + QQuickTransition *displaceTrans = rect->property("displaceTransition").value(); + QVERIFY(displaceTrans); + QCOMPARE(displaceTrans->running(), false); + + QQmlListModel *model = rect->property("model").value(); + 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" -- cgit v1.2.3