KDStateMachineEditor API Documentation  1.2.9
A framework for creating Qt State Machine metacode using a graphical user interface
state.h
1 /*
2  This file is part of the KDAB State Machine Editor Library.
3 
4  SPDX-FileCopyrightText: 2014-2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5  Author: Kevin Funk <kevin.funk@kdab.com>
6 
7  SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8 
9  Licensees holding valid commercial KDAB State Machine Editor Library
10  licenses may use this file in accordance with the KDAB State Machine Editor
11  Library License Agreement provided with the Software.
12 
13  Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 */
15 
16 #ifndef KDSME_MODEL_STATE_H
17 #define KDSME_MODEL_STATE_H
18 
19 #include "element.h"
20 
21 namespace KDSME {
22 
23 class RuntimeController;
24 class Transition;
25 class SignalTransition;
26 class TimeoutTransition;
27 
28 class KDSME_CORE_EXPORT State : public Element
29 {
30  Q_OBJECT
31  Q_ENUMS(ChildMode)
32  Q_PROPERTY(QString onEntry READ onEntry WRITE setOnEntry NOTIFY onEntryChanged FINAL)
33  Q_PROPERTY(QString onExit READ onExit WRITE setOnExit NOTIFY onExitChanged FINAL)
34  Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode NOTIFY childModeChanged FINAL)
35  Q_PROPERTY(bool isComposite READ isComposite NOTIFY isCompositeChanged FINAL)
36  Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged FINAL)
37 
38 public:
39  enum ChildMode {
40  ExclusiveStates,
41  ParallelStates,
42  };
43 
44  explicit State(State* parent = nullptr);
45  ~State();
46 
47  Type type() const override;
48 
49  Q_INVOKABLE KDSME::State* parentState() const;
50 
51  State* initialState() const;
52  void setInitialState(State* initialState);
53 
54  QList<State*> childStates() const;
55 
56  QList<Transition*> transitions() const;
57  void addTransition(Transition* transition);
58  SignalTransition *addSignalTransition(State* target, const QString &silgnal = QString());
59  TimeoutTransition *addTimeoutTransition(State* target, int timeout);
60 
64  QString onEntry() const;
65  void setOnEntry(const QString& onEntry);
66 
70  QString onExit() const;
71  void setOnExit(const QString& onExit);
72 
73  ChildMode childMode() const;
74  void setChildMode(ChildMode childMode);
75 
79  bool isComposite() const;
80 
81  bool isExpanded() const;
82  void setExpanded(bool expanded);
83 
84  Q_INVOKABLE KDSME::StateMachine* machine() const;
85 
86 protected:
87  bool event(QEvent* event) override;
88 
89 Q_SIGNALS:
90  void onEntryChanged(const QString& onEntry);
91  void onExitChanged(const QString& onExit);
92  void childModeChanged(ChildMode childMode);
93  void isCompositeChanged(bool isComposite);
94  void expandedChanged(bool expanded);
95 
96 private:
97  struct Private;
99 };
100 
101 class KDSME_CORE_EXPORT HistoryState : public State
102 {
103  Q_OBJECT
104  Q_ENUMS(HistoryType)
105  Q_PROPERTY(KDSME::State* defaultState READ defaultState WRITE setDefaultState NOTIFY defaultStateChanged FINAL)
106  Q_PROPERTY(HistoryType historyType READ historyType WRITE setHistoryType NOTIFY historyTypeChanged FINAL)
107 
108 public:
109  enum HistoryType {
110  ShallowHistory,
111  DeepHistory
112  };
113 
114  explicit HistoryState(State* parent = nullptr);
115  explicit HistoryState(HistoryType type, State* parent = nullptr);
116  ~HistoryState();
117 
118  Type type() const override;
119  QString toDisplayString() const override;
120 
121  State* defaultState() const;
122  void setDefaultState(State *state);
123 
124  HistoryType historyType() const;
125  void setHistoryType(HistoryType historyType);
126 
127 Q_SIGNALS:
128  void defaultStateChanged(State *state);
129  void historyTypeChanged();
130 
131 private:
132  struct Private;
134 };
135 
136 KDSME_CORE_EXPORT QDebug operator<<(QDebug dbg, const State* state);
137 
138 class KDSME_CORE_EXPORT FinalState : public State
139 {
140  Q_OBJECT
141 
142 public:
143  explicit FinalState(State* parent = nullptr);
144  ~FinalState();
145 
146  Type type() const override;
147 
148 private:
149  struct Private;
151 };
152 
153 class KDSME_CORE_EXPORT StateMachine : public State
154 {
155  Q_OBJECT
156  Q_PROPERTY(KDSME::RuntimeController* runtimeController READ runtimeController WRITE setRuntimeController NOTIFY runtimeControllerChanged)
157 
158 public:
159  explicit StateMachine(QObject* parent = nullptr);
160  ~StateMachine();
161 
162  Type type() const override;
163 
164  RuntimeController* runtimeController() const;
165  void setRuntimeController(RuntimeController* runtimeController);
166 
167 Q_SIGNALS:
168  void runtimeControllerChanged(RuntimeController* runtimeController);
169 
170 private:
171  struct Private;
173 };
174 
175 class KDSME_CORE_EXPORT PseudoState : public State
176 {
177  Q_OBJECT
178  Q_PROPERTY(Kind kind READ kind WRITE setKind NOTIFY kindChanged FINAL)
179 
180 public:
181  enum Kind {
182  InitialState
183  };
184  Q_ENUMS(Kind)
185 
186  explicit PseudoState(Kind kind = InitialState, State* parent = nullptr);
187  ~PseudoState();
188 
189  Type type() const override;
190 
191  Kind kind() const;
192  void setKind(Kind kind);
193 
194  QString kindString() const;
195 
196  QString toDisplayString() const override;
197 
198 Q_SIGNALS:
199  void kindChanged(Kind kind);
200 
201 private:
202  struct Private;
204 };
205 
206 KDSME_CORE_EXPORT QDebug operator<<(QDebug dbg, const PseudoState* state);
207 
208 }
209 
210 Q_DECLARE_METATYPE(KDSME::PseudoState::Kind)
211 
212 #endif
Definition: state.h:138
Definition: state.h:153
Definition: state.h:175
Definition: transition.h:75
Definition: state.h:101
Definition: state.h:28
Definition: transition.h:23
Definition: runtimecontroller.h:30
Definition: transition.h:97
Definition: element.h:34
Definition: mainwindow.h:21

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor