Changeset View
Changeset View
Standalone View
Standalone View
sensors/SensorTreeModel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2019 Eike Hein <hein@kde.org> | ||||
3 | Copyright (C) 2020 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Library General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2 of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <memory> | ||||
24 | #include <QAbstractItemModel> | ||||
25 | #include "sensors_export.h" | ||||
26 | | ||||
27 | namespace KSysGuard | ||||
28 | { | ||||
29 | | ||||
30 | class SensorInfo; | ||||
31 | | ||||
32 | /** | ||||
33 | * A model representing a tree of sensors that are available from the daemon. | ||||
34 | * | ||||
35 | * This model exposes the daemon's sensors as a tree, based on their path. Each | ||||
36 | * sensor is assumed to be structured in a format similar to | ||||
37 | * `category/object/sensor`. This model will then expose a tree, with `category` | ||||
38 | * as top level, `object` below it and finally `sensor` itself. | ||||
39 | */ | ||||
40 | class SENSORS_EXPORT SensorTreeModel : public QAbstractItemModel | ||||
41 | { | ||||
42 | Q_OBJECT | ||||
43 | | ||||
44 | public: | ||||
45 | enum AdditionalRoles { | ||||
46 | SensorId = Qt::UserRole + 1, | ||||
47 | }; | ||||
48 | Q_ENUM(AdditionalRoles) | ||||
49 | | ||||
50 | explicit SensorTreeModel(QObject *parent = nullptr); | ||||
51 | virtual ~SensorTreeModel(); | ||||
52 | | ||||
53 | QHash<int, QByteArray> roleNames() const override; | ||||
54 | QVariant headerData(int section, Qt::Orientation, int role) const override; | ||||
55 | QStringList mimeTypes() const override; | ||||
56 | | ||||
57 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
58 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | ||||
59 | | ||||
60 | Qt::ItemFlags flags(const QModelIndex &index) const override; | ||||
61 | | ||||
62 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
63 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
64 | | ||||
65 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||||
66 | QModelIndex parent(const QModelIndex &index) const override; | ||||
67 | | ||||
68 | | ||||
69 | private: | ||||
70 | void init(); | ||||
71 | void onSensorAdded(const QString &sensor); | ||||
72 | void onSensorRemoved(const QString &sensor); | ||||
73 | void onMetaDataChanged(const QString &sensorId, const SensorInfo &info); | ||||
74 | | ||||
75 | class Private; | ||||
76 | const std::unique_ptr<Private> d; | ||||
77 | }; | ||||
78 | | ||||
79 | } |