aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Edmundson <kde@davidedmundson.co.uk>2020-08-27 12:52:48 +0100
committerDavid Edmundson <kde@davidedmundson.co.uk>2020-08-28 14:12:14 +0000
commit60f18e6c3c816f4bca7c72e5a4f114787309485a (patch)
tree7a9ec2de061793b348678835d56397f0f8669f7e
parent0f1b47f2ab4b374a6d85dcf9dd63e1159cc7ea65 (diff)
downloadkconfig-60f18e6c3c816f4bca7c72e5a4f114787309485a.tar.gz
kconfig-60f18e6c3c816f4bca7c72e5a4f114787309485a.tar.bz2
Introduce method to query KConfigSkeletonItem default value
5.64 added an isDefault method however this doesn't suffice for usage in KConfigDialogManager which compares a current value to the default. KConfigDialogManager currently uses a hack with side effects. Exposing the value directly solves that.
-rw-r--r--src/core/kcoreconfigskeleton.cpp17
-rw-r--r--src/core/kcoreconfigskeleton.h9
-rw-r--r--src/core/kcoreconfigskeleton_p.h1
3 files changed, 27 insertions, 0 deletions
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp
index d02705d9..bfa3a60f 100644
--- a/src/core/kcoreconfigskeleton.cpp
+++ b/src/core/kcoreconfigskeleton.cpp
@@ -167,6 +167,12 @@ bool KConfigSkeletonItem::isSaveNeeded() const
return d->mIsSaveNeededImpl();
}
+QVariant KConfigSkeletonItem::getDefault() const
+{
+ Q_D(const KConfigSkeletonItem);
+ return d->mGetDefaultImpl();
+}
+
void KConfigSkeletonItem::readImmutability(const KConfigGroup &group)
{
Q_D(KConfigSkeletonItem);
@@ -185,6 +191,12 @@ void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool ()> &impl
d->mIsSaveNeededImpl = impl;
}
+void KConfigSkeletonItem::setGetDefaultImpl(const std::function<QVariant ()> &impl)
+{
+ Q_D(KConfigSkeletonItem);
+ d->mGetDefaultImpl = impl;
+}
+
KPropertySkeletonItem::KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
: KConfigSkeletonItem(*new KPropertySkeletonItemPrivate(object, propertyName, defaultValue), {}, {})
{
@@ -196,6 +208,10 @@ KPropertySkeletonItem::KPropertySkeletonItem(QObject *object, const QByteArray &
Q_D(const KPropertySkeletonItem);
return d->mReference != d->mLoadedValue;
});
+ setGetDefaultImpl([this] {
+ Q_D(const KPropertySkeletonItem);
+ return d->mDefaultValue;
+ });
}
QVariant KPropertySkeletonItem::property() const
@@ -1555,6 +1571,7 @@ KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem
setIsDefaultImpl([this] { return mItem->isDefault(); });
setIsSaveNeededImpl([this] { return mItem->isSaveNeeded(); });
+ setGetDefaultImpl([this] {return mItem->getDefault(); });
}
KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem()
diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h
index 9cf131b2..69f52060 100644
--- a/src/core/kcoreconfigskeleton.h
+++ b/src/core/kcoreconfigskeleton.h
@@ -230,6 +230,12 @@ public:
*/
bool isSaveNeeded() const;
+ /**
+ * Returns the default value
+ * @since 5.74
+ */
+ QVariant getDefault() const;
+
protected:
explicit KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key);
@@ -247,6 +253,7 @@ protected:
// KF6: Use proper pure virtuals in KConfigSkeletonItem
void setIsDefaultImpl(const std::function<bool()> &impl);
void setIsSaveNeededImpl(const std::function<bool()> &impl);
+ void setGetDefaultImpl(const std::function<QVariant()> &impl);
KConfigSkeletonItemPrivate *const d_ptr;
};
@@ -324,6 +331,8 @@ public:
{
setIsDefaultImpl([this] { return mReference == mDefault; });
setIsSaveNeededImpl([this] { return mReference != mLoadedValue; });
+ setGetDefaultImpl([this] { return QVariant::fromValue(mDefault); });
+
}
/**
diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h
index 389bc4f7..006bd45f 100644
--- a/src/core/kcoreconfigskeleton_p.h
+++ b/src/core/kcoreconfigskeleton_p.h
@@ -54,6 +54,7 @@ public:
// HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem
std::function<bool()> mIsDefaultImpl;
std::function<bool()> mIsSaveNeededImpl;
+ std::function<QVariant()> mGetDefaultImpl;
};
class KPropertySkeletonItemPrivate : public KConfigSkeletonItemPrivate