summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/animation/appchooser/main.cpp2
-rw-r--r--src/corelib/statemachine/qabstractstate.cpp60
-rw-r--r--src/corelib/statemachine/qabstractstate.h11
-rw-r--r--src/corelib/statemachine/qabstractstate_p.h1
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp54
-rw-r--r--src/corelib/statemachine/qstatemachine.h10
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h2
-rw-r--r--tests/auto/qstate/tst_qstate.cpp25
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp41
9 files changed, 73 insertions, 133 deletions
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
index 1a43ed7..6735012 100644
--- a/examples/animation/appchooser/main.cpp
+++ b/examples/animation/appchooser/main.cpp
@@ -104,7 +104,7 @@ int main(int argc, char **argv)
window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *group = new QState(machine.rootState());
group->setObjectName("group");
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 030c63c..396063a 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -76,45 +76,7 @@ QT_BEGIN_NAMESPACE
function to perform custom processing when the state is exited.
*/
-/*!
- \enum QAbstractState::RestorePolicy
-
- This enum specifies the restore policy type for a state. The restore policy
- takes effect when the machine enters a state which sets one or more
- properties. If the restore policy of the state 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 has its restore policy
- set to DoNotRestoreProperties or when it 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. Once the property has been restored, the state machine will clear the
- initial value until it enters a new state which sets the property and which has RestoreProperties
- as its restore policy.
-
- \value GlobalRestorePolicy The restore policy for the state should be retrieved using
- QStateMachine::globalRestorePolicy()
- \value DoNotRestoreProperties The state machine should not save the initial values of properties
- set in the state and restore them later.
- \value RestoreProperties The state machine should save the initial values of properties
- set in the state and restore them later.
-
-
- \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
-*/
-
-/*!
- \property QAbstractState::restorePolicy
-
- \brief the restore policy of this state
-*/
-
-QAbstractStatePrivate::QAbstractStatePrivate()
- : restorePolicy(QAbstractState::GlobalRestorePolicy)
+QAbstractStatePrivate::QAbstractStatePrivate()
{
}
@@ -237,26 +199,6 @@ void QAbstractState::assignProperty(QObject *object, const char *name,
}
/*!
- Sets the restore policy of this state to \a restorePolicy.
-
- The default restore policy is QAbstractState::GlobalRestorePolicy.
-*/
-void QAbstractState::setRestorePolicy(RestorePolicy restorePolicy)
-{
- Q_D(QAbstractState);
- d->restorePolicy = restorePolicy;
-}
-
-/*!
- Returns the restore policy for this state.
-*/
-QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
-{
- Q_D(const QAbstractState);
- return d->restorePolicy;
-}
-
-/*!
\fn QAbstractState::onExit()
This function is called when the state is exited. Reimplement this function
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index 55e9a62..69e6bf1 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -56,15 +56,7 @@ class QAbstractStatePrivate;
class Q_CORE_EXPORT QAbstractState : public QObject
{
Q_OBJECT
- Q_ENUMS(RestorePolicy)
- Q_PROPERTY(RestorePolicy restorePolicy READ restorePolicy WRITE setRestorePolicy)
public:
- enum RestorePolicy {
- GlobalRestorePolicy,
- DoNotRestoreProperties,
- RestoreProperties
- };
-
~QAbstractState();
QState *parentState() const;
@@ -72,9 +64,6 @@ public:
void assignProperty(QObject *object, const char *name,
const QVariant &value);
- void setRestorePolicy(RestorePolicy restorePolicy);
- RestorePolicy restorePolicy() const;
-
Q_SIGNALS:
void entered();
void exited();
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index e47fbd2..8c8f436 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -101,7 +101,6 @@ public:
void emitEntered();
void emitExited();
- QAbstractState::RestorePolicy restorePolicy;
QList<QPropertyAssignment> propertyAssignments;
#ifdef QT_STATEMACHINE_SOLUTION
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index b6ab205..2d3eea1 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -188,7 +188,7 @@ QStateMachinePrivate::QStateMachinePrivate()
processingScheduled = false;
stop = false;
error = QStateMachine::NoError;
- globalRestorePolicy = QAbstractState::DoNotRestoreProperties;
+ globalRestorePolicy = QStateMachine::DoNotRestoreProperties;
rootState = 0;
initialErrorStateForRoot = 0;
#ifndef QT_STATEMACHINE_SOLUTION
@@ -631,14 +631,10 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr
for (int i = 0; i < enteredStates.size(); ++i) {
QAbstractState *s = enteredStates.at(i);
- QAbstractState::RestorePolicy restorePolicy = s->restorePolicy();
- if (restorePolicy == QAbstractState::GlobalRestorePolicy)
- restorePolicy = globalRestorePolicy;
-
QList<QPropertyAssignment> assignments = QAbstractStatePrivate::get(s)->propertyAssignments;
for (int j = 0; j < assignments.size(); ++j) {
const QPropertyAssignment &assn = assignments.at(j);
- if (restorePolicy == QAbstractState::RestoreProperties) {
+ if (globalRestorePolicy == QStateMachine::RestoreProperties) {
registerRestorable(assn.object, assn.propertyName);
}
pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
@@ -1458,6 +1454,32 @@ void QStateMachine::setErrorState(QAbstractState *state)
*/
/*!
+ \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 DoNotRestoreProperties 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 setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
+*/
+
+
+/*!
Returns the error code of the last error that occurred in the state machine.
*/
QStateMachine::Error QStateMachine::error() const
@@ -1486,33 +1508,25 @@ void QStateMachine::clearError()
}
/*!
- Returns the global restore policy of the state machine.
+ Returns the restore policy of the state machine.
- \sa QAbstractState::restorePolicy()
+ \sa setGlobalRestorePolicy()
*/
-QAbstractState::RestorePolicy QStateMachine::globalRestorePolicy() const
+QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const
{
Q_D(const QStateMachine);
return d->globalRestorePolicy;
}
/*!
- Sets the global restore policy of the state machine to \a restorePolicy. The default global
+ Sets the restore policy of the state machine to \a restorePolicy. The default
restore policy is QAbstractState::DoNotRestoreProperties.
- The global restore policy cannot be set to QAbstractState::GlobalRestorePolicy.
-
- \sa QAbstractState::setRestorePolicy()
+ \sa globalRestorePolicy()
*/
-void QStateMachine::setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy)
+void QStateMachine::setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy)
{
Q_D(QStateMachine);
- if (restorePolicy == QState::GlobalRestorePolicy) {
- qWarning("QStateMachine::setGlobalRestorePolicy: Cannot set global restore policy to "
- "GlobalRestorePolicy");
- return;
- }
-
d->globalRestorePolicy = restorePolicy;
}
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index 901d160..9a7a6fc 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -72,7 +72,13 @@ class Q_CORE_EXPORT QStateMachine : public QObject
Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState)
Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState)
Q_PROPERTY(QString errorString READ errorString)
+ Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy)
+ Q_ENUMS(RestorePolicy)
public:
+ enum RestorePolicy {
+ DoNotRestoreProperties,
+ RestoreProperties
+ };
enum Error {
NoError,
@@ -112,8 +118,8 @@ public:
void removeDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
#endif // QT_NO_ANIMATION
- QAbstractState::RestorePolicy globalRestorePolicy() const;
- void setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy);
+ QStateMachine::RestorePolicy globalRestorePolicy() const;
+ void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy);
void postEvent(QEvent *event, int delay = 0);
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 910b751..9f93217 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -171,7 +171,7 @@ public:
QList<QEvent*> externalEventQueue;
QStateMachine::Error error;
- QAbstractState::RestorePolicy globalRestorePolicy;
+ QStateMachine::RestorePolicy globalRestorePolicy;
QString errorString;
QSet<QAbstractState *> pendingErrorStates;
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index f79fcd4..f082caf 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -9,9 +9,7 @@
#include "qstate.h"
#include "qstatemachine.h"
-#include "qactiontransition.h"
#include "qsignaltransition.h"
-#include "qstateaction.h"
// Will try to wait for the condition while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
@@ -45,7 +43,6 @@ private slots:
void assignProperty();
void assignPropertyTwice();
void historyInitialState();
- void addEntryAction();
private:
bool functionCalled;
@@ -214,22 +211,6 @@ public slots:
};
-void tst_QState::addEntryAction()
-{
- QStateMachine sm;
-
- TestClass testObject;
-
- QState *s0 = new QState(sm.rootState());
- s0->addEntryAction(new QStateInvokeMethodAction(&testObject, "slot"));
- sm.setInitialState(s0);
-
- sm.start();
- QCoreApplication::processEvents();
-
- QCOMPARE(testObject.called, true);
-}
-
void tst_QState::assignProperty()
{
QStateMachine machine;
@@ -265,11 +246,11 @@ void tst_QState::assignPropertyTwice()
QCOMPARE(object->property("fooBar").toInt(), 30);
}
-class EventTestTransition: public QActionTransition
+class EventTestTransition: public QAbstractTransition
{
public:
EventTestTransition(QEvent::Type type, QState *targetState)
- : QActionTransition(QList<QAbstractState*>() << targetState), m_type(type)
+ : QAbstractTransition(QList<QAbstractState*>() << targetState), m_type(type)
{
}
@@ -279,6 +260,8 @@ protected:
return e->type() == m_type;
}
+ void onTransition() {}
+
private:
QEvent::Type m_type;
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index bf3ff71..2fa9b1a 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -121,14 +121,17 @@ private slots:
void customErrorStateNotInGraph();
void transitionToStateNotInGraph();
void restoreProperties();
+
void defaultGlobalRestorePolicy();
void globalRestorePolicySetToRestore();
void globalRestorePolicySetToDoNotRestore();
- void restorePolicyNotInherited();
- void mixedRestoreProperties();
- void setRestorePolicyToDoNotRestore();
- void setGlobalRestorePolicyToGlobalRestore();
- void restorePolicyOnChildState();
+
+ //void restorePolicyNotInherited();
+ //void mixedRestoreProperties();
+ //void setRestorePolicyToDoNotRestore();
+ //void setGlobalRestorePolicyToGlobalRestore();
+ //void restorePolicyOnChildState();
+
void transitionWithParent();
void simpleAnimation();
@@ -923,22 +926,20 @@ void tst_QStateMachine::restoreProperties()
object->setProperty("b", 2);
QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *S1 = new QState();
S1->setObjectName("S1");
S1->assignProperty(object, "a", 3);
- S1->setRestorePolicy(QState::RestoreProperties);
machine.addState(S1);
QState *S2 = new QState();
S2->setObjectName("S2");
S2->assignProperty(object, "b", 5);
- S2->setRestorePolicy(QState::RestoreProperties);
machine.addState(S2);
QState *S3 = new QState();
S3->setObjectName("S3");
- S3->setRestorePolicy(QState::RestoreProperties);
machine.addState(S3);
QFinalState *S4 = new QFinalState();
@@ -1668,6 +1669,7 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::restorePolicyNotInherited()
{
QStateMachine machine;
@@ -1714,12 +1716,12 @@ void tst_QStateMachine::restorePolicyNotInherited()
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
-}
+}*/
void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::DoNotRestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -1756,6 +1758,7 @@ void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::setRestorePolicyToDoNotRestore()
{
QObject *object = new QObject();
@@ -1812,19 +1815,20 @@ void tst_QStateMachine::setGlobalRestorePolicyToGlobalRestore()
{
s_countWarnings = false;
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::DoNotRestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
s_msgType = QtDebugMsg;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::RestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::RestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
}
+
void tst_QStateMachine::restorePolicyOnChildState()
{
QStateMachine machine;
@@ -1873,11 +1877,12 @@ void tst_QStateMachine::restorePolicyOnChildState()
QCOMPARE(propertyHolder->property("a").toInt(), 1);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+*/
void tst_QStateMachine::globalRestorePolicySetToRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -1914,6 +1919,7 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+/*
void tst_QStateMachine::mixedRestoreProperties()
{
QStateMachine machine;
@@ -1980,6 +1986,7 @@ void tst_QStateMachine::mixedRestoreProperties()
// Enter s3, restore
QCOMPARE(propertyHolder->property("a").toInt(), 5);
}
+*/
void tst_QStateMachine::transitionWithParent()
{
@@ -2224,7 +2231,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
void tst_QStateMachine::animatedGlobalRestoreProperty()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QObject *object = new QObject();
object->setProperty("foo", 1.0);