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