From 2555221bbcb33e0d12e786eb0b3d08bd9260eeb7 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Wed, 12 May 2010 11:51:56 +1000 Subject: Avoid running animation when loopCount == 0 Task-number: QTBUG-10654 Reviewed-by: Thierry Bastian --- src/corelib/animation/qabstractanimation.cpp | 3 +++ .../qpropertyanimation/tst_qpropertyanimation.cpp | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 01570ad..04342e7 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -369,6 +369,9 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) if (state == newState) return; + if (loopCount == 0) + return; + QAbstractAnimation::State oldState = state; int oldCurrentTime = currentTime; int oldCurrentLoop = currentLoop; diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp index 849b8b2..ea527de 100644 --- a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp @@ -133,6 +133,7 @@ private slots: void twoAnimations(); void deletedInUpdateCurrentTime(); void totalDuration(); + void zeroLoopCount(); }; tst_QPropertyAnimation::tst_QPropertyAnimation() @@ -1214,6 +1215,29 @@ void tst_QPropertyAnimation::totalDuration() QCOMPARE(anim.totalDuration(), 0); } +void tst_QPropertyAnimation::zeroLoopCount() +{ + DummyPropertyAnimation* anim; + anim = new DummyPropertyAnimation; + anim->setStartValue(0); + anim->setDuration(20); + anim->setLoopCount(0); + + QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State))); + QSignalSpy finishedSpy(anim, SIGNAL(finished())); + + QCOMPARE(anim->state(), QAnimationGroup::Stopped); + QCOMPARE(anim->currentValue().toInt(), 0); + QCOMPARE(runningSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 0); + + anim->start(); + + QCOMPARE(anim->state(), QAnimationGroup::Stopped); + QCOMPARE(anim->currentValue().toInt(), 0); + QCOMPARE(runningSpy.count(), 0); + QCOMPARE(finishedSpy.count(), 0); +} QTEST_MAIN(tst_QPropertyAnimation) #include "tst_qpropertyanimation.moc" -- cgit v0.12