diff options
author | Alex Richardson <arichardson.kde@gmail.com> | 2014-02-20 16:56:01 +0100 |
---|---|---|
committer | Alex Richardson <arichardson.kde@gmail.com> | 2014-02-20 18:14:24 +0100 |
commit | 6d3a4405fc2723f5796e845247b6b0eb0448216e (patch) | |
tree | 477c67a7c067ca1b74917bd244485998c8418623 /src/core/kcoreconfigskeleton.cpp | |
parent | 9e3d22c3f549b583eb60c958dd923bf7c5bf4586 (diff) | |
download | kconfig-6d3a4405fc2723f5796e845247b6b0eb0448216e.tar.gz kconfig-6d3a4405fc2723f5796e845247b6b0eb0448216e.tar.bz2 |
Make kconfig_compiler signals actually useful + add unit test
Previously the classes generated by kconfig_compiler would only emit
the defined signals when using the setters provided by that class.
However, when using e.g. KConfigDialog which uses
KConfigSkeletonItem::setProperty() to change the items no signal was
generated.
This patch fixes this by using a wrapper KConfigSkeletonItem
subclass that calls a private itemChanged() method in the generated
class which updates the set of changed properties. As soon as the item
is saved (usrWriteConfig() in the generated class is called) the signal
will be emitted
REVIEW: 115635
REVIEW: 115634
Diffstat (limited to 'src/core/kcoreconfigskeleton.cpp')
-rw-r--r-- | src/core/kcoreconfigskeleton.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp index d9b95b4b..98d9cdcc 100644 --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -1339,3 +1339,77 @@ KConfigSkeletonItem *KCoreConfigSkeleton::findItem(const QString &name) const return d->mItemDict.value(name); } +KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem* item, QObject* object, + KConfigCompilerSignallingItem::NotifyFunction targetFunction, quint64 userData) + : KConfigSkeletonItem(item->group(), item->key()), mItem(item), mTargetFunction(targetFunction), + mObject(object), mUserData(userData) +{ + Q_ASSERT(mTargetFunction); + Q_ASSERT(mItem); + Q_ASSERT(mObject); +} + +KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem() +{ +} + +bool KConfigCompilerSignallingItem::isEqual(const QVariant& p) const +{ + return mItem->isEqual(p); +} + +QVariant KConfigCompilerSignallingItem::property() const +{ + return mItem->property(); +} + +void KConfigCompilerSignallingItem::readConfig(KConfig* c) +{ + QVariant oldValue = mItem->property(); + mItem->readConfig(c); + //readConfig() changes mIsImmutable, update it here as well + KConfigGroup cg(c, mGroup ); + readImmutability(cg); + if (!mItem->isEqual(oldValue)) { + invokeNotifyFunction(); + } +} + +void KConfigCompilerSignallingItem::readDefault(KConfig* c) +{ + mItem->readDefault(c); + //readDefault() changes mIsImmutable, update it here as well + KConfigGroup cg(c, mGroup ); + readImmutability(cg); +} + +void KConfigCompilerSignallingItem::writeConfig(KConfig* c) +{ + mItem->writeConfig(c); +} + +void KConfigCompilerSignallingItem::setDefault() +{ + QVariant oldValue = mItem->property(); + mItem->setDefault(); + if (!mItem->isEqual(oldValue)) { + invokeNotifyFunction(); + } +} + +void KConfigCompilerSignallingItem::setProperty(const QVariant& p) +{ + if (!mItem->isEqual(p)) { + mItem->setProperty(p); + invokeNotifyFunction(); + } +} + +void KConfigCompilerSignallingItem::swapDefault() +{ + QVariant oldValue = mItem->property(); + mItem->swapDefault(); + if (!mItem->isEqual(oldValue)) { + invokeNotifyFunction(); + } +} |