summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine/qhistorystate_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2015-06-18 16:45:32 +0200
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2015-07-23 13:29:46 +0000
commit5fd9fe02ff14438a2d0c93789be138a58583dbe8 (patch)
tree4532d254a6ae22834948c61b81c1876d8beb7719 /src/corelib/statemachine/qhistorystate_p.h
parent5329d739eed83cc9f430f9d97652743558ccd146 (diff)
QStateMachine: add defaultTransition in QHistoryState
The history state had the limitation that it was hard (or impossible) to use when more than one default state had to be entered. For example, using it in a parallel state was impossible without ending up in an infinite loop. This patch changes the QHistoryState to only have an initial transition, and the state selection algorithm is changed accordingly. It also brings QStateMachine closer to the SCXML standard. The existing defaultState is implemented on top of the defaultTransition: when used, a new transition, with the default state as its target, is set as the defaultTransition. Task-number: QTBUG-46703 Change-Id: Ifbb44e4f0f26b72e365af4c94753e4483f9850e7 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/corelib/statemachine/qhistorystate_p.h')
-rw-r--r--src/corelib/statemachine/qhistorystate_p.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/corelib/statemachine/qhistorystate_p.h b/src/corelib/statemachine/qhistorystate_p.h
index 57149e3f86..b0865f7f46 100644
--- a/src/corelib/statemachine/qhistorystate_p.h
+++ b/src/corelib/statemachine/qhistorystate_p.h
@@ -47,11 +47,12 @@
#include "private/qabstractstate_p.h"
+#include <QtCore/qabstracttransition.h>
+#include <QtCore/qhistorystate.h>
#include <QtCore/qlist.h>
QT_BEGIN_NAMESPACE
-class QHistoryState;
class QHistoryStatePrivate : public QAbstractStatePrivate
{
Q_DECLARE_PUBLIC(QHistoryState)
@@ -62,11 +63,28 @@ public:
static QHistoryStatePrivate *get(QHistoryState *q)
{ return q->d_func(); }
- QAbstractState *defaultState;
+ QAbstractTransition *defaultTransition;
QHistoryState::HistoryType historyType;
QList<QAbstractState*> configuration;
};
+class DefaultStateTransition: public QAbstractTransition
+{
+ Q_OBJECT
+
+public:
+ DefaultStateTransition(QHistoryState *source, QAbstractState *target);
+
+protected:
+ // It doesn't matter whether this transition matches any event or not. It is always associated
+ // with a QHistoryState, and as soon as the state-machine detects that it enters a history
+ // state, it will handle this transition as a special case. The history state itself is never
+ // entered either: either the stored configuration will be used, or the target(s) of this
+ // transition are used.
+ virtual bool eventTest(QEvent *event) { Q_UNUSED(event); return false; }
+ virtual void onTransition(QEvent *event) { Q_UNUSED(event); }
+};
+
QT_END_NAMESPACE
#endif