--- src/qstatemachine_orig.cpp 2009-07-26 11:41:00.000000000 +0200 +++ src/qstatemachine.cpp 2009-07-26 12:41:26.000000000 +0200 @@ -455,37 +455,7 @@ QtState *lca = findLCA(lst); for (int j = 1; j < lst.size(); ++j) { QtAbstractState *s = lst.at(j); - if (QtHistoryState *h = qobject_cast(s)) { - QList hconf = QtHistoryStatePrivate::get(h)->configuration; - if (!hconf.isEmpty()) { - for (int k = 0; k < hconf.size(); ++k) { - QtAbstractState *s0 = hconf.at(k); - addStatesToEnter(s0, lca, statesToEnter, statesForDefaultEntry); - } -#ifdef QSTATEMACHINE_DEBUG - qDebug() << q << ": restoring" - << ((QtHistoryStatePrivate::get(h)->historyType == QtState::DeepHistory) ? "deep" : "shallow") - << "history from" << s << ":" << hconf; -#endif - } else { - QList hlst; - if (QtHistoryStatePrivate::get(h)->defaultState) - hlst.append(QtHistoryStatePrivate::get(h)->defaultState); - if (hlst.isEmpty()) { - setError(QtStateMachine::NoDefaultStateInHistoryState, h); - } else { - for (int k = 0; k < hlst.size(); ++k) { - QtAbstractState *s0 = hlst.at(k); - addStatesToEnter(s0, lca, statesToEnter, statesForDefaultEntry); - } -#ifdef QSTATEMACHINE_DEBUG - qDebug() << q << ": initial history targets for" << s << ":" << hlst; -#endif - } - } - } else { - addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry); - } + addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry); if (isParallel(lca)) { QList lcac = QtStatePrivate::get(lca)->childStates(); foreach (QtAbstractState* child,lcac) { @@ -566,45 +536,78 @@ QSet &statesToEnter, QSet &statesForDefaultEntry) { - statesToEnter.insert(s); - if (isParallel(s)) { - QtState *grp = qobject_cast(s); - QList lst = QtStatePrivate::get(grp)->childStates(); - for (int i = 0; i < lst.size(); ++i) { - QtAbstractState *child = lst.at(i); - addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry); - } - } else if (isCompound(s)) { - statesForDefaultEntry.insert(s); - QtState *grp = qobject_cast(s); - QtAbstractState *initial = grp->initialState(); - if (initial != 0) { - addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry); +#ifdef QSTATEMACHINE_DEBUG + Q_Q(QtStateMachine); +#endif + if (QtHistoryState *h = qobject_cast(s)) { + QList hconf = QtHistoryStatePrivate::get(h)->configuration; + if (!hconf.isEmpty()) { + for (int k = 0; k < hconf.size(); ++k) { + QtAbstractState *s0 = hconf.at(k); + addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry); + } +#ifdef QSTATEMACHINE_DEBUG + qDebug() << q << ": restoring" + << ((QtHistoryStatePrivate::get(h)->historyType == QtState::DeepHistory) ? "deep" : "shallow") + << "history from" << s << ":" << hconf; +#endif } else { - setError(QtStateMachine::NoInitialStateError, grp); - return; + QList hlst; + if (QtHistoryStatePrivate::get(h)->defaultState) + hlst.append(QtHistoryStatePrivate::get(h)->defaultState); + if (hlst.isEmpty()) { + setError(QtStateMachine::NoDefaultStateInHistoryState, h); + } else { + for (int k = 0; k < hlst.size(); ++k) { + QtAbstractState *s0 = hlst.at(k); + addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry); + } +#ifdef QSTATEMACHINE_DEBUG + qDebug() << q << ": initial history targets for" << s << ":" << hlst; +#endif + } } - } - QList ancs = properAncestors(s, root); - for (int i = 0; i < ancs.size(); ++i) { - QtState *anc = ancs.at(i); - if (!anc->parentState()) - continue; - statesToEnter.insert(anc); - if (isParallel(anc)) { - QList lst = QtStatePrivate::get(anc)->childStates(); - for (int j = 0; j < lst.size(); ++j) { - QtAbstractState *child = lst.at(j); - bool hasDescendantInList = false; - QSet::const_iterator it; - for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) { - if (isDescendantOf(*it, child)) { - hasDescendantInList = true; - break; + } else { + statesToEnter.insert(s); + if (isParallel(s)) { + QtState *grp = qobject_cast(s); + QList lst = QtStatePrivate::get(grp)->childStates(); + for (int i = 0; i < lst.size(); ++i) { + QtAbstractState *child = lst.at(i); + addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry); + } + } else if (isCompound(s)) { + statesForDefaultEntry.insert(s); + QtState *grp = qobject_cast(s); + QtAbstractState *initial = grp->initialState(); + if (initial != 0) { + addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry); + } else { + setError(QtStateMachine::NoInitialStateError, grp); + return; + } + } + QList ancs = properAncestors(s, root); + for (int i = 0; i < ancs.size(); ++i) { + QtState *anc = ancs.at(i); + if (!anc->parentState()) + continue; + statesToEnter.insert(anc); + if (isParallel(anc)) { + QList lst = QtStatePrivate::get(anc)->childStates(); + for (int j = 0; j < lst.size(); ++j) { + QtAbstractState *child = lst.at(j); + bool hasDescendantInList = false; + QSet::const_iterator it; + for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) { + if (isDescendantOf(*it, child)) { + hasDescendantInList = true; + break; + } } + if (!hasDescendantInList) + addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry); } - if (!hasDescendantInList) - addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry); } } }