summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.cpp9
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.h6
-rw-r--r--src/corelib/animation/qsequentialanimationgroup_p.h11
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp44
4 files changed, 62 insertions, 8 deletions
diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp
index 1d0b799fef..7ce8658628 100644
--- a/src/corelib/animation/qsequentialanimationgroup.cpp
+++ b/src/corelib/animation/qsequentialanimationgroup.cpp
@@ -301,6 +301,11 @@ QAbstractAnimation *QSequentialAnimationGroup::currentAnimation() const
return d->currentAnimation;
}
+QBindable<QAbstractAnimation *> QSequentialAnimationGroup::bindableCurrentAnimation() const
+{
+ return &d_func()->currentAnimation;
+}
+
/*!
\reimp
*/
@@ -424,6 +429,8 @@ bool QSequentialAnimationGroup::event(QEvent *event)
void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool intermediate)
{
Q_Q(QSequentialAnimationGroup);
+ // currentAnimation.removeBindingUnlessInWrapper()
+ // is not necessary here, since it is read only
index = qMin(index, animations.count() - 1);
@@ -443,8 +450,8 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter
if (currentAnimation)
currentAnimation->stop();
- currentAnimation = animations.at(index);
currentAnimationIndex = index;
+ currentAnimation = animations.at(index);
emit q->currentAnimationChanged(currentAnimation);
diff --git a/src/corelib/animation/qsequentialanimationgroup.h b/src/corelib/animation/qsequentialanimationgroup.h
index a33ff07abf..34be474fe2 100644
--- a/src/corelib/animation/qsequentialanimationgroup.h
+++ b/src/corelib/animation/qsequentialanimationgroup.h
@@ -52,7 +52,8 @@ class QSequentialAnimationGroupPrivate;
class Q_CORE_EXPORT QSequentialAnimationGroup : public QAnimationGroup
{
Q_OBJECT
- Q_PROPERTY(QAbstractAnimation* currentAnimation READ currentAnimation NOTIFY currentAnimationChanged)
+ Q_PROPERTY(QAbstractAnimation *currentAnimation READ currentAnimation NOTIFY
+ currentAnimationChanged BINDABLE bindableCurrentAnimation)
public:
QSequentialAnimationGroup(QObject *parent = nullptr);
@@ -62,10 +63,11 @@ public:
QPauseAnimation *insertPause(int index, int msecs);
QAbstractAnimation *currentAnimation() const;
+ QBindable<QAbstractAnimation *> bindableCurrentAnimation() const;
int duration() const override;
Q_SIGNALS:
- void currentAnimationChanged(QAbstractAnimation *current);
+ void currentAnimationChanged(QAbstractAnimation *current) const;
protected:
QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, QObject *parent);
diff --git a/src/corelib/animation/qsequentialanimationgroup_p.h b/src/corelib/animation/qsequentialanimationgroup_p.h
index b788771fe5..369856cb55 100644
--- a/src/corelib/animation/qsequentialanimationgroup_p.h
+++ b/src/corelib/animation/qsequentialanimationgroup_p.h
@@ -53,6 +53,7 @@
#include "qsequentialanimationgroup.h"
#include "private/qanimationgroup_p.h"
+#include "private/qproperty_p.h"
QT_REQUIRE_CONFIG(animation);
@@ -62,10 +63,7 @@ class QSequentialAnimationGroupPrivate : public QAnimationGroupPrivate
{
Q_DECLARE_PUBLIC(QSequentialAnimationGroup)
public:
- QSequentialAnimationGroupPrivate()
- : currentAnimation(nullptr), currentAnimationIndex(-1), lastLoop(0)
- { }
-
+ QSequentialAnimationGroupPrivate() : currentAnimationIndex(-1), lastLoop(0) { }
struct AnimationIndex
{
@@ -87,7 +85,10 @@ public:
bool atEnd() const;
- QAbstractAnimation *currentAnimation;
+ Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QSequentialAnimationGroupPrivate, QAbstractAnimation *,
+ currentAnimation,
+ nullptr // initial value
+ )
int currentAnimationIndex;
// this is the actual duration of uncontrolled animations
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"