Libksysguard

SensorTreeModel.h
1/*
2 SPDX-FileCopyrightText: 2019 Eike Hein <hein@kde.org>
3 SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "sensors_export.h"
11#include <QAbstractItemModel>
12#include <memory>
13
14namespace KSysGuard
15{
16class SensorInfo;
17
18/**
19 * A model representing a tree of sensors that are available from the daemon.
20 *
21 * This model exposes the daemon's sensors as a tree, based on their path. Each
22 * sensor is assumed to be structured in a format similar to
23 * `category/object/sensor`. This model will then expose a tree, with `category`
24 * as top level, `object` below it and finally `sensor` itself.
25 */
26class SENSORS_EXPORT SensorTreeModel : public QAbstractItemModel
27{
28 Q_OBJECT
29
30public:
31 enum AdditionalRoles {
32 SensorId = Qt::UserRole + 1,
33 };
34 Q_ENUM(AdditionalRoles)
35
36 explicit SensorTreeModel(QObject *parent = nullptr);
37 ~SensorTreeModel() override;
38
39 QHash<int, QByteArray> roleNames() const override;
40 QVariant headerData(int section, Qt::Orientation, int role) const override;
41 QStringList mimeTypes() const override;
42
43 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
44 QMimeData *mimeData(const QModelIndexList &indexes) const override;
45
46 Qt::ItemFlags flags(const QModelIndex &index) const override;
47
48 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
49 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
50
51 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
52 QModelIndex parent(const QModelIndex &index) const override;
53
54private:
55 void init();
56 void onSensorAdded(const QString &sensor);
57 void onSensorRemoved(const QString &sensor);
58 void onMetaDataChanged(const QString &sensorId, const SensorInfo &info);
59
60 class Private;
61 const std::unique_ptr<Private> d;
62};
63
64}
A model representing a tree of sensors that are available from the daemon.
UserRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.