diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2020-03-25 16:53:18 +0100 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-04-02 07:29:37 +0200 |
commit | 5a2f1f4c71a71dbc01af71bdbc83ff650475f525 (patch) | |
tree | 0dd431bd88030429d9120f32b5b88b64978dec00 /tests/auto/quick/qquickanimations | |
parent | cbd4456c9db70afda6c8408be7e5da800889d169 (diff) |
Fix signal emission order for zero-duration animations
The order for non-zero-duration animations are:
* started()
* runningChanged(true)
* stopped()
* runningChanged(false)
* finished()
This patch tries to ensure that zero-duration animations have the same signal
emission order.
The problem was that when setRunning(true) was called on zero-duration
animation, it would call itself (setRunning(false)) lower in the call stack in
order to immediately stop again. This had the implication that we could emit
stopped() even before started() was emitted (since the recursive call to
setRunning(false) would actually complete before the ancestor stack frame
setRunning(true) was completed)
To fix this we emit started() *before* we call start() on the animationInstance.
There is still a bug in that runningChanged(true) is still not emitted for a
zero-duration animation, but this patch should improve the current behavior in
the sense that stopped() is not emitted _before_ started().
Task-number: QTBUG-48193
Change-Id: Ic2bc85e648e6746f6a058e2e9136515e7fdb6192
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 8e0711cafd7e78c6e5d77fdda6be91135a355cd1)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquickanimations')
3 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickanimations/data/signalorder.qml b/tests/auto/quick/qquickanimations/data/signalorder.qml new file mode 100644 index 0000000000..35029b0c84 --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/signalorder.qml @@ -0,0 +1,27 @@ +import QtQuick 2.12 + + +Item { + id: wrapper + width: 400; height: 400 + + Rectangle { + id: greenRect + width: 50; height: 50 + color: "red" + + ColorAnimation on color { + id: colorAnimation + objectName: "ColorAnimation" + to: "green" + duration: 10 + running: false + } + + ParallelAnimation { + id: parallelAnimation + objectName: "ParallelAnimation" + running: false + } + } +} diff --git a/tests/auto/quick/qquickanimations/qquickanimations.pro b/tests/auto/quick/qquickanimations/qquickanimations.pro index 1c5494a24a..fa46cb422d 100644 --- a/tests/auto/quick/qquickanimations/qquickanimations.pro +++ b/tests/auto/quick/qquickanimations/qquickanimations.pro @@ -64,6 +64,7 @@ OTHER_FILES += \ data/scriptActionCrash.qml \ data/sequentialAnimationNullChildBug.qml \ data/signals.qml \ + data/signalorder.qml \ data/transitionAssignmentBug.qml \ data/valuesource.qml \ data/valuesource2.qml diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index d9b42bdeb5..e0ce2d7134 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -89,6 +89,8 @@ private slots: void easingProperties(); void rotation(); void startStopSignals(); + void signalOrder_data(); + void signalOrder(); void runningTrueBug(); void nonTransitionBug(); void registrationBug(); @@ -1292,6 +1294,47 @@ void tst_qquickanimations::startStopSignals() QVERIFY(timer.elapsed() >= 200); } +void tst_qquickanimations::signalOrder_data() +{ + QTest::addColumn<QByteArray>("animationType"); + QTest::addColumn<int>("duration"); + + QTest::addRow("ColorAnimation, duration = 10") << QByteArray("ColorAnimation") << 10; + QTest::addRow("ColorAnimation, duration = 0") << QByteArray("ColorAnimation") << 0; + QTest::addRow("ParallelAnimation, duration = 0") << QByteArray("ParallelAnimation") << 0; +} + +void tst_qquickanimations::signalOrder() +{ + QFETCH(QByteArray, animationType); + QFETCH(int, duration); + + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("signalorder.qml")); + QScopedPointer<QObject> obj(c.create()); + auto *root = qobject_cast<QQuickItem *>(obj.data()); + QVERIFY(root); + QQuickAbstractAnimation *animation = root->findChild<QQuickAbstractAnimation*>(animationType); + QVector<const char*> actualSignalOrder; + connect(animation, &QQuickAbstractAnimation::started , [&actualSignalOrder] () { + actualSignalOrder.append("started"); + }); + connect(animation, &QQuickAbstractAnimation::stopped , [&actualSignalOrder] () { + actualSignalOrder.append("stopped"); + }); + connect(animation, &QQuickAbstractAnimation::finished , [&actualSignalOrder] () { + actualSignalOrder.append("finished"); + }); + QSignalSpy finishedSpy(animation, SIGNAL(finished())); + if (QQuickColorAnimation *colorAnimation = qobject_cast<QQuickColorAnimation*>(animation)) + colorAnimation->setDuration(duration); + + animation->start(); + QTRY_VERIFY(finishedSpy.count()); + const QVector<const char*> expectedSignalOrder = { "started", "stopped", "finished" }; + QCOMPARE(actualSignalOrder, expectedSignalOrder); +} + void tst_qquickanimations::runningTrueBug() { //ensure we start correctly when "running: true" is explicitly set |