diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2020-12-17 10:04:17 +0100 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-04-19 15:18:46 +0200 |
commit | 7b6cef0e654eef0d932d1f8afe986eaa9b2299d4 (patch) | |
tree | f566ef4c5e337e8b0307b80f8b4b49097d8a08f1 /tests/auto/corelib/animation | |
parent | 97a8727f0ed87d1f9cb79d702f7d1da3951c2e2a (diff) |
Port QSequentialAnimationGroup to new property system
There is only one property in QSequentialAnimationGroup,
currentAnimation.
This patch ports this property to the new property system
Task-number: QTBUG-85520
Change-Id: Id528d30f551e88a6165bbb6a3c09d44e89257de5
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/animation')
-rw-r--r-- | tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp index f83594e32a..43a8593803 100644 --- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp @@ -71,6 +71,7 @@ private slots: void insertAnimation(); void clear(); void pauseResume(); + void bindings(); }; void tst_QSequentialAnimationGroup::initTestCase() @@ -1667,5 +1668,48 @@ void tst_QSequentialAnimationGroup::pauseResume() QCOMPARE(spy.count(), 1); } +void tst_QSequentialAnimationGroup::bindings() +{ + // create a group consisting of three animations + QSequentialAnimationGroup group; + QPointer<QAbstractAnimation> anim1 = new DummyPropertyAnimation(&group); + QCOMPARE(group.animationCount(), 1); + QPointer<QAbstractAnimation> anim2 = new DummyPropertyAnimation(&group); + QCOMPARE(group.animationCount(), 2); + QPointer<QAbstractAnimation> anim3 = new DummyPropertyAnimation(&group); + QCOMPARE(group.animationCount(), 3); + + // bind a QProperty to group.currentAnimation + QProperty<QAbstractAnimation *> currentAnim; + currentAnim.setBinding([&]() { return group.currentAnimation(); }); + + // check that everything behaves as expected + QSignalSpy spy(&group, &QSequentialAnimationGroup::currentAnimationChanged); + QVERIFY(spy.isValid()); + + int totalDuration = group.duration(); + + group.setCurrentTime(int(totalDuration * 0.5 / 3)); + QCOMPARE(currentAnim.value(), anim1.get()); + QCOMPARE(spy.count(), 0); + + group.setCurrentTime(int(totalDuration * 1.5 / 3)); + QCOMPARE(currentAnim.value(), anim2.get()); + QCOMPARE(spy.count(), 1); + + // change to other style of formulating a binding to test both + currentAnim.setBinding(group.bindableCurrentAnimation().makeBinding()); + + group.setCurrentTime(int(totalDuration * 2.5 / 3)); + QCOMPARE(currentAnim.value(), anim3.get()); + QCOMPARE(spy.count(), 2); + + // currentAnimation is read-only. Binding it to something should have no effect + QProperty<QAbstractAnimation *> leader; + group.bindableCurrentAnimation().setBinding([&]() { return leader.value(); }); + + QCOMPARE(group.currentAnimation(), anim3.get()); +} + QTEST_MAIN(tst_QSequentialAnimationGroup) #include "tst_qsequentialanimationgroup.moc" |