summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp89
-rw-r--r--src/corelib/animation/qabstractanimation_p.h14
-rw-r--r--src/corelib/animation/qanimationgroup.cpp8
-rw-r--r--src/corelib/animation/qanimationgroup_p.h4
-rw-r--r--src/corelib/animation/qparallelanimationgroup.cpp2
-rw-r--r--src/corelib/animation/qparallelanimationgroup_p.h2
-rw-r--r--src/corelib/animation/qpauseanimation.cpp7
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp30
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.cpp14
-rw-r--r--src/corelib/animation/qsequentialanimationgroup_p.h4
-rw-r--r--src/corelib/animation/qvariantanimation.cpp43
-rw-r--r--src/corelib/animation/qvariantanimation.h2
12 files changed, 121 insertions, 98 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index d57ce4ef5f..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.
@@ -283,7 +283,7 @@ void QUnifiedTimer::updateAnimationTimers()
QScopedValueRollback<bool> guard(insideTick, true);
if (profilerCallback)
profilerCallback(delta);
- for (currentAnimationIdx = 0; currentAnimationIdx < animationTimers.count(); ++currentAnimationIdx) {
+ for (currentAnimationIdx = 0; currentAnimationIdx < animationTimers.size(); ++currentAnimationIdx) {
QAbstractAnimationTimer *animation = animationTimers.at(currentAnimationIdx);
animation->updateAnimationsTime(delta);
}
@@ -291,11 +291,11 @@ void QUnifiedTimer::updateAnimationTimers()
}
}
-int QUnifiedTimer::runningAnimationCount()
+qsizetype QUnifiedTimer::runningAnimationCount() const
{
- int count = 0;
- for (int i = 0; i < animationTimers.count(); ++i)
- count += animationTimers.at(i)->runningAnimationCount();
+ qsizetype count = 0;
+ for (const QAbstractAnimationTimer *timer : animationTimers)
+ count += timer->runningAnimationCount();
return count;
}
@@ -309,7 +309,7 @@ void QUnifiedTimer::localRestart()
if (insideRestart)
return;
- if (!pausedAnimationTimers.isEmpty() && (animationTimers.count() + animationTimersToStart.count() == pausedAnimationTimers.count())) {
+ if (!pausedAnimationTimers.isEmpty() && (animationTimers.size() + animationTimersToStart.size() == pausedAnimationTimers.size())) {
driver->stop();
int closestTimeToFinish = closestPausedAnimationTimerTimeToFinish();
// use a precise timer if the pause will be short
@@ -327,7 +327,7 @@ void QUnifiedTimer::restart()
{
{
QScopedValueRollback<bool> guard(insideRestart, true);
- for (int i = 0; i < animationTimers.count(); ++i)
+ for (int i = 0; i < animationTimers.size(); ++i)
animationTimers.at(i)->restartAnimationTimer();
}
@@ -568,7 +568,7 @@ void QAnimationTimer::updateAnimationsTime(qint64 delta)
//when the CPU load is high
if (delta) {
QScopedValueRollback<bool> guard(insideTick, true);
- for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) {
+ for (currentAnimationIdx = 0; currentAnimationIdx < animations.size(); ++currentAnimationIdx) {
QAbstractAnimation *animation = animations.at(currentAnimationIdx);
int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime
+ (animation->direction() == QAbstractAnimation::Forward ? delta : -delta);
@@ -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 2b08ef7756..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.count(); }
+ 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 5502942302..d2572a7462 100644
--- a/src/corelib/animation/qanimationgroup.cpp
+++ b/src/corelib/animation/qanimationgroup.cpp
@@ -138,7 +138,7 @@ int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
void QAnimationGroup::addAnimation(QAbstractAnimation *animation)
{
Q_D(QAnimationGroup);
- insertAnimation(d->animations.count(), animation);
+ insertAnimation(d->animations.size(), animation);
}
/*!
@@ -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.count() - 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 109358b389..d461668dbb 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -22,6 +22,10 @@
\snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \note You can also control an animation's lifespan by choosing a
+ \l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting the
+ animation.
+
The property name and the QObject instance of which property
should be animated are passed to the constructor. You can then
specify the start and end value of the property. The procedure is
@@ -56,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;
@@ -64,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());
@@ -159,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();
@@ -197,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);
@@ -255,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 25d6d1de37..260481dbef 100644
--- a/src/corelib/animation/qsequentialanimationgroup.cpp
+++ b/src/corelib/animation/qsequentialanimationgroup.cpp
@@ -172,7 +172,7 @@ void QSequentialAnimationGroupPrivate::rewindForwards(const AnimationIndex &newA
// we need to force activation because setCurrentAnimation will have no effect
activateCurrentAnimation();
else
- setCurrentAnimation(animations.count() - 1, true);
+ setCurrentAnimation(animations.size() - 1, true);
}
// and now we need to fast rewind from the current position to
@@ -396,7 +396,7 @@ void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool inter
// currentAnimation.removeBindingUnlessInWrapper()
// is not necessary here, since it is read only
- index = qMin(index, animations.count() - 1);
+ index = qMin(index, animations.size() - 1);
if (index == -1) {
Q_ASSERT(animations.isEmpty());
@@ -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,13 +511,13 @@ 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
disconnectUncontrolledAnimation(currentAnimation);
- if (index < animations.count())
+ if (index < animations.size())
setCurrentAnimation(index); //let's try to take the next one
else if (index > 0)
setCurrentAnimation(index - 1);
@@ -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 cd9a01a138..b4d47aae8f 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -156,7 +156,7 @@ void QVariantAnimationPrivate::convertValues(int t)
{
auto type = QMetaType(t);
//this ensures that all the keyValues are of type t
- for (int i = 0; i < keyValues.count(); ++i) {
+ for (int i = 0; i < keyValues.size(); ++i) {
QVariantAnimation::KeyValue &pair = keyValues[i];
pair.second.convert(type);
}
@@ -190,7 +190,7 @@ void QVariantAnimationPrivate::updateInterpolator()
void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
{
// can't interpolate if we don't have at least 2 values
- if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
+ if ((keyValues.size() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
return;
const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
@@ -203,27 +203,27 @@ 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
- if (it->first == 0 && keyValues.count() > 1) {
+ if (it->first == 0 && keyValues.size() > 1) {
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()) {
--it; //position the iterator on the last item
- if (it->first == 1 && keyValues.count() > 1) {
+ if (it->first == 1 && keyValues.size() > 1) {
//we have an end value (item with progress = 1)
currentInterval.start = *(it-1);
currentInterval.end = *it;
} 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();
@@ -405,7 +407,7 @@ void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator fun
// to continue causes the app to crash on exit with a SEGV
if (interpolators) {
const auto locker = qt_scoped_lock(registeredInterpolatorsMutex);
- if (interpolationType >= interpolators->count())
+ if (interpolationType >= interpolators->size())
interpolators->resize(interpolationType + 1);
interpolators->replace(interpolationType, func);
}
@@ -423,7 +425,7 @@ QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int in
QInterpolatorVector *interpolators = registeredInterpolators();
const auto locker = qt_scoped_lock(registeredInterpolatorsMutex);
QVariantAnimation::Interpolator ret = nullptr;
- if (interpolationType < interpolators->count()) {
+ if (interpolationType < interpolators->size()) {
ret = interpolators->at(interpolationType);
if (ret) return ret;
}
@@ -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);