KConfigSkeleton Class Reference
Class for handling preferences settings for an application. More...
#include <kconfigskeleton.h>
Collaboration diagram for KConfigSkeleton:

Public Member Functions | |
KConfigSkeleton (const QString &configname=QString::null) | |
KConfigSkeleton (KSharedConfig::Ptr config) | |
virtual | ~KConfigSkeleton () |
void | setDefaults () |
void | readConfig () |
void | writeConfig () |
void | setCurrentGroup (const QString &group) |
QString | currentGroup () |
void | addItem (KConfigSkeletonItem *, const QString &name=QString::null) |
ItemString * | addItemString (const QString &name, QString &reference, const QString &defaultValue=QString::fromLatin1(""), const QString &key=QString::null) |
ItemPassword * | addItemPassword (const QString &name, QString &reference, const QString &defaultValue=QString::fromLatin1(""), const QString &key=QString::null) |
ItemPath * | addItemPath (const QString &name, QString &reference, const QString &defaultValue=QString::fromLatin1(""), const QString &key=QString::null) |
ItemProperty * | addItemProperty (const QString &name, QVariant &reference, const QVariant &defaultValue=QVariant(), const QString &key=QString::null) |
ItemBool * | addItemBool (const QString &name, bool &reference, bool defaultValue=false, const QString &key=QString::null) |
ItemInt * | addItemInt (const QString &name, int &reference, int defaultValue=0, const QString &key=QString::null) |
ItemUInt * | addItemUInt (const QString &name, unsigned int &reference, unsigned int defaultValue=0, const QString &key=QString::null) |
ItemLong * | addItemLong (const QString &name, long &reference, long defaultValue=0, const QString &key=QString::null) |
ItemULong * | addItemULong (const QString &name, unsigned long &reference, unsigned long defaultValue=0, const QString &key=QString::null) |
ItemInt64 * | addItemInt64 (const QString &name, Q_INT64 &reference, Q_INT64 defaultValue=0, const QString &key=QString::null) |
ItemUInt64 * | addItemUInt64 (const QString &name, Q_UINT64 &reference, Q_UINT64 defaultValue=0, const QString &key=QString::null) |
ItemDouble * | addItemDouble (const QString &name, double &reference, double defaultValue=0.0, const QString &key=QString::null) |
ItemColor * | addItemColor (const QString &name, QColor &reference, const QColor &defaultValue=QColor(128, 128, 128), const QString &key=QString::null) |
ItemFont * | addItemFont (const QString &name, QFont &reference, const QFont &defaultValue=KGlobalSettings::generalFont(), const QString &key=QString::null) |
ItemRect * | addItemRect (const QString &name, QRect &reference, const QRect &defaultValue=QRect(), const QString &key=QString::null) |
ItemPoint * | addItemPoint (const QString &name, QPoint &reference, const QPoint &defaultValue=QPoint(), const QString &key=QString::null) |
ItemSize * | addItemSize (const QString &name, QSize &reference, const QSize &defaultValue=QSize(), const QString &key=QString::null) |
ItemDateTime * | addItemDateTime (const QString &name, QDateTime &reference, const QDateTime &defaultValue=QDateTime(), const QString &key=QString::null) |
ItemStringList * | addItemStringList (const QString &name, QStringList &reference, const QStringList &defaultValue=QStringList(), const QString &key=QString::null) |
ItemIntList * | addItemIntList (const QString &name, QValueList< int > &reference, const QValueList< int > &defaultValue=QValueList< int >(), const QString &key=QString::null) |
KConfig * | config () const |
KConfigSkeletonItem::List | items () const |
bool | isImmutable (const QString &name) |
KConfigSkeletonItem * | findItem (const QString &name) |
bool | useDefaults (bool b) |
Protected Member Functions | |
virtual void | usrUseDefaults (bool) |
virtual void | usrSetDefaults () |
virtual void | usrReadConfig () |
virtual void | usrWriteConfig () |
Detailed Description
Class for handling preferences settings for an application.
- Author:
- Cornelius Schumacher
- See also:
- KConfigSkeletonItem
Normally you will subclass KConfigSkeleton, add data members for the preferences settings and register the members in the constructor of the subclass.
Example:
class MyPrefs : public KConfigSkeleton { public: MyPrefs() { setCurrentGroup("MyGroup"); addItemBool("MySetting1",mMyBool,false); addItemColor("MySetting2",mMyColor,QColor(1,2,3)); setCurrentGroup("MyOtherGroup"); addItemFont("MySetting3",mMyFont,QFont("helvetica",12)); } bool mMyBool; QColor mMyColor; QFont mMyFont; }
It might be convenient in many cases to make this subclass of KConfigSkeleton a singleton for global access from all over the application without passing references to the KConfigSkeleton 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 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 KConfigSkeleton subclasses yourself, but you can use The KDE Configuration Compiler to automatically generate the C++ code from an XML description of the configuration options.
Definition at line 365 of file kconfigskeleton.h.
Constructor & Destructor Documentation
|
Constructor.
Definition at line 847 of file kconfigskeleton.cpp. References KSharedConfig::openConfig(), and KGlobal::sharedConfig(). |
|
Constructor.
Definition at line 862 of file kconfigskeleton.cpp. |
|
Destructor.
Definition at line 870 of file kconfigskeleton.cpp. |
Member Function Documentation
|
Set all registered items to their default values.
Definition at line 905 of file kconfigskeleton.cpp. |
|
Read preferences from config file. All registered items are set to the values read from disk. Definition at line 915 of file kconfigskeleton.cpp. References usrReadConfig(). Referenced by writeConfig(). |
|
Write preferences to config file. The values of all registered items are written to disk. Definition at line 932 of file kconfigskeleton.cpp. References readConfig(), and usrWriteConfig(). Referenced by KConfigDialogManager::updateSettings(). |
|
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 879 of file kconfigskeleton.cpp. |
|
Returns the current group used for addItem() calls.
Definition at line 822 of file kconfigskeleton.h. |
|
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. Definition at line 953 of file kconfigskeleton.cpp. References KConfigSkeletonItem::key(), KConfigSkeletonItem::name(), KConfigSkeletonItem::readDefault(), and KConfigSkeletonItem::setName(). Referenced by addItemBool(), addItemColor(), addItemDateTime(), addItemDouble(), addItemFont(), addItemInt(), addItemInt64(), addItemIntList(), addItemLong(), addItemPassword(), addItemPath(), addItemPoint(), addItemProperty(), addItemRect(), addItemSize(), addItemString(), addItemStringList(), addItemUInt(), addItemUInt64(), and addItemULong(). |
|
Register an item of type QString.
Definition at line 961 of file kconfigskeleton.cpp. References addItem(). |
|
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.
Definition at line 972 of file kconfigskeleton.cpp. References addItem(). |
|
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.
Definition at line 982 of file kconfigskeleton.cpp. References addItem(). |
|
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.
Definition at line 992 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type bool.
Definition at line 1002 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type int.
Definition at line 1012 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type unsigned int.
Definition at line 1022 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type long.
Definition at line 1052 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type unsigned long.
Definition at line 1062 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type Q_INT64.
Definition at line 1032 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type Q_UINT64.
Definition at line 1042 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type double.
Definition at line 1072 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QColor.
Definition at line 1082 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QFont.
Definition at line 1092 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QRect.
Definition at line 1102 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QPoint.
Definition at line 1112 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QSize.
Definition at line 1122 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QDateTime.
Definition at line 1132 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QStringList.
Definition at line 1142 of file kconfigskeleton.cpp. References addItem(). |
|
Register an item of type QValueList<int>.
Definition at line 1152 of file kconfigskeleton.cpp. References addItem(). |
|
Return the KConfig object used for reading and writing the settings.
Definition at line 884 of file kconfigskeleton.cpp. |
|
Return list of items managed by this KConfigSkeleton object.
Definition at line 1149 of file kconfigskeleton.h. |
|
Return whether a certain item is immutable.
Definition at line 1162 of file kconfigskeleton.cpp. References findItem(), and KConfigSkeletonItem::isImmutable(). |
|
Lookup item by name.
Definition at line 1168 of file kconfigskeleton.cpp. Referenced by KConfigDialogManager::hasChanged(), isImmutable(), KConfigDialogManager::parseChildren(), KConfigDialogManager::updateSettings(), and KConfigDialogManager::updateWidgets(). |
|
Indicate whether this object should reflect the actual values or the default values.
Definition at line 889 of file kconfigskeleton.cpp. References usrUseDefaults(). Referenced by KConfigDialogManager::isDefault(), and KConfigDialogManager::updateWidgetsDefault(). |
|
Implemented by subclasses that use special defaults. It should replace the default values with the actual values and vice versa. Definition at line 1178 of file kconfigskeleton.h. Referenced by useDefaults(). |
|
Implemented by subclasses that read special config values.
Definition at line 1189 of file kconfigskeleton.h. Referenced by readConfig(). |
|
Implemented by subclasses that write special config values.
Definition at line 1196 of file kconfigskeleton.h. Referenced by writeConfig(). |
The documentation for this class was generated from the following files: