KDECore
#include <KCoreConfigSkeleton>
Classes | |
class | ItemBool |
class | ItemDateTime |
class | ItemDouble |
class | ItemEnum |
class | ItemInt |
class | ItemIntList |
class | ItemLongLong |
class | ItemPassword |
class | ItemPath |
class | ItemPathList |
class | ItemPoint |
class | ItemProperty |
class | ItemRect |
class | ItemSize |
class | ItemString |
class | ItemStringList |
class | ItemUInt |
class | ItemULongLong |
class | ItemUrl |
class | ItemUrlList |
class | Private |
Public Types | |
typedef ItemLongLong | ItemInt64 |
typedef ItemULongLong | ItemUInt64 |
Signals | |
void | configChanged () |
Protected Member Functions | |
virtual void | usrReadConfig () |
virtual void | usrSetDefaults () |
virtual bool | usrUseDefaults (bool b) |
virtual void | usrWriteConfig () |
Detailed Description
Class for handling preferences settings for an application.
- See also
- KConfigSkeletonItem
This class provides an interface to preferences settings. Preferences items can be registered by the addItem() function corresponding to the data type of the setting. KCoreConfigSkeleton then handles reading and writing of config files and setting of default values.
Normally you will subclass KCoreConfigSkeleton, add data members for the preferences settings and register the members in the constructor of the subclass.
Example:
It might be convenient in many cases to make this subclass of KCoreConfigSkeleton a singleton for global access from all over the application without passing references to the KCoreConfigSkeleton object around.
You can write the data to the configuration file by calling writeConfig() and read the data from the configuration file by calling readConfig(). If you want to watch for config changes, use configChanged() signal.
If you have items, which are not covered by the existing addItem() functions you can add customized code for reading, writing and default setting by implementing the functions usrUseDefaults(), usrReadConfig() and usrWriteConfig().
Internally preferences settings are stored in instances of subclasses of KConfigSkeletonItem. You can also add KConfigSkeletonItem subclasses for your own types and call the generic addItem() to register them.
In many cases you don't have to write the specific KCoreConfigSkeleton subclasses yourself, but you can use The KDE Configuration Compiler to automatically generate the C++ code from an XML description of the configuration options.
Use KConfigSkeleton if you need GUI types as well.
Definition at line 366 of file kcoreconfigskeleton.h.
Member Typedef Documentation
Definition at line 603 of file kcoreconfigskeleton.h.
Definition at line 736 of file kcoreconfigskeleton.h.
Constructor & Destructor Documentation
|
explicit |
Constructor.
- Parameters
-
configname name of config file. If no name is given, the default config file as returned by KGlobal::config() is used parent the parent object (see QObject documentation)
Definition at line 978 of file kcoreconfigskeleton.cpp.
|
explicit |
Constructor.
- Parameters
-
config configuration object to use parent the parent object (see QObject documentation)
Definition at line 994 of file kcoreconfigskeleton.cpp.
|
virtual |
Destructor.
Definition at line 1003 of file kcoreconfigskeleton.cpp.
Member Function Documentation
void KCoreConfigSkeleton::addItem | ( | KConfigSkeletonItem * | item, |
const QString & | name = QString() |
||
) |
Register a custom KConfigSkeletonItem with a given name.
If the name parameter is null, take the name from KConfigSkeletonItem::key(). Note that all names must be unique but that multiple entries can have the same key if they reside in different groups.
KCoreConfigSkeleton takes ownership of the KConfigSkeletonItem.
Definition at line 1108 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemBool * KCoreConfigSkeleton::addItemBool | ( | const QString & | name, |
bool & | reference, | ||
bool | defaultValue = false , |
||
const QString & | key = QString() |
||
) |
Register an item of type bool.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1158 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemDateTime * KCoreConfigSkeleton::addItemDateTime | ( | const QString & | name, |
QDateTime & | reference, | ||
const QDateTime & | defaultValue = QDateTime() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QDateTime.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1270 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemDouble * KCoreConfigSkeleton::addItemDouble | ( | const QString & | name, |
double & | reference, | ||
double | defaultValue = 0.0 , |
||
const QString & | key = QString() |
||
) |
Register an item of type double.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1230 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemInt * KCoreConfigSkeleton::addItemInt | ( | const QString & | name, |
qint32 & | reference, | ||
qint32 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Register an item of type qint32.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1168 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemLongLong * KCoreConfigSkeleton::addItemInt64 | ( | const QString & | name, |
qint64 & | reference, | ||
qint64 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Definition at line 1199 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemIntList * KCoreConfigSkeleton::addItemIntList | ( | const QString & | name, |
QList< int > & | reference, | ||
const QList< int > & | defaultValue = QList < int >() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QList<int>.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1290 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemLongLong * KCoreConfigSkeleton::addItemLongLong | ( | const QString & | name, |
qint64 & | reference, | ||
qint64 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Register an item of type qint64.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1188 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemPassword * KCoreConfigSkeleton::addItemPassword | ( | const QString & | name, |
QString & | reference, | ||
const QString & | defaultValue = QLatin1String("") , |
||
const QString & | key = QString() |
||
) |
Register a password item of type QString.
The string value is written encrypted to the config file. Note that the current encryption scheme is very weak.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1128 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemPath * KCoreConfigSkeleton::addItemPath | ( | const QString & | name, |
QString & | reference, | ||
const QString & | defaultValue = QLatin1String("") , |
||
const QString & | key = QString() |
||
) |
Register a path item of type QString.
The string value is interpreted as a path. This means, dollar expension is activated for this value, so that e.g. $HOME gets expanded.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1138 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemPoint * KCoreConfigSkeleton::addItemPoint | ( | const QString & | name, |
QPoint & | reference, | ||
const QPoint & | defaultValue = QPoint() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QPoint.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1250 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemProperty * KCoreConfigSkeleton::addItemProperty | ( | const QString & | name, |
QVariant & | reference, | ||
const QVariant & | defaultValue = QVariant() , |
||
const QString & | key = QString() |
||
) |
Register a property item of type QVariant.
Note that only the following QVariant types are allowed: String, StringList, Font, Point, Rect, Size, Color, Int, UInt, Bool, Double, DateTime and Date.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1148 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemRect * KCoreConfigSkeleton::addItemRect | ( | const QString & | name, |
QRect & | reference, | ||
const QRect & | defaultValue = QRect() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QRect.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1240 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemSize * KCoreConfigSkeleton::addItemSize | ( | const QString & | name, |
QSize & | reference, | ||
const QSize & | defaultValue = QSize() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QSize.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1260 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemString * KCoreConfigSkeleton::addItemString | ( | const QString & | name, |
QString & | reference, | ||
const QString & | defaultValue = QLatin1String("") , |
||
const QString & | key = QString() |
||
) |
Register an item of type QString.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1117 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemStringList * KCoreConfigSkeleton::addItemStringList | ( | const QString & | name, |
QStringList & | reference, | ||
const QStringList & | defaultValue = QStringList() , |
||
const QString & | key = QString() |
||
) |
Register an item of type QStringList.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1280 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemUInt * KCoreConfigSkeleton::addItemUInt | ( | const QString & | name, |
quint32 & | reference, | ||
quint32 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Register an item of type quint32.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1178 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemULongLong * KCoreConfigSkeleton::addItemUInt64 | ( | const QString & | name, |
quint64 & | reference, | ||
quint64 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Definition at line 1220 of file kcoreconfigskeleton.cpp.
KCoreConfigSkeleton::ItemULongLong * KCoreConfigSkeleton::addItemULongLong | ( | const QString & | name, |
quint64 & | reference, | ||
quint64 | defaultValue = 0 , |
||
const QString & | key = QString() |
||
) |
Register an item of type quint64.
- Parameters
-
name Name used to identify this setting. Names must be unique. reference Pointer to the variable, which is set by readConfig() calls and read by writeConfig() calls. defaultValue Default value, which is used when the config file does not yet contain the key of this item. key Key used in config file. If key is null, name is used as key.
- Returns
- The created item
Definition at line 1209 of file kcoreconfigskeleton.cpp.
KConfig * KCoreConfigSkeleton::config | ( | ) |
Return the KConfig object used for reading and writing the settings.
Definition at line 1018 of file kcoreconfigskeleton.cpp.
const KConfig * KCoreConfigSkeleton::config | ( | ) | const |
Return the KConfig object used for reading and writing the settings.
Definition at line 1023 of file kcoreconfigskeleton.cpp.
|
signal |
This signal is emitted when the configuration change.
QString KCoreConfigSkeleton::currentGroup | ( | ) | const |
Returns the current group used for addItem() calls.
Definition at line 1013 of file kcoreconfigskeleton.cpp.
KConfigSkeletonItem * KCoreConfigSkeleton::findItem | ( | const QString & | name | ) |
Lookup item by name.
Definition at line 1311 of file kcoreconfigskeleton.cpp.
KConfigSkeletonItem * KCoreConfigSkeleton::findItem | ( | const QString & | name | ) | const |
Return whether a certain item is immutable.
Definition at line 1300 of file kcoreconfigskeleton.cpp.
Return whether a certain item is immutable.
- Since
- 4.4
Definition at line 1305 of file kcoreconfigskeleton.cpp.
KConfigSkeletonItem::List KCoreConfigSkeleton::items | ( | ) | const |
Return list of items managed by this KCoreConfigSkeleton object.
Definition at line 1033 of file kcoreconfigskeleton.cpp.
|
virtual |
Read preferences from config file.
All registered items are set to the values read from disk. This method calls usrReadConfig() after reading the settings of the registered items from the KConfig. You can overridde usrReadConfig() in derived classes if you have special requirements. If you need more fine-grained control of storing the settings from the registered items you can override readConfig() in a derived class.
Definition at line 1062 of file kcoreconfigskeleton.cpp.
void KCoreConfigSkeleton::setCurrentGroup | ( | const QString & | group | ) |
Set the config file group for subsequent addItem() calls.
It is valid until setCurrentGroup() is called with a new argument. Call this before you add any items. The default value is "No Group".
Definition at line 1008 of file kcoreconfigskeleton.cpp.
|
virtual |
Set all registered items to their default values.
This method calls usrSetDefaults() after setting the defaults for the registered items. You can overridde usrSetDefaults() in derived classes if you have special requirements. If you need more fine-grained control of setting the default values of the registered items you can override setDefaults() in a derived class.
Definition at line 1053 of file kcoreconfigskeleton.cpp.
void KCoreConfigSkeleton::setSharedConfig | ( | KSharedConfig::Ptr | pConfig | ) |
Set the KSharedConfig object used for reading and writing the settings.
Definition at line 1028 of file kcoreconfigskeleton.cpp.
Specify whether this object should reflect the actual values or the default values.
This method is implemented by usrUseDefaults(), which can be overridden in derived classes if you have special requirements and can call usrUseDefaults() directly. If you don't have control whether useDefaults() or usrUseDefaults() is called override useDefaults() directly.
- Parameters
-
b true to make this object reflect the default values, false to make it reflect the actual values.
- Returns
- The state prior to this call
Definition at line 1038 of file kcoreconfigskeleton.cpp.
|
protectedvirtual |
Perform the actual reading of the configuration file.
Override in derived classes to read special config values. Called from readConfig()
Definition at line 1100 of file kcoreconfigskeleton.cpp.
|
protectedvirtual |
Perform the actual setting of default values.
Override in derived classes to set special default values. Called from setDefaults()
Definition at line 1096 of file kcoreconfigskeleton.cpp.
Implemented by subclasses that use special defaults.
It replaces the default values with the actual values and vice versa. Called from useDefaults()
- Parameters
-
b true to make this object reflect the default values, false to make it reflect the actual values.
- Returns
- The state prior to this call
Definition at line 1091 of file kcoreconfigskeleton.cpp.
|
protectedvirtual |
Perform the actual writing of the configuration file.
Override in derived classes to write special config values. Called from writeConfig()
Definition at line 1104 of file kcoreconfigskeleton.cpp.
|
virtual |
Write preferences to config file.
The values of all registered items are written to disk. This method calls usrWriteConfig() after writing the settings from the registered items to the KConfig. You can overridde usrWriteConfig() in derived classes if you have special requirements. If you need more fine-grained control of storing the settings from the registered items you can override writeConfig() in a derived class.
Definition at line 1074 of file kcoreconfigskeleton.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.