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 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> (cherry picked from commit 7ac5927e5046cf9e024f822822fe0a53396c52e5)
This commit is contained in:
parent
b027e03fed
commit
b4ce1a9c01
@ -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) {
|
||||
@ -1378,7 +1380,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);
|
||||
@ -1398,7 +1400,7 @@ void QAbstractAnimation::stop()
|
||||
{
|
||||
Q_D(QAbstractAnimation);
|
||||
|
||||
if (d->state == Stopped)
|
||||
if (d->state.valueBypassingBindings() == Stopped)
|
||||
return;
|
||||
|
||||
d->setState(Stopped);
|
||||
@ -1414,7 +1416,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;
|
||||
}
|
||||
@ -1432,7 +1434,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user