diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/statemachine/qabstractstate.cpp | 39 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate.h | 4 | ||||
-rw-r--r-- | src/corelib/statemachine/qabstractstate_p.h | 3 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 5 |
4 files changed, 49 insertions, 2 deletions
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 62b7e448f5..da1eff9b4c 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -79,8 +79,17 @@ QT_BEGIN_NAMESPACE function to perform custom processing when the state is exited. */ +/*! + \property QAbstractState::active + \since 5.4 + + \brief the active property of this state. A state is active between + entered() and exited() signals. +*/ + + QAbstractStatePrivate::QAbstractStatePrivate(StateType type) - : stateType(type), isMachine(false), parentState(0) + : stateType(type), isMachine(false), active(false), parentState(0) { } @@ -121,11 +130,19 @@ void QAbstractStatePrivate::emitEntered() { Q_Q(QAbstractState); emit q->entered(QAbstractState::QPrivateSignal()); + if (!active) { + active = true; + emit q->activeChanged(true); + } } void QAbstractStatePrivate::emitExited() { Q_Q(QAbstractState); + if (active) { + active = false; + emit q->activeChanged(false); + } emit q->exited(QAbstractState::QPrivateSignal()); } @@ -174,6 +191,17 @@ QStateMachine *QAbstractState::machine() const } /*! + Returns whether this state is active. + + \sa activeChanged(bool), entered(), exited() +*/ +bool QAbstractState::active() const +{ + Q_D(const QAbstractState); + return d->active; +} + +/*! \fn QAbstractState::onExit(QEvent *event) This function is called when the state is exited. The given \a event is what @@ -204,6 +232,15 @@ QStateMachine *QAbstractState::machine() const */ /*! + \fn QAbstractState::activeChanged(bool active) + \since 5.4 + + This signal is emitted when the active property is changed. + + \sa QAbstractState::active, entered(), exited() +*/ + +/*! \reimp */ bool QAbstractState::event(QEvent *e) diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h index a6ac248b85..4318a5b419 100644 --- a/src/corelib/statemachine/qabstractstate.h +++ b/src/corelib/statemachine/qabstractstate.h @@ -56,12 +56,15 @@ class QAbstractStatePrivate; class Q_CORE_EXPORT QAbstractState : public QObject { Q_OBJECT + Q_PROPERTY(bool active READ active NOTIFY activeChanged) public: ~QAbstractState(); QState *parentState() const; QStateMachine *machine() const; + bool active() const; + Q_SIGNALS: void entered( #if !defined(Q_QDOC) @@ -73,6 +76,7 @@ Q_SIGNALS: QPrivateSignal #endif ); + void activeChanged(bool active); protected: QAbstractState(QState *parent = 0); diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h index b0334dfbb5..40431a8fcb 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -85,8 +85,9 @@ public: void emitEntered(); void emitExited(); - uint stateType:31; + uint stateType:30; uint isMachine:1; + bool active:1; mutable QState *parentState; }; diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index d46fa357ae..a147b85eb7 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1369,6 +1369,11 @@ void QStateMachinePrivate::_q_start() { Q_Q(QStateMachine); Q_ASSERT(state == Starting); + foreach (QAbstractState *state, configuration) { + QAbstractStatePrivate *abstractStatePrivate = QAbstractStatePrivate::get(state); + abstractStatePrivate->active = false; + emit state->activeChanged(false); + } configuration.clear(); qDeleteAll(internalEventQueue); internalEventQueue.clear(); |