KConfig 5.109.0
|
A KConfigSkeleton that populates itself based on KConfigXT XML. More...
#include <KConfigLoader>
Public Member Functions | |
KConfigLoader (const KConfigGroup &config, QIODevice *xml, QObject *parent=nullptr) | |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in. | |
KConfigLoader (const QString &configFile, QIODevice *xml, QObject *parent=nullptr) | |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in. | |
KConfigLoader (KSharedConfigPtr config, QIODevice *xml, QObject *parent=nullptr) | |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in. | |
KConfigSkeletonItem * | findItem (const QString &group, const QString &key) const |
Finds the item for the given group and key. | |
KConfigSkeletonItem * | findItemByName (const QString &name) const |
Finds an item by its name. | |
QStringList | groupList () const |
bool | hasGroup (const QString &group) const |
Check to see if a group exists. | |
QVariant | property (const QString &name) const |
Returns the property (variantized value) of the named item. | |
![]() | |
KConfigSkeleton (const QString &configname=QString(), QObject *parent=nullptr) | |
Constructor. | |
KConfigSkeleton (KSharedConfig::Ptr config, QObject *parent=nullptr) | |
Constructor. | |
ItemColor * | addItemColor (const QString &name, QColor &reference, const QColor &defaultValue=QColor(128, 128, 128), const QString &key=QString()) |
Register an item of type QColor. | |
ItemFont * | addItemFont (const QString &name, QFont &reference, const QFont &defaultValue=QFont(), const QString &key=QString()) |
Register an item of type QFont. | |
![]() | |
KCoreConfigSkeleton (const QString &configname=QString(), QObject *parent=nullptr) | |
Constructor. | |
KCoreConfigSkeleton (KSharedConfig::Ptr config, QObject *parent=nullptr) | |
Constructor. | |
~KCoreConfigSkeleton () override | |
Destructor. | |
void | addItem (KConfigSkeletonItem *item, const QString &name=QString()) |
Register a custom KConfigSkeletonItem item with a given name . | |
ItemBool * | addItemBool (const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString()) |
Register an item of type bool . | |
ItemDateTime * | addItemDateTime (const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString()) |
Register an item of type QDateTime. | |
ItemDouble * | addItemDouble (const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString()) |
Register an item of type double . | |
ItemInt * | addItemInt (const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString()) |
Register an item of type qint32 . | |
ItemLongLong * | addItemInt64 (const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString()) |
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>. | |
ItemLongLong * | addItemLongLong (const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString()) |
Register an item of type qint64 . | |
ItemPassword * | addItemPassword (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString()) |
Register a password item of type QString. | |
ItemPath * | addItemPath (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString()) |
Register a path item of type QString. | |
ItemPoint * | addItemPoint (const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString()) |
Register an item of type QPoint. | |
ItemProperty * | addItemProperty (const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString()) |
Register a property item of type QVariant. | |
ItemRect * | addItemRect (const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString()) |
Register an item of type QRect. | |
ItemSize * | addItemSize (const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString()) |
Register an item of type QSize. | |
ItemString * | addItemString (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString()) |
Register an item of type QString. | |
ItemStringList * | addItemStringList (const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString()) |
Register an item of type QStringList. | |
ItemUInt * | addItemUInt (const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString()) |
Register an item of type quint32 . | |
ItemULongLong * | addItemUInt64 (const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString()) |
ItemULongLong * | addItemULongLong (const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString()) |
Register an item of type quint64 . | |
void | clearItems () |
Removes and deletes all items. | |
KConfig * | config () |
Return the KConfig object used for reading and writing the settings. | |
const KConfig * | config () const |
Return the KConfig object used for reading and writing the settings. | |
QString | currentGroup () const |
Returns the current group used for addItem() calls. | |
KConfigSkeletonItem * | findItem (const QString &name) const |
Lookup item by name. | |
bool | isDefaults () const |
Indicates if all the registered items are set to their default value. | |
bool | isImmutable (const QString &name) const |
Return whether a certain item is immutable. | |
bool | isSaveNeeded () const |
Indicates if any registered item has a different value than the previously loaded value. | |
KConfigSkeletonItem::List | items () const |
Return list of items managed by this KCoreConfigSkeleton object. | |
void | load () |
Read preferences from config file. | |
void | read () |
Read preferences from the KConfig object. | |
void | readConfig () |
void | removeItem (const QString &name) |
Removes and deletes an item by name. | |
void | setCurrentGroup (const QString &group) |
Set the config file group for subsequent addItem() calls. | |
virtual void | setDefaults () |
Set all registered items to their default values. | |
void | setSharedConfig (KSharedConfig::Ptr pConfig) |
Set the KSharedConfig object used for reading and writing the settings. | |
KSharedConfig::Ptr | sharedConfig () const |
Return the KConfig object used for reading and writing the settings. | |
virtual bool | useDefaults (bool b) |
Specify whether this object should reflect the actual values or the default values. | |
Protected Member Functions | |
bool | usrSave () override |
Perform the actual writing of the configuration file. | |
![]() | |
virtual void | usrRead () |
Perform the actual reading of the configuration file. | |
virtual void | usrReadConfig () |
virtual bool | usrSave () |
Perform the actual writing of the configuration file. | |
virtual void | usrSetDefaults () |
Perform the actual setting of default values. | |
virtual bool | usrUseDefaults (bool b) |
Implemented by subclasses that use special defaults. | |
virtual bool | usrWriteConfig () |
Additional Inherited Members | |
![]() | |
typedef ItemLongLong | ItemInt64 |
typedef ItemULongLong | ItemUInt64 |
![]() | |
void | configChanged () |
This signal is emitted when the configuration change. | |
![]() | |
bool | save () |
Write preferences to config file. | |
void | writeConfig () |
A KConfigSkeleton that populates itself based on KConfigXT XML.
This class allows one to ship an XML file and reconstitute it into a KConfigSkeleton object at runtime. Common usage might look like this:
Alternatively, any QIODevice may be used in place of QFile in the example above.
KConfigLoader is useful if it is not possible to use compiled code and by that the kconfig compiler cannot be used. Common examples are scripted plugins which want to provide a configuration interface. With the help of KConfigLoader a dynamically loaded ui file can be populated with the stored values and also stored back to the config file.
An example for populating a QDialog with a dynamically populated UI with the help of a KConfigDialogManager:
Currently the following data types are supported:
KConfigLoader::KConfigLoader | ( | const QString & | configFile, |
QIODevice * | xml, | ||
QObject * | parent = nullptr |
||
) |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in.
configFile | path to the configuration file to use |
xml | the xml data; must be valid KConfigXT data |
parent | optional QObject parent |
KConfigLoader::KConfigLoader | ( | KSharedConfigPtr | config, |
QIODevice * | xml, | ||
QObject * | parent = nullptr |
||
) |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in.
config | the configuration object to use |
xml | the xml data; must be valid KConfigXT data |
parent | optional QObject parent |
KConfigLoader::KConfigLoader | ( | const KConfigGroup & | config, |
QIODevice * | xml, | ||
QObject * | parent = nullptr |
||
) |
Creates a KConfigSkeleton populated using the definition found in the XML data passed in.
config | the group to use as the root for configuration items |
xml | the xml data; must be valid KConfigXT data |
parent | optional QObject parent |
KConfigSkeletonItem * KConfigLoader::findItem | ( | const QString & | group, |
const QString & | key | ||
) | const |
Finds the item for the given group and key.
group | the group in the config file to look in |
key | the configuration key to find |
nullptr
if none KConfigSkeletonItem * KConfigLoader::findItemByName | ( | const QString & | name | ) | const |
Finds an item by its name.
QStringList KConfigLoader::groupList | ( | ) | const |
bool KConfigLoader::hasGroup | ( | const QString & | group | ) | const |
Check to see if a group exists.
group | the name of the group to check for |
QVariant KConfigLoader::property | ( | const QString & | name | ) | const |
Returns the property (variantized value) of the named item.
|
overrideprotectedvirtual |
Perform the actual writing of the configuration file.
Override in derived classes to write special config values. Called from save()
Reimplemented from KCoreConfigSkeleton.