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 Q_INTERFACES(QQmlParserStatus)
35 /**
36 * The parent SensorFaceController that will be used for configuration storage.
37 */
38 Q_PROPERTY(KSysGuard::SensorFaceController *parentController READ parentController WRITE setParentController NOTIFY parentControllerChanged)
39 /**
40 * The name of the config group to read configuration from.
41 */
42 Q_PROPERTY(QString groupName READ groupName WRITE setGroupName NOTIFY groupNameChanged)
43 /**
44 * The sensors to use for this face.
45 *
46 * This will set `highPrioritySensorIds` on the internal SensorFaceController.
47 */
48 Q_PROPERTY(QJsonArray sensors READ sensors WRITE setSensors NOTIFY sensorsChanged)
49 /**
50 * The face to use.
51 *
52 * This sets the faceId of the internal SensorFaceController.
53 */
54 Q_PROPERTY(QString faceId READ faceId WRITE setFaceId NOTIFY faceIdChanged)
55 /**
56 * A map of sensor colors to be used by the face.
57 *
58 * This forwards to the internal SensorFaceController.
59 */
60 Q_PROPERTY(QVariantMap colors READ colors WRITE setColors NOTIFY colorsChanged)
61 /**
62 * A map of sensor labels to be used by the face.
63 *
64 * This forwards to the internal SensorFaceController.
65 */
66 Q_PROPERTY(QVariantMap labels READ labels WRITE setLabels NOTIFY labelsChanged)
67 /**
68 * Whether to allow modifying the face configuration.
69 *
70 * If false (the default), any changes to configuration will be ignored. If
71 * true, changes will be written and stored in the config group.
72 *
73 * \note If multiple FaceLoaders share the same configuration, the face will
74 * need to be recreated after configuration has changed, as there is
75 * currently no way to properly reload the configuration.
76 */
77 Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
78 /**
79 * The face controller that provides the loaded face.
80 */
81 Q_PROPERTY(KSysGuard::SensorFaceController *controller READ controller NOTIFY controllerChanged)
82
83public:
84 FaceLoader(QObject *parent = nullptr);
85 ~FaceLoader() override;
86
87 SensorFaceController *parentController() const;
88 void setParentController(SensorFaceController *newParentController);
89 Q_SIGNAL void parentControllerChanged();
90
91 QString groupName() const;
92 void setGroupName(const QString &newGroupName);
93 Q_SIGNAL void groupNameChanged();
94
95 QJsonArray sensors() const;
96 void setSensors(const QJsonArray &newSensors);
97 Q_SIGNAL void sensorsChanged();
98
99 QString faceId() const;
100 void setFaceId(const QString &newFaceId);
101 Q_SIGNAL void faceIdChanged();
102
103 QVariantMap colors() const;
104 void setColors(const QVariantMap &newColors);
105 Q_SIGNAL void colorsChanged();
106
107 QVariantMap labels() const;
108 void setLabels(const QVariantMap &newLabels);
109 Q_SIGNAL void labelsChanged();
110
111 bool readOnly() const;
112 void setReadOnly(bool newReadOnly);
113 Q_SIGNAL void readOnlyChanged();
114
115 SensorFaceController *controller() const;
116 Q_SIGNAL void controllerChanged();
117
118 Q_INVOKABLE void reload();
119
120 void classBegin() override;
121 void componentComplete() override;
122
123private:
124 class Private;
125 const std::unique_ptr<Private> d;
126};
127
128}
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 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.