Changeset View
Changeset View
Standalone View
Standalone View
src/core/kcoreconfigskeleton.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 129 | { | |||
---|---|---|---|---|---|
130 | return QVariant(); | 130 | return QVariant(); | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | bool KConfigSkeletonItem::isImmutable() const | 133 | bool KConfigSkeletonItem::isImmutable() const | ||
134 | { | 134 | { | ||
135 | return d->mIsImmutable; | 135 | return d->mIsImmutable; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | bool KConfigSkeletonItem::isDefault() const | ||||
139 | { | ||||
140 | return d->mIsDefaultImpl(); | ||||
davidedmundson: Do we need to make this
```
if (d->mIsDefaultImpl){
return d->mIsDefaultImpl();
}
return… | |||||
Initializing to nullptr wouldn't help, you would get the same behavior than with the default constructor. It means it doesn't crash but raises a std::bad_function_call exception, which I think is fine... it's the next best thing to a pure virtual, but it's caught at runtime. I don't think we can do better than this in the current situation. ervin: Initializing to nullptr wouldn't help, you would get the same behavior than with the default… | |||||
141 | } | ||||
142 | | ||||
143 | bool KConfigSkeletonItem::isSaveNeeded() const | ||||
144 | { | ||||
145 | return d->mIsSaveNeededImpl(); | ||||
146 | } | ||||
147 | | ||||
138 | void KConfigSkeletonItem::readImmutability(const KConfigGroup &group) | 148 | void KConfigSkeletonItem::readImmutability(const KConfigGroup &group) | ||
139 | { | 149 | { | ||
140 | d->mIsImmutable = group.isEntryImmutable(mKey); | 150 | d->mIsImmutable = group.isEntryImmutable(mKey); | ||
141 | } | 151 | } | ||
142 | 152 | | |||
153 | void KConfigSkeletonItem::setIsDefaultImpl(const std::function<bool ()> &impl) | ||||
154 | { | ||||
155 | d->mIsDefaultImpl = impl; | ||||
156 | } | ||||
157 | | ||||
158 | void KConfigSkeletonItem::setIsSaveNeededImpl(const std::function<bool ()> &impl) | ||||
159 | { | ||||
160 | d->mIsSaveNeededImpl = impl; | ||||
161 | } | ||||
162 | | ||||
143 | KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, | 163 | KCoreConfigSkeleton::ItemString::ItemString(const QString &_group, const QString &_key, | ||
144 | QString &reference, | 164 | QString &reference, | ||
145 | const QString &defaultValue, | 165 | const QString &defaultValue, | ||
146 | Type type) | 166 | Type type) | ||
147 | : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue), | 167 | : KConfigSkeletonGenericItem<QString>(_group, _key, reference, defaultValue), | ||
148 | mType(type) | 168 | mType(type) | ||
149 | { | 169 | { | ||
150 | } | 170 | } | ||
▲ Show 20 Lines • Show All 935 Lines • ▼ Show 20 Line(s) | |||||
1086 | { | 1106 | { | ||
1087 | KConfigSkeletonItem::List::ConstIterator it; | 1107 | KConfigSkeletonItem::List::ConstIterator it; | ||
1088 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | 1108 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | ||
1089 | (*it)->readConfig(d->mConfig.data()); | 1109 | (*it)->readConfig(d->mConfig.data()); | ||
1090 | } | 1110 | } | ||
1091 | usrRead(); | 1111 | usrRead(); | ||
1092 | } | 1112 | } | ||
1093 | 1113 | | |||
1114 | bool KCoreConfigSkeleton::isDefaults() const | ||||
1115 | { | ||||
1116 | KConfigSkeletonItem::List::ConstIterator it; | ||||
1117 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | ||||
1118 | if (!(*it)->isDefault()) { | ||||
1119 | return false; | ||||
1120 | } | ||||
1121 | } | ||||
1122 | return true; | ||||
1123 | } | ||||
1124 | | ||||
1125 | bool KCoreConfigSkeleton::isSaveNeeded() const | ||||
1126 | { | ||||
1127 | KConfigSkeletonItem::List::ConstIterator it; | ||||
1128 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | ||||
1129 | if ((*it)->isSaveNeeded()) { | ||||
1130 | return true; | ||||
1131 | } | ||||
1132 | } | ||||
1133 | return false; | ||||
1134 | } | ||||
1135 | | ||||
1094 | bool KCoreConfigSkeleton::save() | 1136 | bool KCoreConfigSkeleton::save() | ||
1095 | { | 1137 | { | ||
1096 | //qDebug(); | 1138 | //qDebug(); | ||
1097 | KConfigSkeletonItem::List::ConstIterator it; | 1139 | KConfigSkeletonItem::List::ConstIterator it; | ||
1098 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | 1140 | for (it = d->mItems.constBegin(); it != d->mItems.constEnd(); ++it) { | ||
1099 | (*it)->writeConfig(d->mConfig.data()); | 1141 | (*it)->writeConfig(d->mConfig.data()); | ||
1100 | } | 1142 | } | ||
1101 | if (!usrSave()) { | 1143 | if (!usrSave()) { | ||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Line(s) | |||||
1389 | KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem* item, QObject* object, | 1431 | KConfigCompilerSignallingItem::KConfigCompilerSignallingItem(KConfigSkeletonItem* item, QObject* object, | ||
1390 | KConfigCompilerSignallingItem::NotifyFunction targetFunction, quint64 userData) | 1432 | KConfigCompilerSignallingItem::NotifyFunction targetFunction, quint64 userData) | ||
1391 | : KConfigSkeletonItem(item->group(), item->key()), mItem(item), mTargetFunction(targetFunction), | 1433 | : KConfigSkeletonItem(item->group(), item->key()), mItem(item), mTargetFunction(targetFunction), | ||
1392 | mObject(object), mUserData(userData) | 1434 | mObject(object), mUserData(userData) | ||
1393 | { | 1435 | { | ||
1394 | Q_ASSERT(mTargetFunction); | 1436 | Q_ASSERT(mTargetFunction); | ||
1395 | Q_ASSERT(mItem); | 1437 | Q_ASSERT(mItem); | ||
1396 | Q_ASSERT(mObject); | 1438 | Q_ASSERT(mObject); | ||
1439 | | ||||
1440 | setIsDefaultImpl([this] { return mItem->isDefault(); }); | ||||
1441 | setIsSaveNeededImpl([this] { return mItem->isSaveNeeded(); }); | ||||
1397 | } | 1442 | } | ||
1398 | 1443 | | |||
1399 | KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem() | 1444 | KConfigCompilerSignallingItem::~KConfigCompilerSignallingItem() | ||
1400 | { | 1445 | { | ||
1401 | } | 1446 | } | ||
1402 | 1447 | | |||
1403 | bool KConfigCompilerSignallingItem::isEqual(const QVariant& p) const | 1448 | bool KConfigCompilerSignallingItem::isEqual(const QVariant& p) const | ||
1404 | { | 1449 | { | ||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |
Do we need to make this
and initialize mIsDefaultImpl to nullptr
so that it doesn't crash if someone subclasses KConfigSkeletonItem directly and doesn't implement this?