diff options
Diffstat (limited to 'src/corelib/animation')
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 81 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation_p.h | 14 | ||||
-rw-r--r-- | src/corelib/animation/qanimationgroup.cpp | 6 | ||||
-rw-r--r-- | src/corelib/animation/qanimationgroup_p.h | 4 | ||||
-rw-r--r-- | src/corelib/animation/qparallelanimationgroup.cpp | 2 | ||||
-rw-r--r-- | src/corelib/animation/qparallelanimationgroup_p.h | 2 | ||||
-rw-r--r-- | src/corelib/animation/qpauseanimation.cpp | 7 | ||||
-rw-r--r-- | src/corelib/animation/qpropertyanimation.cpp | 26 | ||||
-rw-r--r-- | src/corelib/animation/qsequentialanimationgroup.cpp | 8 | ||||
-rw-r--r-- | src/corelib/animation/qsequentialanimationgroup_p.h | 4 | ||||
-rw-r--r-- | src/corelib/animation/qvariantanimation.cpp | 31 | ||||
-rw-r--r-- | src/corelib/animation/qvariantanimation.h | 2 |
12 files changed, 103 insertions, 84 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 46ed60d6d1..0f6e263f0e 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -158,7 +158,7 @@ typedef QList<QAbstractAnimation*>::ConstIterator AnimationListConstIt; */ /*! - \fn virtual int QAbstractAnimationTimer::runningAnimationCount() = 0; + \fn virtual qsizetype QAbstractAnimationTimer::runningAnimationCount() = 0; \internal This pure virtual function returns the number of animations the timer is running. @@ -291,11 +291,11 @@ void QUnifiedTimer::updateAnimationTimers() } } -int QUnifiedTimer::runningAnimationCount() +qsizetype QUnifiedTimer::runningAnimationCount() const { - int count = 0; - for (int i = 0; i < animationTimers.size(); ++i) - count += animationTimers.at(i)->runningAnimationCount(); + qsizetype count = 0; + for (const QAbstractAnimationTimer *timer : animationTimers) + count += timer->runningAnimationCount(); return count; } @@ -856,12 +856,15 @@ qint64 QAnimationDriver::elapsed() const QDefaultAnimationDriver::QDefaultAnimationDriver(QUnifiedTimer *timer) : QAnimationDriver(nullptr), m_unified_timer(timer) { - connect(this, SIGNAL(started()), this, SLOT(startTimer())); - connect(this, SIGNAL(stopped()), this, SLOT(stopTimer())); + connect(this, &QAnimationDriver::started, this, &QDefaultAnimationDriver::startTimer); + connect(this, &QAnimationDriver::stopped, this, &QDefaultAnimationDriver::stopTimer); } QDefaultAnimationDriver::~QDefaultAnimationDriver() - = default; +{ + disconnect(this, &QAnimationDriver::started, this, &QDefaultAnimationDriver::startTimer); + disconnect(this, &QAnimationDriver::stopped, this, &QDefaultAnimationDriver::stopTimer); +} void QDefaultAnimationDriver::timerEvent(QTimerEvent *e) { @@ -901,13 +904,13 @@ QAbstractAnimationPrivate::~QAbstractAnimationPrivate() { } void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) { Q_Q(QAbstractAnimation); - if (state == newState) + const QAbstractAnimation::State oldState = state.valueBypassingBindings(); + if (oldState == newState) return; if (loopCount == 0) return; - QAbstractAnimation::State oldState = state; int oldCurrentTime = currentTime; int oldCurrentLoop = currentLoop; QAbstractAnimation::Direction oldDirection = direction; @@ -941,13 +944,15 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) } q->updateState(newState, oldState); - if (!guard || newState != state) //this is to be safe if updateState changes the state + //this is to be safe if updateState changes the state + if (!guard || newState != state.valueBypassingBindings()) return; // Notify state change state.notify(); emit q->stateChanged(newState, oldState); - if (!guard || newState != state) //this is to be safe if updateState changes the state + //this is to be safe if updateState changes the state + if (!guard || newState != state.valueBypassingBindings()) return; switch (state) { @@ -1121,7 +1126,7 @@ void QAbstractAnimation::setDirection(Direction direction) return; } - Qt::beginPropertyUpdateGroup(); + const QScopedPropertyUpdateGroup guard; const int oldCurrentLoop = d->currentLoop; if (state() == Stopped) { if (direction == Backward) { @@ -1148,7 +1153,6 @@ void QAbstractAnimation::setDirection(Direction direction) if (d->currentLoop != oldCurrentLoop) d->currentLoop.notify(); d->direction.notify(); - Qt::endPropertyUpdateGroup(); } QBindable<QAbstractAnimation::Direction> QAbstractAnimation::bindableDirection() @@ -1302,46 +1306,59 @@ void QAbstractAnimation::setCurrentTime(int msecs) msecs = qMax(msecs, 0); // Calculate new time and loop. - int dura = duration(); - int totalDura = dura <= 0 ? dura : ((d->loopCount < 0) ? -1 : dura * d->loopCount); + const int dura = duration(); + const int totalLoopCount = d->loopCount; + const int totalDura = dura <= 0 ? dura : ((totalLoopCount < 0) ? -1 : dura * totalLoopCount); if (totalDura != -1) msecs = qMin(totalDura, msecs); - const int oldCurrentTime = d->totalCurrentTime; - d->totalCurrentTime = msecs; + d->totalCurrentTime.removeBindingUnlessInWrapper(); + + const int oldCurrentTime = d->totalCurrentTime.valueBypassingBindings(); + d->totalCurrentTime.setValueBypassingBindings(msecs); + + QAbstractAnimation::Direction currentDirection = d->direction; // Update new values. - int oldLoop = d->currentLoop; - d->currentLoop = ((dura <= 0) ? 0 : (msecs / dura)); - if (d->currentLoop == d->loopCount) { + const int oldLoop = d->currentLoop.valueBypassingBindings(); + int newCurrentLoop = (dura <= 0) ? 0 : (msecs / dura); + if (newCurrentLoop == totalLoopCount) { //we're at the end d->currentTime = qMax(0, dura); - d->currentLoop = qMax(0, d->loopCount - 1); + newCurrentLoop = qMax(0, totalLoopCount - 1); } else { - if (d->direction == Forward) { + if (currentDirection == Forward) { d->currentTime = (dura <= 0) ? msecs : (msecs % dura); } else { d->currentTime = (dura <= 0) ? msecs : ((msecs - 1) % dura) + 1; if (d->currentTime == dura) - d->currentLoop = d->currentLoop - 1; + newCurrentLoop = newCurrentLoop - 1; } } + d->currentLoop.setValueBypassingBindings(newCurrentLoop); + // this is a virtual function, so it can update the properties as well updateCurrentTime(d->currentTime); - if (d->currentLoop != oldLoop) + + // read the property values again + newCurrentLoop = d->currentLoop.valueBypassingBindings(); + currentDirection = d->direction; + const int newTotalCurrentTime = d->totalCurrentTime.valueBypassingBindings(); + + if (newCurrentLoop != oldLoop) d->currentLoop.notify(); /* Notify before calling stop: As seen in tst_QSequentialAnimationGroup::clear * we might delete the animation when stop is called. Thus after stop no member * of the object must be used anymore. */ - if (oldCurrentTime != d->totalCurrentTime) + if (oldCurrentTime != newTotalCurrentTime) d->totalCurrentTime.notify(); // All animations are responsible for stopping the animation when their // own end state is reached; in this case the animation is time driven, // and has reached the end. - if ((d->direction == Forward && d->totalCurrentTime == totalDura) - || (d->direction == Backward && d->totalCurrentTime == 0)) { + if ((currentDirection == Forward && newTotalCurrentTime == totalDura) + || (currentDirection == Backward && newTotalCurrentTime == 0)) { stop(); } } @@ -1365,7 +1382,7 @@ void QAbstractAnimation::setCurrentTime(int msecs) void QAbstractAnimation::start(DeletionPolicy policy) { Q_D(QAbstractAnimation); - if (d->state == Running) + if (d->state.valueBypassingBindings() == Running) return; d->deleteWhenStopped = policy; d->setState(Running); @@ -1385,7 +1402,7 @@ void QAbstractAnimation::stop() { Q_D(QAbstractAnimation); - if (d->state == Stopped) + if (d->state.valueBypassingBindings() == Stopped) return; d->setState(Stopped); @@ -1401,7 +1418,7 @@ void QAbstractAnimation::stop() void QAbstractAnimation::pause() { Q_D(QAbstractAnimation); - if (d->state == Stopped) { + if (d->state.valueBypassingBindings() == Stopped) { qWarning("QAbstractAnimation::pause: Cannot pause a stopped animation"); return; } @@ -1419,7 +1436,7 @@ void QAbstractAnimation::pause() void QAbstractAnimation::resume() { Q_D(QAbstractAnimation); - if (d->state != Paused) { + if (d->state.valueBypassingBindings() != Paused) { qWarning("QAbstractAnimation::resume: " "Cannot resume an animation that is not paused"); return; diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 5be59543c8..cbe3f6339e 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -17,7 +17,6 @@ #include <QtCore/qbasictimer.h> #include <QtCore/qdatetime.h> -#include <QtCore/qtimer.h> #include <QtCore/qelapsedtimer.h> #include <private/qobject_p.h> #include <private/qproperty_p.h> @@ -29,7 +28,7 @@ QT_BEGIN_NAMESPACE class QAnimationGroup; class QAbstractAnimation; -class QAbstractAnimationPrivate : public QObjectPrivate +class Q_CORE_EXPORT QAbstractAnimationPrivate : public QObjectPrivate { public: QAbstractAnimationPrivate(); @@ -48,7 +47,7 @@ public: { q_func()->setDirection(direction); } - void emitDirectionChanged() { emit q_func()->directionChanged(direction); } + void emitDirectionChanged() { Q_EMIT q_func()->directionChanged(direction); } Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, QAbstractAnimation::Direction, direction, &QAbstractAnimationPrivate::setDirection, &QAbstractAnimationPrivate::emitDirectionChanged, @@ -61,7 +60,7 @@ public: Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, int, loopCount, 1) - void emitCurrentLoopChanged() { emit q_func()->currentLoopChanged(currentLoop); } + void emitCurrentLoopChanged() { Q_EMIT q_func()->currentLoopChanged(currentLoop); } Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QAbstractAnimationPrivate, int, currentLoop, nullptr, &QAbstractAnimationPrivate::emitCurrentLoopChanged, 0) @@ -116,7 +115,8 @@ public: virtual void updateAnimationsTime(qint64 delta) = 0; virtual void restartAnimationTimer() = 0; - virtual int runningAnimationCount() = 0; +#define QT_QAbstractAnimationTimer_runningAnimationCount_IS_CONST + virtual qsizetype runningAnimationCount() const = 0; bool isRegistered = false; bool isPaused = false; @@ -163,7 +163,7 @@ public: void updateAnimationTimers(); //useful for profiling/debugging - int runningAnimationCount(); + qsizetype runningAnimationCount() const; void registerProfilerCallback(void (*cb)(qint64)); void startAnimationDriver(); @@ -247,7 +247,7 @@ public: void updateAnimationsTime(qint64 delta) override; //useful for profiling/debugging - int runningAnimationCount() override { return animations.size(); } + qsizetype runningAnimationCount() const override { return animations.size(); } private Q_SLOTS: void startAnimations(); diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp index e8ffd99dcb..d2572a7462 100644 --- a/src/corelib/animation/qanimationgroup.cpp +++ b/src/corelib/animation/qanimationgroup.cpp @@ -186,7 +186,7 @@ void QAnimationGroup::removeAnimation(QAbstractAnimation *animation) qWarning("QAnimationGroup::remove: cannot remove null animation"); return; } - int index = d->animations.indexOf(animation); + qsizetype index = d->animations.indexOf(animation); if (index == -1) { qWarning("QAnimationGroup::remove: animation is not part of this group"); return; @@ -261,7 +261,7 @@ void QAnimationGroupPrivate::clear(bool onDestruction) const QList<QAbstractAnimation *> animationsCopy = animations; // taking a copy animations.clear(); // Clearing backwards so the indices doesn't change while we remove animations. - for (int i = animationsCopy.size() - 1; i >= 0; --i) { + for (qsizetype i = animationsCopy.size() - 1; i >= 0; --i) { QAbstractAnimation *animation = animationsCopy.at(i); animation->setParent(nullptr); QAbstractAnimationPrivate::get(animation)->group = nullptr; @@ -275,7 +275,7 @@ void QAnimationGroupPrivate::clear(bool onDestruction) } } -void QAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *) +void QAnimationGroupPrivate::animationRemoved(qsizetype index, QAbstractAnimation *) { Q_Q(QAnimationGroup); Q_UNUSED(index); diff --git a/src/corelib/animation/qanimationgroup_p.h b/src/corelib/animation/qanimationgroup_p.h index 8885989e4e..334f780968 100644 --- a/src/corelib/animation/qanimationgroup_p.h +++ b/src/corelib/animation/qanimationgroup_p.h @@ -34,8 +34,8 @@ public: isGroup = true; } - virtual void animationInsertedAt(int) { } - virtual void animationRemoved(int, QAbstractAnimation *); + virtual void animationInsertedAt(qsizetype) { } + virtual void animationRemoved(qsizetype, QAbstractAnimation *); void clear(bool onDestruction); diff --git a/src/corelib/animation/qparallelanimationgroup.cpp b/src/corelib/animation/qparallelanimationgroup.cpp index 58d49bff5d..cea22bcacb 100644 --- a/src/corelib/animation/qparallelanimationgroup.cpp +++ b/src/corelib/animation/qparallelanimationgroup.cpp @@ -255,7 +255,7 @@ bool QParallelAnimationGroupPrivate::isUncontrolledAnimationFinished(QAbstractAn return uncontrolledFinishTime.value(anim, -1) >= 0; } -void QParallelAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *anim) +void QParallelAnimationGroupPrivate::animationRemoved(qsizetype index, QAbstractAnimation *anim) { QAnimationGroupPrivate::animationRemoved(index, anim); disconnectUncontrolledAnimation(anim); diff --git a/src/corelib/animation/qparallelanimationgroup_p.h b/src/corelib/animation/qparallelanimationgroup_p.h index 773c768141..62c53d3609 100644 --- a/src/corelib/animation/qparallelanimationgroup_p.h +++ b/src/corelib/animation/qparallelanimationgroup_p.h @@ -42,7 +42,7 @@ public: void connectUncontrolledAnimations(); void disconnectUncontrolledAnimations(); - void animationRemoved(int index, QAbstractAnimation *) override; + void animationRemoved(qsizetype index, QAbstractAnimation *) override; // private slot void _q_uncontrolledAnimationFinished(); diff --git a/src/corelib/animation/qpauseanimation.cpp b/src/corelib/animation/qpauseanimation.cpp index eb1e6c3c81..344b21946e 100644 --- a/src/corelib/animation/qpauseanimation.cpp +++ b/src/corelib/animation/qpauseanimation.cpp @@ -94,11 +94,10 @@ void QPauseAnimation::setDuration(int msecs) } Q_D(QPauseAnimation); - if (msecs != d->duration) { - d->duration = msecs; + d->duration.removeBindingUnlessInWrapper(); + if (msecs != d->duration.valueBypassingBindings()) { + d->duration.setValueBypassingBindings(msecs); d->duration.notify(); - } else { - d->duration.removeBindingUnlessInWrapper(); } } diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 985371d30f..d461668dbb 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -60,7 +60,8 @@ QT_BEGIN_NAMESPACE void QPropertyAnimationPrivate::updateMetaProperty() { - if (!targetObject || propertyName.value().isEmpty()) { + const QObject *target = targetObject.valueBypassingBindings(); + if (!target || propertyName.value().isEmpty()) { propertyType = QMetaType::UnknownType; propertyIndex = -1; return; @@ -68,19 +69,19 @@ void QPropertyAnimationPrivate::updateMetaProperty() //propertyType will be set to a valid type only if there is a Q_PROPERTY //otherwise it will be set to QVariant::Invalid at the end of this function - propertyType = targetObject->property(propertyName.value()).userType(); - propertyIndex = targetObject->metaObject()->indexOfProperty(propertyName.value()); + propertyType = target->property(propertyName.value()).userType(); + propertyIndex = target->metaObject()->indexOfProperty(propertyName.value()); if (propertyType != QMetaType::UnknownType) convertValues(propertyType); if (propertyIndex == -1) { //there is no Q_PROPERTY on the object propertyType = QMetaType::UnknownType; - if (!targetObject->dynamicPropertyNames().contains(propertyName)) + if (!target->dynamicPropertyNames().contains(propertyName)) qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of " "your QObject", propertyName.value().constData()); - } else if (!targetObject->metaObject()->property(propertyIndex).isWritable()) { + } else if (!target->metaObject()->property(propertyIndex).isWritable()) { qWarning("QPropertyAnimation: you're trying to animate the non-writable property %s of " "your QObject", propertyName.value().constData()); @@ -163,15 +164,16 @@ void QPropertyAnimation::setTargetObject(QObject *target) } d->targetObject.removeBindingUnlessInWrapper(); - if (d->targetObject == target) + const QObject *oldTarget = d->targetObject.valueBypassingBindings(); + if (oldTarget == target) return; - if (d->targetObject != nullptr) - QObject::disconnect(d->targetObject, &QObject::destroyed, this, nullptr); + if (oldTarget != nullptr) + QObject::disconnect(oldTarget, &QObject::destroyed, this, nullptr); d->targetObject.setValueBypassingBindings(target); - if (d->targetObject != nullptr) { - QObject::connect(d->targetObject, &QObject::destroyed, this, + if (target != nullptr) { + QObject::connect(target, &QObject::destroyed, this, [d] { d->targetObjectDestroyed(); }); } d->updateMetaProperty(); @@ -201,7 +203,7 @@ void QPropertyAnimation::setPropertyName(const QByteArray &propertyName) d->propertyName.removeBindingUnlessInWrapper(); - if (d->propertyName == propertyName) + if (d->propertyName.valueBypassingBindings() == propertyName) return; d->propertyName.setValueBypassingBindings(propertyName); @@ -259,7 +261,7 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState, { Q_CONSTINIT static QBasicMutex mutex; auto locker = qt_unique_lock(mutex); - typedef QPair<QObject *, QByteArray> QPropertyAnimationPair; + using QPropertyAnimationPair = std::pair<QObject *, QByteArray>; typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash; Q_CONSTINIT static QPropertyAnimationHash hash; diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp index 8e99d9cee0..260481dbef 100644 --- a/src/corelib/animation/qsequentialanimationgroup.cpp +++ b/src/corelib/animation/qsequentialanimationgroup.cpp @@ -472,7 +472,7 @@ void QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished() the group at index \a index. Note: We only support insertion after the current animation */ -void QSequentialAnimationGroupPrivate::animationInsertedAt(int index) +void QSequentialAnimationGroupPrivate::animationInsertedAt(qsizetype index) { if (currentAnimation == nullptr) { setCurrentAnimation(0); // initialize the current animation @@ -500,7 +500,7 @@ void QSequentialAnimationGroupPrivate::animationInsertedAt(int index) the group at index \a index. The animation is no more listed when this method is called. */ -void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnimation *anim) +void QSequentialAnimationGroupPrivate::animationRemoved(qsizetype index, QAbstractAnimation *anim) { Q_Q(QSequentialAnimationGroup); QAnimationGroupPrivate::animationRemoved(index, anim); @@ -511,7 +511,7 @@ void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnim if (actualDuration.size() > index) actualDuration.removeAt(index); - const int currentIndex = animations.indexOf(currentAnimation); + const qsizetype currentIndex = animations.indexOf(currentAnimation); if (currentIndex == -1) { //we're removing the current animation @@ -529,7 +529,7 @@ void QSequentialAnimationGroupPrivate::animationRemoved(int index, QAbstractAnim // duration of the previous animations up to the current animation currentTime = 0; - for (int i = 0; i < currentAnimationIndex; ++i) { + for (qsizetype i = 0; i < currentAnimationIndex; ++i) { const int current = animationActualTotalDuration(i); currentTime += current; } diff --git a/src/corelib/animation/qsequentialanimationgroup_p.h b/src/corelib/animation/qsequentialanimationgroup_p.h index fc791e0c77..cbdf204d0a 100644 --- a/src/corelib/animation/qsequentialanimationgroup_p.h +++ b/src/corelib/animation/qsequentialanimationgroup_p.h @@ -44,8 +44,8 @@ public: void setCurrentAnimation(int index, bool intermediate = false); void activateCurrentAnimation(bool intermediate = false); - void animationInsertedAt(int index) override; - void animationRemoved(int index, QAbstractAnimation *anim) override; + void animationInsertedAt(qsizetype index) override; + void animationRemoved(qsizetype index, QAbstractAnimation *anim) override; bool atEnd() const; diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index cf84200f2a..b4d47aae8f 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -203,7 +203,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) //let's update currentInterval QVariantAnimation::KeyValues::const_iterator it = std::lower_bound(keyValues.constBegin(), keyValues.constEnd(), - qMakePair(progress, QVariant()), + std::pair{progress, QVariant{}}, animationValueLessThan); if (it == keyValues.constBegin()) { //the item pointed to by it is the start element in the range @@ -211,7 +211,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) currentInterval.start = *it; currentInterval.end = *(it+1); } else { - currentInterval.start = qMakePair(qreal(0), defaultStartEndValue); + currentInterval.start = {qreal(0), defaultStartEndValue}; currentInterval.end = *it; } } else if (it == keyValues.constEnd()) { @@ -223,7 +223,7 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) } else { //we use the default end value here currentInterval.start = *it; - currentInterval.end = qMakePair(qreal(1), defaultStartEndValue); + currentInterval.end = {qreal(1), defaultStartEndValue}; } } else { currentInterval.start = *(it-1); @@ -264,9 +264,10 @@ void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) QVariant QVariantAnimationPrivate::valueAt(qreal step) const { - QVariantAnimation::KeyValues::const_iterator result = - std::lower_bound(keyValues.constBegin(), keyValues.constEnd(), qMakePair(step, QVariant()), animationValueLessThan); - if (result != keyValues.constEnd() && !animationValueLessThan(qMakePair(step, QVariant()), *result)) + const auto sought = std::pair{step, QVariant()}; + const auto result = std::lower_bound(keyValues.cbegin(), keyValues.cend(), sought, + animationValueLessThan); + if (result != keyValues.cend() && !animationValueLessThan(sought, *result)) return result->second; return QVariant(); @@ -353,8 +354,9 @@ QEasingCurve QVariantAnimation::easingCurve() const void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) { Q_D(QVariantAnimation); - const bool valueChanged = easing != d->easing; - d->easing = easing; + d->easing.removeBindingUnlessInWrapper(); + const bool valueChanged = easing != d->easing.valueBypassingBindings(); + d->easing.setValueBypassingBindings(easing); d->recalculateCurrentInterval(); if (valueChanged) d->easing.notify(); @@ -482,13 +484,12 @@ void QVariantAnimation::setDuration(int msecs) qWarning("QVariantAnimation::setDuration: cannot set a negative duration"); return; } - if (d->duration == msecs) { - d->duration.removeBindingUnlessInWrapper(); - return; + d->duration.removeBindingUnlessInWrapper(); + if (d->duration.valueBypassingBindings() != msecs) { + d->duration.setValueBypassingBindings(msecs); + d->recalculateCurrentInterval(); + d->duration.notify(); } - d->duration = msecs; - d->recalculateCurrentInterval(); - d->duration.notify(); } QBindable<int> QVariantAnimation::bindableDuration() @@ -552,7 +553,7 @@ QVariant QVariantAnimation::keyValueAt(qreal step) const /*! \typedef QVariantAnimation::KeyValue - This is a typedef for QPair<qreal, QVariant>. + This is a typedef for std::pair<qreal, QVariant>. */ /*! \typedef QVariantAnimation::KeyValues diff --git a/src/corelib/animation/qvariantanimation.h b/src/corelib/animation/qvariantanimation.h index 640c057ef8..4bdb971357 100644 --- a/src/corelib/animation/qvariantanimation.h +++ b/src/corelib/animation/qvariantanimation.h @@ -26,7 +26,7 @@ class Q_CORE_EXPORT QVariantAnimation : public QAbstractAnimation BINDABLE bindableEasingCurve) public: - typedef QPair<qreal, QVariant> KeyValue; + using KeyValue = std::pair<qreal, QVariant>; typedef QList<KeyValue> KeyValues; QVariantAnimation(QObject *parent = nullptr); |