QAbstractAnimation: avoid spurious dependencies on the state property

The state property is read-only, meaning that it can only be modified
from the class internals. At the same time, the public start(), stop(),
pause(), and resume() methods, as well as a private setState() method
can be called from other property setters, thus creating an unwanted
dependency on state.

Fix it by using valueBypassingBindings() when reading the state.

Task-number: QTBUG-116346
Pick-to: 6.5
Change-Id: I404cd2141ea52b8ffed5edbb4261a535cd329ec2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit ab9f5a9a0b13c33e103d159a40869a69a9583899)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2023-08-30 16:00:40 +02:00 committed by Qt Cherry-pick Bot
parent 08dd6dce63
commit 7ac5927e50

View File

@ -901,13 +901,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 +941,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) {
@ -1377,7 +1379,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);
@ -1397,7 +1399,7 @@ void QAbstractAnimation::stop()
{
Q_D(QAbstractAnimation);
if (d->state == Stopped)
if (d->state.valueBypassingBindings() == Stopped)
return;
d->setState(Stopped);
@ -1413,7 +1415,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;
}
@ -1431,7 +1433,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;