CuteHMI - Services (CuteHMI.Services.2)
ServiceListModel.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICELISTMODEL_HPP
2 #define H_EXTENSIONS_CUTEHMI_SERVICES_2_INCLUDE_CUTEHMI_SERVICES_SERVICELISTMODEL_HPP
3 
4 #include "internal/common.hpp"
5 #include "Service.hpp"
6 
7 #include <QAbstractListModel>
8 
9 namespace cutehmi {
10 namespace services {
11 
15 class CUTEHMI_SERVICES_API ServiceListModel:
16  public QAbstractListModel
17 {
18  Q_OBJECT
19  typedef QAbstractListModel Parent;
20 
21  public:
22  enum Role {
23  NAME_ROLE = Qt::UserRole,
24  STATUS_ROLE
25  };
26 
27  ServiceListModel(QObject * parent = nullptr);
28 
29  ~ServiceListModel() override;
30 
31  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
32 
33  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
34 
35  QHash<int, QByteArray> roleNames() const override;
36 
37  Q_INVOKABLE Service * at(int row);
38 
39  const Service * at(int row) const;
40 
41  void append(Service * service);
42 
43  void remove(Service * service);
44 
45  void clear();
46 
47  private:
48  typedef QList<Service *> ServicesContainer;
49 
50  struct Members
51  {
52  ServicesContainer services;
53  };
54 
55  MPtr<Members> m;
56 };
57 
58 }
59 }
60 
61 #endif
62 
63 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
64 //(c)C: This file is a part of CuteHMI.
65 //(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.
66 //(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.
67 //(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/>.
cutehmi::services::Service
Service.
Definition: Service.hpp:22
QAbstractListModel
QList< Service * >
cutehmi::MPtr< Members >
QObject
cutehmi
cutehmi::services::ServiceListModel::Role
Role
Definition: ServiceListModel.hpp:22
QModelIndex
QVariant
QHash
cutehmi::services::ServiceListModel
Notification list model.
Definition: ServiceListModel.hpp:15