From 4f07fd724a7cc763d57f4b2e23d407b820bb8880 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Fri, 15 May 2009 12:40:00 +0200 Subject: Update current value on QVariantAnimation::setKeyValues The current value was udpated on setKeyValueAt, but not on setKeyValues and this was leading to a semantic inconsistency. Reviewed-by: janarve --- src/corelib/animation/qvariantanimation.cpp | 1 + .../qpropertyanimation/tst_qpropertyanimation.cpp | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index fbce917..cad9341 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -550,6 +550,7 @@ void QVariantAnimation::setKeyValues(const KeyValues &keyValues) d->keyValues = keyValues; qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan); d->currentInterval.start.first = 2; // this will force the refresh + d->updateCurrentValue(); d->hasStartValue = !d->keyValues.isEmpty() && d->keyValues.at(0).first == 0; } diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp index c753477..7e910d4 100644 --- a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp @@ -42,6 +42,7 @@ #include #include +#include #include //TESTED_CLASS=QPropertyAnimation @@ -96,6 +97,7 @@ private slots: void operationsInStates_data(); void operationsInStates(); void oneKeyValue(); + void updateOnSetKeyValues(); }; tst_QPropertyAnimation::tst_QPropertyAnimation() @@ -881,5 +883,37 @@ void tst_QPropertyAnimation::oneKeyValue() QCOMPARE(o.property("ole").toInt(), 42); } +void tst_QPropertyAnimation::updateOnSetKeyValues() +{ + QObject o; + o.setProperty("ole", 100); + QCOMPARE(o.property("ole").toInt(), 100); + + QPropertyAnimation animation(&o, "ole"); + animation.setStartValue(100); + animation.setEndValue(200); + animation.setDuration(100); + + animation.setCurrentTime(50); + QCOMPARE(animation.currentValue().toInt(), 150); + animation.setKeyValueAt(0.0, 300); + QCOMPARE(animation.currentValue().toInt(), 250); + + o.setProperty("ole", 100); + QPropertyAnimation animation2(&o, "ole"); + QVariantAnimation::KeyValues kValues; + kValues << QVariantAnimation::KeyValue(0.0, 100) << QVariantAnimation::KeyValue(1.0, 200); + animation2.setKeyValues(kValues); + animation2.setDuration(100); + animation2.setCurrentTime(50); + QCOMPARE(animation2.currentValue().toInt(), 150); + + kValues.clear(); + kValues << QVariantAnimation::KeyValue(0.0, 300) << QVariantAnimation::KeyValue(1.0, 200); + animation2.setKeyValues(kValues); + + QCOMPARE(animation2.currentValue().toInt(), animation.currentValue().toInt()); +} + QTEST_MAIN(tst_QPropertyAnimation) #include "tst_qpropertyanimation.moc" -- cgit v0.12