summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine/qabstractstate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/statemachine/qabstractstate.cpp')
-rw-r--r--src/corelib/statemachine/qabstractstate.cpp124
1 files changed, 44 insertions, 80 deletions
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 89dcff9..3f84314 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -41,9 +41,10 @@
#include "qabstractstate.h"
#include "qabstractstate_p.h"
+#include "qstate.h"
+#include "qstate_p.h"
#include "qstatemachine.h"
#include "qstatemachine_p.h"
-#include "qstate.h"
QT_BEGIN_NAMESPACE
@@ -59,10 +60,11 @@ QT_BEGIN_NAMESPACE
of a QStateMachine. It defines the interface that all state objects have in
common. QAbstractState is part of \l{The State Machine Framework}.
- The assignProperty() function is used for defining property assignments that
- should be performed when a state is entered.
+ The entered() signal is emitted when the state has been entered. The
+ exited() signal is emitted when the state has been exited.
- The parentState() function returns the state's parent state.
+ The parentState() function returns the state's parent state. The machine()
+ function returns the state machine that the state is part of.
\section1 Subclassing
@@ -73,45 +75,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()
{
}
@@ -137,16 +101,28 @@ QStateMachine *QAbstractStatePrivate::machine() const
return 0;
}
-void QAbstractStatePrivate::callOnEntry()
+void QAbstractStatePrivate::callOnEntry(QEvent *e)
+{
+ Q_Q(QAbstractState);
+ q->onEntry(e);
+}
+
+void QAbstractStatePrivate::callOnExit(QEvent *e)
{
Q_Q(QAbstractState);
- q->onEntry();
+ q->onExit(e);
}
-void QAbstractStatePrivate::callOnExit()
+void QAbstractStatePrivate::emitEntered()
{
Q_Q(QAbstractState);
- q->onExit();
+ emit q->entered();
+}
+
+void QAbstractStatePrivate::emitExited()
+{
+ Q_Q(QAbstractState);
+ emit q->exited();
}
/*!
@@ -204,55 +180,43 @@ QState *QAbstractState::parentState() const
}
/*!
- Instructs this state to set the property with the given \a name of the given
- \a object to the given \a value when the state is entered.
+ Returns the state machine that this state is part of, or 0 if the state is
+ not part of a state machine.
*/
-void QAbstractState::assignProperty(QObject *object, const char *name,
- const QVariant &value)
+QStateMachine *QAbstractState::machine() const
{
- Q_D(QAbstractState);
- for (int i = 0; i < d->propertyAssignments.size(); ++i) {
- QPropertyAssignment &assn = d->propertyAssignments[i];
- if ((assn.object == object) && (assn.propertyName == name)) {
- assn.value = value;
- return;
- }
- }
- d->propertyAssignments.append(QPropertyAssignment(object, name, value));
+ Q_D(const QAbstractState);
+ return d->machine();
}
/*!
- Sets the restore policy of this state to \a restorePolicy.
-
- The default restore policy is QAbstractState::GlobalRestorePolicy.
+ \fn QAbstractState::onExit(QEvent *event)
+
+ This function is called when the state is exited. The given \a event is what
+ caused the state to be exited. Reimplement this function to perform custom
+ processing when the state is exited.
*/
-void QAbstractState::setRestorePolicy(RestorePolicy restorePolicy)
-{
- Q_D(QAbstractState);
- d->restorePolicy = restorePolicy;
-}
/*!
- Returns the restore policy for this state.
+ \fn QAbstractState::onEntry(QEvent *event)
+
+ This function is called when the state is entered. The given \a event is
+ what caused the state to be entered. Reimplement this function to perform
+ custom processing when the state is entered.
*/
-QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
-{
- Q_D(const QAbstractState);
- return d->restorePolicy;
-}
/*!
- \fn QAbstractState::onExit()
+ \fn QAbstractState::entered()
- This function is called when the state is exited. Reimplement this function
- to perform custom processing when the state is exited.
+ This signal is emitted when the state has been entered (after onEntry() has
+ been called).
*/
/*!
- \fn QAbstractState::onEntry()
+ \fn QAbstractState::exited()
- This function is called when the state is entered. Reimplement this function
- to perform custom processing when the state is entered.
+ This signal is emitted when the state has been exited (after onExit() has
+ been called).
*/
/*!