Libksysguard

SensorUnitModel.h
1/*
2 * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#pragma once
8
9#include <memory>
10
11#include <QAbstractListModel>
12#include <qqmlregistration.h>
13
14#include "sensors_export.h"
15
16namespace KSysGuard
17{
18class SensorInfo;
19
20/**
21 * A model that lists the units for a given list of sensors.
22 *
23 * This model will provide a list of units for a given list of sensors. It
24 * includes all the prefixes starting at the base unit of a sensor. For example,
25 * for a sensor with unit "bytes" it will list "bytes", "kilobytes", "megabytes"
26 * etc. If instead the unit were "megabytes", the model would list "megabytes",
27 * "gigabytes", etc. The units for all sensors are listed, with duplicates
28 * removed. They are sorted based on the order of units in Formatter's Unit.h.
29 *
30 * Three roles are exposed:
31 * - "unit": The actual Unit enum value for this unit.
32 * - "symbol": The textual symbol for the unit, like "KiB/s".
33 * - "multiplier": The multiplier to apply to the unit value to convert it to
34 * the base unit. For example, to convert from kilobytes to
35 * bytes the multiplier would be 1024.
36 */
37class SENSORS_EXPORT SensorUnitModel : public QAbstractListModel
38{
39 Q_OBJECT
40 QML_ELEMENT
41 /**
42 * The list of sensors to list units for.
43 */
44 Q_PROPERTY(QStringList sensors READ sensors WRITE setSensors NOTIFY sensorsChanged)
45 /**
46 * Indicates the model has retrieved all the information of the requested sensors.
47 *
48 * This will be false right after setting the value of `sensors`. It will
49 * change to true once the information for all sensors has been retrieved.
50 */
51 Q_PROPERTY(bool ready READ ready NOTIFY readyChanged)
52
53public:
54 enum Roles {
55 UnitRole = Qt::UserRole,
56 SymbolRole,
57 MultiplierRole,
58 };
59 Q_ENUM(Roles)
60
61 SensorUnitModel(QObject *parent = nullptr);
62 ~SensorUnitModel() override;
63
64 QStringList sensors() const;
65 void setSensors(const QStringList &newSensors);
66 Q_SIGNAL void sensorsChanged();
67
68 bool ready() const;
69 Q_SIGNAL void readyChanged();
70
71 QHash<int, QByteArray> roleNames() const override;
72
73 int rowCount(const QModelIndex &parent) const override;
74 QVariant data(const QModelIndex &index, int role) const override;
75
76private:
77 void metaDataChanged(const QString &id, const SensorInfo &info);
78
79 class Private;
80 const std::unique_ptr<Private> d;
81};
82
83}
A model that lists the units for a given list of sensors.
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.