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)
|
void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
|
||||||
{
|
{
|
||||||
Q_Q(QAbstractAnimation);
|
Q_Q(QAbstractAnimation);
|
||||||
if (state == newState)
|
const QAbstractAnimation::State oldState = state.valueBypassingBindings();
|
||||||
|
if (oldState == newState)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (loopCount == 0)
|
if (loopCount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QAbstractAnimation::State oldState = state;
|
|
||||||
int oldCurrentTime = currentTime;
|
int oldCurrentTime = currentTime;
|
||||||
int oldCurrentLoop = currentLoop;
|
int oldCurrentLoop = currentLoop;
|
||||||
QAbstractAnimation::Direction oldDirection = direction;
|
QAbstractAnimation::Direction oldDirection = direction;
|
||||||
@ -941,13 +941,15 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
q->updateState(newState, oldState);
|
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;
|
return;
|
||||||
|
|
||||||
// Notify state change
|
// Notify state change
|
||||||
state.notify();
|
state.notify();
|
||||||
emit q->stateChanged(newState, oldState);
|
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;
|
return;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -1378,7 +1380,7 @@ void QAbstractAnimation::setCurrentTime(int msecs)
|
|||||||
void QAbstractAnimation::start(DeletionPolicy policy)
|
void QAbstractAnimation::start(DeletionPolicy policy)
|
||||||
{
|
{
|
||||||
Q_D(QAbstractAnimation);
|
Q_D(QAbstractAnimation);
|
||||||
if (d->state == Running)
|
if (d->state.valueBypassingBindings() == Running)
|
||||||
return;
|
return;
|
||||||
d->deleteWhenStopped = policy;
|
d->deleteWhenStopped = policy;
|
||||||
d->setState(Running);
|
d->setState(Running);
|
||||||
@ -1398,7 +1400,7 @@ void QAbstractAnimation::stop()
|
|||||||
{
|
{
|
||||||
Q_D(QAbstractAnimation);
|
Q_D(QAbstractAnimation);
|
||||||
|
|
||||||
if (d->state == Stopped)
|
if (d->state.valueBypassingBindings() == Stopped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->setState(Stopped);
|
d->setState(Stopped);
|
||||||
@ -1414,7 +1416,7 @@ void QAbstractAnimation::stop()
|
|||||||
void QAbstractAnimation::pause()
|
void QAbstractAnimation::pause()
|
||||||
{
|
{
|
||||||
Q_D(QAbstractAnimation);
|
Q_D(QAbstractAnimation);
|
||||||
if (d->state == Stopped) {
|
if (d->state.valueBypassingBindings() == Stopped) {
|
||||||
qWarning("QAbstractAnimation::pause: Cannot pause a stopped animation");
|
qWarning("QAbstractAnimation::pause: Cannot pause a stopped animation");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1432,7 +1434,7 @@ void QAbstractAnimation::pause()
|
|||||||
void QAbstractAnimation::resume()
|
void QAbstractAnimation::resume()
|
||||||
{
|
{
|
||||||
Q_D(QAbstractAnimation);
|
Q_D(QAbstractAnimation);
|
||||||
if (d->state != Paused) {
|
if (d->state.valueBypassingBindings() != Paused) {
|
||||||
qWarning("QAbstractAnimation::resume: "
|
qWarning("QAbstractAnimation::resume: "
|
||||||
"Cannot resume an animation that is not paused");
|
"Cannot resume an animation that is not paused");
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user