File indexing completed on 2024-05-12 15:34:12

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2001, 2002, 2003 Cornelius Schumacher <schumacher@kde.org>
0005     SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KCORECONFIGSKELETON_H
0011 #define KCORECONFIGSKELETON_H
0012 
0013 #include <kconfigcore_export.h>
0014 
0015 #include <kconfiggroup.h>
0016 #include <ksharedconfig.h>
0017 
0018 #include <QDate>
0019 #include <QHash>
0020 #include <QRect>
0021 #include <QStringList>
0022 #include <QUrl>
0023 #include <QVariant>
0024 
0025 class KCoreConfigSkeletonPrivate;
0026 
0027 class KConfigSkeletonItemPrivate;
0028 /**
0029  * \class KConfigSkeletonItem kcoreconfigskeleton.h <KCoreConfigSkeleton>
0030  *
0031  * @short Class for storing a preferences setting
0032  * @author Cornelius Schumacher
0033  * @see KCoreConfigSkeleton
0034  *
0035  * This class represents one preferences setting as used by @ref KCoreConfigSkeleton.
0036  * Subclasses of KConfigSkeletonItem implement storage functions for a certain type of
0037  * setting. Normally you don't have to use this class directly. Use the special
0038  * addItem() functions of KCoreConfigSkeleton instead. If you subclass this class you will
0039  * have to register instances with the function KCoreConfigSkeleton::addItem().
0040  */
0041 class KCONFIGCORE_EXPORT KConfigSkeletonItem
0042 {
0043     Q_DECLARE_PRIVATE(KConfigSkeletonItem)
0044 public:
0045     typedef QList<KConfigSkeletonItem *> List;
0046     typedef QHash<QString, KConfigSkeletonItem *> Dict;
0047     typedef QHash<QString, KConfigSkeletonItem *>::Iterator DictIterator;
0048 
0049     /**
0050      * Constructor.
0051      *
0052      * @param _group Config file group.
0053      * @param _key Config file key.
0054      */
0055     KConfigSkeletonItem(const QString &_group, const QString &_key);
0056 
0057     /**
0058      * Destructor.
0059      */
0060     virtual ~KConfigSkeletonItem();
0061 
0062     /**
0063      * Set config file group.
0064      */
0065     void setGroup(const QString &_group);
0066 
0067     /**
0068      * Return name of config file group.
0069      */
0070     QString group() const;
0071 
0072     /**
0073      * Set config file group but giving the KConfigGroup.
0074      * Allow the item to be in nested groups.
0075      * @since 5.68
0076      */
0077     void setGroup(const KConfigGroup &cg);
0078 
0079     /**
0080      * Return a KConfigGroup, the one provided by setGroup(const KConfigGroup&) if it's valid,
0081      * or make one from @p config and item's group.
0082      * @see setGroup(const QString &_group)
0083      * @see setGroup(KConfigGroup cg)
0084      * @since 5.68
0085      */
0086     KConfigGroup configGroup(KConfig *config) const;
0087 
0088     /**
0089      * Set config file key.
0090      */
0091     void setKey(const QString &_key);
0092 
0093     /**
0094      * Return config file key.
0095      */
0096     QString key() const;
0097 
0098     /**
0099      * Set internal name of entry.
0100      */
0101     void setName(const QString &_name);
0102 
0103     /**
0104      * Return internal name of entry.
0105      */
0106     QString name() const;
0107 
0108     /**
0109      * Set label providing a translated one-line description of the item.
0110      */
0111     void setLabel(const QString &l);
0112 
0113     /**
0114      * Return the label of the item.
0115      * @see setLabel()
0116      */
0117     QString label() const;
0118 
0119     /**
0120      * Set ToolTip description of item.
0121      * @since 4.2
0122      */
0123     void setToolTip(const QString &t);
0124 
0125     /**
0126      * Return ToolTip description of item.
0127      * @see setToolTip()
0128      * @since 4.2
0129      */
0130     QString toolTip() const;
0131 
0132     /**
0133      * Set WhatsThis description of item.
0134      */
0135     void setWhatsThis(const QString &w);
0136 
0137     /**
0138      * Return WhatsThis description of item.
0139      * @see setWhatsThis()
0140      */
0141     QString whatsThis() const;
0142 
0143     /**
0144      * The write flags to be used when writing configuration.
0145      * @since 5.58
0146      */
0147     void setWriteFlags(KConfigBase::WriteConfigFlags flags);
0148 
0149     /**
0150      * Return write flags to be used when writing configuration.
0151      * They should be passed to every call of KConfigGroup::writeEntry() and KConfigGroup::revertToDefault().
0152      * @since 5.58
0153      */
0154     KConfigBase::WriteConfigFlags writeFlags() const;
0155 
0156     /**
0157      * This function is called by @ref KCoreConfigSkeleton to read the value for this setting
0158      * from a config file.
0159      */
0160     virtual void readConfig(KConfig *) = 0;
0161 
0162     /**
0163      * This function is called by @ref KCoreConfigSkeleton to write the value of this setting
0164      * to a config file.
0165      * Make sure to pass writeFlags() to every call of KConfigGroup::writeEntry() and KConfigGroup::revertToDefault().
0166      */
0167     virtual void writeConfig(KConfig *) = 0;
0168 
0169     /**
0170      * Read global default value.
0171      */
0172     virtual void readDefault(KConfig *) = 0;
0173 
0174     /**
0175      * Set item to @p p
0176      */
0177     virtual void setProperty(const QVariant &p) = 0;
0178 
0179     /**
0180      * Check whether the item is equal to @p p.
0181      *
0182      * Use this function to compare items that use custom types,
0183      * because QVariant::operator== will not work for those.
0184      *
0185      * @param p QVariant to compare to
0186      * @return @c true if the item is equal to @p p, @c false otherwise
0187      */
0188     virtual bool isEqual(const QVariant &p) const = 0;
0189 
0190     /**
0191      * Return item as property
0192      */
0193     virtual QVariant property() const = 0;
0194 
0195     /**
0196      * Return minimum value of item or invalid if not specified
0197      */
0198     virtual QVariant minValue() const;
0199 
0200     /**
0201      * Return maximum value of item or invalid if not specified
0202      */
0203     virtual QVariant maxValue() const;
0204 
0205     /**
0206      * Sets the current value to the default value.
0207      */
0208     virtual void setDefault() = 0;
0209 
0210     /**
0211      * Exchanges the current value with the default value
0212      * Used by KCoreConfigSkeleton::useDefaults(bool);
0213      */
0214     virtual void swapDefault() = 0;
0215 
0216     /**
0217      * Return if the entry can be modified.
0218      */
0219     bool isImmutable() const;
0220 
0221     /**
0222      * Indicates if the item is set to its default value.
0223      *
0224      * @since 5.64
0225      */
0226     bool isDefault() const;
0227 
0228     /**
0229      * Indicates if the item has a different value than the
0230      * previously loaded value.
0231      *
0232      * @since 5.64
0233      */
0234     bool isSaveNeeded() const;
0235 
0236     /**
0237      * Returns the default value
0238      * @since 5.74
0239      */
0240     QVariant getDefault() const;
0241 
0242 protected:
0243     KCONFIGCORE_NO_EXPORT explicit KConfigSkeletonItem(KConfigSkeletonItemPrivate &dd, const QString &_group, const QString &_key);
0244 
0245     /**
0246      * Sets mIsImmutable to @c true if mKey in config is immutable.
0247      * @param group KConfigGroup to check if mKey is immutable in
0248      */
0249     void readImmutability(const KConfigGroup &group);
0250 
0251     QString mGroup; ///< The group name for this item
0252     QString mKey; ///< The config key for this item
0253     QString mName; ///< The name of this item
0254 
0255     // HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem
0256     // KF6: Use proper pure virtuals in KConfigSkeletonItem
0257     void setIsDefaultImpl(const std::function<bool()> &impl);
0258     void setIsSaveNeededImpl(const std::function<bool()> &impl);
0259     void setGetDefaultImpl(const std::function<QVariant()> &impl);
0260 
0261     KConfigSkeletonItemPrivate *const d_ptr;
0262 };
0263 
0264 class KPropertySkeletonItemPrivate;
0265 
0266 /**
0267  * \class KPropertySkeletonItem kcoreconfigskeleton.h <KCoreConfigSkeleton>
0268  *
0269  * @short Class for proxying a QObject property as a preferences setting
0270  * @author Kevin Ottens
0271  * @see KConfigSkeletonItem
0272  *
0273  * This class represents one preferences setting as used by @ref KCoreConfigSkeleton.
0274  * Unlike other @ref KConfigSkeletonItem subclasses, this one won't store the preference
0275  * in KConfig but will use a QObject property as storage.
0276  * You will have to register instances of this class with the function KCoreConfigSkeleton::addItem().
0277  *
0278  * @since 5.65
0279  */
0280 class KCONFIGCORE_EXPORT KPropertySkeletonItem : public KConfigSkeletonItem
0281 {
0282     Q_DECLARE_PRIVATE(KPropertySkeletonItem)
0283 public:
0284     /**
0285      * Constructor
0286      *
0287      * @param object The QObject instance which we'll manage the property of
0288      * @param propertyName The name of the property in @p object which we'll manage
0289      * @param defaultValue The default value of the property
0290      */
0291     KPropertySkeletonItem(QObject *object, const QByteArray &propertyName, const QVariant &defaultValue);
0292 
0293     /** @copydoc KConfigSkeletonItem::property() */
0294     QVariant property() const override;
0295     /** @copydoc KConfigSkeletonItem::setProperty(const QVariant &) */
0296     void setProperty(const QVariant &p) override;
0297     /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) */
0298     bool isEqual(const QVariant &p) const override;
0299 
0300     /** @copydoc KConfigSkeletonItem::readConfig(KConfig *) */
0301     void readConfig(KConfig *) override;
0302     /** @copydoc KConfigSkeletonItem::writeConfig(KConfig *) */
0303     void writeConfig(KConfig *) override;
0304 
0305     /** @copydoc KConfigSkeletonItem::readDefault(KConfig *) */
0306     void readDefault(KConfig *) override;
0307     /** @copydoc KConfigSkeletonItem::setDefault() */
0308     void setDefault() override;
0309     /** @copydoc KConfigSkeletonItem::swapDefault() */
0310     void swapDefault() override;
0311 
0312     /**
0313      * Set a notify function, it will be invoked when the value of the property changes.
0314      * @since 5.68
0315      */
0316     void setNotifyFunction(const std::function<void()> &impl);
0317 };
0318 
0319 /**
0320  * \class KConfigSkeletonGenericItem kcoreconfigskeleton.h <KCoreConfigSkeleton>
0321  *
0322  * @short Base class for storing a preferences setting of type @p T.
0323  */
0324 template<typename T>
0325 class KConfigSkeletonGenericItem : public KConfigSkeletonItem
0326 {
0327 public:
0328     /**
0329      * @copydoc KConfigSkeletonItem(const QString&, const QString&)
0330      * @param reference The initial value to hold in the item
0331      * @param defaultValue The default value for the item
0332      */
0333     KConfigSkeletonGenericItem(const QString &_group, const QString &_key, T &reference, T defaultValue)
0334         : KConfigSkeletonItem(_group, _key)
0335         , mReference(reference)
0336         , mDefault(defaultValue)
0337         , mLoadedValue(defaultValue)
0338     {
0339         setIsDefaultImpl([this] {
0340             return mReference == mDefault;
0341         });
0342         setIsSaveNeededImpl([this] {
0343             return mReference != mLoadedValue;
0344         });
0345         setGetDefaultImpl([this] {
0346             return QVariant::fromValue(mDefault);
0347         });
0348     }
0349 
0350     /**
0351      * Set value of this KConfigSkeletonItem.
0352      */
0353     void setValue(const T &v)
0354     {
0355         mReference = v;
0356     }
0357 
0358     /**
0359      * Return value of this KConfigSkeletonItem.
0360      */
0361     T &value()
0362     {
0363         return mReference;
0364     }
0365 
0366     /**
0367      * Return const value of this KConfigSkeletonItem.
0368      */
0369     const T &value() const
0370     {
0371         return mReference;
0372     }
0373 
0374     /**
0375      * Set default value for this item.
0376      */
0377     virtual void setDefaultValue(const T &v)
0378     {
0379         mDefault = v;
0380     }
0381 
0382     /**
0383      * Set the value for this item to the default value
0384      */
0385     void setDefault() override
0386     {
0387         mReference = mDefault;
0388     }
0389 
0390     /** @copydoc KConfigSkeletonItem::writeConfig(KConfig *) */
0391     void writeConfig(KConfig *config) override
0392     {
0393         if (mReference != mLoadedValue) { // Is this needed?
0394             KConfigGroup cg = configGroup(config);
0395             if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
0396                 cg.revertToDefault(mKey, writeFlags());
0397             } else {
0398                 cg.writeEntry(mKey, mReference, writeFlags());
0399             }
0400             mLoadedValue = mReference;
0401         }
0402     }
0403 
0404     /** @copydoc KConfigSkeletonItem::readDefault(KConfig*) */
0405     void readDefault(KConfig *config) override
0406     {
0407         config->setReadDefaults(true);
0408         readConfig(config);
0409         config->setReadDefaults(false);
0410         mDefault = mReference;
0411     }
0412 
0413     /** @copydoc KConfigSkeletonItem::swapDefault() */
0414     void swapDefault() override
0415     {
0416         T tmp = mReference;
0417         mReference = mDefault;
0418         mDefault = tmp;
0419     }
0420 
0421 protected:
0422     T &mReference; ///< Stores the value for this item
0423     T mDefault; ///< The default value for this item
0424     T mLoadedValue;
0425 };
0426 
0427 /**
0428  * \class KConfigCompilerSignallingItem kcoreconfigskeleton.h <KCoreConfigSkeleton>
0429  *
0430  * @author Alex Richardson
0431  *
0432  * This class wraps a @ref KConfigSkeletonItem and invokes a function whenever the value changes.
0433  * That function must take one quint64 parameter. Whenever the property value of the wrapped KConfigSkeletonItem
0434  * changes this function will be invoked with the stored user data passed in the constructor.
0435  * It does not call a function with the new value since this class is designed solely for the \ref kconfig_compiler generated
0436  * code and is therefore probably not suited for any other usecases.
0437  *
0438  * @see KConfigSkeletonItem
0439  */
0440 class KCONFIGCORE_EXPORT KConfigCompilerSignallingItem : public KConfigSkeletonItem
0441 {
0442 public:
0443     typedef void (QObject::*NotifyFunction)(quint64 arg);
0444     /**
0445      * Constructor.
0446      *
0447      * @param item the KConfigSkeletonItem to wrap
0448      * @param targetFunction the method to invoke whenever the value of @p item changes
0449      * @param object The object on which the method is invoked.
0450      * @param userData This data will be passed to @p targetFunction on every property change
0451      */
0452     KConfigCompilerSignallingItem(KConfigSkeletonItem *item, QObject *object, NotifyFunction targetFunction, quint64 userData);
0453     ~KConfigCompilerSignallingItem() override;
0454 
0455     void readConfig(KConfig *) override;
0456     void writeConfig(KConfig *) override;
0457     void readDefault(KConfig *) override;
0458     void setProperty(const QVariant &p) override;
0459     bool isEqual(const QVariant &p) const override;
0460     QVariant property() const override;
0461     QVariant minValue() const override;
0462     QVariant maxValue() const override;
0463     void setDefault() override;
0464     void swapDefault() override;
0465     // KF6 TODO - fix this
0466     // Ideally we would do this in an overload of KConfigSkeletonItem, but
0467     // given we can't, I've shadowed the method. This isn't pretty, but given
0468     // the docs say it should generally only be used from auto generated code,
0469     // should be fine.
0470     void setWriteFlags(KConfigBase::WriteConfigFlags flags);
0471     KConfigBase::WriteConfigFlags writeFlags() const;
0472     void setGroup(const KConfigGroup &cg);
0473     KConfigGroup configGroup(KConfig *config) const;
0474     // END TODO
0475 
0476 private:
0477     inline void invokeNotifyFunction()
0478     {
0479         // call the pointer to member function using the strange ->* operator
0480         (mObject->*mTargetFunction)(mUserData);
0481     }
0482 
0483 private:
0484     QScopedPointer<KConfigSkeletonItem> mItem;
0485     NotifyFunction mTargetFunction;
0486     QObject *mObject;
0487     quint64 mUserData;
0488 };
0489 
0490 /**
0491  * \class KCoreConfigSkeleton kcoreconfigskeleton.h <KCoreConfigSkeleton>
0492  *
0493  * @short Class for handling preferences settings for an application.
0494  * @author Cornelius Schumacher
0495  *
0496  * This class provides an interface to preferences settings. Preferences items
0497  * can be registered by the addItem() function corresponding to the data type of
0498  * the setting. KCoreConfigSkeleton then handles reading and writing of config files and
0499  * setting of default values.
0500  *
0501  * Normally you will subclass KCoreConfigSkeleton, add data members for the preferences
0502  * settings and register the members in the constructor of the subclass.
0503  *
0504  * Example:
0505  * \code
0506  * class MyPrefs : public KCoreConfigSkeleton
0507  * {
0508  *   public:
0509  *     MyPrefs()
0510  *     {
0511  *       setCurrentGroup("MyGroup");
0512  *       addItemBool("MySetting1", mMyBool, false);
0513  *       addItemPoint("MySetting2", mMyPoint, QPoint(100, 200));
0514  *
0515  *       setCurrentGroup("MyOtherGroup");
0516  *       addItemDouble("MySetting3", mMyDouble, 3.14);
0517  *     }
0518  *
0519  *     bool mMyBool;
0520  *     QPoint mMyPoint;
0521  *     double mMyDouble;
0522  * }
0523  * \endcode
0524  *
0525  * It might be convenient in many cases to make this subclass of KCoreConfigSkeleton a
0526  * singleton for global access from all over the application without passing
0527  * references to the KCoreConfigSkeleton object around.
0528  *
0529  * You can write the data to the configuration file by calling @ref save()
0530  * and read the data from the configuration file by calling @ref readConfig().
0531  * If you want to watch for config changes, use @ref configChanged() signal.
0532  *
0533  * If you have items, which are not covered by the existing addItem() functions
0534  * you can add customized code for reading, writing and default setting by
0535  * implementing the functions @ref usrUseDefaults(), @ref usrRead() and
0536  * @ref usrSave().
0537  *
0538  * Internally preferences settings are stored in instances of subclasses of
0539  * @ref KConfigSkeletonItem. You can also add KConfigSkeletonItem subclasses
0540  * for your own types and call the generic @ref addItem() to register them.
0541  *
0542  * In many cases you don't have to write the specific KCoreConfigSkeleton
0543  * subclasses yourself, but you can use \ref kconfig_compiler to automatically
0544  * generate the C++ code from an XML description of the configuration options.
0545  *
0546  * Use KConfigSkeleton if you need GUI types as well.
0547  *
0548  * @see KConfigSkeletonItem
0549  */
0550 class KCONFIGCORE_EXPORT KCoreConfigSkeleton : public QObject
0551 {
0552     Q_OBJECT
0553 public:
0554     /**
0555      * Class for handling a string preferences item.
0556      */
0557     class KCONFIGCORE_EXPORT ItemString : public KConfigSkeletonGenericItem<QString>
0558     {
0559     public:
0560         /** The type of string that is held in this item */
0561         enum Type {
0562             Normal, ///< A normal string
0563             Password, ///< A password string
0564             Path, ///< A path to a file or directory
0565         };
0566 
0567         /**
0568          * @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem
0569          * @param type The type of string held by the item
0570          */
0571         ItemString(const QString &_group,
0572                    const QString &_key,
0573                    QString &reference,
0574                    const QString &defaultValue = QLatin1String(""), // NOT QString() !!
0575                    Type type = Normal);
0576 
0577         /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
0578         void writeConfig(KConfig *config) override;
0579 
0580         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0581         void readConfig(KConfig *config) override;
0582 
0583         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0584         void setProperty(const QVariant &p) override;
0585 
0586         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0587         bool isEqual(const QVariant &p) const override;
0588 
0589         /** @copydoc KConfigSkeletonItem::property() const */
0590         QVariant property() const override;
0591 
0592     private:
0593         Type mType;
0594     };
0595 
0596     /**
0597      * Class for handling a password preferences item.
0598      */
0599     class KCONFIGCORE_EXPORT ItemPassword : public ItemString
0600     {
0601     public:
0602         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0603         ItemPassword(const QString &_group, const QString &_key, QString &reference,
0604                      const QString &defaultValue = QLatin1String("")); // NOT QString() !!
0605     };
0606 
0607     /**
0608      * Class for handling a path preferences item.
0609      */
0610     class KCONFIGCORE_EXPORT ItemPath : public ItemString
0611     {
0612     public:
0613         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0614         ItemPath(const QString &_group, const QString &_key, QString &reference, const QString &defaultValue = QString());
0615     };
0616 
0617     /**
0618      * Class for handling a url preferences item.
0619      */
0620     class KCONFIGCORE_EXPORT ItemUrl : public KConfigSkeletonGenericItem<QUrl>
0621     {
0622     public:
0623         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0624         ItemUrl(const QString &_group, const QString &_key, QUrl &reference, const QUrl &defaultValue = QUrl());
0625 
0626         /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
0627         void writeConfig(KConfig *config) override;
0628 
0629         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0630         void readConfig(KConfig *config) override;
0631 
0632         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0633         void setProperty(const QVariant &p) override;
0634 
0635         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0636         bool isEqual(const QVariant &p) const override;
0637 
0638         /** @copydoc KConfigSkeletonItem::property() const */
0639         QVariant property() const override;
0640     };
0641 
0642     /**
0643      * Class for handling a QVariant preferences item.
0644      */
0645     class KCONFIGCORE_EXPORT ItemProperty : public KConfigSkeletonGenericItem<QVariant>
0646     {
0647     public:
0648         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0649         ItemProperty(const QString &_group, const QString &_key, QVariant &reference, const QVariant &defaultValue = QVariant());
0650 
0651         void readConfig(KConfig *config) override;
0652         void setProperty(const QVariant &p) override;
0653 
0654         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0655         bool isEqual(const QVariant &p) const override;
0656 
0657         /** @copydoc KConfigSkeletonItem::property() const */
0658         QVariant property() const override;
0659     };
0660 
0661     /**
0662      * Class for handling a bool preferences item.
0663      */
0664     class KCONFIGCORE_EXPORT ItemBool : public KConfigSkeletonGenericItem<bool>
0665     {
0666     public:
0667         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0668         ItemBool(const QString &_group, const QString &_key, bool &reference, bool defaultValue = true);
0669 
0670         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0671         void readConfig(KConfig *config) override;
0672 
0673         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0674         void setProperty(const QVariant &p) override;
0675 
0676         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0677         bool isEqual(const QVariant &p) const override;
0678 
0679         /** @copydoc KConfigSkeletonItem::property() const */
0680         QVariant property() const override;
0681     };
0682 
0683     /**
0684      * Class for handling a 32-bit integer preferences item.
0685      */
0686     class KCONFIGCORE_EXPORT ItemInt : public KConfigSkeletonGenericItem<qint32>
0687     {
0688     public:
0689         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0690         ItemInt(const QString &_group, const QString &_key, qint32 &reference, qint32 defaultValue = 0);
0691 
0692         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0693         void readConfig(KConfig *config) override;
0694 
0695         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0696         void setProperty(const QVariant &p) override;
0697 
0698         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0699         bool isEqual(const QVariant &p) const override;
0700 
0701         /** @copydoc KConfigSkeletonItem::property() */
0702         QVariant property() const override;
0703 
0704         /** Get the minimum value that is allowed to be stored in this item */
0705         QVariant minValue() const override;
0706 
0707         /** Get the maximum value this is allowed to be stored in this item */
0708         QVariant maxValue() const override;
0709 
0710         /**
0711          * Set the minimum value for the item.
0712          * @see minValue()
0713          */
0714         void setMinValue(qint32);
0715 
0716         /**
0717          * Set the maximum value for the item.
0718          * @see maxValue
0719          */
0720         void setMaxValue(qint32);
0721 
0722     private:
0723         bool mHasMin : 1;
0724         bool mHasMax : 1;
0725         qint32 mMin;
0726         qint32 mMax;
0727     };
0728 
0729     /**
0730      * Class for handling a 64-bit integer preferences item.
0731      */
0732     class KCONFIGCORE_EXPORT ItemLongLong : public KConfigSkeletonGenericItem<qint64>
0733     {
0734     public:
0735         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0736         ItemLongLong(const QString &_group, const QString &_key, qint64 &reference, qint64 defaultValue = 0);
0737 
0738         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0739         void readConfig(KConfig *config) override;
0740 
0741         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0742         void setProperty(const QVariant &p) override;
0743 
0744         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0745         bool isEqual(const QVariant &p) const override;
0746 
0747         /** @copydoc KConfigSkeletonItem::property() */
0748         QVariant property() const override;
0749 
0750         /** @copydoc ItemInt::minValue() */
0751         QVariant minValue() const override;
0752 
0753         /** @copydoc ItemInt::maxValue() */
0754         QVariant maxValue() const override;
0755 
0756         /** @copydoc ItemInt::setMinValue(qint32) */
0757         void setMinValue(qint64);
0758 
0759         /** @copydoc ItemInt::setMaxValue(qint32) */
0760         void setMaxValue(qint64);
0761 
0762     private:
0763         bool mHasMin : 1;
0764         bool mHasMax : 1;
0765         qint64 mMin;
0766         qint64 mMax;
0767     };
0768 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
0769     typedef KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use ItemLongLong") ItemLongLong ItemInt64;
0770 #endif
0771 
0772     /**
0773      * Class for handling enums.
0774      */
0775     class KCONFIGCORE_EXPORT ItemEnum : public ItemInt
0776     {
0777     public:
0778         struct Choice {
0779             QString name;
0780             QString label;
0781             QString toolTip;
0782             QString whatsThis;
0783         };
0784 
0785         /**
0786          * @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem
0787          * @param choices The list of enums that can be stored in this item
0788          */
0789         ItemEnum(const QString &_group, const QString &_key, qint32 &reference, const QList<Choice> &choices, qint32 defaultValue = 0);
0790 
0791         QList<Choice> choices() const;
0792 
0793         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0794         void readConfig(KConfig *config) override;
0795 
0796         /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
0797         void writeConfig(KConfig *config) override;
0798 
0799 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 103)
0800         // Source compatibility with 4.x
0801         typedef KCONFIGCORE_DEPRECATED_VERSION_BELATED(5, 103, 5, 0, "Use Choice") Choice Choice2;
0802         /**
0803          * @deprecated since 5.0, use choices() const.
0804          */
0805         KCONFIGCORE_DEPRECATED_VERSION_BELATED(5, 103, 5, 0, "Use choices().")
0806         QList<Choice> choices2() const;
0807 #endif
0808 
0809         /**
0810          * Returns the value for for the choice with the given @p name
0811          */
0812         QString valueForChoice(const QString &name) const;
0813 
0814         /**
0815          * Stores a choice value for @p name
0816          */
0817         void setValueForChoice(const QString &name, const QString &valueForChoice);
0818 
0819     private:
0820         QList<Choice> mChoices;
0821     };
0822 
0823     /**
0824      * Class for handling an unsigned 32-bit integer preferences item.
0825      */
0826     class KCONFIGCORE_EXPORT ItemUInt : public KConfigSkeletonGenericItem<quint32>
0827     {
0828     public:
0829         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0830         ItemUInt(const QString &_group, const QString &_key, quint32 &reference, quint32 defaultValue = 0);
0831 
0832         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0833         void readConfig(KConfig *config) override;
0834 
0835         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0836         void setProperty(const QVariant &p) override;
0837 
0838         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0839         bool isEqual(const QVariant &p) const override;
0840 
0841         /** @copydoc KConfigSkeletonItem::property() */
0842         QVariant property() const override;
0843 
0844         /** @copydoc ItemInt::minValue() */
0845         QVariant minValue() const override;
0846 
0847         /** @copydoc ItemInt::maxValue() */
0848         QVariant maxValue() const override;
0849 
0850         /** @copydoc ItemInt::setMinValue(qint32) */
0851         void setMinValue(quint32);
0852 
0853         /** @copydoc ItemInt::setMaxValue(qint32) */
0854         void setMaxValue(quint32);
0855 
0856     private:
0857         bool mHasMin : 1;
0858         bool mHasMax : 1;
0859         quint32 mMin;
0860         quint32 mMax;
0861     };
0862 
0863     /**
0864      * Class for handling unsigned 64-bit integer preferences item.
0865      */
0866     class KCONFIGCORE_EXPORT ItemULongLong : public KConfigSkeletonGenericItem<quint64>
0867     {
0868     public:
0869         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0870         ItemULongLong(const QString &_group, const QString &_key, quint64 &reference, quint64 defaultValue = 0);
0871 
0872         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0873         void readConfig(KConfig *config) override;
0874 
0875         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0876         void setProperty(const QVariant &p) override;
0877 
0878         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0879         bool isEqual(const QVariant &p) const override;
0880 
0881         /** @copydoc KConfigSkeletonItem::property() */
0882         QVariant property() const override;
0883 
0884         /** @copydoc ItemInt::minValue() */
0885         QVariant minValue() const override;
0886 
0887         /** @copydoc ItemInt::maxValue() */
0888         QVariant maxValue() const override;
0889 
0890         /** @copydoc ItemInt::setMinValue(qint32) */
0891         void setMinValue(quint64);
0892 
0893         /** @copydoc ItemInt::setMaxValue(qint32) */
0894         void setMaxValue(quint64);
0895 
0896     private:
0897         bool mHasMin : 1;
0898         bool mHasMax : 1;
0899         quint64 mMin;
0900         quint64 mMax;
0901     };
0902 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
0903     typedef KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use ItemULongLong") ItemULongLong ItemUInt64;
0904 #endif
0905 
0906     /**
0907      * Class for handling a floating point preference item.
0908      */
0909     class KCONFIGCORE_EXPORT ItemDouble : public KConfigSkeletonGenericItem<double>
0910     {
0911     public:
0912         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0913         ItemDouble(const QString &_group, const QString &_key, double &reference, double defaultValue = 0);
0914 
0915         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0916         void readConfig(KConfig *config) override;
0917 
0918         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0919         void setProperty(const QVariant &p) override;
0920 
0921         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0922         bool isEqual(const QVariant &p) const override;
0923 
0924         /** @copydoc KConfigSkeletonItem::property() */
0925         QVariant property() const override;
0926 
0927         /** @copydoc ItemInt::minValue() */
0928         QVariant minValue() const override;
0929 
0930         /** @copydoc ItemInt::maxValue() */
0931         QVariant maxValue() const override;
0932 
0933         /** @copydoc ItemInt::setMinValue() */
0934         void setMinValue(double);
0935 
0936         /** @copydoc ItemInt::setMaxValue() */
0937         void setMaxValue(double);
0938 
0939     private:
0940         bool mHasMin : 1;
0941         bool mHasMax : 1;
0942         double mMin;
0943         double mMax;
0944     };
0945 
0946     /**
0947      * Class for handling a QRect preferences item.
0948      */
0949     class KCONFIGCORE_EXPORT ItemRect : public KConfigSkeletonGenericItem<QRect>
0950     {
0951     public:
0952         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0953         ItemRect(const QString &_group, const QString &_key, QRect &reference, const QRect &defaultValue = QRect());
0954 
0955         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0956         void readConfig(KConfig *config) override;
0957 
0958         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0959         void setProperty(const QVariant &p) override;
0960 
0961         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0962         bool isEqual(const QVariant &p) const override;
0963 
0964         /** @copydoc KConfigSkeletonItem::property() */
0965         QVariant property() const override;
0966     };
0967 
0968     /**
0969      * Class for handling a QPoint preferences item.
0970      */
0971     class KCONFIGCORE_EXPORT ItemPoint : public KConfigSkeletonGenericItem<QPoint>
0972     {
0973     public:
0974         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0975         ItemPoint(const QString &_group, const QString &_key, QPoint &reference, const QPoint &defaultValue = QPoint());
0976 
0977         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
0978         void readConfig(KConfig *config) override;
0979 
0980         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
0981         void setProperty(const QVariant &p) override;
0982 
0983         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
0984         bool isEqual(const QVariant &p) const override;
0985 
0986         /** @copydoc KConfigSkeletonItem::property() */
0987         QVariant property() const override;
0988     };
0989 
0990     /**
0991      * Class for handling a QSize preferences item.
0992      */
0993     class KCONFIGCORE_EXPORT ItemSize : public KConfigSkeletonGenericItem<QSize>
0994     {
0995     public:
0996         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
0997         ItemSize(const QString &_group, const QString &_key, QSize &reference, const QSize &defaultValue = QSize());
0998 
0999         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
1000         void readConfig(KConfig *config) override;
1001 
1002         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
1003         void setProperty(const QVariant &p) override;
1004 
1005         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
1006         bool isEqual(const QVariant &p) const override;
1007 
1008         /** @copydoc KConfigSkeletonItem::property() */
1009         QVariant property() const override;
1010     };
1011 
1012     /**
1013      * Class for handling a QDateTime preferences item.
1014      */
1015     class KCONFIGCORE_EXPORT ItemDateTime : public KConfigSkeletonGenericItem<QDateTime>
1016     {
1017     public:
1018         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
1019         ItemDateTime(const QString &_group, const QString &_key, QDateTime &reference, const QDateTime &defaultValue = QDateTime());
1020 
1021         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
1022         void readConfig(KConfig *config) override;
1023 
1024         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
1025         void setProperty(const QVariant &p) override;
1026 
1027         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
1028         bool isEqual(const QVariant &p) const override;
1029 
1030         /** @copydoc KConfigSkeletonItem::property() */
1031         QVariant property() const override;
1032     };
1033 
1034     /**
1035      * Class for handling a string list preferences item.
1036      */
1037     class KCONFIGCORE_EXPORT ItemStringList : public KConfigSkeletonGenericItem<QStringList>
1038     {
1039     public:
1040         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
1041         ItemStringList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList());
1042 
1043         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
1044         void readConfig(KConfig *config) override;
1045 
1046         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
1047         void setProperty(const QVariant &p) override;
1048 
1049         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
1050         bool isEqual(const QVariant &p) const override;
1051 
1052         /** @copydoc KConfigSkeletonItem::property() */
1053         QVariant property() const override;
1054     };
1055 
1056     /**
1057      * Class for handling a path list preferences item.
1058      */
1059     class KCONFIGCORE_EXPORT ItemPathList : public ItemStringList
1060     {
1061     public:
1062         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
1063         ItemPathList(const QString &_group, const QString &_key, QStringList &reference, const QStringList &defaultValue = QStringList());
1064 
1065         /** @copydoc KConfigSkeletonItem::readConfig */
1066         void readConfig(KConfig *config) override;
1067         /** @copydoc KConfigSkeletonItem::writeConfig */
1068         void writeConfig(KConfig *config) override;
1069     };
1070 
1071     /**
1072      * Class for handling a url list preferences item.
1073      */
1074     class KCONFIGCORE_EXPORT ItemUrlList : public KConfigSkeletonGenericItem<QList<QUrl>>
1075     {
1076     public:
1077         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
1078         ItemUrlList(const QString &_group, const QString &_key, QList<QUrl> &reference, const QList<QUrl> &defaultValue = QList<QUrl>());
1079 
1080         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
1081         void readConfig(KConfig *config) override;
1082 
1083         /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
1084         void writeConfig(KConfig *config) override;
1085 
1086         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
1087         void setProperty(const QVariant &p) override;
1088 
1089         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
1090         bool isEqual(const QVariant &p) const override;
1091 
1092         /** @copydoc KConfigSkeletonItem::property() */
1093         QVariant property() const override;
1094     };
1095 
1096     /**
1097      * Class for handling an integer list preferences item.
1098      */
1099     class KCONFIGCORE_EXPORT ItemIntList : public KConfigSkeletonGenericItem<QList<int>>
1100     {
1101     public:
1102         /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
1103         ItemIntList(const QString &_group, const QString &_key, QList<int> &reference, const QList<int> &defaultValue = QList<int>());
1104 
1105         /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
1106         void readConfig(KConfig *config) override;
1107 
1108         /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
1109         void setProperty(const QVariant &p) override;
1110 
1111         /** @copydoc KConfigSkeletonItem::isEqual(const QVariant &) const */
1112         bool isEqual(const QVariant &p) const override;
1113 
1114         /** @copydoc KConfigSkeletonItem::property() */
1115         QVariant property() const override;
1116     };
1117 
1118 public:
1119     /**
1120      * Constructor.
1121      *
1122      * @param configname name of config file. If no name is given, the default
1123      *                   config file as returned by KSharedConfig::openConfig() is used
1124      * @param parent the parent object (see QObject documentation)
1125      */
1126     explicit KCoreConfigSkeleton(const QString &configname = QString(), QObject *parent = nullptr);
1127 
1128     /**
1129      * Constructor.
1130      *
1131      * @param config configuration object to use
1132      * @param parent the parent object (see QObject documentation)
1133      */
1134     explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject *parent = nullptr);
1135 
1136     /**
1137      * Destructor
1138      */
1139     ~KCoreConfigSkeleton() override;
1140 
1141     /**
1142      * Set all registered items to their default values.
1143      * This method calls usrSetDefaults() after setting the defaults for the
1144      * registered items. You can override usrSetDefaults() in derived classes
1145      * if you have special requirements.
1146      * If you need more fine-grained control of setting the default values of
1147      * the registered items you can override setDefaults() in a derived class.
1148      */
1149     virtual void setDefaults();
1150 
1151     /**
1152      * Read preferences from config file. All registered items are set to the
1153      * values read from disk.
1154      * This method calls usrRead() after reading the settings of the
1155      * registered items from the KConfig. You can override usrRead()
1156      * in derived classes if you have special requirements.
1157      */
1158     void load();
1159 
1160 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1161     /**
1162      * @deprecated since 5.0, call load() instead (to reload from disk) or just read()
1163      * if the underlying KConfig object is already up-to-date.
1164      */
1165     KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::load() or KCoreConfigSkeleton::read()")
1166     void readConfig()
1167     {
1168         load();
1169     }
1170 #endif
1171 
1172     /**
1173      * Read preferences from the KConfig object.
1174      * This method assumes that the KConfig object was previously loaded,
1175      * i.e. it uses the in-memory values from KConfig without reloading from disk.
1176      *
1177      * This method calls usrRead() after reading the settings of the
1178      * registered items from the KConfig. You can override usrRead()
1179      * in derived classes if you have special requirements.
1180      * @since 5.0
1181      */
1182     void read();
1183 
1184     /**
1185      * Indicates if all the registered items are set to their default value.
1186      *
1187      * @since 5.64
1188      */
1189     bool isDefaults() const;
1190 
1191     /**
1192      * Indicates if any registered item has a different value than the
1193      * previously loaded value.
1194      *
1195      * @since 5.64
1196      */
1197     bool isSaveNeeded() const;
1198 
1199     /**
1200      * Set the config file group for subsequent addItem() calls. It is valid
1201      * until setCurrentGroup() is called with a new argument. Call this before
1202      * you add any items. The default value is "No Group".
1203      */
1204     void setCurrentGroup(const QString &group);
1205 
1206     /**
1207      * Returns the current group used for addItem() calls.
1208      */
1209     QString currentGroup() const;
1210 
1211     /**
1212      * Register a custom @ref KConfigSkeletonItem @p item with a given @p name.
1213      *
1214      * If @p name is a null string, take the name from KConfigSkeletonItem::key().
1215      *
1216      * @note All names must be unique but multiple entries can have
1217      * the same key if they reside in different groups.
1218      *
1219      * KCoreConfigSkeleton takes ownership of @p item.
1220      */
1221     void addItem(KConfigSkeletonItem *item, const QString &name = QString());
1222 
1223     /**
1224      * Register an item of type QString.
1225      *
1226      * @param name Name used to identify this setting. Names must be unique.
1227      * @param reference Pointer to the variable, which is set by readConfig()
1228      * calls and read by save() calls.
1229      * @param defaultValue Default value, which is used when the config file
1230      * does not yet contain the key of this item.
1231      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1232      * @return The created item
1233      */
1234     ItemString *addItemString(const QString &name,
1235                               QString &reference,
1236                               const QString &defaultValue = QLatin1String(""), // NOT QString() !!
1237                               const QString &key = QString());
1238 
1239     /**
1240      * Register a password item of type QString. The string value is written
1241      * encrypted to the config file.
1242      *
1243      * @note The current encryption scheme is very weak.
1244      *
1245      * @param name Name used to identify this setting. Names must be unique.
1246      * @param reference Pointer to the variable, which is set by readConfig()
1247      * calls and read by save() calls.
1248      * @param defaultValue Default value, which is used when the config file
1249      * does not yet contain the key of this item.
1250      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1251      * @return The created item
1252      */
1253     ItemPassword *addItemPassword(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString());
1254 
1255     /**
1256      * Register a path item of type QString. The string value is interpreted
1257      * as a path. This means, dollar expansion is activated for this value, so
1258      * that e.g. @c $HOME gets expanded.
1259      *
1260      * @param name Name used to identify this setting. Names must be unique.
1261      * @param reference Pointer to the variable, which is set by readConfig()
1262      * calls and read by save() calls.
1263      * @param defaultValue Default value, which is used when the config file
1264      * does not yet contain the key of this item.
1265      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1266      * @return The created item
1267      */
1268     ItemPath *addItemPath(const QString &name, QString &reference, const QString &defaultValue = QLatin1String(""), const QString &key = QString());
1269 
1270     /**
1271      * Register a property item of type QVariant.
1272      *
1273      * @note The following QVariant types are allowed:
1274      * String, StringList, Font, Point, Rect, Size,
1275      * Color, Int, UInt, Bool, Double, DateTime and Date.
1276      *
1277      * @param name Name used to identify this setting. Names must be unique.
1278      * @param reference Pointer to the variable, which is set by readConfig()
1279      * calls and read by save() calls.
1280      * @param defaultValue Default value, which is used when the config file
1281      * does not yet contain the key of this item.
1282      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1283      * @return The created item
1284      */
1285     ItemProperty *addItemProperty(const QString &name, QVariant &reference, const QVariant &defaultValue = QVariant(), const QString &key = QString());
1286     /**
1287      * Register an item of type @c bool.
1288      *
1289      * @param name Name used to identify this setting. Names must be unique.
1290      * @param reference Pointer to the variable, which is set by readConfig()
1291      * calls and read by save() calls.
1292      * @param defaultValue Default value, which is used when the config file
1293      * does not yet contain the key of this item.
1294      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1295      * @return The created item
1296      */
1297     ItemBool *addItemBool(const QString &name, bool &reference, bool defaultValue = false, const QString &key = QString());
1298 
1299     /**
1300      * Register an item of type @c qint32.
1301      *
1302      * @param name Name used to identify this setting. Names must be unique.
1303      * @param reference Pointer to the variable, which is set by readConfig()
1304      * calls and read by save() calls.
1305      * @param defaultValue Default value, which is used when the config file
1306      * does not yet contain the key of this item.
1307      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1308      * @return The created item
1309      */
1310     ItemInt *addItemInt(const QString &name, qint32 &reference, qint32 defaultValue = 0, const QString &key = QString());
1311 
1312     /**
1313      * Register an item of type @c quint32.
1314      *
1315      * @param name Name used to identify this setting. Names must be unique.
1316      * @param reference Pointer to the variable, which is set by readConfig()
1317      * calls and read by save() calls.
1318      * @param defaultValue Default value, which is used when the config file
1319      * does not yet contain the key of this item.
1320      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1321      * @return The created item
1322      */
1323     ItemUInt *addItemUInt(const QString &name, quint32 &reference, quint32 defaultValue = 0, const QString &key = QString());
1324 
1325     /**
1326      * Register an item of type @c qint64.
1327      *
1328      * @param name Name used to identify this setting. Names must be unique.
1329      * @param reference Pointer to the variable, which is set by readConfig()
1330      * calls and read by save() calls.
1331      * @param defaultValue Default value, which is used when the config file
1332      * does not yet contain the key of this item.
1333      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1334      * @return The created item
1335      */
1336     ItemLongLong *addItemLongLong(const QString &name, qint64 &reference, qint64 defaultValue = 0, const QString &key = QString());
1337 
1338 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1339     /**
1340      * @deprecated Since 5.0, use addItemLongLong().
1341      */
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 
1346     /**
1347      * Register an item of type @c quint64.
1348      *
1349      * @param name Name used to identify this setting. Names must be unique.
1350      * @param reference Pointer to the variable, which is set by readConfig()
1351      * calls and read by save() calls.
1352      * @param defaultValue Default value, which is used when the config file
1353      * does not yet contain the key of this item.
1354      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1355      * @return The created item
1356      */
1357     ItemULongLong *addItemULongLong(const QString &name, quint64 &reference, quint64 defaultValue = 0, const QString &key = QString());
1358 
1359 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1360     /**
1361      * @deprecated Since 5.0, use addItemULongLong().
1362      */
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 
1367     /**
1368      * Register an item of type @c double.
1369      *
1370      * @param name Name used to identify this setting. Names must be unique.
1371      * @param reference Pointer to the variable, which is set by readConfig()
1372      * calls and read by save() calls.
1373      * @param defaultValue Default value, which is used when the config file
1374      * does not yet contain the key of this item.
1375      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1376      * @return The created item
1377      */
1378     ItemDouble *addItemDouble(const QString &name, double &reference, double defaultValue = 0.0, const QString &key = QString());
1379 
1380     /**
1381      * Register an item of type QRect.
1382      *
1383      * @param name Name used to identify this setting. Names must be unique.
1384      * @param reference Pointer to the variable, which is set by readConfig()
1385      * calls and read by save() calls.
1386      * @param defaultValue Default value, which is used when the config file
1387      * does not yet contain the key of this item.
1388      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1389      * @return The created item
1390      */
1391     ItemRect *addItemRect(const QString &name, QRect &reference, const QRect &defaultValue = QRect(), const QString &key = QString());
1392 
1393     /**
1394      * Register an item of type QPoint.
1395      *
1396      * @param name Name used to identify this setting. Names must be unique.
1397      * @param reference Pointer to the variable, which is set by readConfig()
1398      * calls and read by save() calls.
1399      * @param defaultValue Default value, which is used when the config file
1400      * does not yet contain the key of this item.
1401      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1402      * @return The created item
1403      */
1404     ItemPoint *addItemPoint(const QString &name, QPoint &reference, const QPoint &defaultValue = QPoint(), const QString &key = QString());
1405 
1406     /**
1407      * Register an item of type QSize.
1408      *
1409      * @param name Name used to identify this setting. Names must be unique.
1410      * @param reference Pointer to the variable, which is set by readConfig()
1411      * calls and read by save() calls.
1412      * @param defaultValue Default value, which is used when the config file
1413      * does not yet contain the key of this item.
1414      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1415      * @return The created item
1416      */
1417     ItemSize *addItemSize(const QString &name, QSize &reference, const QSize &defaultValue = QSize(), const QString &key = QString());
1418 
1419     /**
1420      * Register an item of type QDateTime.
1421      *
1422      * @param name Name used to identify this setting. Names must be unique.
1423      * @param reference Pointer to the variable, which is set by readConfig()
1424      * calls and read by save() calls.
1425      * @param defaultValue Default value, which is used when the config file
1426      * does not yet contain the key of this item.
1427      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1428      * @return The created item
1429      */
1430     ItemDateTime *addItemDateTime(const QString &name, QDateTime &reference, const QDateTime &defaultValue = QDateTime(), const QString &key = QString());
1431 
1432     /**
1433      * Register an item of type QStringList.
1434      *
1435      * @param name Name used to identify this setting. Names must be unique.
1436      * @param reference Pointer to the variable, which is set by readConfig()
1437      * calls and read by save() calls.
1438      * @param defaultValue Default value, which is used when the config file
1439      * does not yet contain the key of this item.
1440      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1441      * @return The created item
1442      */
1443     ItemStringList *
1444     addItemStringList(const QString &name, QStringList &reference, const QStringList &defaultValue = QStringList(), const QString &key = QString());
1445 
1446     /**
1447      * Register an item of type QList<int>.
1448      *
1449      * @param name Name used to identify this setting. Names must be unique.
1450      * @param reference Pointer to the variable, which is set by readConfig()
1451      * calls and read by save() calls.
1452      * @param defaultValue Default value, which is used when the config file
1453      * does not yet contain the key of this item.
1454      * @param key Key used in config file. If @p key is a null string, @p name is used as key.
1455      * @return The created item
1456      */
1457     ItemIntList *addItemIntList(const QString &name, QList<int> &reference, const QList<int> &defaultValue = QList<int>(), const QString &key = QString());
1458 
1459     /**
1460      * Return the @ref KConfig object used for reading and writing the settings.
1461      */
1462     KConfig *config();
1463 
1464     /**
1465      * Return the @ref KConfig object used for reading and writing the settings.
1466      */
1467     const KConfig *config() const;
1468 
1469     /**
1470      * Return the @ref KConfig object used for reading and writing the settings.
1471      * @since 5.0
1472      */
1473     KSharedConfig::Ptr sharedConfig() const;
1474 
1475     /**
1476      * Set the @ref KSharedConfig object used for reading and writing the settings.
1477      */
1478     void setSharedConfig(KSharedConfig::Ptr pConfig);
1479 
1480     /**
1481      * Return list of items managed by this KCoreConfigSkeleton object.
1482      */
1483     KConfigSkeletonItem::List items() const;
1484 
1485     /**
1486      * Removes and deletes an item by name
1487      * @param name the name of the item to remove
1488      */
1489     void removeItem(const QString &name);
1490 
1491     /**
1492      * Removes and deletes all items
1493      */
1494     void clearItems();
1495 
1496     /**
1497      * Return whether a certain item is immutable
1498      * @since 4.4
1499      */
1500     Q_INVOKABLE bool isImmutable(const QString &name) const;
1501 
1502     /**
1503      * Lookup item by name
1504      * @since 4.4
1505      */
1506     KConfigSkeletonItem *findItem(const QString &name) const;
1507 
1508     /**
1509      * Specify whether this object should reflect the actual values or the
1510      * default values.
1511      * This method is implemented by usrUseDefaults(), which can be overridden
1512      * in derived classes if you have special requirements and can call
1513      * usrUseDefaults() directly.
1514      * If you don't have control whether useDefaults() or usrUseDefaults() is
1515      * called override useDefaults() directly.
1516      * @param b @c true to make this object reflect the default values,
1517      *          @c false to make it reflect the actual values.
1518      * @return The state prior to this call
1519      */
1520     virtual bool useDefaults(bool b);
1521 
1522 public Q_SLOTS:
1523     /**
1524      * Write preferences to config file. The values of all registered items are
1525      * written to disk.
1526      * This method calls usrSave() after writing the settings from the
1527      * registered items to the KConfig. You can override usrSave()
1528      * in derived classes if you have special requirements.
1529      */
1530     bool save();
1531 
1532 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 0)
1533     /**
1534      * @deprecated since 5.0, call save() instead.
1535      */
1536     KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Use KCoreConfigSkeleton::save()")
1537     void writeConfig()
1538     {
1539         save();
1540     }
1541 #endif
1542 
1543 Q_SIGNALS:
1544     /**
1545      * This signal is emitted when the configuration change.
1546      */
1547     void configChanged();
1548 
1549 protected:
1550     /**
1551      * Implemented by subclasses that use special defaults.
1552      * It replaces the default values with the actual values and
1553      * vice versa.  Called from @ref useDefaults()
1554      * @param b @c true to make this object reflect the default values,
1555      *          @c false to make it reflect the actual values.
1556      * @return The state prior to this call
1557      */
1558     virtual bool usrUseDefaults(bool b);
1559 
1560     /**
1561      * Perform the actual setting of default values.
1562      * Override in derived classes to set special default values.
1563      * Called from @ref setDefaults()
1564      */
1565     virtual void usrSetDefaults();
1566 
1567     /**
1568      * Perform the actual reading of the configuration file.
1569      * Override in derived classes to read special config values.
1570      * Called from @ref read()
1571      */
1572     virtual void usrRead();
1573 
1574     /**
1575      * Perform the actual writing of the configuration file.
1576      * Override in derived classes to write special config values.
1577      * Called from @ref save()
1578      */
1579     virtual bool usrSave();
1580 
1581 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1582     /**
1583      * @deprecated since 5.0, override usrRead instead.  This method is still called from usrRead
1584      * for compatibility.
1585      */
1586     KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Override KCoreConfigSkeleton::usrRead()")
1587     virtual void usrReadConfig();
1588 #endif
1589 
1590 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
1591     /**
1592      * @deprecated since 5.0, override usrSave instead.  This method is still called from usrSave
1593      * for compatibility.
1594      */
1595     KCONFIGCORE_DEPRECATED_VERSION(5, 0, "Override KCoreConfigSkeleton::usrSave()")
1596     virtual bool usrWriteConfig();
1597 #endif
1598 
1599 private:
1600     KCoreConfigSkeletonPrivate *const d;
1601     friend class KConfigSkeleton;
1602 };
1603 
1604 #endif