From cd1351401ffdfe5e6097b4b41a632655f9fa6e03 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 13 Jul 2012 19:30:33 +0200 Subject: statemachine: Move RestorePolicy enum to QState class This makes it possible to add API for setting the restore policy per state, or even per property assignment (QTBUG-17861). This change is fully source compatible with Qt4. Change-Id: I53628546b070f6fc84891f86e7ad7bd8ef5ba285 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstate.cpp | 25 +++++++++++++++++++ src/corelib/statemachine/qstate.h | 7 +++++- src/corelib/statemachine/qstatemachine.cpp | 40 ++++++------------------------ src/corelib/statemachine/qstatemachine.h | 12 +++------ src/corelib/statemachine/qstatemachine_p.h | 2 +- 5 files changed, 42 insertions(+), 44 deletions(-) (limited to 'src/corelib/statemachine') diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 481f0e92a2..afe0225727 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -124,6 +124,31 @@ QT_BEGIN_NAMESPACE is entered, all its child states are entered in parallel. */ +/*! + \enum QState::RestorePolicy + + This enum specifies the restore policy type. The restore policy + takes effect when the machine enters a state which sets one or more + properties. If the restore policy is set to RestoreProperties, + the state machine will save the original value of the property before the + new value is set. + + Later, when the machine either enters a state which does not set + a value for the given property, the property will automatically be restored + to its initial value. + + Only one initial value will be saved for any given property. If a value for a property has + already been saved by the state machine, it will not be overwritten until the property has been + successfully restored. + + \value DontRestoreProperties The state machine should not save the initial values of properties + and restore them later. + \value RestoreProperties The state machine should save the initial values of properties + and restore them later. + + \sa QStateMachine::globalRestorePolicy, QState::assignProperty() +*/ + QStatePrivate::QStatePrivate() : QAbstractStatePrivate(StandardState), errorState(0), initialState(0), childMode(QState::ExclusiveStates), diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 63a11b4e4f..2989bd4d7e 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -63,13 +63,18 @@ class Q_CORE_EXPORT QState : public QAbstractState Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState) Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState) Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode) - Q_ENUMS(ChildMode) + Q_ENUMS(ChildMode RestorePolicy) public: enum ChildMode { ExclusiveStates, ParallelStates }; + enum RestorePolicy { + DontRestoreProperties, + RestoreProperties + }; + QState(QState *parent = 0); QState(ChildMode childMode, QState *parent = 0); ~QState(); diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 2d6ced3051..b6973881d5 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -159,7 +159,7 @@ QT_BEGIN_NAMESPACE \brief the restore policy for states of this state machine. The default value of this property is - QStateMachine::DontRestoreProperties. + QState::DontRestoreProperties. */ #ifndef QT_NO_ANIMATION @@ -191,7 +191,7 @@ QStateMachinePrivate::QStateMachinePrivate() stop = false; stopProcessingReason = EventQueueEmpty; error = QStateMachine::NoError; - globalRestorePolicy = QStateMachine::DontRestoreProperties; + globalRestorePolicy = QState::DontRestoreProperties; signalEventGenerator = 0; #ifndef QT_NO_ANIMATION animated = true; @@ -575,7 +575,7 @@ void QStateMachinePrivate::enterStates(QEvent *event, const QList assignments = propertyAssignmentsForState.value(s); for (int i = 0; i < assignments.size(); ++i) { const QPropertyAssignment &assn = assignments.at(i); - if (globalRestorePolicy == QStateMachine::RestoreProperties) { + if (globalRestorePolicy == QState::RestoreProperties) { if (assn.explicitlySet) { if (!hasRestorable(s, assn.object, assn.propertyName)) { QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); @@ -1250,7 +1250,7 @@ void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QLi // ### connect to just the top-level animation? QObject::connect(a, SIGNAL(finished()), q, SLOT(_q_animationFinished()), Qt::UniqueConnection); } - if ((globalRestorePolicy == QStateMachine::RestoreProperties) + if ((globalRestorePolicy == QState::RestoreProperties) && !hasRestorable(state, assn.object, assn.propertyName)) { QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); @@ -1982,32 +1982,6 @@ QStateMachine::~QStateMachine() \sa setErrorState() */ -/*! - \enum QStateMachine::RestorePolicy - - This enum specifies the restore policy type. The restore policy - takes effect when the machine enters a state which sets one or more - properties. If the restore policy is set to RestoreProperties, - the state machine will save the original value of the property before the - new value is set. - - Later, when the machine either enters a state which does not set - a value for the given property, the property will automatically be restored - to its initial value. - - Only one initial value will be saved for any given property. If a value for a property has - already been saved by the state machine, it will not be overwritten until the property has been - successfully restored. - - \value DontRestoreProperties The state machine should not save the initial values of properties - and restore them later. - \value RestoreProperties The state machine should save the initial values of properties - and restore them later. - - \sa QStateMachine::globalRestorePolicy, QState::assignProperty() -*/ - - /*! Returns the error code of the last error that occurred in the state machine. */ @@ -2041,7 +2015,7 @@ void QStateMachine::clearError() \sa setGlobalRestorePolicy() */ -QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const +QState::RestorePolicy QStateMachine::globalRestorePolicy() const { Q_D(const QStateMachine); return d->globalRestorePolicy; @@ -2049,11 +2023,11 @@ QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const /*! Sets the restore policy of the state machine to \a restorePolicy. The default - restore policy is QAbstractState::DontRestoreProperties. + restore policy is QState::DontRestoreProperties. \sa globalRestorePolicy() */ -void QStateMachine::setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy) +void QStateMachine::setGlobalRestorePolicy(QState::RestorePolicy restorePolicy) { Q_D(QStateMachine); d->globalRestorePolicy = restorePolicy; diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h index 964b89a66e..cc9c8aa652 100644 --- a/src/corelib/statemachine/qstatemachine.h +++ b/src/corelib/statemachine/qstatemachine.h @@ -63,8 +63,7 @@ class Q_CORE_EXPORT QStateMachine : public QState { Q_OBJECT Q_PROPERTY(QString errorString READ errorString) - Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy) - Q_ENUMS(RestorePolicy) + Q_PROPERTY(QState::RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy) #ifndef QT_NO_ANIMATION Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated) #endif @@ -107,11 +106,6 @@ public: HighPriority }; - enum RestorePolicy { - DontRestoreProperties, - RestoreProperties - }; - enum Error { NoError, NoInitialStateError, @@ -141,8 +135,8 @@ public: void removeDefaultAnimation(QAbstractAnimation *animation); #endif // QT_NO_ANIMATION - QStateMachine::RestorePolicy globalRestorePolicy() const; - void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy); + QState::RestorePolicy globalRestorePolicy() const; + void setGlobalRestorePolicy(QState::RestorePolicy restorePolicy); void postEvent(QEvent *event, EventPriority priority = NormalPriority); int postDelayedEvent(QEvent *event, int delay); diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 9e1f425779..cf20ee31ca 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -224,7 +224,7 @@ public: QMutex externalEventMutex; QStateMachine::Error error; - QStateMachine::RestorePolicy globalRestorePolicy; + QState::RestorePolicy globalRestorePolicy; QString errorString; QSet pendingErrorStates; -- cgit v1.2.3