CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
AbstractListModel.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_ABSTRACTLISTMODEL_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_ABSTRACTLISTMODEL_HPP
3 
4 #include "internal/common.hpp"
5 #include "internal/DbServiceableMixin.hpp"
6 #include "Schema.hpp"
7 
8 #include <cutehmi/services/Serviceable.hpp>
9 
10 #include <QAbstractListModel>
11 
12 namespace cutehmi {
13 namespace dataacquisition {
14 
15 class CUTEHMI_DATAACQUISITION_API AbstractListModel:
16  public QAbstractListModel,
17  public services::Serviceable,
18  private internal::DbServiceableMixin<AbstractListModel>
19 {
20  Q_OBJECT
21 
23 
24  public:
25  static constexpr int INITIAL_INTERVAL = 1000;
26 
30  Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
31 
32 
38  Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
39 
40  Q_PROPERTY(cutehmi::dataacquisition::Schema * schema READ schema WRITE setSchema NOTIFY schemaChanged)
41 
42  AbstractListModel(QObject * parent = nullptr);
43 
44  virtual bool busy() const = 0;
45 
46  int interval() const;
47 
48  void setInterval(int interval);
49 
50  Schema * schema() const;
51 
52  void setSchema(Schema * schema);
53 
54  std::unique_ptr<ServiceStatuses> configureStarting(QState * starting) override;
55 
56  std::unique_ptr<ServiceStatuses> configureStarted(QState * active, const QState * idling, const QState * yielding) override;
57 
58  std::unique_ptr<ServiceStatuses> configureStopping(QState * stopping) override;
59 
60  std::unique_ptr<ServiceStatuses> configureBroken(QState * broken) override;
61 
62  std::unique_ptr<ServiceStatuses> configureRepairing(QState * repairing) override;
63 
64  std::unique_ptr<ServiceStatuses> configureEvacuating(QState * evacuating) override;
65 
66  std::unique_ptr<QAbstractTransition> transitionToStarted() const override;
67 
68  std::unique_ptr<QAbstractTransition> transitionToStopped() const override;
69 
70  std::unique_ptr<QAbstractTransition> transitionToBroken() const override;
71 
72  std::unique_ptr<QAbstractTransition> transitionToYielding() const override;
73 
74  std::unique_ptr<QAbstractTransition> transitionToIdling() const override;
75 
76  public slots:
77  virtual void requestUpdate() = 0;
78 
79  signals:
80  void intervalChanged();
81 
82  void schemaChanged();
83 
84  void busyChanged();
85 
86  protected slots:
87  virtual void confirmUpdateFinished() = 0;
88 
89  CUTEHMI_PROTECTED_SIGNALS:
90  void broke();
91 
92  void started();
93 
94  void stopped();
95 
96  void databaseConnected();
97 
98  void schemaValidated();
99 
100  void updateTimerStarted();
101 
102  void updateTimerStopped();
103 
104  void updateFinished();
105 
106 
107  private slots:
108  void onSchemaValidated(bool result);
109 
110  void startUpdateTimer();
111 
112  void stopUpdateTimer();
113 
114  private:
115  std::unique_ptr<services::Serviceable::ServiceStatuses> configureStartingOrRepairing(QState * parent);
116 
117  struct Members {
118  Schema * schema;
119  int interval;
120  QTimer updateTimer;
121 
122  Members():
123  schema(nullptr),
124  interval(INITIAL_INTERVAL)
125  {
126  }
127  };
128 
129  MPtr<Members> m;
130 };
131 
132 }
133 }
134 
135 #endif
136 
137 //(c)C: Copyright © 2020-2021, Michał Policht <michal@policht.pl>. All rights reserved.
138 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
139 //(c)C: This file is a part of CuteHMI.
140 //(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.
141 //(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.
142 //(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/>.
143 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
144 //(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:
145 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
146 //(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.
QTimer
QState
QAbstractListModel
cutehmi::dataacquisition::AbstractListModel
Definition: AbstractListModel.hpp:15
cutehmi::MPtr< Members >
QObject
cutehmi
cutehmi::services::Serviceable
QAbstractTransition
std
cutehmi::dataacquisition::Schema
Database schema.
Definition: Schema.hpp:14
QHash
cutehmi::dataacquisition::internal::DbServiceableMixin
Definition: DbServiceableMixin.hpp:16