diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-11-18 18:06:44 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-11-22 09:17:28 +0000 |
commit | 198c94527b48eb402a4043ed5f6c24b04de43f76 (patch) | |
tree | 821501404c6f1e01a7e348d03ab6ceae028b22d3 /src | |
parent | 9e85ae4674ed44e9c04dedb4ea4959833b6322cd (diff) |
Distinguish invalid state/transition types from IDs and drop root state
Types and IDs are conceptually different and shouldn't be mixed up this
way. Also, as far as I can see, there is no real need to invent a
synthetic root state. Leaving that out saves us a lot of inconsistency
(e.g. the root state didn't show up in allStates(), and you couldn't
ask it for stateChildren()). Without the root state some transitions
originate from the invalid state, but that is an equally good
characterization for initial transitions as the synthetic root
state.
Change-Id: I3738df08d0e3702433dabd3fb837f0ddaea57465
Reviewed-by: Jan Arne Petersen <jan.petersen@kdab.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/scxml/qscxmlstatemachineinfo.cpp | 16 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachineinfo_p.h | 8 |
2 files changed, 9 insertions, 15 deletions
diff --git a/src/scxml/qscxmlstatemachineinfo.cpp b/src/scxml/qscxmlstatemachineinfo.cpp index 7dea3f2..32074cd 100644 --- a/src/scxml/qscxmlstatemachineinfo.cpp +++ b/src/scxml/qscxmlstatemachineinfo.cpp @@ -97,16 +97,9 @@ QString QScxmlStateMachineInfo::stateName(int stateId) const { Q_D(const QScxmlStateMachineInfo); - if (stateId < StateMachineRootState && stateId >= d->stateTable()->stateCount) + if (stateId < 0 || stateId >= d->stateTable()->stateCount) return QString(); - if (stateId == StateMachineRootState) { - if (d->stateTable()->name < 0) - return QString(); - else - return d->stateMachinePrivate()->m_tableData->string(d->stateTable()->name); - } - auto state = d->stateTable()->state(stateId); if (state.name >= 0) return d->stateMachinePrivate()->m_tableData->string(state.name); @@ -118,12 +111,9 @@ QScxmlStateMachineInfo::StateType QScxmlStateMachineInfo::stateType(StateId stat { Q_D(const QScxmlStateMachineInfo); - if (stateId < StateMachineRootState || stateId >= d->stateTable()->stateCount) + if (stateId < 0 || stateId >= d->stateTable()->stateCount) return InvalidState; - if (stateId == -1) - return StateMachineRootState; - auto state = d->stateTable()->state(stateId); switch (state.type) { default: return InvalidState; @@ -173,7 +163,7 @@ QScxmlStateMachineInfo::StateId QScxmlStateMachineInfo::transitionSource(Transit Q_D(const QScxmlStateMachineInfo); if (transitionId < 0 || transitionId >= d->stateTable()->transitionCount) - return InvalidState; + return InvalidStateId; auto transition = d->stateTable()->transition(transitionId); return transition.source; diff --git a/src/scxml/qscxmlstatemachineinfo_p.h b/src/scxml/qscxmlstatemachineinfo_p.h index e0877a3..10d4c02 100644 --- a/src/scxml/qscxmlstatemachineinfo_p.h +++ b/src/scxml/qscxmlstatemachineinfo_p.h @@ -66,15 +66,19 @@ class Q_SCXML_EXPORT QScxmlStateMachineInfo: public QObject public: // types typedef int StateId; typedef int TransitionId; + + static const StateId InvalidStateId = -1; + static const TransitionId InvalidTransitionId = -1; + enum StateType : int { - InvalidState = -2, - StateMachineRootState = -1, + InvalidState = -1, NormalState = 0, ParallelState = 1, FinalState = 2, ShallowHistoryState = 3, DeepHistoryState = 4 }; + enum TransitionType : int { InvalidTransition = -1, InternalTransition = 0, |