Changeset View
Changeset View
Standalone View
Standalone View
src/qmlcontrols/kcmcontrols/settingstateproxy.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2020 Kevin Ottens <kevin.ottens@enioka.com> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Library General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Library General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public License | ||||
15 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef SETTINGSTATEPROXY_H | ||||
21 | #define SETTINGSTATEPROXY_H | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | #include <QPointer> | ||||
25 | | ||||
26 | #include <KCoreConfigSkeleton> | ||||
27 | | ||||
28 | /** | ||||
29 | * This element allows to represent in a declarative way the | ||||
30 | * state of a particular setting in a config object. | ||||
31 | * | ||||
32 | * @since 5.69 | ||||
33 | */ | ||||
34 | class SettingStateProxy : public QObject | ||||
35 | { | ||||
36 | Q_OBJECT | ||||
37 | | ||||
38 | /** | ||||
39 | * The config object which will be monitored for setting state changes | ||||
40 | */ | ||||
41 | Q_PROPERTY(KCoreConfigSkeleton *configObject READ configObject WRITE setConfigObject NOTIFY configObjectChanged) | ||||
42 | | ||||
43 | /** | ||||
44 | * The name of the item representing the setting in the config object | ||||
45 | */ | ||||
46 | Q_PROPERTY(QString itemName READ itemName WRITE setItemName NOTIFY itemNameChanged) | ||||
47 | | ||||
48 | | ||||
49 | /** | ||||
50 | * Indicates if the setting is marked as immutable | ||||
51 | */ | ||||
52 | Q_PROPERTY(bool immutable READ isImmutable NOTIFY immutableChanged) | ||||
53 | | ||||
54 | | ||||
55 | /** | ||||
56 | * Indicates if the setting differs from its default value | ||||
57 | */ | ||||
58 | Q_PROPERTY(bool defaulted READ isDefaulted NOTIFY defaultedChanged) | ||||
59 | public: | ||||
60 | using QObject::QObject; | ||||
61 | | ||||
62 | KCoreConfigSkeleton *configObject() const; | ||||
63 | void setConfigObject(KCoreConfigSkeleton *configObject); | ||||
64 | | ||||
65 | QString itemName() const; | ||||
66 | void setItemName(const QString &itemName); | ||||
67 | | ||||
68 | bool isImmutable() const; | ||||
69 | bool isDefaulted() const; | ||||
70 | | ||||
71 | Q_INVOKABLE void resetToDefault(); | ||||
72 | | ||||
73 | Q_SIGNALS: | ||||
74 | void configObjectChanged(); | ||||
75 | void itemNameChanged(); | ||||
76 | | ||||
77 | void immutableChanged(); | ||||
78 | void defaultedChanged(); | ||||
79 | | ||||
80 | private Q_SLOTS: | ||||
81 | void updateState(); | ||||
82 | | ||||
83 | private: | ||||
84 | void connectSetting(); | ||||
85 | | ||||
86 | QPointer<KCoreConfigSkeleton> m_configObject; | ||||
87 | QString m_itemName; | ||||
88 | bool m_immutable = false; | ||||
89 | bool m_defaulted = true; | ||||
90 | }; | ||||
91 | | ||||
92 | #endif |