diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-05-14 15:52:09 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-05-15 11:58:56 (GMT) |
commit | 9227f6249de0e60a2a428549848c875c01dbf4d2 (patch) | |
tree | 4554e33278d1bd2f2476115b27d70376deed5121 /src/corelib/animation/qvariantanimation.cpp | |
parent | 92ff29b161709f4503d628e468c0eec1daf5835a (diff) | |
download | Qt-9227f6249de0e60a2a428549848c875c01dbf4d2.zip Qt-9227f6249de0e60a2a428549848c875c01dbf4d2.tar.gz Qt-9227f6249de0e60a2a428549848c875c01dbf4d2.tar.bz2 |
Avoid interpolating if we have less than 2 key values in QVariantAnimation
If we have less than 2 key values, we should neither try to interpolate
nor set the current value.
Reviewed-by: janarve
Diffstat (limited to 'src/corelib/animation/qvariantanimation.cpp')
-rw-r--r-- | src/corelib/animation/qvariantanimation.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index 58f0e03..fbce917 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -186,12 +186,20 @@ void QVariantAnimationPrivate::convertValues(int t) void QVariantAnimationPrivate::updateCurrentValue() { + // can't interpolate if we have only 1 key value + if (keyValues.count() <= 1) + return; + Q_Q(QVariantAnimation); + const qreal progress = easing.valueForProgress(((duration == 0) ? qreal(1) : qreal(currentTime) / qreal(duration))); if (progress < currentInterval.start.first || progress > currentInterval.end.first) { //let's update currentInterval - QVariantAnimation::KeyValues::const_iterator itStart = qLowerBound(keyValues.constBegin(), keyValues.constEnd(), qMakePair(progress, QVariant()), animationValueLessThan); + QVariantAnimation::KeyValues::const_iterator itStart = qLowerBound(keyValues.constBegin(), + keyValues.constEnd(), + qMakePair(progress, QVariant()), + animationValueLessThan); QVariantAnimation::KeyValues::const_iterator itEnd = itStart; // If we are at the end we should continue to use the last keyValues in case of extrapolation (progress > 1.0). @@ -199,10 +207,8 @@ void QVariantAnimationPrivate::updateCurrentValue() if (itStart != keyValues.constEnd()) { //this can't happen because we always prepend the default start value there - if (itStart == keyValues.begin()) { + if (itStart == keyValues.constBegin()) { ++itEnd; - if (itEnd == keyValues.constEnd()) - return; //there is no upper bound } else { --itStart; } |