KConfig 5.109.0
Public Member Functions | Protected Member Functions | List of all members
KConfigLoader

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.
 
KConfigSkeletonItemfindItem (const QString &group, const QString &key) const
 Finds the item for the given group and key.
 
KConfigSkeletonItemfindItemByName (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.
 
- Public Member Functions inherited from KConfigSkeleton
 KConfigSkeleton (const QString &configname=QString(), QObject *parent=nullptr)
 Constructor.
 
 KConfigSkeleton (KSharedConfig::Ptr config, QObject *parent=nullptr)
 Constructor.
 
ItemColoraddItemColor (const QString &name, QColor &reference, const QColor &defaultValue=QColor(128, 128, 128), const QString &key=QString())
 Register an item of type QColor.
 
ItemFontaddItemFont (const QString &name, QFont &reference, const QFont &defaultValue=QFont(), const QString &key=QString())
 Register an item of type QFont.
 
- Public Member Functions inherited from KCoreConfigSkeleton
 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.
 
ItemBooladdItemBool (const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString())
 Register an item of type bool.
 
ItemDateTimeaddItemDateTime (const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString())
 Register an item of type QDateTime.
 
ItemDoubleaddItemDouble (const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString())
 Register an item of type double.
 
ItemIntaddItemInt (const QString &name, qint32 &reference, qint32 defaultValue=0, const QString &key=QString())
 Register an item of type qint32.
 
ItemLongLongaddItemInt64 (const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
 
ItemIntListaddItemIntList (const QString &name, QList< int > &reference, const QList< int > &defaultValue=QList< int >(), const QString &key=QString())
 Register an item of type QList<int>.
 
ItemLongLongaddItemLongLong (const QString &name, qint64 &reference, qint64 defaultValue=0, const QString &key=QString())
 Register an item of type qint64.
 
ItemPasswordaddItemPassword (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
 Register a password item of type QString.
 
ItemPathaddItemPath (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
 Register a path item of type QString.
 
ItemPointaddItemPoint (const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString())
 Register an item of type QPoint.
 
ItemPropertyaddItemProperty (const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString())
 Register a property item of type QVariant.
 
ItemRectaddItemRect (const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString())
 Register an item of type QRect.
 
ItemSizeaddItemSize (const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString())
 Register an item of type QSize.
 
ItemStringaddItemString (const QString &name, QString &reference, const QString &defaultValue=QLatin1String(""), const QString &key=QString())
 Register an item of type QString.
 
ItemStringListaddItemStringList (const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString())
 Register an item of type QStringList.
 
ItemUIntaddItemUInt (const QString &name, quint32 &reference, quint32 defaultValue=0, const QString &key=QString())
 Register an item of type quint32.
 
ItemULongLongaddItemUInt64 (const QString &name, quint64 &reference, quint64 defaultValue=0, const QString &key=QString())
 
ItemULongLongaddItemULongLong (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.
 
KConfigconfig ()
 Return the KConfig object used for reading and writing the settings.
 
const KConfigconfig () const
 Return the KConfig object used for reading and writing the settings.
 
QString currentGroup () const
 Returns the current group used for addItem() calls.
 
KConfigSkeletonItemfindItem (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.
 
- Protected Member Functions inherited from KCoreConfigSkeleton
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

- Public Types inherited from KCoreConfigSkeleton
typedef ItemLongLong ItemInt64
 
typedef ItemULongLong ItemUInt64
 
- Signals inherited from KCoreConfigSkeleton
void configChanged ()
 This signal is emitted when the configuration change.
 
- Public Slots inherited from KCoreConfigSkeleton
bool save ()
 Write preferences to config file.
 
void writeConfig ()
 

Detailed Description

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:

QFile file(xmlFilePath);
KConfigLoader appletConfig(configFilePath, &file);
A KConfigSkeleton that populates itself based on KConfigXT XML.
Definition kconfigloader.h:89

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:

QDialog *dialog = new QDialog();
QFile xmlFile("path/to/kconfigxt.xml");
KConfigGroup cg = KSharedConfig::openConfig()->group(QString());
KConfigLoader *configLoader = new KConfigLoader(cg, &xmlFile, this);
// load the ui file
QUiLoader *loader = new QUiLoader(this);
QFile uiFile("path/to/userinterface.ui");
uiFile.open(QFile::ReadOnly);
QWidget *customConfigForm = loader->load(&uiFile, dialog);
uiFile.close();
KConfigDialogManager *manager = new KConfigDialogManager(customConfigForm, configLoader);
if (dialog->exec() == QDialog::Accepted) {
manager->updateSettings();
}
A class for one specific group in a KConfig object.
Definition kconfiggroup.h:39
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
Creates a KSharedConfig object to manipulate a configuration file.

Currently the following data types are supported:

Constructor & Destructor Documentation

◆ KConfigLoader() [1/3]

KConfigLoader::KConfigLoader ( const QString &  configFile,
QIODevice *  xml,
QObject *  parent = nullptr 
)

Creates a KConfigSkeleton populated using the definition found in the XML data passed in.

Parameters
configFilepath to the configuration file to use
xmlthe xml data; must be valid KConfigXT data
parentoptional QObject parent

◆ KConfigLoader() [2/3]

KConfigLoader::KConfigLoader ( KSharedConfigPtr  config,
QIODevice *  xml,
QObject *  parent = nullptr 
)

Creates a KConfigSkeleton populated using the definition found in the XML data passed in.

Parameters
configthe configuration object to use
xmlthe xml data; must be valid KConfigXT data
parentoptional QObject parent

◆ KConfigLoader() [3/3]

KConfigLoader::KConfigLoader ( const KConfigGroup config,
QIODevice *  xml,
QObject *  parent = nullptr 
)

Creates a KConfigSkeleton populated using the definition found in the XML data passed in.

Parameters
configthe group to use as the root for configuration items
xmlthe xml data; must be valid KConfigXT data
parentoptional QObject parent

Member Function Documentation

◆ findItem()

KConfigSkeletonItem * KConfigLoader::findItem ( const QString &  group,
const QString &  key 
) const

Finds the item for the given group and key.

Parameters
groupthe group in the config file to look in
keythe configuration key to find
Returns
the associated KConfigSkeletonItem, or nullptr if none

◆ findItemByName()

KConfigSkeletonItem * KConfigLoader::findItemByName ( const QString &  name) const

Finds an item by its name.

◆ groupList()

QStringList KConfigLoader::groupList ( ) const
Returns
the list of groups defined by the XML

◆ hasGroup()

bool KConfigLoader::hasGroup ( const QString &  group) const

Check to see if a group exists.

Parameters
groupthe name of the group to check for
Returns
true if the group exists, or false if it does not

◆ property()

QVariant KConfigLoader::property ( const QString &  name) const

Returns the property (variantized value) of the named item.

◆ usrSave()

bool KConfigLoader::usrSave ( )
overrideprotectedvirtual

Perform the actual writing of the configuration file.

Override in derived classes to write special config values. Called from save()

Reimplemented from KCoreConfigSkeleton.