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 "sensors_export.h" | ||||
24 | #include <QAbstractItemModel> | ||||
25 | #include <memory> | ||||
26 | | ||||
27 | namespace KSysGuard | ||||
28 | { | ||||
29 | class SensorInfo; | ||||
30 | | ||||
31 | /** | ||||
32 | * A model representing a tree of sensors that are available from the daemon. | ||||
33 | * | ||||
34 | * This model exposes the daemon's sensors as a tree, based on their path. Each | ||||
35 | * sensor is assumed to be structured in a format similar to | ||||
36 | * `category/object/sensor`. This model will then expose a tree, with `category` | ||||
37 | * as top level, `object` below it and finally `sensor` itself. | ||||
38 | */ | ||||
39 | class SENSORS_EXPORT SensorTreeModel : public QAbstractItemModel | ||||
40 | { | ||||
41 | Q_OBJECT | ||||
42 | | ||||
43 | public: | ||||
44 | enum AdditionalRoles { | ||||
45 | SensorId = Qt::UserRole + 1, | ||||
46 | }; | ||||
47 | Q_ENUM(AdditionalRoles) | ||||
48 | | ||||
49 | explicit SensorTreeModel(QObject *parent = nullptr); | ||||
50 | virtual ~SensorTreeModel(); | ||||
51 | | ||||
52 | QHash<int, QByteArray> roleNames() const override; | ||||
53 | QVariant headerData(int section, Qt::Orientation, int role) const override; | ||||
54 | QStringList mimeTypes() const override; | ||||
55 | | ||||
56 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
57 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | ||||
58 | | ||||
59 | Qt::ItemFlags flags(const QModelIndex &index) const override; | ||||
60 | | ||||
61 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
62 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
63 | | ||||
64 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||||
65 | QModelIndex parent(const QModelIndex &index) const override; | ||||
66 | | ||||
67 | private: | ||||
68 | void init(); | ||||
69 | void onSensorAdded(const QString &sensor); | ||||
70 | void onSensorRemoved(const QString &sensor); | ||||
71 | void onMetaDataChanged(const QString &sensorId, const SensorInfo &info); | ||||
72 | | ||||
73 | class Private; | ||||
74 | const std::unique_ptr<Private> d; | ||||
75 | }; | ||||
76 | | ||||
77 | } |