aboutsummaryrefslogtreecommitdiff
path: root/src/core/kcoreconfigskeleton.h
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@enioka.com>2019-10-10 13:25:44 +0200
committerKevin Ottens <kevin.ottens@enioka.com>2019-10-10 13:26:21 +0200
commit4c3d3751968422ff5cba56b5da2036a1bceba314 (patch)
tree50ab07c230acd982a94eee7e8c750c2900946578 /src/core/kcoreconfigskeleton.h
parent5fa1a3312ab24908d870ce2a2399695ac98d828d (diff)
downloadkconfig-4c3d3751968422ff5cba56b5da2036a1bceba314.tar.gz
kconfig-4c3d3751968422ff5cba56b5da2036a1bceba314.tar.bz2
Add convenience for defaults/dirty states to KCoreConfigSkeleton
Summary: It allows to verify if all the items of the skeleton are in their default values or if they hold any value deviating from the latest loaded values from KConfig. We didn't really need this during the KCModule/QtWidgets time since we could write KConfigDialogManager just fine without it. But for use with QML and aiming at having similar magic in KQuickAddons::ConfigModule such convenience functions will be needed. Reviewers: #plasma, #frameworks, dfaure, mart Subscribers: apol, kossebau, davidedmundson, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D24494
Diffstat (limited to 'src/core/kcoreconfigskeleton.h')
-rw-r--r--src/core/kcoreconfigskeleton.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h
index 771d8cc9..6e792efd 100644
--- a/src/core/kcoreconfigskeleton.h
+++ b/src/core/kcoreconfigskeleton.h
@@ -210,6 +210,21 @@ public:
*/
bool isImmutable() const;
+ /**
+ * Indicates if the item is set to its default value.
+ *
+ * @since 5.64
+ */
+ bool isDefault() const;
+
+ /**
+ * Indicates if the item has a different value than the
+ * previously loaded value.
+ *
+ * @since 5.64
+ */
+ bool isSaveNeeded() const;
+
protected:
/**
* sets mIsImmutable to true if mKey in config is immutable
@@ -221,6 +236,11 @@ protected:
QString mKey; ///< The config key for this item
QString mName; ///< The name of this item
+ // HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem
+ // KF6: Use proper pure virtuals in KConfigSkeletonItem
+ void setIsDefaultImpl(const std::function<bool()> &impl);
+ void setIsSaveNeededImpl(const std::function<bool()> &impl);
+
private:
KConfigSkeletonItemPrivate *const d;
};
@@ -240,6 +260,8 @@ public:
: KConfigSkeletonItem(_group, _key), mReference(reference),
mDefault(defaultValue), mLoadedValue(defaultValue)
{
+ setIsDefaultImpl([this] { return mReference == mDefault; });
+ setIsSaveNeededImpl([this] { return mReference != mLoadedValue; });
}
/**
@@ -1078,6 +1100,21 @@ public:
void read();
/**
+ * Indicates if all the registered items are set to their default value.
+ *
+ * @since 5.64
+ */
+ bool isDefaults() const;
+
+ /**
+ * Indicates if any registered item has a different value than the
+ * previously loaded value.
+ *
+ * @since 5.64
+ */
+ bool isSaveNeeded() const;
+
+ /**
* Set the config file group for subsequent addItem() calls. It is valid
* until setCurrentGroup() is called with a new argument. Call this before
* you add any items. The default value is "No Group".