diff options
author | Benjamin Port <benjamin.port@enioka.com> | 2020-02-12 10:51:32 +0100 |
---|---|---|
committer | Benjamin Port <benjamin.port@enioka.com> | 2020-02-12 11:26:16 +0100 |
commit | 059a4feee45b91d819d7675fe5b3cc220f29c6ee (patch) | |
tree | f3de15d8c020d6c05e5ca5e128a405e38bf64a43 | |
parent | 1def4714cb919ed73cec840ecd7a583de0a7712b (diff) | |
download | kconfig-059a4feee45b91d819d7675fe5b3cc220f29c6ee.tar.gz kconfig-059a4feee45b91d819d7675fe5b3cc220f29c6ee.tar.bz2 |
Add setNotifyFunction to KPropertySkeletonItem
Summary: This function will be called when the property value change
Reviewers: ervin, meven, crossi
Subscribers: kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D27342
-rw-r--r-- | src/core/kcoreconfigskeleton.cpp | 24 | ||||
-rw-r--r-- | src/core/kcoreconfigskeleton.h | 6 | ||||
-rw-r--r-- | src/core/kcoreconfigskeleton_p.h | 1 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index 7566301b..be2fe27c 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -205,7 +205,13 @@ QVariant KPropertySkeletonItem::property() const void KPropertySkeletonItem::setProperty(const QVariant &p) { Q_D(KPropertySkeletonItem); + if (d->mReference == p) { + return; + } d->mReference = p; + if (d->mNotifyFunction) { + d->mNotifyFunction(); + } } bool KPropertySkeletonItem::isEqual(const QVariant &p) const @@ -217,7 +223,7 @@ bool KPropertySkeletonItem::isEqual(const QVariant &p) const void KPropertySkeletonItem::readConfig(KConfig *) { Q_D(KPropertySkeletonItem); - d->mReference = d->mObject->property(d->mPropertyName.constData()); + setProperty(d->mObject->property(d->mPropertyName.constData())); d->mLoadedValue = d->mReference; } @@ -231,19 +237,31 @@ void KPropertySkeletonItem::writeConfig(KConfig *) void KPropertySkeletonItem::readDefault(KConfig *) { Q_D(KPropertySkeletonItem); - d->mReference = d->mConstDefaultValue; + setProperty(d->mConstDefaultValue); } void KPropertySkeletonItem::setDefault() { Q_D(KPropertySkeletonItem); - d->mReference = d->mDefaultValue; + setProperty(d->mDefaultValue); } void KPropertySkeletonItem::swapDefault() { Q_D(KPropertySkeletonItem); + if (d->mReference == d->mDefaultValue) { + return; + } std::swap(d->mReference, d->mDefaultValue); + if (d->mNotifyFunction) { + d->mNotifyFunction(); + } +} + +void KPropertySkeletonItem::setNotifyFunction(const std::function<void ()> &impl) +{ + Q_D(KPropertySkeletonItem); + d->mNotifyFunction = impl; } KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h index a6f58ebe..7abc4052 100644 --- a/src/core/kcoreconfigskeleton.h +++ b/src/core/kcoreconfigskeleton.h @@ -294,6 +294,12 @@ public: void setDefault() override; /** @copydoc KConfigSkeletonItem::swapDefault() */ void swapDefault() override; + + /** + * Set a notify function, it will be invoked when the value of the property changes. + * @since 5.68 + */ + void setNotifyFunction(const std::function<void ()> &impl); }; diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h index 19f6f4bb..871122c0 100644 --- a/src/core/kcoreconfigskeleton_p.h +++ b/src/core/kcoreconfigskeleton_p.h @@ -86,6 +86,7 @@ public: const QVariant mConstDefaultValue; QVariant mReference; QVariant mLoadedValue; + std::function<void()> mNotifyFunction; }; |