diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-11-29 12:32:50 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-11-29 12:32:50 +0100 |
commit | bc476e8803b1be71014a4cd6a93abfcbb04465e5 (patch) | |
tree | 3fa5a2fa65bec6b68ca2fa4f576cafecbcef2491 /src | |
parent | 20f1f1b1a027dfe5dcdd91d25590095e99eb2bf3 (diff) | |
parent | 8a3dae92910e9df5817d9cde16aef81e76bfc60f (diff) |
Merge 5.8 into 5.8.0
Change-Id: I8fa59d8b2559aa620eb533ed4274ea1b7374d2c7
Diffstat (limited to 'src')
-rw-r--r-- | src/scxml/qscxmlstatemachineinfo.cpp | 80 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachineinfo_p.h | 13 |
2 files changed, 75 insertions, 18 deletions
diff --git a/src/scxml/qscxmlstatemachineinfo.cpp b/src/scxml/qscxmlstatemachineinfo.cpp index d3a23f9..d81956a 100644 --- a/src/scxml/qscxmlstatemachineinfo.cpp +++ b/src/scxml/qscxmlstatemachineinfo.cpp @@ -64,6 +64,13 @@ QScxmlStateMachineInfo::QScxmlStateMachineInfo(QScxmlStateMachine *stateMachine) QScxmlStateMachinePrivate::get(stateMachine)->attach(this); } +QScxmlStateMachine *QScxmlStateMachineInfo::stateMachine() const +{ + Q_D(const QScxmlStateMachineInfo); + + return d->stateMachine(); +} + QVector<QScxmlStateMachineInfo::StateId> QScxmlStateMachineInfo::allStates() const { Q_D(const QScxmlStateMachineInfo); @@ -90,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); @@ -107,16 +107,24 @@ QString QScxmlStateMachineInfo::stateName(int stateId) const return QString(); } +QScxmlStateMachineInfo::StateId QScxmlStateMachineInfo::stateParent(StateId stateId) const +{ + Q_D(const QScxmlStateMachineInfo); + + if (stateId < 0 || stateId >= d->stateTable()->stateCount) + return InvalidStateId; + + auto state = d->stateTable()->state(stateId); + return state.parent; +} + QScxmlStateMachineInfo::StateType QScxmlStateMachineInfo::stateType(StateId stateId) const { 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; @@ -132,12 +140,18 @@ QVector<QScxmlStateMachineInfo::StateId> QScxmlStateMachineInfo::stateChildren(S { Q_D(const QScxmlStateMachineInfo); + int childStates = QScxmlExecutableContent::StateTable::InvalidIndex; + if (stateId == InvalidStateId) + childStates = d->stateTable()->childStates; + if (stateId >= 0 && stateId < d->stateTable()->stateCount) + childStates = d->stateTable()->state(stateId).childStates; + QVector<QScxmlStateMachineInfo::StateId> all; - auto state = d->stateTable()->state(stateId); - if (state.childStates == QScxmlExecutableContent::StateTable::InvalidIndex) + if (childStates == QScxmlExecutableContent::StateTable::InvalidIndex) return all; - auto kids = d->stateTable()->array(state.childStates); + const auto kids = d->stateTable()->array(childStates); + all.reserve(kids.size()); for (auto childId : kids) { all.append(childId); } @@ -161,12 +175,25 @@ QScxmlStateMachineInfo::TransitionType QScxmlStateMachineInfo::transitionType(QS } } +QScxmlStateMachineInfo::TransitionId QScxmlStateMachineInfo::initialTransition(StateId stateId) const +{ + Q_D(const QScxmlStateMachineInfo); + + if (stateId == InvalidStateId) + return d->stateTable()->initialTransition; + + if (stateId < 0 || stateId >= d->stateTable()->stateCount) + return InvalidTransitionId; + + return d->stateTable()->state(stateId).initialTransition; +} + QScxmlStateMachineInfo::StateId QScxmlStateMachineInfo::transitionSource(TransitionId transitionId) const { Q_D(const QScxmlStateMachineInfo); if (transitionId < 0 || transitionId >= d->stateTable()->transitionCount) - return InvalidState; + return InvalidStateId; auto transition = d->stateTable()->transition(transitionId); return transition.source; @@ -191,6 +218,27 @@ QVector<QScxmlStateMachineInfo::StateId> QScxmlStateMachineInfo::transitionTarge return targets; } +QVector<QString> QScxmlStateMachineInfo::transitionEvents(TransitionId transitionId) const +{ + Q_D(const QScxmlStateMachineInfo); + + QVector<QString> events; + if (transitionId < 0 || transitionId >= d->stateTable()->transitionCount) + return events; + + auto transition = d->stateTable()->transition(transitionId); + if (transition.events == QScxmlExecutableContent::StateTable::InvalidIndex) + return events; + + auto eventIds = d->stateTable()->array(transition.events); + events.reserve(eventIds.size()); + for (auto eventId : eventIds) { + events.append(d->stateMachinePrivate()->m_tableData->string(eventId)); + } + + return events; +} + QVector<QScxmlStateMachineInfo::StateId> QScxmlStateMachineInfo::configuration() const { Q_D(const QScxmlStateMachineInfo); diff --git a/src/scxml/qscxmlstatemachineinfo_p.h b/src/scxml/qscxmlstatemachineinfo_p.h index a80ef35..7a8ca50 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, @@ -85,14 +89,19 @@ public: // types public: // methods QScxmlStateMachineInfo(QScxmlStateMachine *stateMachine); + QScxmlStateMachine *stateMachine() const; + QVector<StateId> allStates() const; QVector<TransitionId> allTransitions() const; QString stateName(int stateId) const; + StateId stateParent(StateId stateId) const; StateType stateType(int stateId) const; QVector<StateId> stateChildren(StateId stateId) const; + TransitionId initialTransition(StateId stateId) const; TransitionType transitionType(TransitionId transitionId) const; StateId transitionSource(TransitionId transitionId) const; QVector<StateId> transitionTargets(TransitionId transitionId) const; + QVector<QString> transitionEvents(TransitionId transitionId) const; QVector<StateId> configuration() const; Q_SIGNALS: |