diff options
Diffstat (limited to 'src/corelib/statemachine/qabstracttransition.cpp')
-rw-r--r-- | src/corelib/statemachine/qabstracttransition.cpp | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp index 36de7f5..6ddb416 100644 --- a/src/corelib/statemachine/qabstracttransition.cpp +++ b/src/corelib/statemachine/qabstracttransition.cpp @@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE \brief The QAbstractTransition class is the base class of transitions between QAbstractState objects. + \since 4.6 \ingroup statemachine The QAbstractTransition class is the abstract base class of transitions @@ -59,11 +60,9 @@ QT_BEGIN_NAMESPACE QStateMachine. QAbstractTransition is part of \l{The State Machine Framework}. - The QTransition class provides a default (action-based) implementation of - the QAbstractTransition interface. - The sourceState() function returns the source of the transition. The - targetStates() function returns the targets of the transition. + targetStates() function returns the targets of the transition. The machine() + function returns the state machine that the transition is part of. Transitions can cause animations to be played. Use the addAnimation() function to add an animation to the transition. @@ -80,19 +79,19 @@ QT_BEGIN_NAMESPACE */ /*! - \property QAbstractTransition::source + \property QAbstractTransition::sourceState \brief the source state (parent) of this transition */ /*! - \property QAbstractTransition::target + \property QAbstractTransition::targetState \brief the target state of this transition */ /*! - \property QAbstractTransition::targets + \property QAbstractTransition::targetStates \brief the target states of this transition @@ -132,10 +131,10 @@ bool QAbstractTransitionPrivate::callEventTest(QEvent *e) const return q->eventTest(e); } -void QAbstractTransitionPrivate::callOnTransition() +void QAbstractTransitionPrivate::callOnTransition(QEvent *e) { Q_Q(QAbstractTransition); - q->onTransition(); + q->onTransition(e); } QState *QAbstractTransitionPrivate::sourceState() const @@ -180,8 +179,7 @@ QAbstractTransition::QAbstractTransition(const QList<QAbstractState*> &targets, #ifdef QT_STATEMACHINE_SOLUTION d_ptr->q_ptr = this; #endif - Q_D(QAbstractTransition); - d->targetStates = targets; + setTargetStates(targets); } /*! @@ -221,8 +219,7 @@ QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd, #ifdef QT_STATEMACHINE_SOLUTION d_ptr->q_ptr = this; #endif - Q_D(QAbstractTransition); - d->targetStates = targets; + setTargetStates(targets); } /*! @@ -266,7 +263,7 @@ void QAbstractTransition::setTargetState(QAbstractState* target) if (!target) d->targetStates.clear(); else - d->targetStates = QList<QAbstractState*>() << target; + setTargetStates(QList<QAbstractState*>() << target); } /*! @@ -276,7 +273,13 @@ void QAbstractTransition::setTargetState(QAbstractState* target) QList<QAbstractState*> QAbstractTransition::targetStates() const { Q_D(const QAbstractTransition); - return d->targetStates; + QList<QAbstractState*> result; + for (int i = 0; i < d->targetStates.size(); ++i) { + QAbstractState *target = d->targetStates.at(i); + if (target) + result.append(target); + } + return result; } /*! @@ -285,7 +288,32 @@ QList<QAbstractState*> QAbstractTransition::targetStates() const void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets) { Q_D(QAbstractTransition); - d->targetStates = targets; + + for (int i=0; i<targets.size(); ++i) { + QAbstractState *target = targets.at(i); + if (!target) { + qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null"); + return; + } + if (target->machine() != 0 && target->machine()->rootState() == target) { + qWarning("QAbstractTransition::setTargetStates: root state cannot be target of transition"); + return; + } + } + + d->targetStates.clear(); + for (int i = 0; i < targets.size(); ++i) + d->targetStates.append(targets.at(i)); +} + +/*! + Returns the state machine that this transition is part of, or 0 if the + transition is not part of a state machine. +*/ +QStateMachine *QAbstractTransition::machine() const +{ + Q_D(const QAbstractTransition); + return d->machine(); } #ifndef QT_NO_ANIMATION @@ -344,10 +372,11 @@ QList<QAbstractAnimation*> QAbstractTransition::animations() const */ /*! - \fn QAbstractTransition::onTransition() + \fn QAbstractTransition::onTransition(QEvent *event) - This function is called when the transition is triggered. Reimplement this - function to perform custom processing when the transition is triggered. + This function is called when the transition is triggered. The given \a event + is what caused the transition to trigger. Reimplement this function to + perform custom processing when the transition is triggered. */ /*! |