From 4c3d3751968422ff5cba56b5da2036a1bceba314 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 10 Oct 2019 13:25:44 +0200 Subject: 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 --- src/core/kcoreconfigskeleton.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/core/kcoreconfigskeleton.cpp') diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index b3eb0019..34c58ff6 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -135,11 +135,31 @@ bool KConfigSkeletonItem::isImmutable() const return d->mIsImmutable; } +bool KConfigSkeletonItem::isDefault() const +{ + return d->mIsDefaultImpl(); +} + +bool KConfigSkeletonItem::isSaveNeeded() const +{ + return d->mIsSaveNeededImpl(); +} + void KConfigSkeletonItem::readImmutability(const KConfigGroup &group) { d->mIsImmutable = group.isEntryImmutable(mKey); } +void KConfigSkeletonItem::setIsDefaultImpl(const std::function &impl) +{ + d->mIsDefaultImpl = impl; +} + +void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function &impl) +{ + d->mIsSaveNeededImpl = impl; +} + KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue, @@ -1091,6 +1111,28 @@ void KCoreConfigSkeleton::read() usrRead(); } +bool KCoreConfigSkeleton::isDefaults() const +{ + KConfigSkeletonItem::List::ConstIterator it; + for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { + if (!(*it)->isDefault()) { + return false; + } + } + return true; +} + +bool KCoreConfigSkeleton::isSaveNeeded() const +{ + KConfigSkeletonItem::List::ConstIterator it; + for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { + if ((*it)->isSaveNeeded()) { + return true; + } + } + return false; +} + bool KCoreConfigSkeleton::save() { //qDebug(); @@ -1394,6 +1436,9 @@ KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem Q_ASSERT(mTargetFunction); Q_ASSERT(mItem); Q_ASSERT(mObject); + + setIsDefaultImpl([this] { return mItem->isDefault(); }); + setIsSaveNeededImpl([this] { return mItem->isSaveNeeded(); }); } KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem() -- cgit v1.2.1