KDStateMachineEditor  1.0.0
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  Copyright (C) 2014-2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
5  All rights reserved.
6  Author: Kevin Funk <kevin.funk@kdab.com>
7 
8  Licensees holding valid commercial KDAB State Machine Editor Library
9  licenses may use this file in accordance with the KDAB State Machine Editor
10  Library License Agreement provided with the Software.
11 
12  This file may be distributed and/or modified under the terms of the
13  GNU Lesser General Public License version 2.1 as published by the
14  Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
15 
16  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 
19  Contact info@kdab.com if any conditions of this licensing are not
20  clear to you.
21 */
22 
23 #ifndef KDSME_MODEL_STATE_H
24 #define KDSME_MODEL_STATE_H
25 
26 #include "element.h"
27 
28 namespace KDSME {
29 
30 class RuntimeController;
31 class Transition;
32 class SignalTransition;
33 class TimeoutTransition;
34 
35 class KDSME_CORE_EXPORT State : public Element
36 {
37  Q_OBJECT
38  Q_ENUMS(ChildMode)
39  Q_PROPERTY(QString onEntry READ onEntry WRITE setOnEntry NOTIFY onEntryChanged FINAL)
40  Q_PROPERTY(QString onExit READ onExit WRITE setOnExit NOTIFY onExitChanged FINAL)
41  Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode NOTIFY childModeChanged FINAL)
42  Q_PROPERTY(bool isComposite READ isComposite NOTIFY isCompositeChanged FINAL)
43  Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged FINAL)
44 
45 public:
46  enum ChildMode {
47  ExclusiveStates,
48  ParallelStates,
49  };
50 
51  explicit State(State* parent = nullptr);
52  ~State();
53 
54  virtual Type type() const override;
55 
56  Q_INVOKABLE KDSME::State* parentState() const;
57 
58  State* initialState() const;
59  void setInitialState(State* initialState);
60 
61  QList<State*> childStates() const;
62 
63  QList<Transition*> transitions() const;
64  void addTransition(Transition* transition);
65  SignalTransition *addSignalTransition(State* target, const QString &silgnal = QString());
66  TimeoutTransition *addTimeoutTransition(State* target, int timeout);
67 
71  QString onEntry() const;
72  void setOnEntry(const QString& onEntry);
73 
77  QString onExit() const;
78  void setOnExit(const QString& onExit);
79 
80  ChildMode childMode() const;
81  void setChildMode(ChildMode childMode);
82 
86  bool isComposite() const;
87 
88  bool isExpanded() const;
89  void setExpanded(bool expanded);
90 
91  Q_INVOKABLE KDSME::StateMachine* machine() const;
92 
93 protected:
94  virtual bool event(QEvent* event) override;
95 
96 Q_SIGNALS:
97  void onEntryChanged(const QString& onEntry);
98  void onExitChanged(const QString& onExit);
99  void childModeChanged(ChildMode childMode);
100  void isCompositeChanged(bool isComposite);
101  void expandedChanged(bool expanded);
102 
103 private:
104  struct Private;
105  QScopedPointer<Private> d;
106 };
107 
108 class KDSME_CORE_EXPORT HistoryState : public State
109 {
110  Q_OBJECT
111  Q_ENUMS(HistoryType)
112  Q_PROPERTY(KDSME::State* defaultState READ defaultState WRITE setDefaultState NOTIFY defaultStateChanged FINAL)
113  Q_PROPERTY(HistoryType historyType READ historyType WRITE setHistoryType NOTIFY historyTypeChanged FINAL)
114 
115 public:
116  enum HistoryType {
117  ShallowHistory,
118  DeepHistory
119  };
120 
121  explicit HistoryState(State* parent = nullptr);
122  explicit HistoryState(HistoryType type, State* parent = nullptr);
123  virtual ~HistoryState();
124 
125  virtual Type type() const override;
126  virtual QString toDisplayString() const override;
127 
128  State* defaultState() const;
129  void setDefaultState(State *state);
130 
131  HistoryType historyType() const;
132  void setHistoryType(HistoryType historyType);
133 
134 Q_SIGNALS:
135  void defaultStateChanged(State *state);
136  void historyTypeChanged();
137 
138 private:
139  struct Private;
140  QScopedPointer<Private> d;
141 };
142 
143 KDSME_CORE_EXPORT QDebug operator<<(QDebug dbg, const State* representative);
144 
145 class KDSME_CORE_EXPORT FinalState : public State
146 {
147  Q_OBJECT
148 
149 public:
150  explicit FinalState(State* parent = nullptr);
151  virtual ~FinalState();
152 
153  virtual Type type() const override;
154 
155 private:
156  struct Private;
157  QScopedPointer<Private> d;
158 };
159 
160 class KDSME_CORE_EXPORT StateMachine : public State
161 {
162  Q_OBJECT
163  Q_PROPERTY(KDSME::RuntimeController* runtimeController READ runtimeController WRITE setRuntimeController NOTIFY runtimeControllerChanged)
164 
165 public:
166  explicit StateMachine(QObject* parent = nullptr);
167  virtual ~StateMachine();
168 
169  virtual Type type() const override;
170 
171  RuntimeController* runtimeController() const;
172  void setRuntimeController(RuntimeController* runtimeController);
173 
174 Q_SIGNALS:
175  void runtimeControllerChanged(RuntimeController* runtimeController);
176 
177 private:
178  struct Private;
179  QScopedPointer<Private> d;
180 };
181 
182 class KDSME_CORE_EXPORT PseudoState : public State
183 {
184  Q_OBJECT
185  Q_PROPERTY(Kind kind READ kind WRITE setKind NOTIFY kindChanged FINAL)
186 
187 public:
188  enum Kind {
189  InitialState
190  };
191  Q_ENUMS(Kind)
192 
193  explicit PseudoState(Kind kind = InitialState, State* parent = nullptr);
194  virtual ~PseudoState();
195 
196  virtual Type type() const override;
197 
198  Kind kind() const;
199  void setKind(Kind kind);
200 
201  QString kindString() const;
202 
203  virtual QString toDisplayString() const override;
204 
205 Q_SIGNALS:
206  void kindChanged(Kind kind);
207 
208 private:
209  struct Private;
210  QScopedPointer<Private> d;
211 };
212 
213 KDSME_CORE_EXPORT QDebug operator<<(QDebug dbg, const PseudoState* representative);
214 
215 }
216 
217 Q_DECLARE_METATYPE(KDSME::PseudoState::Kind)
218 
219 #endif
Definition: state.h:145
Definition: state.h:160
Definition: state.h:182
Definition: transition.h:82
Definition: state.h:108
Definition: state.h:35
Definition: transition.h:30
Definition: runtimecontroller.h:37
Definition: transition.h:104
Definition: element.h:41
Definition: abstractexporter.h:33

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
https://github.com/KDAB/KDStateMachineEditor