KConfig 5.109.0
kcoreconfigskeleton.h
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef KCORECONFIGSKELETON_H
11#define KCORECONFIGSKELETON_H
12
13#include <kconfigcore_export.h>
14
15#include <kconfiggroup.h>
16#include <ksharedconfig.h>
17
18#include <QDate>
19#include <QHash>
20#include <QRect>
21#include <QStringList>
22#include <QUrl>
23#include <QVariant>
24
25class KCoreConfigSkeletonPrivate;
26
27class KConfigSkeletonItemPrivate;
41class KCONFIGCORE_EXPORT KConfigSkeletonItem
42{
43 Q_DECLARE_PRIVATE(KConfigSkeletonItem)
44public:
45 typedef QList<KConfigSkeletonItem *> List;
46 typedef QHash<QString, KConfigSkeletonItem *> Dict;
47 typedef QHash<QString, KConfigSkeletonItem *>::Iterator DictIterator;
48
55 KConfigSkeletonItem(const QString &_group, const QString &_key);
56
61
65 void setGroup(const QString &_group);
66
70 QString group() const;
71
77 void setGroup(const KConfigGroup &cg);
78
87
91 void setKey(const QString &_key);
92
96 QString key() const;
97
101 void setName(const QString &_name);
102
106 QString name() const;
107
111 void setLabel(const QString &l);
112
117 QString label() const;
118
123 void setToolTip(const QString &t);
124
130 QString toolTip() const;
131
135 void setWhatsThis(const QString &w);
136
141 QString whatsThis() const;
142
148
155
160 virtual void readConfig(KConfig *) = 0;
161
167 virtual void writeConfig(KConfig *) = 0;
168
172 virtual void readDefault(KConfig *) = 0;
173
177 virtual void setProperty(const QVariant &p) = 0;
178
188 virtual bool isEqual(const QVariant &p) const = 0;
189
193 virtual QVariant property() const = 0;
194
198 virtual QVariant minValue() const;
199
203 virtual QVariant maxValue() const;
204
208 virtual void setDefault() = 0;
209
214 virtual void swapDefault() = 0;
215
219 bool isImmutable() const;
220
226 bool isDefault() const;
227
234 bool isSaveNeeded() const;
235
240 QVariant getDefault() const;
241
242protected:
243 KCONFIGCORE_NO_EXPORT explicit KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key);
244
249 void readImmutability(const KConfigGroup &group);
250
251 QString mGroup;
252 QString mKey;
253 QString mName;
254
255 // HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem
256 // KF6: Use proper pure virtuals in KConfigSkeletonItem
257 void setIsDefaultImpl(const std::function<bool()> &impl);
258 void setIsSaveNeededImpl(const std::function<bool()> &impl);
259 void setGetDefaultImpl(const std::function<QVariant()> &impl);
260
261 KConfigSkeletonItemPrivate *const d_ptr;
262};
263
264class KPropertySkeletonItemPrivate;
265
280class KCONFIGCORE_EXPORT KPropertySkeletonItem : public KConfigSkeletonItem
281{
282 Q_DECLARE_PRIVATE(KPropertySkeletonItem)
283public:
291 KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue);
292
294 QVariant property() const override;
296 void setProperty(const QVariant &p) override;
298 bool isEqual(const QVariant &p) const override;
299
301 void readConfig(KConfig *) override;
303 void writeConfig(KConfig *) override;
304
306 void readDefault(KConfig *) override;
308 void setDefault() override;
310 void swapDefault() override;
311
316 void setNotifyFunction(const std::function<void()> &impl);
317};
318
324template<typename T>
326{
327public:
333 KConfigSkeletonGenericItem(const QString &_group, const QString &_key, T &reference, T defaultValue)
334 : KConfigSkeletonItem(_group, _key)
335 , mReference(reference)
336 , mDefault(defaultValue)
337 , mLoadedValue(defaultValue)
338 {
339 setIsDefaultImpl([this] {
340 return mReference == mDefault;
341 });
342 setIsSaveNeededImpl([this] {
343 return mReference != mLoadedValue;
344 });
345 setGetDefaultImpl([this] {
346 return QVariant::fromValue(mDefault);
347 });
348 }
349
353 void setValue(const T &v)
354 {
355 mReference = v;
356 }
357
361 T &value()
362 {
363 return mReference;
364 }
365
369 const T &value() const
370 {
371 return mReference;
372 }
373
377 virtual void setDefaultValue(const T &v)
378 {
379 mDefault = v;
380 }
381
385 void setDefault() override
386 {
388 }
389
391 void writeConfig(KConfig *config) override
392 {
393 if (mReference != mLoadedValue) { // Is this needed?
394 KConfigGroup cg = configGroup(config);
395 if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
397 } else {
399 }
400 mLoadedValue = mReference;
401 }
402 }
403
405 void readDefault(KConfig *config) override
406 {
407 config->setReadDefaults(true);
408 readConfig(config);
409 config->setReadDefaults(false);
411 }
412
414 void swapDefault() override
415 {
416 T tmp = mReference;
418 mDefault = tmp;
419 }
420
421protected:
424 T mLoadedValue;
425};
426
440class KCONFIGCORE_EXPORT KConfigCompilerSignallingItem : public KConfigSkeletonItem
441{
442public:
443 typedef void (QObject::*NotifyFunction)(quint64 arg);
452 KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData);
454
455 void readConfig(KConfig *) override;
456 void writeConfig(KConfig *) override;
457 void readDefault(KConfig *) override;
458 void setProperty(const QVariant &p) override;
459 bool isEqual(const QVariant &p) const override;
460 QVariant property() const override;
461 QVariant minValue() const override;
462 QVariant maxValue() const override;
463 void setDefault() override;
464 void swapDefault() override;
465 // KF6 TODO - fix this
466 // Ideally we would do this in an overload of KConfigSkeletonItem, but
467 // given we can't, I've shadowed the method. This isn't pretty, but given
468 // the docs say it should generally only be used from auto generated code,
469 // should be fine.
470 void setWriteFlags(KConfigBase::WriteConfigFlags flags);
471 KConfigBase::WriteConfigFlags writeFlags() const;
472 void setGroup(const KConfigGroup &cg);
473 KConfigGroup configGroup(KConfig *config) const;
474 // END TODO
475
476private:
477 inline void invokeNotifyFunction()
478 {
479 // call the pointer to member function using the strange ->* operator
480 (mObject->*mTargetFunction)(mUserData);
481 }
482
483private:
484 QScopedPointer<KConfigSkeletonItem> mItem;
485 NotifyFunction mTargetFunction;
486 QObject *mObject;
487 quint64 mUserData;
488};
489
550class KCONFIGCORE_EXPORT KCoreConfigSkeleton : public QObject
551{
552 Q_OBJECT
553public:
557 class KCONFIGCORE_EXPORT ItemString : public KConfigSkeletonGenericItem<QString>
558 {
559 public:
561 enum Type {
565 };
566
571 ItemString(const QString &_group,
572 const QString &_key,
573 QString &reference,
574 const QString &defaultValue = QLatin1String(""), // NOT QString() !!
575 Type type = Normal);
576
578 void writeConfig(KConfig *config) override;
579
581 void readConfig(KConfig *config) override;
582
584 void setProperty(const QVariant &p) override;
585
587 bool isEqual(const QVariant &p) const override;
588
590 QVariant property() const override;
591
592 private:
593 Type mType;
594 };
595
599 class KCONFIGCORE_EXPORT ItemPassword : public ItemString
600 {
601 public:
603 ItemPassword(const QString &_group, const QString &_key, QString &reference,
604 const QString &defaultValue = QLatin1String("")); // NOT QString() !!
605 };
606
610 class KCONFIGCORE_EXPORT ItemPath : public ItemString
611 {
612 public:
614 ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue = QString());
615 };
616
620 class KCONFIGCORE_EXPORT ItemUrl : public KConfigSkeletonGenericItem<QUrl>
621 {
622 public:
624 ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue = QUrl());
625
627 void writeConfig(KConfig *config) override;
628
630 void readConfig(KConfig *config) override;
631
633 void setProperty(const QVariant &p) override;
634
636 bool isEqual(const QVariant &p) const override;
637
639 QVariant property() const override;
640 };
641
645 class KCONFIGCORE_EXPORT ItemProperty : public KConfigSkeletonGenericItem<QVariant>
646 {
647 public:
649 ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue = QVariant());
650
651 void readConfig(KConfig *config) override;
652 void setProperty(const QVariant &p) override;
653
655 bool isEqual(const QVariant &p) const override;
656
658 QVariant property() const override;
659 };
660
664 class KCONFIGCORE_EXPORT ItemBool : public KConfigSkeletonGenericItem<bool>
665 {
666 public:
668 ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue = true);
669
671 void readConfig(KConfig *config) override;
672
674 void setProperty(const QVariant &p) override;
675
677 bool isEqual(const QVariant &p) const override;
678
680 QVariant property() const override;
681 };
682
686 class KCONFIGCORE_EXPORT ItemInt : public KConfigSkeletonGenericItem<qint32>
687 {
688 public:
690 ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue = 0);
691
693 void readConfig(KConfig *config) override;
694
696 void setProperty(const QVariant &p) override;
697
699 bool isEqual(const QVariant &p) const override;
700
702 QVariant property() const override;
703
705 QVariant minValue() const override;
706
708 QVariant maxValue() const override;
709
714 void setMinValue(qint32);
715
720 void setMaxValue(qint32);
721
722 private:
723 bool mHasMin : 1;
724 bool mHasMax : 1;
725 qint32 mMin;
726 qint32 mMax;
727 };
728
732 class KCONFIGCORE_EXPORT ItemLongLong : public KConfigSkeletonGenericItem<qint64>
733 {
734 public:
736 ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue = 0);
737
739 void readConfig(KConfig *config) override;
740
742 void setProperty(const QVariant &p) override;
743
745 bool isEqual(const QVariant &p) const override;
746
748 QVariant property() const override;
749
751 QVariant minValue() const override;
752
754 QVariant maxValue() const override;
755
757 void setMinValue(qint64);
758
760 void setMaxValue(qint64);
761
762 private:
763 bool mHasMin : 1;
764 bool mHasMax : 1;
765 qint64 mMin;
766 qint64 mMax;
767 };
768#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
769 typedef KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use ItemLongLong") ItemLongLong ItemInt64;
770#endif
771
775 class KCONFIGCORE_EXPORT ItemEnum : public ItemInt
776 {
777 public:
778 struct Choice {
779 QString name;
780 QString label;
781 QString toolTip;
782 QString whatsThis;
783 };
784
789 ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue = 0);
790
791 QList<Choice> choices() const;
792
794 void readConfig(KConfig *config) override;
795
797 void writeConfig(KConfig *config) override;
798
799#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 103)
800 // Source compatibility with 4.x
801 typedef KCONFIGCORE_DEPRECATED_VERSION_BELATED(5, 103, 5, 0, "Use Choice") Choice Choice2;
805 KCONFIGCORE_DEPRECATED_VERSION_BELATED(5, 103, 5, 0, "Use choices().")
806 QList<Choice> choices2() const;
807#endif
808
812 QString valueForChoice(const QString &name) const;
813
817 void setValueForChoice(const QString &name, const QString &valueForChoice);
818
819 private:
820 QList<Choice> mChoices;
821 };
822
826 class KCONFIGCORE_EXPORT ItemUInt : public KConfigSkeletonGenericItem<quint32>
827 {
828 public:
830 ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue = 0);
831
833 void readConfig(KConfig *config) override;
834
836 void setProperty(const QVariant &p) override;
837
839 bool isEqual(const QVariant &p) const override;
840
842 QVariant property() const override;
843
845 QVariant minValue() const override;
846
848 QVariant maxValue() const override;
849
851 void setMinValue(quint32);
852
854 void setMaxValue(quint32);
855
856 private:
857 bool mHasMin : 1;
858 bool mHasMax : 1;
859 quint32 mMin;
860 quint32 mMax;
861 };
862
866 class KCONFIGCORE_EXPORT ItemULongLong : public KConfigSkeletonGenericItem<quint64>
867 {
868 public:
870 ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue = 0);
871
873 void readConfig(KConfig *config) override;
874
876 void setProperty(const QVariant &p) override;
877
879 bool isEqual(const QVariant &p) const override;
880
882 QVariant property() const override;
883
885 QVariant minValue() const override;
886
888 QVariant maxValue() const override;
889
891 void setMinValue(quint64);
892
894 void setMaxValue(quint64);
895
896 private:
897 bool mHasMin : 1;
898 bool mHasMax : 1;
899 quint64 mMin;
900 quint64 mMax;
901 };
902#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
903 typedef KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use ItemULongLong") ItemULongLong ItemUInt64;
904#endif
905
909 class KCONFIGCORE_EXPORT ItemDouble : public KConfigSkeletonGenericItem<double>
910 {
911 public:
913 ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue = 0);
914
916 void readConfig(KConfig *config) override;
917
919 void setProperty(const QVariant &p) override;
920
922 bool isEqual(const QVariant &p) const override;
923
925 QVariant property() const override;
926
928 QVariant minValue() const override;
929
931 QVariant maxValue() const override;
932
934 void setMinValue(double);
935
937 void setMaxValue(double);
938
939 private:
940 bool mHasMin : 1;
941 bool mHasMax : 1;
942 double mMin;
943 double mMax;
944 };
945
949 class KCONFIGCORE_EXPORT ItemRect : public KConfigSkeletonGenericItem<QRect>
950 {
951 public:
953 ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue = QRect());
954
956 void readConfig(KConfig *config) override;
957
959 void setProperty(const QVariant &p) override;
960
962 bool isEqual(const QVariant &p) const override;
963
965 QVariant property() const override;
966 };
967
971 class KCONFIGCORE_EXPORT ItemPoint : public KConfigSkeletonGenericItem<QPoint>
972 {
973 public:
975 ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue = QPoint());
976
978 void readConfig(KConfig *config) override;
979
981 void setProperty(const QVariant &p) override;
982
984 bool isEqual(const QVariant &p) const override;
985
987 QVariant property() const override;
988 };
989
993 class KCONFIGCORE_EXPORT ItemSize : public KConfigSkeletonGenericItem<QSize>
994 {
995 public:
997 ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue = QSize());
998
1000 void readConfig(KConfig *config) override;
1001
1003 void setProperty(const QVariant &p) override;
1004
1006 bool isEqual(const QVariant &p) const override;
1007
1009 QVariant property() const override;
1010 };
1011
1015 class KCONFIGCORE_EXPORT ItemDateTime : public KConfigSkeletonGenericItem<QDateTime>
1016 {
1017 public:
1019 ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue = QDateTime());
1020
1022 void readConfig(KConfig *config) override;
1023
1025 void setProperty(const QVariant &p) override;
1026
1028 bool isEqual(const QVariant &p) const override;
1029
1031 QVariant property() const override;
1032 };
1033
1037 class KCONFIGCORE_EXPORT ItemStringList : public KConfigSkeletonGenericItem<QStringList>
1038 {
1039 public:
1041 ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList());
1042
1044 void readConfig(KConfig *config) override;
1045
1047 void setProperty(const QVariant &p) override;
1048
1050 bool isEqual(const QVariant &p) const override;
1051
1053 QVariant property() const override;
1054 };
1055
1059 class KCONFIGCORE_EXPORT ItemPathList : public ItemStringList
1060 {
1061 public:
1063 ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList());
1064
1066 void readConfig(KConfig *config) override;
1068 void writeConfig(KConfig *config) override;
1069 };
1070
1074 class KCONFIGCORE_EXPORT ItemUrlList : public KConfigSkeletonGenericItem<QList<QUrl>>
1075 {
1076 public:
1078 ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue = QList<QUrl>());
1079
1081 void readConfig(KConfig *config) override;
1082
1084 void writeConfig(KConfig *config) override;
1085
1087 void setProperty(const QVariant &p) override;
1088
1090 bool isEqual(const QVariant &p) const override;
1091
1093 QVariant property() const override;
1094 };
1095
1099 class KCONFIGCORE_EXPORT ItemIntList : public KConfigSkeletonGenericItem<QList<int>>
1100 {
1101 public:
1103 ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue = QList<int>());
1104
1106 void readConfig(KConfig *config) override;
1107
1109 void setProperty(const QVariant &p) override;
1110
1112 bool isEqual(const QVariant &p) const override;
1113
1115 QVariant property() const override;
1116 };
1117
1118public:
1126 explicit KCoreConfigSkeleton(const QString &configname = QString(), QObject *parent = nullptr);
1127
1134 explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = nullptr);
1135
1140
1149 virtual void setDefaults();
1150
1158 void load();
1159
1160#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1165 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::load() or KCoreConfigSkeleton::read()")
1166 void readConfig()
1167 {
1168 load();
1169 }
1170#endif
1171
1182 void read();
1183
1189 bool isDefaults() const;
1190
1197 bool isSaveNeeded() const;
1198
1204 void setCurrentGroup(const QString &group);
1205
1209 QString currentGroup() const;
1210
1221 void addItem(KConfigSkeletonItem *item, const QString &name = QString());
1222
1234 ItemString *addItemString(const QString &name,
1235 QString &reference,
1236 const QString &defaultValue = QLatin1String(""), // NOT QString() !!
1237 const QString &key = QString());
1238
1253 ItemPassword *addItemPassword(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString());
1254
1268 ItemPath *addItemPath(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString());
1269
1285 ItemProperty *addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue = QVariant(), const QString &key = QString());
1297 ItemBool *addItemBool(const QString &name, bool &reference, bool defaultValue = false, const QString &key = QString());
1298
1310 ItemInt *addItemInt(const QString &name, qint32 &reference, qint32 defaultValue = 0, const QString &key = QString());
1311
1323 ItemUInt *addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue = 0, const QString &key = QString());
1324
1336 ItemLongLong *addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue = 0, const QString &key = QString());
1337
1338#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1342 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::addItemLongLong(...)")
1343 ItemLongLong *addItemInt64(const QString &name, qint64 &reference, qint64 defaultValue = 0, const QString &key = QString());
1344#endif
1345
1357 ItemULongLong *addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue = 0, const QString &key = QString());
1358
1359#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1363 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::addItemULongLong(...)")
1364 ItemULongLong *addItemUInt64(const QString &name, quint64 &reference, quint64 defaultValue = 0, const QString &key = QString());
1365#endif
1366
1378 ItemDouble *addItemDouble(const QString &name, double &reference, double defaultValue = 0.0, const QString &key = QString());
1379
1391 ItemRect *addItemRect(const QString &name, QRect &reference, const QRect &defaultValue = QRect(), const QString &key = QString());
1392
1404 ItemPoint *addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue = QPoint(), const QString &key = QString());
1405
1417 ItemSize *addItemSize(const QString &name, QSize &reference, const QSize &defaultValue = QSize(), const QString &key = QString());
1418
1430 ItemDateTime *addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue = QDateTime(), const QString &key = QString());
1431
1444 addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue = QStringList(), const QString &key = QString());
1445
1457 ItemIntList *addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue = QList<int>(), const QString &key = QString());
1458
1463
1467 const KConfig *config() const;
1468
1473 KSharedConfig::Ptr sharedConfig() const;
1474
1478 void setSharedConfig(KSharedConfig::Ptr pConfig);
1479
1483 KConfigSkeletonItem::List items() const;
1484
1489 void removeItem(const QString &name);
1490
1495
1500 Q_INVOKABLE bool isImmutable(const QString &name) const;
1501
1506 KConfigSkeletonItem *findItem(const QString &name) const;
1507
1520 virtual bool useDefaults(bool b);
1521
1522public Q_SLOTS:
1530 bool save();
1531
1532#if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1536 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::save()")
1537 void writeConfig()
1538 {
1539 save();
1540 }
1541#endif
1542
1543Q_SIGNALS:
1548
1549protected:
1558 virtual bool usrUseDefaults(bool b);
1559
1565 virtual void usrSetDefaults();
1566
1572 virtual void usrRead();
1573
1579 virtual bool usrSave();
1580
1581#if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1586 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Override KCoreConfigSkeleton::usrRead()")
1587 virtual void usrReadConfig();
1588#endif
1589
1590#if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1595 KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Override KCoreConfigSkeleton::usrSave()")
1596 virtual bool usrWriteConfig();
1597#endif
1598
1599private:
1600 KCoreConfigSkeletonPrivate *const d;
1601 friend class KConfigSkeleton;
1602};
1603
1604#endif
QFlags< WriteConfigFlag > WriteConfigFlags
Stores a combination of #WriteConfigFlag values.
Definition kconfigbase.h:67
Definition kcoreconfigskeleton.h:441
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void readDefault(KConfig *) override
Read global default value.
QVariant maxValue() const override
Return maximum value of item or invalid if not specified.
QVariant minValue() const override
Return minimum value of item or invalid if not specified.
void setDefault() override
Sets the current value to the default value.
void setProperty(const QVariant &p) override
Set item to p.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData)
Constructor.
QVariant property() const override
Return item as property.
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
A class for one specific group in a KConfig object.
Definition kconfiggroup.h:39
bool hasDefault(const QString &key) const
Whether a default is specified for an entry in either the system wide configuration file or the globa...
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
void revertToDefault(const QString &key)
Reverts an entry to the default settings.
Base class for storing a preferences setting of type T.
Definition kcoreconfigskeleton.h:326
void readDefault(KConfig *config) override
Read global default value.
Definition kcoreconfigskeleton.h:405
KConfigSkeletonGenericItem(const QString &_group, const QString &_key, T &reference, T defaultValue)
Constructor.
Definition kcoreconfigskeleton.h:333
T mDefault
The default value for this item.
Definition kcoreconfigskeleton.h:423
T & value()
Return value of this KConfigSkeletonItem.
Definition kcoreconfigskeleton.h:361
const T & value() const
Return const value of this KConfigSkeletonItem.
Definition kcoreconfigskeleton.h:369
T & mReference
Stores the value for this item.
Definition kcoreconfigskeleton.h:422
virtual void setDefaultValue(const T &v)
Set default value for this item.
Definition kcoreconfigskeleton.h:377
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
Definition kcoreconfigskeleton.h:391
void setDefault() override
Set the value for this item to the default value.
Definition kcoreconfigskeleton.h:385
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
Definition kcoreconfigskeleton.h:414
void setValue(const T &v)
Set value of this KConfigSkeletonItem.
Definition kcoreconfigskeleton.h:353
Class for storing a preferences setting.
Definition kcoreconfigskeleton.h:42
KConfigSkeletonItem(const QString &_group, const QString &_key)
Constructor.
KConfigGroup configGroup(KConfig *config) const
Return a KConfigGroup, the one provided by setGroup(const KConfigGroup&) if it's valid,...
virtual bool isEqual(const QVariant &p) const =0
Check whether the item is equal to p.
bool isImmutable() const
Return if the entry can be modified.
virtual void writeConfig(KConfig *)=0
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QString name() const
Return internal name of entry.
virtual QVariant minValue() const
Return minimum value of item or invalid if not specified.
void readImmutability(const KConfigGroup &group)
Sets mIsImmutable to true if mKey in config is immutable.
void setToolTip(const QString &t)
Set ToolTip description of item.
void setWriteFlags(KConfigBase::WriteConfigFlags flags)
The write flags to be used when writing configuration.
virtual void swapDefault()=0
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
QString mKey
The config key for this item.
Definition kcoreconfigskeleton.h:252
virtual void readDefault(KConfig *)=0
Read global default value.
QString key() const
Return config file key.
void setGroup(const QString &_group)
Set config file group.
QVariant getDefault() const
Returns the default value.
virtual void setDefault()=0
Sets the current value to the default value.
void setName(const QString &_name)
Set internal name of entry.
void setLabel(const QString &l)
Set label providing a translated one-line description of the item.
QString whatsThis() const
Return WhatsThis description of item.
virtual QVariant maxValue() const
Return maximum value of item or invalid if not specified.
void setGroup(const KConfigGroup &cg)
Set config file group but giving the KConfigGroup.
QString mGroup
The group name for this item.
Definition kcoreconfigskeleton.h:251
QString toolTip() const
Return ToolTip description of item.
QString group() const
Return name of config file group.
KConfigBase::WriteConfigFlags writeFlags() const
Return write flags to be used when writing configuration.
virtual void setProperty(const QVariant &p)=0
Set item to p.
void setKey(const QString &_key)
Set config file key.
virtual void readConfig(KConfig *)=0
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QString label() const
Return the label of the item.
bool isSaveNeeded() const
Indicates if the item has a different value than the previously loaded value.
void setWhatsThis(const QString &w)
Set WhatsThis description of item.
virtual QVariant property() const =0
Return item as property.
QString mName
The name of this item.
Definition kcoreconfigskeleton.h:253
virtual ~KConfigSkeletonItem()
Destructor.
bool isDefault() const
Indicates if the item is set to its default value.
Class for handling preferences settings for an application.
Definition kconfigskeleton.h:28
The central class of the KDE configuration data system.
Definition kconfig.h:57
void setReadDefaults(bool b)
defaults
Class for handling a bool preferences item.
Definition kcoreconfigskeleton.h:665
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue=true)
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
Class for handling a QDateTime preferences item.
Definition kcoreconfigskeleton.h:1016
void setProperty(const QVariant &p) override
Set item to p.
ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue=QDateTime())
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for handling a floating point preference item.
Definition kcoreconfigskeleton.h:910
QVariant property() const override
Return item as property.
ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue=0)
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void setMinValue(double)
Set the minimum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
void setMaxValue(double)
Set the maximum value for the item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
Class for handling enums.
Definition kcoreconfigskeleton.h:776
void setValueForChoice(const QString &name, const QString &valueForChoice)
Stores a choice value for name.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QString valueForChoice(const QString &name) const
Returns the value for for the choice with the given name.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList< Choice > &choices, qint32 defaultValue=0)
Constructor.
Class for handling an integer list preferences item.
Definition kcoreconfigskeleton.h:1100
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemIntList(const QString &_group, const QString &_key, QList< int > &reference, const QList< int > &defaultValue=QList< int >())
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setProperty(const QVariant &p) override
Set item to p.
Class for handling a 32-bit integer preferences item.
Definition kcoreconfigskeleton.h:687
void setMaxValue(qint32)
Set the maximum value for the item.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMinValue(qint32)
Set the minimum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue=0)
Constructor.
QVariant property() const override
Return item as property.
Class for handling a 64-bit integer preferences item.
Definition kcoreconfigskeleton.h:733
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
QVariant property() const override
Return item as property.
void setMaxValue(qint64)
Set the maximum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue=0)
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMinValue(qint64)
Set the minimum value for the item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
Class for handling a password preferences item.
Definition kcoreconfigskeleton.h:600
ItemPassword(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""))
Constructor.
Class for handling a path list preferences item.
Definition kcoreconfigskeleton.h:1060
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
Class for handling a path preferences item.
Definition kcoreconfigskeleton.h:611
ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QString())
Constructor.
Class for handling a QPoint preferences item.
Definition kcoreconfigskeleton.h:972
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue=QPoint())
Constructor.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
Class for handling a QVariant preferences item.
Definition kcoreconfigskeleton.h:646
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue=QVariant())
Constructor.
Class for handling a QRect preferences item.
Definition kcoreconfigskeleton.h:950
void setProperty(const QVariant &p) override
Set item to p.
ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue=QRect())
Constructor.
QVariant property() const override
Return item as property.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
Class for handling a QSize preferences item.
Definition kcoreconfigskeleton.h:994
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue=QSize())
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for handling a string list preferences item.
Definition kcoreconfigskeleton.h:1038
ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue=QStringList())
Constructor.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
QVariant property() const override
Return item as property.
void setProperty(const QVariant &p) override
Set item to p.
Class for handling a string preferences item.
Definition kcoreconfigskeleton.h:558
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Type
The type of string that is held in this item.
Definition kcoreconfigskeleton.h:561
@ Path
A path to a file or directory.
Definition kcoreconfigskeleton.h:564
@ Normal
A normal string.
Definition kcoreconfigskeleton.h:562
@ Password
A password string.
Definition kcoreconfigskeleton.h:563
QVariant property() const override
Return item as property.
ItemString(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue=QLatin1String(""), Type type=Normal)
Constructor.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
Class for handling an unsigned 32-bit integer preferences item.
Definition kcoreconfigskeleton.h:827
ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue=0)
Constructor.
QVariant property() const override
Return item as property.
void setMinValue(quint32)
Set the minimum value for the item.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setMaxValue(quint32)
Set the maximum value for the item.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
Class for handling unsigned 64-bit integer preferences item.
Definition kcoreconfigskeleton.h:867
QVariant maxValue() const override
Get the maximum value this is allowed to be stored in this item.
ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue=0)
Constructor.
void setMaxValue(quint64)
Set the maximum value for the item.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void setMinValue(quint64)
Set the minimum value for the item.
QVariant property() const override
Return item as property.
QVariant minValue() const override
Get the minimum value that is allowed to be stored in this item.
Class for handling a url list preferences item.
Definition kcoreconfigskeleton.h:1075
void setProperty(const QVariant &p) override
Set item to p.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
QVariant property() const override
Return item as property.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
ItemUrlList(const QString &_group, const QString &_key, QList< QUrl > &reference, const QList< QUrl > &defaultValue=QList< QUrl >())
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for handling a url preferences item.
Definition kcoreconfigskeleton.h:621
void setProperty(const QVariant &p) override
Set item to p.
void readConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
QVariant property() const override
Return item as property.
void writeConfig(KConfig *config) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue=QUrl())
Constructor.
bool isEqual(const QVariant &p) const override
Check whether the item is equal to p.
Class for handling preferences settings for an application.
Definition kcoreconfigskeleton.h:551
virtual bool usrUseDefaults(bool b)
Implemented by subclasses that use special defaults.
ItemDouble * addItemDouble(const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString())
Register an item of type double.
virtual void setDefaults()
Set all registered items to their default values.
virtual bool usrSave()
Perform the actual writing of the configuration file.
void load()
Read preferences from config file.
QString currentGroup() const
Returns the current group used for addItem() calls.
void setSharedConfig(KSharedConfig::Ptr pConfig)
Set the KSharedConfig object used for reading and writing the settings.
ItemProperty * addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString())
Register a property item of type QVariant.
ItemLongLong * addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
Register an item of type qint64.
KSharedConfig::Ptr sharedConfig() const
Return the KConfig object used for reading and writing the settings.
ItemStringList * addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString())
Register an item of type QStringList.
ItemInt * addItemInt(const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString())
Register an item of type qint32.
void configChanged()
This signal is emitted when the configuration change.
bool isSaveNeeded() const
Indicates if any registered item has a different value than the previously loaded value.
ItemIntList * addItemIntList(const QString &name, QList< int > &reference, const QList< int > &defaultValue=QList< int >(), const QString &key=QString())
Register an item of type QList<int>.
ItemPoint * addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString())
Register an item of type QPoint.
ItemULongLong * addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
Register an item of type quint64.
KConfigSkeletonItem * findItem(const QString &name) const
Lookup item by name.
ItemUInt * addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString())
Register an item of type quint32.
ItemSize * addItemSize(const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString())
Register an item of type QSize.
void removeItem(const QString &name)
Removes and deletes an item by name.
ItemRect * addItemRect(const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString())
Register an item of type QRect.
KConfig * config()
Return the KConfig object used for reading and writing the settings.
ItemDateTime * addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString())
Register an item of type QDateTime.
KCoreConfigSkeleton(const QString &configname=QString(), QObject *parent=nullptr)
Constructor.
KConfigSkeletonItem::List items() const
Return list of items managed by this KCoreConfigSkeleton object.
ItemPassword * addItemPassword(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a password item of type QString.
void clearItems()
Removes and deletes all items.
bool isImmutable(const QString &name) const
Return whether a certain item is immutable.
~KCoreConfigSkeleton() override
Destructor.
bool save()
Write preferences to config file.
virtual void usrRead()
Perform the actual reading of the configuration file.
const KConfig * config() const
Return the KConfig object used for reading and writing the settings.
ItemPath * addItemPath(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register a path item of type QString.
void read()
Read preferences from the KConfig object.
KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject *parent=nullptr)
Constructor.
void addItem(KConfigSkeletonItem *item, const QString &name=QString())
Register a custom KConfigSkeletonItem item with a given name.
ItemString * addItemString(const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
Register an item of type QString.
virtual bool useDefaults(bool b)
Specify whether this object should reflect the actual values or the default values.
bool isDefaults() const
Indicates if all the registered items are set to their default value.
ItemBool * addItemBool(const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString())
Register an item of type bool.
virtual void usrSetDefaults()
Perform the actual setting of default values.
void setCurrentGroup(const QString &group)
Set the config file group for subsequent addItem() calls.
Class for proxying a QObject property as a preferences setting.
Definition kcoreconfigskeleton.h:281
bool isEqual(const QVariant &p) const override
void setDefault() override
Sets the current value to the default value.
QVariant property() const override
Return item as property.
KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue)
Constructor.
void setNotifyFunction(const std::function< void()> &impl)
Set a notify function, it will be invoked when the value of the property changes.
void swapDefault() override
Exchanges the current value with the default value Used by KCoreConfigSkeleton::useDefaults(bool);.
void readConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to read the value for this setting from a config file.
void writeConfig(KConfig *) override
This function is called by KCoreConfigSkeleton to write the value of this setting to a config file.
void setProperty(const QVariant &p) override
Set item to p.
void readDefault(KConfig *) override
Read global default value.