Libksysguard

FaceLoader.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 <QJsonArray>
10#include <QObject>
11#include <QQmlParserStatus>
12
13#include "SensorFaceController.h"
14#include "sensorfaces_export.h"
15
16namespace KSysGuard
17{
18
19/**
20 * A helper class to make it easier to load faces when used inside a face.
21 *
22 * This is primarily intended to support use cases where there is a sensor face
23 * that wants to load a different face as a child, for example the Grid face
24 * uses this to creates individual faces for each grid cell.
25 *
26 * This will create a new SensorFaceController that makes use of the
27 * parentController's config group for reading settings. The child group name
28 * is set by the groupName property. By default, the new controller is read
29 * only and does not write to the config group.
30 */
31class SENSORFACES_EXPORT FaceLoader : public QObject, public QQmlParserStatus
32{
33 Q_OBJECT
34 QML_ELEMENT
35 Q_INTERFACES(QQmlParserStatus)
36 /**
37 * The parent SensorFaceController that will be used for configuration storage.
38 */
39 Q_PROPERTY(KSysGuard::SensorFaceController *parentController READ parentController WRITE setParentController NOTIFY parentControllerChanged)
40 /**
41 * The name of the config group to read configuration from.
42 */
43 Q_PROPERTY(QString groupName READ groupName WRITE setGroupName NOTIFY groupNameChanged)
44 /**
45 * The sensors to use for this face.
46 *
47 * This will set `highPrioritySensorIds` on the internal SensorFaceController.
48 */
49 Q_PROPERTY(QJsonArray sensors READ sensors WRITE setSensors NOTIFY sensorsChanged)
50 /**
51 * The face to use.
52 *
53 * This sets the faceId of the internal SensorFaceController.
54 */
55 Q_PROPERTY(QString faceId READ faceId WRITE setFaceId NOTIFY faceIdChanged)
56 /**
57 * A map of sensor colors to be used by the face.
58 *
59 * This forwards to the internal SensorFaceController.
60 */
61 Q_PROPERTY(QVariantMap colors READ colors WRITE setColors NOTIFY colorsChanged)
62 /**
63 * A map of sensor labels to be used by the face.
64 *
65 * This forwards to the internal SensorFaceController.
66 */
67 Q_PROPERTY(QVariantMap labels READ labels WRITE setLabels NOTIFY labelsChanged)
68 /**
69 * The minimum time that needs to elapse, in milliseconds, between updates of the face.
70 *
71 * This forward to the internal SensorFaceController.
72 */
73 Q_PROPERTY(int updateRateLimit READ updateRateLimit WRITE setUpdateRateLimit NOTIFY updateRateLimitChanged)
74 /**
75 * Whether to allow modifying the face configuration.
76 *
77 * If false (the default), any changes to configuration will be ignored. If
78 * true, changes will be written and stored in the config group.
79 *
80 * \note If multiple FaceLoaders share the same configuration, the face will
81 * need to be recreated after configuration has changed, as there is
82 * currently no way to properly reload the configuration.
83 */
84 Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
85 /**
86 * The face controller that provides the loaded face.
87 */
88 Q_PROPERTY(KSysGuard::SensorFaceController *controller READ controller NOTIFY controllerChanged)
89
90public:
91 FaceLoader(QObject *parent = nullptr);
92 ~FaceLoader() override;
93
94 SensorFaceController *parentController() const;
95 void setParentController(SensorFaceController *newParentController);
96 Q_SIGNAL void parentControllerChanged();
97
98 QString groupName() const;
99 void setGroupName(const QString &newGroupName);
100 Q_SIGNAL void groupNameChanged();
101
102 QJsonArray sensors() const;
103 void setSensors(const QJsonArray &newSensors);
104 Q_SIGNAL void sensorsChanged();
105
106 QString faceId() const;
107 void setFaceId(const QString &newFaceId);
108 Q_SIGNAL void faceIdChanged();
109
110 QVariantMap colors() const;
111 void setColors(const QVariantMap &newColors);
112 Q_SIGNAL void colorsChanged();
113
114 QVariantMap labels() const;
115 void setLabels(const QVariantMap &newLabels);
116 Q_SIGNAL void labelsChanged();
117
118 int updateRateLimit() const;
119 void setUpdateRateLimit(int limit);
120 Q_SIGNAL void updateRateLimitChanged();
121
122 bool readOnly() const;
123 void setReadOnly(bool newReadOnly);
124 Q_SIGNAL void readOnlyChanged();
125
126 SensorFaceController *controller() const;
127 Q_SIGNAL void controllerChanged();
128
129 Q_INVOKABLE void reload();
130
131 void classBegin() override;
132 void componentComplete() override;
133
134private:
135 class Private;
136 const std::unique_ptr<Private> d;
137};
138
139}
A helper class to make it easier to load faces when used inside a face.
Definition FaceLoader.h:32
The SensorFaceController links sensor faces and applications in which these faces are shown.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.