From 7bfe66e825e98b049dfdb0b6008e3f334909eec7 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 7 May 2009 10:20:25 +0200 Subject: 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) --- src/corelib/statemachine/qstatemachine.cpp | 20 ++++++++++---------- 1 file 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 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(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() << currentErrorState << currentContext); - addStatesToEnter(currentErrorState, lca, pendingErrorStates, pendingErrorStatesForDefaultEntry); - } + Q_ASSERT(currentErrorState != 0); + QState *lca = findLCA(QList() << currentErrorState << currentContext); + addStatesToEnter(currentErrorState, lca, pendingErrorStates, pendingErrorStatesForDefaultEntry); } #ifndef QT_NO_ANIMATION -- cgit v0.12