diff options
Diffstat (limited to 'src')
| -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;  }; | 
