diff options
author | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-11-07 21:34:18 +0100 |
---|---|---|
committer | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-11-22 09:36:02 +0000 |
commit | 3f29f3d6452f735757cb8f84dfc20cdcba791613 (patch) | |
tree | 11f40ed6a40cc3368fedfea193f4994c3447348b /src/qml/kconfigpropertymap.h | |
parent | c3be6d02f6c061707c6d93e06889a2e56b994d87 (diff) | |
download | kconfig-3f29f3d6452f735757cb8f84dfc20cdcba791613.tar.gz kconfig-3f29f3d6452f735757cb8f84dfc20cdcba791613.tar.bz2 |
Copy ConfigPropertyMap from KDeclarative to new KConfig QML module
This way consumers which want to use the ConfigPropertyMap don't have to
pull in KDeclarative's entire dependency tree.
Also we can remove the automatic saving of the config, previously
this was opt-out - which makes is difficult to deprecate anything.
This way the API design is also more clear, since the object only takes care of exposing the
data to QML. The writing has to be done manually, which makes more sense anyways when we have
the notify opt-in.
As discussed on the KF6 weekly thread, an optional QML submodule is seen as the best
way to handle the QML dependency.
Task: https://phabricator.kde.org/T12131
Relates to https://phabricator.kde.org/T12126, after his change the KDeclarative stuff can be deprecated.
Because we don't register the property map in any QML plugin, there is
no conflict in duplicating and modifying it now.
Diffstat (limited to 'src/qml/kconfigpropertymap.h')
-rw-r--r-- | src/qml/kconfigpropertymap.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/qml/kconfigpropertymap.h b/src/qml/kconfigpropertymap.h new file mode 100644 index 00000000..3795e099 --- /dev/null +++ b/src/qml/kconfigpropertymap.h @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2013 Marco Martin <notmart@gmail.com> + SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org> + SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#ifndef KCONFIGPROPERTYMAP_H +#define KCONFIGPROPERTYMAP_H + +#include <QQmlPropertyMap> +#include <memory> + +class KCoreConfigSkeleton; + +#include <kconfigqml_export.h> + +class KConfigPropertyMapPrivate; + +/** + * @class KConfigPropertyMap configpropertymap.h ConfigPropertyMap + * + * An object that (optionally) automatically saves changes in a + * property map to a configuration object (e.g. a KConfig file). + * @since 5.89 + */ +class KCONFIGQML_EXPORT KConfigPropertyMap : public QQmlPropertyMap +{ + Q_OBJECT + +public: + KConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent = nullptr); + ~KConfigPropertyMap() override; + + /** + * Whether notifications on config changes are enabled. Disabled by default. + * @see KConfigBase::Notify + * @return true if writes send (dbus) notifications + */ + bool isNotify() const; + + /** + * Enable or disable notifications on config changes. + * @see KConfigBase::Notify + * @param notify whether to send notifications + */ + void setNotify(bool notify); + + /** + * @brief Whether the value at the given key is immutable + * + * @return true if the value is immutable, false if it isn't or it doesn't exist + */ + Q_INVOKABLE bool isImmutable(const QString &key) const; + + /** + * Saves the state of the property map on disk. + */ + void writeConfig(); + +protected: + QVariant updateValue(const QString &key, const QVariant &input) override; + +private: + std::unique_ptr<KConfigPropertyMapPrivate> const d; +}; + +#endif |