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
13#include "sensors_export.h"
14
15namespace KSysGuard
16{
17class SensorInfo;
18
19/**
20 * A model that lists the units for a given list of sensors.
21 *
22 * This model will provide a list of units for a given list of sensors. It
23 * includes all the prefixes starting at the base unit of a sensor. For example,
24 * for a sensor with unit "bytes" it will list "bytes", "kilobytes", "megabytes"
25 * etc. If instead the unit were "megabytes", the model would list "megabytes",
26 * "gigabytes", etc. The units for all sensors are listed, with duplicates
27 * removed. They are sorted based on the order of units in Formatter's Unit.h.
28 *
29 * Three roles are exposed:
30 * - "unit": The actual Unit enum value for this unit.
31 * - "symbol": The textual symbol for the unit, like "KiB/s".
32 * - "multiplier": The multiplier to apply to the unit value to convert it to
33 * the base unit. For example, to convert from kilobytes to
34 * bytes the multiplier would be 1024.
35 */
36class SENSORS_EXPORT SensorUnitModel : public QAbstractListModel
37{
38 Q_OBJECT
39 /**
40 * The list of sensors to list units for.
41 */
42 Q_PROPERTY(QStringList sensors READ sensors WRITE setSensors NOTIFY sensorsChanged)
43 /**
44 * Indicates the model has retrieved all the information of the requested sensors.
45 *
46 * This will be false right after setting the value of `sensors`. It will
47 * change to true once the information for all sensors has been retrieved.
48 */
49 Q_PROPERTY(bool ready READ ready NOTIFY readyChanged)
50
51public:
52 enum Roles {
53 UnitRole = Qt::UserRole,
54 SymbolRole,
55 MultiplierRole,
56 };
57 Q_ENUM(Roles)
58
59 SensorUnitModel(QObject *parent = nullptr);
60 ~SensorUnitModel() override;
61
62 QStringList sensors() const;
63 void setSensors(const QStringList &newSensors);
64 Q_SIGNAL void sensorsChanged();
65
66 bool ready() const;
67 Q_SIGNAL void readyChanged();
68
69 QHash<int, QByteArray> roleNames() const override;
70
71 virtual int rowCount(const QModelIndex &parent) const override;
72 virtual QVariant data(const QModelIndex &index, int role) const override;
73
74private:
75 void metaDataChanged(const QString &id, const SensorInfo &info);
76
77 class Private;
78 const std::unique_ptr<Private> d;
79};
80
81}
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 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.