diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-04-28 11:29:37 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-04-29 06:29:47 (GMT) |
commit | 4f6b9b1779fe33f876f96c196c3feef7e72992a0 (patch) | |
tree | 3131513d79437f85ba411a4c5fe12143b1d62504 | |
parent | 9c28c75052a38eb3b317c2ac7ad2a26c73deeb2d (diff) | |
download | Qt-4f6b9b1779fe33f876f96c196c3feef7e72992a0.zip Qt-4f6b9b1779fe33f876f96c196c3feef7e72992a0.tar.gz Qt-4f6b9b1779fe33f876f96c196c3feef7e72992a0.tar.bz2 |
move assignProperty() to QState
Doesn't belong in the abstract base class.
-rw-r--r-- | doc/src/statemachine.qdoc | 9 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate.cpp | 24 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate.h | 3 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate_p.h | 20 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.cpp | 21 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate.h | 4 | ||||
-rw-r--r-- | src/corelib/statemachine/qstate_p.h | 19 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 12 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine_p.h | 2 |
9 files changed, 58 insertions, 56 deletions
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc index 97c09b9..1462ec1 100644 --- a/doc/src/statemachine.qdoc +++ b/doc/src/statemachine.qdoc @@ -76,11 +76,10 @@ becomes part of your application's event loop. The above state machine is perfectly fine, but it doesn't \e do anything; it - merely transitions from one state to another. The - QAbstractState::assignProperty() function can be used to have a state set a - property of a QObject when the state is entered. In the following snippet, - the value that should be assigned to a QLabel's text property is specified - for each state: + merely transitions from one state to another. The QState::assignProperty() + function can be used to have a state set a property of a QObject when the + state is entered. In the following snippet, the value that should be + assigned to a QLabel's text property is specified for each state: \code s1->assignProperty(label, "text", "In state s1"); diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 396063a..12f14d7 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,9 +60,6 @@ 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. @@ -181,24 +179,6 @@ 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. -*/ -void QAbstractState::assignProperty(QObject *object, const char *name, - const QVariant &value) -{ - 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)); -} - -/*! \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 69e6bf1..a5f1440 100644 --- a/src/corelib/statemachine/qabstractstate.h +++ b/src/corelib/statemachine/qabstractstate.h @@ -61,9 +61,6 @@ public: QState *parentState() const; - void assignProperty(QObject *object, const char *name, - const QVariant &value); - Q_SIGNALS: void entered(); void exited(); diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h index 8c8f436..bbe12d6 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -57,28 +57,10 @@ #include <private/qobject_p.h> #endif -#include <QtCore/qlist.h> -#include <QtCore/qbytearray.h> -#include <QtCore/qvariant.h> - QT_BEGIN_NAMESPACE -class QAbstractTransition; -class QHistoryState; class QStateMachine; -struct QPropertyAssignment -{ - QPropertyAssignment(QObject *o, const QByteArray &n, - const QVariant &v, bool es = true) - : object(o), propertyName(n), value(v), explicitlySet(es) - {} - QObject *object; - QByteArray propertyName; - QVariant value; - bool explicitlySet; -}; - class QAbstractState; class Q_CORE_EXPORT QAbstractStatePrivate #ifndef QT_STATEMACHINE_SOLUTION @@ -101,8 +83,6 @@ public: void emitEntered(); void emitExited(); - QList<QPropertyAssignment> propertyAssignments; - #ifdef QT_STATEMACHINE_SOLUTION QAbstractState *q_ptr; #endif diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 9bda250..5c3418b 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -65,6 +65,9 @@ QT_BEGIN_NAMESPACE The addTransition() function adds a transition. The removeTransition() function removes a transition. + The assignProperty() function is used for defining property assignments that + should be performed when a state is entered. + \section1 States with Child States For non-parallel state groups, the setInitialState() function must be called @@ -216,6 +219,24 @@ QList<QAbstractTransition*> QStatePrivate::transitions() 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. +*/ +void QState::assignProperty(QObject *object, const char *name, + const QVariant &value) +{ + Q_D(QState); + 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)); +} + +/*! Returns this state group's error state. \sa QStateMachine::errorState(), QStateMachine::setErrorState() diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h index 70211c1..0dd99dc 100644 --- a/src/corelib/statemachine/qstate.h +++ b/src/corelib/statemachine/qstate.h @@ -91,8 +91,12 @@ public: QAbstractState *initialState() const; void setInitialState(QAbstractState *state); + void assignProperty(QObject *object, const char *name, + const QVariant &value); + Q_SIGNALS: void finished(); + void polished(); protected: void onEntry(); diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 2df6823..603bc18 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -56,9 +56,26 @@ #include "qabstractstate_p.h" #include <QtCore/qlist.h> +#include <QtCore/qbytearray.h> +#include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE +struct QPropertyAssignment +{ + QPropertyAssignment(QObject *o, const QByteArray &n, + const QVariant &v, bool es = true) + : object(o), propertyName(n), value(v), explicitlySet(es) + {} + QObject *object; + QByteArray propertyName; + QVariant value; + bool explicitlySet; +}; + +class QAbstractTransition; +class QHistoryState; + class QState; class Q_CORE_EXPORT QStatePrivate : public QAbstractStatePrivate { @@ -79,6 +96,8 @@ public: QAbstractState *errorState; bool isParallelGroup; QAbstractState *initialState; + + QList<QPropertyAssignment> propertyAssignments; }; QT_END_NAMESPACE diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 632390f..1434bc0 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -40,6 +40,8 @@ ****************************************************************************/ #include "qstatemachine.h" +#include "qstate.h" +#include "qstate_p.h" #include "qstatemachine_p.h" #include "qabstracttransition.h" #include "qabstracttransition_p.h" @@ -52,8 +54,6 @@ #include "qfinalstate.h" #include "qhistorystate.h" #include "qhistorystate_p.h" -#include "qstate.h" -#include "qstate_p.h" #ifndef QT_STATEMACHINE_SOLUTION #include "private/qobject_p.h" #include "private/qthread_p.h" @@ -641,9 +641,11 @@ void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &tr QList<QPropertyAssignment> propertyAssignments; QHash<RestorableId, QVariant> pendingRestorables = registeredRestorables; for (int i = 0; i < enteredStates.size(); ++i) { - QAbstractState *s = enteredStates.at(i); + QState *s = qobject_cast<QState*>(enteredStates.at(i)); + if (!s) + continue; - QList<QPropertyAssignment> assignments = QAbstractStatePrivate::get(s)->propertyAssignments; + QList<QPropertyAssignment> assignments = QStatePrivate::get(s)->propertyAssignments; for (int j = 0; j < assignments.size(); ++j) { const QPropertyAssignment &assn = assignments.at(j); if (globalRestorePolicy == QStateMachine::RestoreProperties) { @@ -1487,7 +1489,7 @@ void QStateMachine::setErrorState(QAbstractState *state) \value RestoreProperties The state machine should save the initial values of properties and restore them later. - \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty() + \sa setRestorePolicy(), restorePolicy(), QState::assignProperty() */ diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 9f93217..323473d 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -62,7 +62,7 @@ #include <QtCore/qpair.h> #include <QtCore/qset.h> -#include "qabstractstate_p.h" +#include "qstate_p.h" QT_BEGIN_NAMESPACE |