Add NOTIFY signals for QtQuick Animation classes to/from properties

Task-number: QTBUG-63178
Change-Id: Id3cd21625c17a3febba759e6895cb92db6ba314f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Kevin Krammer 2017-09-15 12:43:58 +02:00 committed by Shawn Rutledge
parent 8f22b51d44
commit af128db8eb
3 changed files with 37 additions and 10 deletions

View File

@ -2112,7 +2112,7 @@ void QQuickPropertyAnimation::setFrom(const QVariant &f)
return;
d->from = f;
d->fromIsDefined = f.isValid();
emit fromChanged(f);
emit fromChanged();
}
/*!
@ -2139,7 +2139,7 @@ void QQuickPropertyAnimation::setTo(const QVariant &t)
return;
d->to = t;
d->toIsDefined = t.isValid();
emit toChanged(t);
emit toChanged();
}
/*!

View File

@ -309,8 +309,8 @@ protected:
QObject *defaultTarget = 0) override;
Q_SIGNALS:
void durationChanged(int);
void fromChanged(const QVariant &);
void toChanged(const QVariant &);
void fromChanged();
void toChanged();
void easingChanged(const QEasingCurve &);
void propertiesChanged(const QString &);
void targetChanged();
@ -340,8 +340,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickNumberAnimation : public QQuickPropertyAnimat
Q_OBJECT
Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
Q_PROPERTY(qreal from READ from WRITE setFrom)
Q_PROPERTY(qreal to READ to WRITE setTo)
Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
public:
QQuickNumberAnimation(QObject *parent=0);
@ -365,8 +365,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickVector3dAnimation : public QQuickPropertyAnim
Q_OBJECT
Q_DECLARE_PRIVATE(QQuickPropertyAnimation)
Q_PROPERTY(QVector3D from READ from WRITE setFrom)
Q_PROPERTY(QVector3D to READ to WRITE setTo)
Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged)
Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged)
public:
QQuickVector3dAnimation(QObject *parent=0);
@ -385,8 +385,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimation : public QQuickPropertyAnim
Q_OBJECT
Q_DECLARE_PRIVATE(QQuickRotationAnimation)
Q_PROPERTY(qreal from READ from WRITE setFrom)
Q_PROPERTY(qreal to READ to WRITE setTo)
Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
public:

View File

@ -120,12 +120,16 @@ void tst_qquickanimations::simpleProperty()
{
QQuickRectangle rect;
QQuickPropertyAnimation animation;
QSignalSpy fromChangedSpy(&animation, &QQuickPropertyAnimation::fromChanged);
QSignalSpy toChangedSpy(&animation, &QQuickPropertyAnimation::toChanged);
animation.setTargetObject(&rect);
animation.setProperty("x");
animation.setTo(200);
QCOMPARE(animation.target(), &rect);
QCOMPARE(animation.property(), QLatin1String("x"));
QCOMPARE(animation.to().toReal(), 200.0);
QCOMPARE(fromChangedSpy.count(), 0);
QCOMPARE(toChangedSpy.count(), 1);
animation.start();
QVERIFY(animation.isRunning());
QTest::qWait(animation.duration());
@ -139,18 +143,25 @@ void tst_qquickanimations::simpleProperty()
animation.setCurrentTime(125);
QCOMPARE(animation.currentTime(), 125);
QCOMPARE(rect.x(),100.0);
animation.setFrom(100);
QCOMPARE(fromChangedSpy.count(), 1);
QCOMPARE(toChangedSpy.count(), 1);
}
void tst_qquickanimations::simpleNumber()
{
QQuickRectangle rect;
QQuickNumberAnimation animation;
QSignalSpy fromChangedSpy(&animation, &QQuickNumberAnimation::fromChanged);
QSignalSpy toChangedSpy(&animation, &QQuickNumberAnimation::toChanged);
animation.setTargetObject(&rect);
animation.setProperty("x");
animation.setTo(200);
QCOMPARE(animation.target(), &rect);
QCOMPARE(animation.property(), QLatin1String("x"));
QCOMPARE(animation.to(), qreal(200));
QCOMPARE(fromChangedSpy.count(), 0);
QCOMPARE(toChangedSpy.count(), 1);
animation.start();
QVERIFY(animation.isRunning());
QTest::qWait(animation.duration());
@ -164,18 +175,25 @@ void tst_qquickanimations::simpleNumber()
animation.setCurrentTime(125);
QCOMPARE(animation.currentTime(), 125);
QCOMPARE(rect.x(), qreal(100));
animation.setFrom(100);
QCOMPARE(fromChangedSpy.count(), 1);
QCOMPARE(toChangedSpy.count(), 1);
}
void tst_qquickanimations::simpleColor()
{
QQuickRectangle rect;
QQuickColorAnimation animation;
QSignalSpy fromChangedSpy(&animation, &QQuickColorAnimation::fromChanged);
QSignalSpy toChangedSpy(&animation, &QQuickColorAnimation::toChanged);
animation.setTargetObject(&rect);
animation.setProperty("color");
animation.setTo(QColor("red"));
QCOMPARE(animation.target(), &rect);
QCOMPARE(animation.property(), QLatin1String("color"));
QCOMPARE(animation.to(), QColor("red"));
QCOMPARE(fromChangedSpy.count(), 0);
QCOMPARE(toChangedSpy.count(), 1);
animation.start();
QVERIFY(animation.isRunning());
QTest::qWait(animation.duration());
@ -193,6 +211,8 @@ void tst_qquickanimations::simpleColor()
rect.setColor(QColor("green"));
animation.setFrom(QColor("blue"));
QCOMPARE(animation.from(), QColor("blue"));
QCOMPARE(fromChangedSpy.count(), 1);
QCOMPARE(toChangedSpy.count(), 1);
animation.restart();
QCOMPARE(rect.color(), QColor("blue"));
QVERIFY(animation.isRunning());
@ -204,6 +224,8 @@ void tst_qquickanimations::simpleRotation()
{
QQuickRectangle rect;
QQuickRotationAnimation animation;
QSignalSpy fromChangedSpy(&animation, &QQuickRotationAnimation::fromChanged);
QSignalSpy toChangedSpy(&animation, &QQuickRotationAnimation::toChanged);
animation.setTargetObject(&rect);
animation.setProperty("rotation");
animation.setTo(270);
@ -211,6 +233,8 @@ void tst_qquickanimations::simpleRotation()
QCOMPARE(animation.property(), QLatin1String("rotation"));
QCOMPARE(animation.to(), qreal(270));
QCOMPARE(animation.direction(), QQuickRotationAnimation::Numerical);
QCOMPARE(fromChangedSpy.count(), 0);
QCOMPARE(toChangedSpy.count(), 1);
animation.start();
QVERIFY(animation.isRunning());
QTest::qWait(animation.duration());
@ -224,6 +248,9 @@ void tst_qquickanimations::simpleRotation()
animation.setCurrentTime(125);
QCOMPARE(animation.currentTime(), 125);
QCOMPARE(rect.rotation(), qreal(135));
animation.setFrom(90);
QCOMPARE(fromChangedSpy.count(), 1);
QCOMPARE(toChangedSpy.count(), 1);
}
void tst_qquickanimations::simplePath()