KPrefs Class Reference
Class for handling preferences settings for an application. More...
#include <kprefs.h>
Public Member Functions | |
KPrefs (const QString &configname=QString::null) | |
Constructor. | |
virtual | ~KPrefs () |
Destructor. | |
void | setDefaults () |
Set preferences to default values. | |
void | readConfig () |
Read preferences from config file. | |
void | writeConfig () |
Write preferences to config file. | |
void | addItem (KPrefsItem *) |
Register a custom KPrefsItem. | |
void | addItemBool (const QString &key, bool *reference, bool defaultValue=false) |
Register an item of type bool. | |
void | addItemInt (const QString &key, int *reference, int defaultValue=0) |
Register an item of type int. | |
void | addItemColor (const QString &key, QColor *reference, const QColor &defaultValue=QColor(128, 128, 128)) |
Register an item of type QColor. | |
void | addItemFont (const QString &key, QFont *reference, const QFont &defaultValue=QFont("helvetica", 12)) |
Register an item of type QFont. | |
void | addItemString (const QString &key, QString *reference, const QString &defaultValue="") |
Register an item of type QString. | |
void | addItemPassword (const QString &key, QString *reference, const QString &defaultValue="") |
Register a password item of type QString. | |
void | addItemStringList (const QString &key, QStringList *reference, const QStringList &defaultValue=QStringList()) |
Register an item of type QStringList. | |
void | addItemIntList (const QString &key, QValueList< int > *reference, const QValueList< int > &defaultValue=QValueList< int >()) |
Register an item of type QValueList<int>. | |
Static Public Member Functions | |
void | setCurrentGroup (const QString &group) |
Set the config file group for subsequent addItem() calls. | |
Protected Member Functions | |
virtual void | usrSetDefaults () |
Implemented by subclasses that use special defaults. | |
virtual void | usrReadConfig () |
Implemented by subclasses that read special config values. | |
virtual void | usrWriteConfig () |
Implemented by subclasses that write special config values. | |
KConfig * | config () const |
Return the KConfig object used for reading and writing the settings. |
Detailed Description
Class for handling preferences settings for an application.
- Author:
- Cornelius Schumacher
- See also:
- KPrefsItem
Normally you will subclass KPrefs, add data members for the preferences settings and register the members in the constructor of the subclass.
Example:
class MyPrefs : public KPrefs { public: MyPrefs() { setCurrentGroup("MyGroup"); addItemBool("MySetting1",&mMyBool,false); addItemColor("MySetting2",&mMyColor,QColor(1,2,3));
setCurrentGroup("MyOtherGroup"); addItemFont("MySetting3",&mMyFont,QFont("helvetica",12)); }
It might be convenient in many cases to make this subclass of KPrefs a singleton for global access from all over the application without passing references to the KPrefs object around.
You can set all values to default values by calling setDefaults(), 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 usrSetDefaults(), usrReadConfig() and usrWriteConfig().
Internally preferences settings are stored in instances of subclasses of KPrefsItem. You can also add KPrefsItem subclasses for your own types and call the generic addItem() to register them.
Definition at line 130 of file kprefs.h.
Constructor & Destructor Documentation
|
Constructor.
Definition at line 348 of file kprefs.cpp. References QString::isEmpty(), and QPtrList< KPrefsItem >::setAutoDelete(). |
|
Destructor.
Definition at line 362 of file kprefs.cpp. |
Member Function Documentation
|
Set preferences to default values. All registered items are set to their default values. Definition at line 380 of file kprefs.cpp. References QPtrList< KPrefsItem >::first(), QPtrList< KPrefsItem >::next(), KPrefsItem::setDefault(), and usrSetDefaults(). Referenced by KPrefsDialog::setDefaults(). |
|
Read preferences from config file. All registered items are set to the values read from disk. Definition at line 390 of file kprefs.cpp. References QPtrList< KPrefsItem >::first(), QPtrList< KPrefsItem >::next(), KPrefsItem::readConfig(), and usrReadConfig(). |
|
Write preferences to config file. The values of all registered items are written to disk. Definition at line 400 of file kprefs.cpp. References QPtrList< KPrefsItem >::first(), QPtrList< KPrefsItem >::next(), usrWriteConfig(), and KPrefsItem::writeConfig(). Referenced by KPrefsDialog::writeConfig(). |
|
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 369 of file kprefs.cpp. |
|
Register a custom KPrefsItem.
Definition at line 413 of file kprefs.cpp. References QPtrList< KPrefsItem >::append(). Referenced by addItemBool(), addItemColor(), addItemFont(), addItemInt(), addItemIntList(), addItemPassword(), addItemString(), and addItemStringList(). |
|
Register an item of type bool.
Definition at line 418 of file kprefs.cpp. References addItem(). |
|
Register an item of type int.
Definition at line 423 of file kprefs.cpp. References addItem(). |
|
Register an item of type QColor.
Definition at line 428 of file kprefs.cpp. References addItem(). |
|
Register an item of type QFont.
Definition at line 433 of file kprefs.cpp. References addItem(). |
|
Register an item of type QString.
Definition at line 438 of file kprefs.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 443 of file kprefs.cpp. References addItem(). |
|
Register an item of type QStringList.
Definition at line 448 of file kprefs.cpp. References addItem(). |
|
Register an item of type QValueList<int>.
Definition at line 454 of file kprefs.cpp. References addItem(). |
|
Implemented by subclasses that use special defaults.
Definition at line 278 of file kprefs.h. Referenced by setDefaults(). |
|
Implemented by subclasses that read special config values.
Definition at line 282 of file kprefs.h. Referenced by readConfig(). |
|
Implemented by subclasses that write special config values.
Definition at line 286 of file kprefs.h. Referenced by writeConfig(). |
|
Return the KConfig object used for reading and writing the settings.
Definition at line 375 of file kprefs.cpp. |
The documentation for this class was generated from the following files: