File indexing completed on 2024-04-21 05:31:42
0001 /* 0002 SPDX-FileCopyrightText: 2019 Eike Hein <hein@kde.org> 0003 SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "sensors_export.h" 0011 #include <QAbstractItemModel> 0012 #include <memory> 0013 0014 namespace KSysGuard 0015 { 0016 class SensorInfo; 0017 0018 /** 0019 * A model representing a tree of sensors that are available from the daemon. 0020 * 0021 * This model exposes the daemon's sensors as a tree, based on their path. Each 0022 * sensor is assumed to be structured in a format similar to 0023 * `category/object/sensor`. This model will then expose a tree, with `category` 0024 * as top level, `object` below it and finally `sensor` itself. 0025 */ 0026 class SENSORS_EXPORT SensorTreeModel : public QAbstractItemModel 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 enum AdditionalRoles { 0032 SensorId = Qt::UserRole + 1, 0033 }; 0034 Q_ENUM(AdditionalRoles) 0035 0036 explicit SensorTreeModel(QObject *parent = nullptr); 0037 ~SensorTreeModel() override; 0038 0039 QHash<int, QByteArray> roleNames() const override; 0040 QVariant headerData(int section, Qt::Orientation, int role) const override; 0041 QStringList mimeTypes() const override; 0042 0043 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0044 QMimeData *mimeData(const QModelIndexList &indexes) const override; 0045 0046 Qt::ItemFlags flags(const QModelIndex &index) const override; 0047 0048 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0049 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0050 0051 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0052 QModelIndex parent(const QModelIndex &index) const override; 0053 0054 private: 0055 void init(); 0056 void onSensorAdded(const QString &sensor); 0057 void onSensorRemoved(const QString &sensor); 0058 void onMetaDataChanged(const QString &sensorId, const SensorInfo &info); 0059 0060 class Private; 0061 const std::unique_ptr<Private> d; 0062 }; 0063 0064 }