diff options
author | Kevin Krammer <kevin.krammer@kdab.com> | 2017-09-15 12:43:58 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-12-16 19:11:56 +0000 |
commit | af128db8ebb0ecfb97827415a0a4de0c5fac7869 (patch) | |
tree | f86995c820072643db82871c7bf40d195c8ba97a | |
parent | 8f22b51d442132e0374cd8a749962bb7075a61d4 (diff) |
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>
-rw-r--r-- | src/quick/util/qquickanimation.cpp | 4 | ||||
-rw-r--r-- | src/quick/util/qquickanimation_p.h | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquickanimations/tst_qquickanimations.cpp | 27 |
3 files changed, 37 insertions, 10 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index bfac46adb9..76b9b8f343 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -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(); } /*! diff --git a/src/quick/util/qquickanimation_p.h b/src/quick/util/qquickanimation_p.h index e27871dcaa..5edbcc089a 100644 --- a/src/quick/util/qquickanimation_p.h +++ b/src/quick/util/qquickanimation_p.h @@ -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: diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 4a7a77416a..d28d065d17 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -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() |