From 4f6b9b1779fe33f876f96c196c3feef7e72992a0 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Tue, 28 Apr 2009 13:29:37 +0200 Subject: move assignProperty() to QState Doesn't belong in the abstract base class. --- doc/src/statemachine.qdoc | 9 ++++----- src/corelib/statemachine/qabstractstate.cpp | 24 ++---------------------- src/corelib/statemachine/qabstractstate.h | 3 --- src/corelib/statemachine/qabstractstate_p.h | 20 -------------------- src/corelib/statemachine/qstate.cpp | 21 +++++++++++++++++++++ src/corelib/statemachine/qstate.h | 4 ++++ src/corelib/statemachine/qstate_p.h | 19 +++++++++++++++++++ src/corelib/statemachine/qstatemachine.cpp | 12 +++++++----- 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 #endif -#include -#include -#include - 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 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 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 +#include +#include 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 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 &tr QList propertyAssignments; QHash pendingRestorables = registeredRestorables; for (int i = 0; i < enteredStates.size(); ++i) { - QAbstractState *s = enteredStates.at(i); + QState *s = qobject_cast(enteredStates.at(i)); + if (!s) + continue; - QList assignments = QAbstractStatePrivate::get(s)->propertyAssignments; + QList 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 #include -#include "qabstractstate_p.h" +#include "qstate_p.h" QT_BEGIN_NAMESPACE -- cgit v0.12