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

KDE's Doxygen guidelines are available online.