1 | /* |
2 | SPDX-FileCopyrightText: 2013 Marco Martin <notmart@gmail.com> |
3 | SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org> |
4 | SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KCONFIGPROPERTYMAP_H |
10 | #define KCONFIGPROPERTYMAP_H |
11 | |
12 | #include <QQmlPropertyMap> |
13 | #include <memory> |
14 | #include <qqmlregistration.h> |
15 | |
16 | class KCoreConfigSkeleton; |
17 | |
18 | #include <kconfigqml_export.h> |
19 | |
20 | class KConfigPropertyMapPrivate; |
21 | |
22 | /** |
23 | * @class KConfigPropertyMap configpropertymap.h ConfigPropertyMap |
24 | * |
25 | * An object that (optionally) automatically saves changes in a |
26 | * property map to a configuration object (e.g. a KConfig file). |
27 | * @since 5.89 |
28 | */ |
29 | class KCONFIGQML_EXPORT KConfigPropertyMap : public QQmlPropertyMap |
30 | { |
31 | Q_OBJECT |
32 | QML_ANONYMOUS |
33 | |
34 | public: |
35 | KConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent = nullptr); |
36 | ~KConfigPropertyMap() override; |
37 | |
38 | /** |
39 | * Whether notifications on config changes are enabled. Disabled by default. |
40 | * @see KConfigBase::Notify |
41 | * @return true if writes send (dbus) notifications |
42 | */ |
43 | bool isNotify() const; |
44 | |
45 | /** |
46 | * Enable or disable notifications on config changes. |
47 | * @see KConfigBase::Notify |
48 | * @param notify whether to send notifications |
49 | */ |
50 | void setNotify(bool notify); |
51 | |
52 | /** |
53 | * @brief Whether the value at the given key is immutable |
54 | * |
55 | * @return true if the value is immutable, false if it isn't or it doesn't exist |
56 | */ |
57 | Q_INVOKABLE bool isImmutable(const QString &key) const; |
58 | |
59 | /** |
60 | * Saves the state of the property map on disk. |
61 | */ |
62 | Q_INVOKABLE void writeConfig(); |
63 | |
64 | protected: |
65 | QVariant updateValue(const QString &key, const QVariant &input) override; |
66 | |
67 | private: |
68 | std::unique_ptr<KConfigPropertyMapPrivate> const d; |
69 | }; |
70 | |
71 | #endif |
72 | |