CuteHMI - Services (CuteHMI.Services.2)
StateInterface.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_INTERNAL_STATEINTERFACE_HPP
2 #define H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_INTERNAL_STATEINTERFACE_HPP
3 
4 #include "common.hpp"
5 
6 #include <QObject>
7 #include <QState>
8 #include <QSignalTransition>
9 
10 #include <array>
11 
12 namespace cutehmi {
13 namespace services {
14 namespace internal {
15 
16 class CUTEHMI_SERVICES_API StateInterface:
17  public QObject
18 {
19  Q_OBJECT
20 
21  public:
22  Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged)
23 
24  StateInterface(QObject * parent = nullptr);
25 
26  QString status() const;
27 
28  void setStatus(const QString & status);
29 
30  Q_INVOKABLE QAbstractState * find(const QString & name);
31 
32  QState & stopped();
33 
34  const QState & stopped() const;
35 
36  QState & interrupted();
37 
38  const QState & interrupted() const;
39 
40  QState & starting();
41 
42  const QState & starting() const;
43 
44  QState & started();
45 
46  const QState & started() const;
47 
48  QState & idling();
49 
50  const QState & idling() const;
51 
52  QState & yielding();
53 
54  const QState & yielding() const;
55 
56  QState & active();
57 
58  const QState & active() const;
59 
60  QState & stopping();
61 
62  const QState & stopping() const;
63 
64  QState & broken();
65 
66  const QState & borken() const;
67 
68  QState & repairing();
69 
70  const QState & repairing() const;
71 
72  QState & evacuating();
73 
74  const QState & evacuating() const;
75 
76  signals:
77  void statusChanged();
78 
79  private:
80  struct Members
81  {
82  enum MainStateNames : std::size_t {
83  STOPPED = 0,
84  INTERRUPTED,
85  STARTING,
86  STARTED,
87  STOPPING,
88  BROKEN,
89  REPAIRING,
90  EVACUATING
91  };
92 
93  typedef std::array<QState, 8> MainStatesContainer;
94 
95  MainStatesContainer mainStates;
96  QString status;
97  QState * idling;
98  QState * yielding;
99  QState * active;
100 
101  Members():
102  mainStates{},
103  idling(new QState(& mainStates[STARTED])),
104  yielding(new QState(& mainStates[STARTED])),
105  active(new QState(& mainStates[STARTED]))
106  {
107  }
108  };
109 
110  MPtr<Members> m;
111 };
112 
113 }
114 }
115 }
116 
117 #endif
118 
119 //(c)C: Copyright © 2019-2020, Michał Policht <michal@policht.pl>. All rights reserved.
120 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
121 //(c)C: This file is a part of CuteHMI.
122 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
123 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
124 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
125 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
126 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
127 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
128 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
QAbstractState
QState
cutehmi::services::internal::StateInterface
Definition: StateInterface.hpp:16
MPtr< Members >
QObject
cutehmi
QString
std::array< QState, 8 >
std::size_t