1 | /* |
2 | SPDX-FileCopyrightText: 2020 Kevin Ottens <kevin.ottens@enioka.com> |
3 | SPDX-FileCopyrightText: 2020 Cyril Rossi <cyril.rossi@enioka.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef SETTINGSTATEPROXY_H |
9 | #define SETTINGSTATEPROXY_H |
10 | |
11 | #include <QObject> |
12 | #include <QPointer> |
13 | #include <QQmlEngine> |
14 | |
15 | #include <KCoreConfigSkeleton> |
16 | |
17 | /*! |
18 | * \qmltype SettingStateProxy |
19 | * \inqmlmodule org.kde.kcmutils |
20 | * \brief Allows to represent the state of a particular setting |
21 | * in a config object in a declarative way. |
22 | * |
23 | * \since 5.73 |
24 | */ |
25 | class SettingStateProxy : public QObject |
26 | { |
27 | Q_OBJECT |
28 | QML_ELEMENT |
29 | |
30 | /*! |
31 | * \qmlproperty bool SettingStateProxy::configObject |
32 | * \brief The config object which will be monitored for setting state changes. |
33 | */ |
34 | Q_PROPERTY(KCoreConfigSkeleton *configObject READ configObject WRITE setConfigObject NOTIFY configObjectChanged) |
35 | |
36 | /*! |
37 | * \qmlproperty bool SettingStateProxy::settingName |
38 | * \brief The name of the setting in the config object. |
39 | */ |
40 | Q_PROPERTY(QString settingName READ settingName WRITE setSettingName NOTIFY settingNameChanged) |
41 | |
42 | /*! |
43 | * \qmlproperty bool SettingStateProxy::immutable |
44 | * \brief Indicates if the setting is marked as immutable. |
45 | */ |
46 | Q_PROPERTY(bool immutable READ isImmutable NOTIFY immutableChanged) |
47 | |
48 | /*! |
49 | * \qmlproperty bool SettingStateProxy::defaulted |
50 | * \brief Indicates if the setting differs from its default value. |
51 | */ |
52 | Q_PROPERTY(bool defaulted READ isDefaulted NOTIFY defaultedChanged) |
53 | |
54 | public: |
55 | using QObject::QObject; |
56 | |
57 | KCoreConfigSkeleton *configObject() const; |
58 | void setConfigObject(KCoreConfigSkeleton *configObject); |
59 | |
60 | QString settingName() const; |
61 | void setSettingName(const QString &settingName); |
62 | |
63 | bool isImmutable() const; |
64 | bool isDefaulted() const; |
65 | |
66 | Q_SIGNALS: |
67 | void configObjectChanged(); |
68 | void settingNameChanged(); |
69 | |
70 | void immutableChanged(); |
71 | void defaultedChanged(); |
72 | |
73 | private Q_SLOTS: |
74 | /*! |
75 | * \qmlmethod void SettingStateProxy::updateState() |
76 | */ |
77 | void updateState(); |
78 | |
79 | private: |
80 | void connectSetting(); |
81 | |
82 | QPointer<KCoreConfigSkeleton> m_configObject; |
83 | QString m_settingName; |
84 | bool m_immutable = false; |
85 | bool m_defaulted = true; |
86 | }; |
87 | |
88 | #endif |
89 | |