diff options
author | Robert Griebl <robert.griebl@qt.io> | 2020-10-19 18:15:47 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2020-11-28 11:56:58 +0100 |
commit | 71588f7b3d179e0d77e4853bbe7908beb2518963 (patch) | |
tree | 695f5fc941a8e5fc6344260d2940a311a7861a17 /tests/auto/quick | |
parent | ddfb954cf4b407e246c325e794424484681ca76a (diff) |
Fix Animators requiring an explicit from value
Contrary to the documentation, Animators have always had the requirement
that an explicit from value was specified, which isn't very convenient
e.g. in Transitions.
This patch was tested against a (quite big) real world customer
application using Qt 5.12 and Qt 5.15.
Also a new unit test was added to test this feature.
I couldn't find another way to access the actual AnimatorJob besides
querying the window's AnimatorController, so I had to add an auto-test
only export on that class.
Task-number: QTBUG-66475
Pick-to: 6.0 6.0.0
Change-Id: Icc2a220a13f587d69594a4b2ed345abf0438e29e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/quick')
4 files changed, 142 insertions, 4 deletions
diff --git a/tests/auto/quick/qquickanimators/CMakeLists.txt b/tests/auto/quick/qquickanimators/CMakeLists.txt index 8a39659627..4ad5624f85 100644 --- a/tests/auto/quick/qquickanimators/CMakeLists.txt +++ b/tests/auto/quick/qquickanimators/CMakeLists.txt @@ -13,9 +13,13 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qquickanimators SOURCES ../../shared/util.cpp ../../shared/util.h + ../shared/geometrytestutil.cpp ../shared/geometrytestutil.h + ../shared/viewtestutil.cpp ../shared/viewtestutil.h + ../shared/visualtestutil.cpp ../shared/visualtestutil.h tst_qquickanimators.cpp DEFINES QT_DISABLE_DEPRECATED_BEFORE=0 + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" INCLUDE_DIRECTORIES ../../shared PUBLIC_LIBRARIES @@ -28,7 +32,7 @@ qt_internal_add_test(tst_qquickanimators ) #### Keys ignored in scope 1:.:.:qquickanimators.pro:<TRUE>: -# OTHER_FILES = "data/positionerWithAnimator.qml" "data/windowWithAnimator.qml" +# OTHER_FILES = "data/positionerWithAnimator.qml" "data/windowWithAnimator.qml" "data/animatorImplicitFrom.qml" ## Scopes: ##################################################################### diff --git a/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml b/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml new file mode 100644 index 0000000000..2d2ebe2ff8 --- /dev/null +++ b/tests/auto/quick/qquickanimators/data/animatorImplicitFrom.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 + +Rectangle { + width: 200 + height: 200 + color: "white" + + property alias left_animator: left_animator + property alias right_animator: right_animator + property alias rectangle: rect + + Rectangle { + id: rect + width: 100 + height: 200 + color: "red" + + state: "left" + states: [ + State { + name: "left" + }, + State { + name: "right" + } + ] + + transitions: [ + Transition { + to: "left" + + XAnimator { + id: left_animator + target: rect + duration: 500 + to: 0 + } + }, + Transition { + to: "right" + + XAnimator { + id: right_animator + target: rect + duration: 500 + to: 100 + } + } + ] + } +} diff --git a/tests/auto/quick/qquickanimators/qquickanimators.pro b/tests/auto/quick/qquickanimators/qquickanimators.pro index 75be8a8e4f..788c959040 100644 --- a/tests/auto/quick/qquickanimators/qquickanimators.pro +++ b/tests/auto/quick/qquickanimators/qquickanimators.pro @@ -3,6 +3,7 @@ TARGET = tst_qquickanimators SOURCES += tst_qquickanimators.cpp include (../../shared/util.pri) +include (../shared/util.pri) macos:CONFIG -= app_bundle @@ -13,4 +14,5 @@ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 OTHER_FILES += \ data/positionerWithAnimator.qml \ - data/windowWithAnimator.qml + data/windowWithAnimator.qml \ + data/animatorImplicitFrom.qml diff --git a/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp b/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp index b35e4b4cc9..b13f3bd343 100644 --- a/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp +++ b/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp @@ -31,8 +31,11 @@ #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickanimator_p.h> -#include <QtQuick/private/qquickrepeater_p.h> #include <QtQuick/private/qquicktransition_p.h> +#include <QtQuick/private/qquickrepeater_p.h> +#include <QtQuick/private/qquickanimatorcontroller_p.h> +#include <QtQuick/private/qquickanimation_p_p.h> +#include <QtQuick/private/qquickitem_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -47,6 +50,7 @@ private slots: void testMultiWinAnimator_data(); void testMultiWinAnimator(); void testTransitions(); + void testTransitionsWithImplicitFrom(); }; void tst_Animators::testMultiWinAnimator_data() @@ -126,7 +130,56 @@ void tst_Animators::testTransitions() QCOMPARE(child->scale(), qreal(1)); } -#include "tst_qquickanimators.moc" +void tst_Animators::testTransitionsWithImplicitFrom() +{ + QScopedPointer<QQuickView> view(createView()); + view->setSource(testFileUrl("animatorImplicitFrom.qml")); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view.data())); + QQuickItem *root = view->rootObject(); + QVERIFY(root); + + QQuickItem *rectangle = root->property("rectangle").value<QQuickItem *>(); + QVERIFY(rectangle); + + // the controller has access to actual AnimatorJob instances + QQuickAnimatorController *controller = QQuickWindowPrivate::get(view.data())->animationController.data(); + QVERIFY(controller); + + // verify initial state + QCOMPARE(rectangle->x(), 0); + QCOMPARE(rectangle->state(), "left"); + QVERIFY(controller->m_runningAnimators.isEmpty()); + + // transition to the "right" state + rectangle->setState("right"); + QTRY_VERIFY_WITH_TIMEOUT(!controller->m_runningAnimators.isEmpty(), 1000); + auto r_job = *controller->m_runningAnimators.constBegin(); + QVERIFY(r_job); + QCOMPARE(r_job->from(), 0); + QCOMPARE(r_job->to(), 100); + QTRY_VERIFY_WITH_TIMEOUT(controller->m_runningAnimators.isEmpty(), 1000); + + // verify state after first transition + QTRY_COMPARE_WITH_TIMEOUT(rectangle->x(), 100, 1000); // the render thread has to sync first + QCOMPARE(rectangle->state(), "right"); + QVERIFY(controller->m_runningAnimators.isEmpty()); + + // transition back to the "left" state + rectangle->setState("left"); + QTRY_VERIFY_WITH_TIMEOUT(!controller->m_runningAnimators.isEmpty(), 1000); + auto l_job = *controller->m_runningAnimators.constBegin(); + QVERIFY(l_job); + QCOMPARE(l_job->from(), 100); // this was not working in older Qt versions + QCOMPARE(l_job->to(), 0); + QTRY_VERIFY_WITH_TIMEOUT(controller->m_runningAnimators.isEmpty(), 1000); + + // verify the final state + QTRY_COMPARE_WITH_TIMEOUT(rectangle->x(), 0, 1000); // the render thread has to sync first + QCOMPARE(rectangle->state(), "left"); + QVERIFY(controller->m_runningAnimators.isEmpty()); +} QTEST_MAIN(tst_Animators) +#include "tst_qquickanimators.moc" |