statemachine: Purge restorable properties when they are restored
Previously, a registered restorable property would only be unregistered if the property was animated (see QStateMachinePrivate::_q_animationFinished()). But if a property is set directly, it should also be unregistered; otherwise, the state machine would use the previously saved (stale) value the next time that property should be restored. Change-Id: I5d246aa5355ddd0ba5f81b0186a9f0e4f3bbaa3f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>bb10
parent
bc5a4d28af
commit
2f18e72762
|
|
@ -841,6 +841,8 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr
|
|||
for (int i = 0; i < assignments.size(); ++i) {
|
||||
const QPropertyAssignment &assn = assignments.at(i);
|
||||
assn.write();
|
||||
if (!assn.explicitlySet)
|
||||
unregisterRestorable(assn.object, assn.propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ private slots:
|
|||
void deletePropertyAssignmentObjectBeforeEntry();
|
||||
void deletePropertyAssignmentObjectBeforeRestore();
|
||||
void deleteInitialState();
|
||||
void setPropertyAfterRestore();
|
||||
};
|
||||
|
||||
class TestState : public QState
|
||||
|
|
@ -4086,5 +4087,50 @@ void tst_QStateMachine::deleteInitialState()
|
|||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
void tst_QStateMachine::setPropertyAfterRestore()
|
||||
{
|
||||
QStateMachine machine;
|
||||
machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
|
||||
|
||||
QObject *object = new QObject(&machine);
|
||||
object->setProperty("a", 1);
|
||||
|
||||
QState *s1 = new QState(&machine);
|
||||
machine.setInitialState(s1);
|
||||
s1->assignProperty(object, "a", 2);
|
||||
|
||||
QState *s2 = new QState(&machine);
|
||||
s1->addTransition(new EventTransition(QEvent::User, s2));
|
||||
|
||||
QState *s3 = new QState(&machine);
|
||||
s3->assignProperty(object, "a", 4);
|
||||
s2->addTransition(new EventTransition(QEvent::User, s3));
|
||||
|
||||
QState *s4 = new QState(&machine);
|
||||
s3->addTransition(new EventTransition(QEvent::User, s4));
|
||||
|
||||
machine.start();
|
||||
QTRY_VERIFY(machine.configuration().contains(s1));
|
||||
QCOMPARE(object->property("a").toInt(), 2);
|
||||
|
||||
machine.postEvent(new QEvent(QEvent::User));
|
||||
QTRY_VERIFY(machine.configuration().contains(s2));
|
||||
QCOMPARE(object->property("a").toInt(), 1); // restored
|
||||
|
||||
// Set property outside of state machine; this is the value
|
||||
// that should be remembered in the next transition
|
||||
object->setProperty("a", 3);
|
||||
|
||||
machine.postEvent(new QEvent(QEvent::User));
|
||||
QTRY_VERIFY(machine.configuration().contains(s3));
|
||||
QCOMPARE(object->property("a").toInt(), 4);
|
||||
|
||||
machine.postEvent(new QEvent(QEvent::User));
|
||||
QTRY_VERIFY(machine.configuration().contains(s4));
|
||||
QCOMPARE(object->property("a").toInt(), 3); // restored
|
||||
|
||||
delete object;
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QStateMachine)
|
||||
#include "tst_qstatemachine.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue