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>
This commit is contained in:
parent
97a8727f0e
commit
7b6cef0e65
@ -301,6 +301,11 @@ QAbstractAnimation *QSequentialAnimationGroup::currentAnimation() const
|
|||||||
return d->currentAnimation;
|
return d->currentAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QBindable<QAbstractAnimation *> QSequentialAnimationGroup::bindableCurrentAnimation() const
|
||||||
|
{
|
||||||
|
return &d_func()->currentAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@ -424,6 +429,8 @@ bool QSequentialAnimationGroup::event(QEvent *event)
|
|||||||
void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool intermediate)
|
void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool intermediate)
|
||||||
{
|
{
|
||||||
Q_Q(QSequentialAnimationGroup);
|
Q_Q(QSequentialAnimationGroup);
|
||||||
|
// currentAnimation.removeBindingUnlessInWrapper()
|
||||||
|
// is not necessary here, since it is read only
|
||||||
|
|
||||||
index = qMin(index, animations.count() - 1);
|
index = qMin(index, animations.count() - 1);
|
||||||
|
|
||||||
@ -443,8 +450,8 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter
|
|||||||
if (currentAnimation)
|
if (currentAnimation)
|
||||||
currentAnimation->stop();
|
currentAnimation->stop();
|
||||||
|
|
||||||
currentAnimation = animations.at(index);
|
|
||||||
currentAnimationIndex = index;
|
currentAnimationIndex = index;
|
||||||
|
currentAnimation = animations.at(index);
|
||||||
|
|
||||||
emit q->currentAnimationChanged(currentAnimation);
|
emit q->currentAnimationChanged(currentAnimation);
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@ class QSequentialAnimationGroupPrivate;
|
|||||||
class Q_CORE_EXPORT QSequentialAnimationGroup : public QAnimationGroup
|
class Q_CORE_EXPORT QSequentialAnimationGroup : public QAnimationGroup
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QAbstractAnimation* currentAnimation READ currentAnimation NOTIFY currentAnimationChanged)
|
Q_PROPERTY(QAbstractAnimation *currentAnimation READ currentAnimation NOTIFY
|
||||||
|
currentAnimationChanged BINDABLE bindableCurrentAnimation)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSequentialAnimationGroup(QObject *parent = nullptr);
|
QSequentialAnimationGroup(QObject *parent = nullptr);
|
||||||
@ -62,10 +63,11 @@ public:
|
|||||||
QPauseAnimation *insertPause(int index, int msecs);
|
QPauseAnimation *insertPause(int index, int msecs);
|
||||||
|
|
||||||
QAbstractAnimation *currentAnimation() const;
|
QAbstractAnimation *currentAnimation() const;
|
||||||
|
QBindable<QAbstractAnimation *> bindableCurrentAnimation() const;
|
||||||
int duration() const override;
|
int duration() const override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void currentAnimationChanged(QAbstractAnimation *current);
|
void currentAnimationChanged(QAbstractAnimation *current) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, QObject *parent);
|
QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, QObject *parent);
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#include "qsequentialanimationgroup.h"
|
#include "qsequentialanimationgroup.h"
|
||||||
#include "private/qanimationgroup_p.h"
|
#include "private/qanimationgroup_p.h"
|
||||||
|
#include "private/qproperty_p.h"
|
||||||
|
|
||||||
QT_REQUIRE_CONFIG(animation);
|
QT_REQUIRE_CONFIG(animation);
|
||||||
|
|
||||||
@ -62,10 +63,7 @@ class QSequentialAnimationGroupPrivate : public QAnimationGroupPrivate
|
|||||||
{
|
{
|
||||||
Q_DECLARE_PUBLIC(QSequentialAnimationGroup)
|
Q_DECLARE_PUBLIC(QSequentialAnimationGroup)
|
||||||
public:
|
public:
|
||||||
QSequentialAnimationGroupPrivate()
|
QSequentialAnimationGroupPrivate() : currentAnimationIndex(-1), lastLoop(0) { }
|
||||||
: currentAnimation(nullptr), currentAnimationIndex(-1), lastLoop(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
struct AnimationIndex
|
struct AnimationIndex
|
||||||
{
|
{
|
||||||
@ -87,7 +85,10 @@ public:
|
|||||||
|
|
||||||
bool atEnd() const;
|
bool atEnd() const;
|
||||||
|
|
||||||
QAbstractAnimation *currentAnimation;
|
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QSequentialAnimationGroupPrivate, QAbstractAnimation *,
|
||||||
|
currentAnimation,
|
||||||
|
nullptr // initial value
|
||||||
|
)
|
||||||
int currentAnimationIndex;
|
int currentAnimationIndex;
|
||||||
|
|
||||||
// this is the actual duration of uncontrolled animations
|
// this is the actual duration of uncontrolled animations
|
||||||
|
@ -71,6 +71,7 @@ private slots:
|
|||||||
void insertAnimation();
|
void insertAnimation();
|
||||||
void clear();
|
void clear();
|
||||||
void pauseResume();
|
void pauseResume();
|
||||||
|
void bindings();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QSequentialAnimationGroup::initTestCase()
|
void tst_QSequentialAnimationGroup::initTestCase()
|
||||||
@ -1667,5 +1668,48 @@ void tst_QSequentialAnimationGroup::pauseResume()
|
|||||||
QCOMPARE(spy.count(), 1);
|
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)
|
QTEST_MAIN(tst_QSequentialAnimationGroup)
|
||||||
#include "tst_qsequentialanimationgroup.moc"
|
#include "tst_qsequentialanimationgroup.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user