diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-04-29 09:40:38 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-04-29 09:41:13 (GMT) |
commit | fa612960f423aa413d6d83813807a470aef27d7d (patch) | |
tree | 0eda17fc34fd88831cb15168b28eba0e1ca4e5a3 | |
parent | c731d50a8ac908da982c911c73509cdd766c4c0f (diff) | |
download | Qt-fa612960f423aa413d6d83813807a470aef27d7d.zip Qt-fa612960f423aa413d6d83813807a470aef27d7d.tar.gz Qt-fa612960f423aa413d6d83813807a470aef27d7d.tar.bz2 |
replace QState::Type with QState::childMode property
Result of API review.
-rw-r--r-- | doc/src/statemachine.qdoc | 11 | ||||
-rw-r--r-- | examples/statemachine/clockticking/main.cpp | 2 | ||||
-rw-r--r-- | examples/statemachine/pingpong/main.cpp | 2 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.cpp | 58 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.h | 16 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate_p.h | 2 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 4 |
8 files changed, 70 insertions, 29 deletions
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc index 1462ec1..60ae815 100644 --- a/doc/src/statemachine.qdoc +++ b/doc/src/statemachine.qdoc @@ -241,11 +241,11 @@ \caption This is a caption \endomit - To create a parallel state group, pass QState::ParallelStateGroup to the - QState constructor. + To create a parallel state group, pass QState::ParallelStates to the QState + constructor. \code - QState *s1 = new QState(QState::ParallelStateGroup); + QState *s1 = new QState(QState::ParallelStates); // s11 and s12 will be entered in parallel QState *s11 = new QState(s1); QState *s12 = new QState(s1); @@ -253,9 +253,8 @@ \section1 Detecting that a Composite State has Finished - A child state can be final; when a final child state is entered, a - QStateFinishedEvent is generated for the parent state. You can use the - QStateFinishedTransition class to trigger a transition based on this event. + A child state can be final; when a final child state is entered, the parent + state emits the QState::finished() signal. \img statemachine-finished.png \omit diff --git a/examples/statemachine/clockticking/main.cpp b/examples/statemachine/clockticking/main.cpp index 301060b..9b54f29 100644 --- a/examples/statemachine/clockticking/main.cpp +++ b/examples/statemachine/clockticking/main.cpp @@ -104,7 +104,7 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); QStateMachine machine; - QState *group = new QState(QState::ParallelGroup); + QState *group = new QState(QState::ParallelStates); group->setObjectName("group"); ClockState *clock = new ClockState(group); diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp index ec1ebf2..68f7115 100644 --- a/examples/statemachine/pingpong/main.cpp +++ b/examples/statemachine/pingpong/main.cpp @@ -112,7 +112,7 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); QStateMachine machine; - QState *group = new QState(QState::ParallelGroup); + QState *group = new QState(QState::ParallelStates); group->setObjectName("group"); Pinger *pinger = new Pinger(group); diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index dd3af51..5b49f1f 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -81,20 +81,37 @@ QT_BEGIN_NAMESPACE */ /*! - \enum QState::Type + \property QState::initialState - This enum specifies the type of a state. + \brief the initial state of this state +*/ + +/*! + \property QState::errorState + + \brief the error state of this state +*/ + +/*! + \property QState::childMode + + \brief the child mode of this state +*/ + +/*! + \enum QState::ChildMode + + This enum specifies how a state's child states are treated. - \value Normal A normal state. If the state has no child states, it is an - atomic state; otherwise, the child states are mutually exclusive and an + \value ExclusiveStates The child states are mutually exclusive and an initial state must be set by calling QState::setInitialState(). - \value ParallelGroup The state is a parallel group state. When a parallel - group state is entered, all its child states are entered in parallel. + \value ParallelStates The child states are parallel. When the parent state + is entered, all its child states are entered in parallel. */ QStatePrivate::QStatePrivate() - : errorState(0), isParallelGroup(false), initialState(0) + : errorState(0), initialState(0), childMode(QState::ExclusiveStates) { } @@ -131,13 +148,14 @@ QState::QState(QState *parent) } /*! - Constructs a new state of the given \a type with the given \a parent state. + Constructs a new state with the given \a childMode and the given \a parent + state. */ -QState::QState(Type type, QState *parent) +QState::QState(ChildMode childMode, QState *parent) : QAbstractState(*new QStatePrivate, parent) { Q_D(QState); - d->isParallelGroup = (type == ParallelGroup); + d->childMode = childMode; } /*! @@ -393,7 +411,7 @@ QAbstractState *QState::initialState() const void QState::setInitialState(QAbstractState *state) { Q_D(QState); - if (d->isParallelGroup) { + if (d->childMode == QState::ParallelStates) { qWarning("QState::setInitialState: ignoring attempt to set initial state " "of parallel state group %p", this); return; @@ -407,6 +425,24 @@ void QState::setInitialState(QAbstractState *state) } /*! + Returns the child mode of this state. +*/ +QState::ChildMode QState::childMode() const +{ + Q_D(const QState); + return d->childMode; +} + +/*! + Sets the child \a mode of this state. +*/ +void QState::setChildMode(ChildMode mode) +{ + Q_D(QState); + d->childMode = mode; +} + +/*! \reimp */ bool QState::event(QEvent *e) diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 33f0709..926d41f 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -55,21 +55,24 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) class QAbstractTransition; -class QHistoryState; class QSignalTransition; class QStatePrivate; class Q_CORE_EXPORT QState : public QAbstractState { Q_OBJECT + 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) public: - enum Type { - Normal, - ParallelGroup + enum ChildMode { + ExclusiveStates, + ParallelStates }; QState(QState *parent = 0); - QState(Type type, QState *parent = 0); + QState(ChildMode childMode, QState *parent = 0); ~QState(); QAbstractState *errorState() const; @@ -84,6 +87,9 @@ public: QAbstractState *initialState() const; void setInitialState(QAbstractState *state); + ChildMode childMode() const; + void setChildMode(ChildMode mode); + void assignProperty(QObject *object, const char *name, const QVariant &value); diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 603bc18..0c8c858 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -94,8 +94,8 @@ public: void emitFinished(); QAbstractState *errorState; - bool isParallelGroup; QAbstractState *initialState; + QState::ChildMode childMode; QList<QPropertyAssignment> propertyAssignments; }; diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 020700e..0ddeac9 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -751,7 +751,7 @@ bool QStateMachinePrivate::isFinal(const QAbstractState *s) bool QStateMachinePrivate::isParallel(const QAbstractState *s) { const QState *ss = qobject_cast<const QState*>(s); - return ss && QStatePrivate::get(ss)->isParallelGroup; + return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates); } bool QStateMachinePrivate::isCompound(const QAbstractState *s) @@ -766,7 +766,7 @@ bool QStateMachinePrivate::isCompound(const QAbstractState *s) bool QStateMachinePrivate::isAtomic(const QAbstractState *s) { const QState *ss = qobject_cast<const QState*>(s); - return (ss && !QStatePrivate::get(ss)->isParallelGroup + return (ss && (QStatePrivate::get(ss)->childMode != QState::ParallelStates) && QStatePrivate::get(ss)->childStates().isEmpty()) || isFinal(s); } diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 2733855..7187b14 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1281,7 +1281,7 @@ void tst_QStateMachine::parallelStates() { QStateMachine machine; - QState *s1 = new QState(QState::ParallelGroup); + QState *s1 = new QState(QState::ParallelStates); QState *s1_1 = new QState(s1); QState *s1_1_1 = new QState(s1_1); QFinalState *s1_1_f = new QFinalState(s1_1); @@ -2886,7 +2886,7 @@ void tst_QStateMachine::parallelStateTransition() { QStateMachine machine; - QState *parallelState = new QState(QState::ParallelGroup, machine.rootState()); + QState *parallelState = new QState(QState::ParallelStates, machine.rootState()); machine.setInitialState(parallelState); QState *s1 = new QState(parallelState); |