summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-07-07 04:33:30 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-11 08:42:24 +0200
commita7d6efb6e3c0f8fddf95d121f856b00d552f3a08 (patch)
treefcf36eddf14416383c0d882635dcb52c2cf1e324
parent018cd808fd8dbe5ccd88021d50b6b16162ab0631 (diff)
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>
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp50
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h4
2 files changed, 9 insertions, 45 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 5bc883bf85..2e37af3194 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -186,7 +186,6 @@ QStateMachinePrivate::QStateMachinePrivate()
isMachine = true;
state = NotRunning;
- _startState = 0;
processing = false;
processingScheduled = false;
stop = false;
@@ -511,9 +510,11 @@ QList<QAbstractState*> QStateMachinePrivate::computeStatesToEnter(const QList<QA
QList<QAbstractState*> lst = t->targetStates();
if (lst.isEmpty())
continue;
- lst.prepend(t->sourceState());
+ QAbstractState *src = t->sourceState();
+ if (src)
+ lst.prepend(src);
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);
addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
if (isParallel(lca)) {
@@ -1282,16 +1283,6 @@ void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QLi
namespace {
-class StartState : public QState
-{
-public:
- StartState(QState *parent)
- : QState(parent) {}
-protected:
- void onEntry(QEvent *) {}
- void onExit(QEvent *) {}
-};
-
class InitialTransition : public QAbstractTransition
{
public:
@@ -1305,20 +1296,6 @@ protected:
} // 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()
{
Q_Q(QStateMachine);
@@ -1348,22 +1325,13 @@ void QStateMachinePrivate::_q_start()
state = Running;
processingScheduled = true; // we call _q_process() below
- QState *start = startState();
- Q_ASSERT(start != 0);
-
- 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);
- }
+ QList<QAbstractTransition*> transitions;
+ QAbstractTransition *initialTransition = new InitialTransition(initial);
+ transitions.append(initialTransition);
QEvent nullEvent(QEvent::None);
executeTransitionContent(&nullEvent, transitions);
- QList<QAbstractState*> exitedStates = QList<QAbstractState*>() << start;
+ QList<QAbstractState*> exitedStates = QList<QAbstractState*>();
QSet<QAbstractState*> statesForDefaultEntry;
QList<QAbstractState*> enteredStates = computeStatesToEnter(transitions,
statesForDefaultEntry);
@@ -1379,7 +1347,7 @@ void QStateMachinePrivate::_q_start()
, selectedAnimations
#endif
);
- removeStartState();
+ delete initialTransition;
#ifdef QSTATEMACHINE_DEBUG
qDebug() << q << ": initial configuration:" << configuration;
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 2f57f548b2..c68ff411b1 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -127,9 +127,6 @@ public:
QState *rootState() const;
- QState *startState();
- void removeStartState();
-
void clearHistory();
void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
@@ -208,7 +205,6 @@ public:
#endif
State state;
- QState *_startState;
bool processing;
bool processingScheduled;
bool stop;