--- src/qstatemachine_history_fixed.cpp 2009-07-26 18:21:12.000000000 +0200 +++ src/qstatemachine.cpp 2009-07-27 15:46:45.000000000 +0200 @@ -273,6 +273,27 @@ } } +QtState *QtStateMachinePrivate::findActiveLCA(const QList &states) +{ + if (states.isEmpty()) + return rootState; + QList ancestors = properAncestors(states.at(0), 0); + for (int i = 0; i < ancestors.size(); ++i) { + QtState *anc = ancestors.at(i); + if (!configuration.contains(anc)) + continue; + bool ok = true; + for (int j = states.size() - 1; (j > 0) && ok; --j) { + const QtAbstractState *s = states.at(j); + if (!isDescendantOf(s, anc)) + ok = false; + } + if (ok) + return anc; + } + return rootState; +} + QtState *QtStateMachinePrivate::findLCA(const QList &states) { if (states.isEmpty()) @@ -378,8 +399,18 @@ QList lst = t->targetStates(); if (lst.isEmpty()) continue; - lst.prepend(t->sourceState()); - QtAbstractState *lca = findLCA(lst); + QtAbstractState *lca; + if (isDescendantOf(t->targetState(), t->sourceState())) + { + lst.prepend(t->targetState()); + lca = findActiveLCA(lst); + } + else + { + lst.prepend(t->sourceState()); + lca = findLCA(lst); + } + { QSet::const_iterator it; for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) { @@ -451,8 +482,17 @@ QList lst = t->targetStates(); if (lst.isEmpty()) continue; - lst.prepend(t->sourceState()); - QtState *lca = findLCA(lst); + QtState *lca; + if (isDescendantOf(t->targetState(), t->sourceState())) + { + lst.prepend(t->targetState()); + lca = findActiveLCA(lst); + } + else + { + lst.prepend(t->sourceState()); + lca = findLCA(lst); + } for (int j = 1; j < lst.size(); ++j) { QtAbstractState *s = lst.at(j); addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry); diff -ru src_old/qstatemachine_p.h src/qstatemachine_p.h --- src_old/qstatemachine_p.h 2009-07-26 18:38:06.000000000 +0200 +++ src/qstatemachine_p.h 2009-07-26 18:37:15.000000000 +0200 @@ -109,6 +109,7 @@ static QtStateMachinePrivate *get(QtStateMachine *q); + QtState *findActiveLCA(const QList &states); static QtState *findLCA(const QList &states); static bool stateEntryLessThan(QtAbstractState *s1, QtAbstractState *s2);