diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2019-04-16 14:50:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-05-21 17:58:50 +0200 |
commit | 7257358e44b373ebdd147162f7b5596d27420e7b (patch) | |
tree | 185e6f200acbde5cc6ed8c34e8fedf1e6343f718 /src | |
parent | dc68b297ca9007e6ea9d96a23a58316c5aae0eb1 (diff) |
StateMachine: Warn about invalid childMode changes
In QML there is 1 way to set the childMode property on a state
machine, so for invalid values we can generate a nice warning. The
fix for the behavior of the underlying QStateMachine is in
cfdbfcebbda5f26b89c70df6b191b17ef242e9d7
Task-number: QTBUG-49975
Change-Id: I142bdaed2e5336b95bf659066143ac6c2cadeb62
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/statemachine/statemachine.cpp | 13 | ||||
-rw-r--r-- | src/imports/statemachine/statemachine.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/imports/statemachine/statemachine.cpp b/src/imports/statemachine/statemachine.cpp index ca6c59b6ac..a983644018 100644 --- a/src/imports/statemachine/statemachine.cpp +++ b/src/imports/statemachine/statemachine.cpp @@ -51,6 +51,7 @@ StateMachine::StateMachine(QObject *parent) : QStateMachine(parent), m_completed(false), m_running(false) { connect(this, SIGNAL(runningChanged(bool)), SIGNAL(qmlRunningChanged())); + connect(this, SIGNAL(childModeChanged()), SLOT(checkChildMode())); } bool StateMachine::isRunning() const @@ -66,6 +67,15 @@ void StateMachine::setRunning(bool running) m_running = running; } +void StateMachine::checkChildMode() +{ + if (childMode() != QState::ExclusiveStates) { + qmlWarning(this) << "Setting the childMode of a StateMachine to anything else than\n" + "QState.ExclusiveStates will result in an invalid state machine,\n" + "and can lead to incorrect behavior!"; + } +} + void StateMachine::componentComplete() { if (QStateMachine::initialState() == nullptr && childMode() == QState::ExclusiveStates) @@ -129,6 +139,9 @@ QQmlListProperty<QObject> StateMachine::children() erroneous state, the machine will stop executing and an error message will be printed to the console. + \warning Setting the childMode of a StateMachine to anything else than QState::ExclusiveStates + will result in an invalid state machine, and can lead to incorrect behavior. + \clearfloat \sa QAbstractState, State, SignalTransition, TimeoutTransition, HistoryState {The Declarative State Machine Framework} diff --git a/src/imports/statemachine/statemachine.h b/src/imports/statemachine/statemachine.h index cb0ab43f8b..1fa7a9da43 100644 --- a/src/imports/statemachine/statemachine.h +++ b/src/imports/statemachine/statemachine.h @@ -69,6 +69,9 @@ public: bool isRunning() const; void setRunning(bool running); +private Q_SLOTS: + void checkChildMode(); + Q_SIGNALS: void childrenChanged(); /*! |