CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
DataObject.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_DATAOBJECT_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_DATAOBJECT_HPP
3 
4 #include "internal/common.hpp"
5 
6 #include <cutehmi/InplaceError.hpp>
7 #include <cutehmi/shareddatabase/DatabaseWorker.hpp>
8 
9 #include <QObject>
10 #include <QVector>
11 #include <QSqlQuery>
12 #include <QSqlError>
13 #include <QMutex>
14 
15 namespace cutehmi {
16 namespace dataacquisition {
17 
21 class CUTEHMI_DATAACQUISITION_API DataObject:
22  public QObject
23 {
24  Q_OBJECT
25 
26  public:
30  Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName RESET resetConnectionName NOTIFY connectionNameChanged)
31 
32 
35  Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
36 
37  DataObject(QObject * parent = nullptr);
38 
39  QString connectionName() const;
40 
41  void setConnectionName(const QString & connectionName);
42 
43  void resetConnectionName();
44 
45  bool busy() const;
46 
47  signals:
48  void connectionNameChanged();
49 
50  void busyChanged();
51 
52  void errored(cutehmi::InplaceError error);
53 
54  protected:
61  void pushError(const QSqlError & sqlError);
62 
72  shareddatabase::DatabaseWorker * worker(std::function<void(QSqlDatabase & db)> task) const;
73 
74  protected slots:
78  void incrementBusy();
79 
83  void decrementBusy();
84 
91  virtual void processErrors();
92 
97  void printError(cutehmi::InplaceError error) const;
98 
99  private slots:
100  void onDatabaseWorkerStriked(const QString & reason);
101 
102  private:
104 
105  struct Members
106  {
107  QString connectionName;
108  mutable QMutex sqlErrorsMutex;
109  SQLErrorsContainer sqlErrors;
110  int busy;
111 
112  Members():
113  busy(0)
114  {
115  }
116  };
117 
118  MPtr<Members> m;
119 };
120 
121 }
122 }
123 
124 #endif
125 
126 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
127 //(c)C: This file is a part of CuteHMI.
128 //(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.
129 //(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.
130 //(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/>.
QMutex
cutehmi::dataacquisition::DataObject
Database object.
Definition: DataObject.hpp:21
QSqlError
QSqlDatabase
cutehmi::InplaceError
cutehmi::MPtr< Members >
QObject
cutehmi
QString
std
QVector