Port QPauseAnimation to the new property system

Task-number: QTBUG-85520
Change-Id: I8c0ee86598f4c0f093f64b2891ee835a43964b84
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Sona Kurazyan 2020-12-14 11:12:30 +01:00
parent feb20459bd
commit 519420641f
3 changed files with 54 additions and 2 deletions

View File

@ -63,18 +63,22 @@
#include "qpauseanimation.h"
#include "qabstractanimation_p.h"
#include "private/qproperty_p.h"
QT_BEGIN_NAMESPACE
class QPauseAnimationPrivate : public QAbstractAnimationPrivate
{
Q_DECLARE_PUBLIC(QPauseAnimation)
public:
QPauseAnimationPrivate() : QAbstractAnimationPrivate(), duration(250)
{
isPause = true;
}
int duration;
void setDuration(int msecs) { q_func()->setDuration(msecs); }
Q_OBJECT_COMPAT_PROPERTY(QPauseAnimationPrivate, int, duration,
&QPauseAnimationPrivate::setDuration)
};
/*!
@ -128,6 +132,12 @@ void QPauseAnimation::setDuration(int msecs)
d->duration = msecs;
}
QBindable<int> QPauseAnimation::bindableDuration()
{
Q_D(QPauseAnimation);
return &d->duration;
}
/*!
\reimp
*/

View File

@ -51,7 +51,7 @@ class QPauseAnimationPrivate;
class Q_CORE_EXPORT QPauseAnimation : public QAbstractAnimation
{
Q_OBJECT
Q_PROPERTY(int duration READ duration WRITE setDuration)
Q_PROPERTY(int duration READ duration WRITE setDuration BINDABLE bindableDuration)
public:
QPauseAnimation(QObject *parent = nullptr);
QPauseAnimation(int msecs, QObject *parent = nullptr);
@ -59,6 +59,7 @@ public:
int duration() const override;
void setDuration(int msecs);
QBindable<int> bindableDuration();
protected:
bool event(QEvent *e) override;

View File

@ -105,6 +105,7 @@ private slots:
void sequentialGroupWithPause();
void multipleSequentialGroups();
void zeroDuration();
void bindings();
};
void tst_QPauseAnimation::initTestCase()
@ -442,5 +443,45 @@ void tst_QPauseAnimation::zeroDuration()
QCOMPARE(animation.m_updateCurrentTimeCount, 1);
}
void tst_QPauseAnimation::bindings()
{
TestablePauseAnimation animation;
QProperty<int> duration;
animation.bindableDuration().setBinding(Qt::makePropertyBinding(duration));
duration = 42;
QCOMPARE(animation.duration(), 42);
// negative values must be ignored
QTest::ignoreMessage(QtWarningMsg,
"QPauseAnimation::setDuration: cannot set a negative duration");
duration = -1;
QCOMPARE(animation.duration(), 42);
QCOMPARE(duration, -1);
// Setting an invalid value shouldn't clear the binding
QTest::ignoreMessage(QtWarningMsg,
"QPauseAnimation::setDuration: cannot set a negative duration");
animation.setDuration(-1);
QVERIFY(animation.bindableDuration().hasBinding());
QCOMPARE(animation.duration(), 42);
QProperty<int> durationObserver;
durationObserver.setBinding(animation.bindableDuration().makeBinding());
animation.setDuration(46);
QCOMPARE(durationObserver, 46);
// Setting a valid value should clear the binding
QVERIFY(!animation.bindableDuration().hasBinding());
// Setting an invalid value also doesn't affect the observer
QTest::ignoreMessage(QtWarningMsg,
"QPauseAnimation::setDuration: cannot set a negative duration");
animation.setDuration(-1);
QCOMPARE(durationObserver, 46);
}
QTEST_MAIN(tst_QPauseAnimation)
#include "tst_qpauseanimation.moc"