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 * Whether to allow modifying the face configuration.
70 *
71 * If false (the default), any changes to configuration will be ignored. If
72 * true, changes will be written and stored in the config group.
73 *
74 * \note If multiple FaceLoaders share the same configuration, the face will
75 * need to be recreated after configuration has changed, as there is
76 * currently no way to properly reload the configuration.
77 */
78 Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
79 /**
80 * The face controller that provides the loaded face.
81 */
82 Q_PROPERTY(KSysGuard::SensorFaceController *controller READ controller NOTIFY controllerChanged)
83
84public:
85 FaceLoader(QObject *parent = nullptr);
86 ~FaceLoader() override;
87
88 SensorFaceController *parentController() const;
89 void setParentController(SensorFaceController *newParentController);
90 Q_SIGNAL void parentControllerChanged();
91
92 QString groupName() const;
93 void setGroupName(const QString &newGroupName);
94 Q_SIGNAL void groupNameChanged();
95
96 QJsonArray sensors() const;
97 void setSensors(const QJsonArray &newSensors);
98 Q_SIGNAL void sensorsChanged();
99
100 QString faceId() const;
101 void setFaceId(const QString &newFaceId);
102 Q_SIGNAL void faceIdChanged();
103
104 QVariantMap colors() const;
105 void setColors(const QVariantMap &newColors);
106 Q_SIGNAL void colorsChanged();
107
108 QVariantMap labels() const;
109 void setLabels(const QVariantMap &newLabels);
110 Q_SIGNAL void labelsChanged();
111
112 bool readOnly() const;
113 void setReadOnly(bool newReadOnly);
114 Q_SIGNAL void readOnlyChanged();
115
116 SensorFaceController *controller() const;
117 Q_SIGNAL void controllerChanged();
118
119 Q_INVOKABLE void reload();
120
121 void classBegin() override;
122 void componentComplete() override;
123
124private:
125 class Private;
126 const std::unique_ptr<Private> d;
127};
128
129}
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 Fri Oct 11 2024 12:17:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.