statemachine: Get rid of hidden start state

The hidden start state was used as a mechanism for performing the
initial transition (to the real initial state,
QStateMachine::setInitialState()), but it mutated the state machine
in a way that causes problems when the root state is a parallel
state group (see future commit).

Change-Id: I41ac4f6bcabf3bec0a412e46282a1373928105a3
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Kent Hansen 2012-07-07 04:33:30 +02:00 committed by Qt by Nokia
parent 018cd808fd
commit a7d6efb6e3
2 changed files with 9 additions and 45 deletions

View File

@ -186,7 +186,6 @@ QStateMachinePrivate::QStateMachinePrivate()
isMachine = true; isMachine = true;
state = NotRunning; state = NotRunning;
_startState = 0;
processing = false; processing = false;
processingScheduled = false; processingScheduled = false;
stop = false; stop = false;
@ -511,9 +510,11 @@ QList<QAbstractState*> QStateMachinePrivate::computeStatesToEnter(const QList<QA
QList<QAbstractState*> lst = t->targetStates(); QList<QAbstractState*> lst = t->targetStates();
if (lst.isEmpty()) if (lst.isEmpty())
continue; continue;
lst.prepend(t->sourceState()); QAbstractState *src = t->sourceState();
if (src)
lst.prepend(src);
QState *lca = findLCA(lst); QState *lca = findLCA(lst);
for (int j = 1; j < lst.size(); ++j) { for (int j = src ? 1 : 0; j < lst.size(); ++j) {
QAbstractState *s = lst.at(j); QAbstractState *s = lst.at(j);
addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry); addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
if (isParallel(lca)) { if (isParallel(lca)) {
@ -1282,16 +1283,6 @@ void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QLi
namespace { namespace {
class StartState : public QState
{
public:
StartState(QState *parent)
: QState(parent) {}
protected:
void onEntry(QEvent *) {}
void onExit(QEvent *) {}
};
class InitialTransition : public QAbstractTransition class InitialTransition : public QAbstractTransition
{ {
public: public:
@ -1305,20 +1296,6 @@ protected:
} // namespace } // namespace
QState *QStateMachinePrivate::startState()
{
Q_Q(QStateMachine);
if (_startState == 0)
_startState = new StartState(q);
return _startState;
}
void QStateMachinePrivate::removeStartState()
{
delete _startState;
_startState = 0;
}
void QStateMachinePrivate::clearHistory() void QStateMachinePrivate::clearHistory()
{ {
Q_Q(QStateMachine); Q_Q(QStateMachine);
@ -1348,22 +1325,13 @@ void QStateMachinePrivate::_q_start()
state = Running; state = Running;
processingScheduled = true; // we call _q_process() below processingScheduled = true; // we call _q_process() below
QState *start = startState(); QList<QAbstractTransition*> transitions;
Q_ASSERT(start != 0); QAbstractTransition *initialTransition = new InitialTransition(initial);
transitions.append(initialTransition);
QList<QAbstractTransition*> transitions = QStatePrivate::get(start)->transitions();
// If a transition has already been added, then we skip this step, as the
// initial transition in that case has been overridden.
if (transitions.isEmpty()) {
QAbstractTransition *initialTransition = new InitialTransition(initial);
start->addTransition(initialTransition);
transitions.append(initialTransition);
}
QEvent nullEvent(QEvent::None); QEvent nullEvent(QEvent::None);
executeTransitionContent(&nullEvent, transitions); executeTransitionContent(&nullEvent, transitions);
QList<QAbstractState*> exitedStates = QList<QAbstractState*>() << start; QList<QAbstractState*> exitedStates = QList<QAbstractState*>();
QSet<QAbstractState*> statesForDefaultEntry; QSet<QAbstractState*> statesForDefaultEntry;
QList<QAbstractState*> enteredStates = computeStatesToEnter(transitions, QList<QAbstractState*> enteredStates = computeStatesToEnter(transitions,
statesForDefaultEntry); statesForDefaultEntry);
@ -1379,7 +1347,7 @@ void QStateMachinePrivate::_q_start()
, selectedAnimations , selectedAnimations
#endif #endif
); );
removeStartState(); delete initialTransition;
#ifdef QSTATEMACHINE_DEBUG #ifdef QSTATEMACHINE_DEBUG
qDebug() << q << ": initial configuration:" << configuration; qDebug() << q << ": initial configuration:" << configuration;

View File

@ -127,9 +127,6 @@ public:
QState *rootState() const; QState *rootState() const;
QState *startState();
void removeStartState();
void clearHistory(); void clearHistory();
void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList); void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
@ -208,7 +205,6 @@ public:
#endif #endif
State state; State state;
QState *_startState;
bool processing; bool processing;
bool processingScheduled; bool processingScheduled;
bool stop; bool stop;