diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-07 08:20:25 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-07 08:20:25 (GMT) |
commit | 7bfe66e825e98b049dfdb0b6008e3f334909eec7 (patch) | |
tree | 83d9f7295efc4da2303d072f7d1dfa4498d7c4b0 /src/corelib/statemachine/qstatemachine.cpp | |
parent | ed900ca77ad3c3e337054346213dc38a58137818 (diff) | |
download | Qt-7bfe66e825e98b049dfdb0b6008e3f334909eec7.zip Qt-7bfe66e825e98b049dfdb0b6008e3f334909eec7.tar.gz Qt-7bfe66e825e98b049dfdb0b6008e3f334909eec7.tar.bz2 |
Make sure machine enters error state if history state has no default state
Keep searching the parent hierarchy for error states even if a state in the
hierarchy cannot be cast to QState. Also make currentErrorState==0 an assert,
since there should always be an error state (we default to the special
initialErrorState if we are unable to find anything else), otherwise the
machine might get into an undefined state (e.g. configuration is empty)
Diffstat (limited to 'src/corelib/statemachine/qstatemachine.cpp')
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 7d6616a..41d4c6c 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -582,6 +582,7 @@ void QStateMachinePrivate::addStatesToEnter(QAbstractState *s, QState *root, QList<QAbstractState*> hlst; if (QHistoryStatePrivate::get(h)->defaultState) hlst.append(QHistoryStatePrivate::get(h)->defaultState); + if (hlst.isEmpty()) { setError(QStateMachine::NoDefaultStateInHistoryState, h); } else { @@ -946,15 +947,15 @@ QAbstractState *QStateMachinePrivate::findErrorState(QAbstractState *context) // Find error state recursively in parent hierarchy if not set explicitly for context state QAbstractState *errorState = 0; + QState *s = qobject_cast<QState*>(context); - if (s) { + if (s) errorState = s->errorState(); - if (!errorState) - errorState = findErrorState(s->parentState()); - return errorState; - } - return errorState; + if (!errorState) + errorState = findErrorState(context->parentState()); + + return errorState; } void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractState *currentContext) @@ -990,10 +991,9 @@ void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractSta currentErrorState = initialErrorStateForRoot; } - if (currentErrorState) { - QState *lca = findLCA(QList<QAbstractState*>() << currentErrorState << currentContext); - addStatesToEnter(currentErrorState, lca, pendingErrorStates, pendingErrorStatesForDefaultEntry); - } + Q_ASSERT(currentErrorState != 0); + QState *lca = findLCA(QList<QAbstractState*>() << currentErrorState << currentContext); + addStatesToEnter(currentErrorState, lca, pendingErrorStates, pendingErrorStatesForDefaultEntry); } #ifndef QT_NO_ANIMATION |