KConfigDialogManager

Search for usage in LXR

#include <KConfigDialogManager>

Inheritance diagram for KConfigDialogManager:

Signals

void settingsChanged ()
 
void settingsChanged (QWidget *widget)
 
void widgetModified ()
 

Public Slots

void setDefaultsIndicatorsVisible (bool enabled)
 
void updateSettings ()
 
void updateWidgets ()
 
void updateWidgetsDefault ()
 

Public Member Functions

 KConfigDialogManager (QWidget *parent, KConfigSkeleton *conf)
 
 KConfigDialogManager (QWidget *parent, KCoreConfigSkeleton *conf)
 
 ~KConfigDialogManager () override
 
void addWidget (QWidget *widget)
 
bool hasChanged () const
 
bool isDefault () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QHash< QString, QByteArray > * changedMap ()
 
static QHash< QString, QByteArray > * propertyMap ()
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

QByteArray getCustomProperty (const QWidget *widget) const
 
QByteArray getCustomPropertyChangedSignal (const QWidget *widget) const
 
QByteArray getUserProperty (const QWidget *widget) const
 
QByteArray getUserPropertyChangedSignal (const QWidget *widget) const
 
void init (bool trackChanges)
 
bool parseChildren (const QWidget *widget, bool trackChanges)
 
QVariant property (QWidget *w) const
 
void setProperty (QWidget *w, const QVariant &v)
 
void setupWidget (QWidget *widget, KConfigSkeletonItem *item)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Static Protected Member Functions

static void initMaps ()
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Provides a means of automatically retrieving, saving and resetting KConfigSkeleton based settings in a dialog.

The KConfigDialogManager class provides a means of automatically retrieving, saving and resetting basic settings. It also can emit signals when settings have been changed (settings were saved) or modified (the user changes a checkbox from on to off).

The object names of the widgets to be managed have to correspond to the names of the configuration entries in the KConfigSkeleton object plus an additional "kcfg_" prefix. For example a widget with the object name "kcfg_MyOption" would be associated to the configuration entry "MyOption".

The widget classes of Qt and KDE Frameworks are supported out of the box, for other widgets see below:

Using Custom Widgets

Custom widget classes are supported if they have a Q_PROPERTY defined for the property representing the value edited by the widget. By default the property is used for which "USER true" is set. For using another property, see below.

Example:

A class ColorEditWidget is used in the settings UI to select a color. The color value is set and read as type QColor. For that it has a definition of the value property similar to this:

Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)

And of course it has the definition and implementation of the respective read & write methods and the notify signal. This class then can be used directly with KConfigDialogManager and does not need further setup. For supporting also KDE Frameworks versions older than 5.32 see below for how to register the property change signal.

Using Other Properties than The USER Property
To use a widget's property that is not the USER property, the property to use can be selected by setting onto the widget instance a property with the key "kcfg_property" and as the value the name of the property:
ColorEditWidget *myWidget = new ColorEditWidget;
myWidget->setProperty("kcfg_property", QByteArray("redColorPart"));
This selection of the property to use is just valid for this widget instance. When using a UI file, the "kcfg_property" property can also be set using Qt Designer.
Configuring Classes to use Other Properties Globally

Alternatively a non-USER property can be defined for a widget class globally by registering it for the class in the KConfigDialogManager::propertyMap(). This global registration has lower priority than any "kcfg_property" property set on a class instance though, so the latter overrules this global setting. Note: setting the property in the propertyMap affects any instances of that widget class in the current application, so use only when needed and prefer instead the "kcfg_property" property. Especially with software with many libraries and 3rd-party plugins in one process there is a chance of conflicting settings.

Example:

If the ColorEditWidget has another property redColor defined by

Q_PROPERTY(int redColorPart READ redColorPart WRITE setRedColorPart NOTIFY redColorPartChanged)

and this one should be used in the settings, call somewhere in the code before using the settings:

KConfigDialogManager::propertyMap()->insert("ColorEditWidget", QByteArray("redColorPart"));
Using Different Signals than The NOTIFY Signal

If some non-default signal should be used, e.g. because the property to use does not have a NOTIFY setting, for a given widget instance the signal to use can be set by a property with the key "kcfg_propertyNotify" and as the value the signal signature. This will take priority over the signal noted by NOTIFY for the chosen property as well as the content of KConfigDialogManager::changedMap(). Since 5.32.

Example:

If for a class OtherColorEditWidget there was no NOTIFY set on the USER property, but some signal colorSelected(QColor) defined which would be good enough to reflect the settings change, defined by

Q_PROPERTY(QColor color READ color WRITE setColor USER true)
void colorSelected(const QColor &color);

the signal to use would be defined by this:

OtherColorEditWidget *myWidget = new OtherColorEditWidget;
myWidget->setProperty("kcfg_propertyNotify", QByteArray(SIGNAL(colorSelected(QColor))));
Supporting Older Versions of KDE Frameworks

Before version 5.32 of KDE Frameworks, the signal notifying about a change of the property value in the widget had to be manually registered for any custom widget, using KConfigDialogManager::changedMap(). The same also had to be done for custom signals with widgets from Qt and KDE Frameworks. So for code which needs to also work with older versions of the KDE Frameworks, this still needs to be done. Starting with version 5.32, where the new signal handling is effective, the signal registered via KConfigDialogManager::changedMap() will take precedence over the one read from the Q_PROPERTY declaration, but is overridden for a given widget instance by the "kcfg_propertyNotify" property.

Examples:

For the class ColorEditWidget from the previous example this will register the change signal as needed:

KConfigDialogManager::changedMap()->insert("ColorEditWidget", QByteArray(SIGNAL(colorChanged(QColor))));

For KDE Framework versions starting with 5.32 this will override then the signal as read from the USER property, but as it is the same signal, nothing will break.

If wants to reduce conflicts and also only add code to the build as needed, one would add both a buildtime switch and a runtime switch like

#include <kconfigwidgets_version.h>
#include <kcoreaddons.h>
// [...]
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5,32,0)
if (KCoreAddons::version() < QT_VERSION_CHECK(5,32,0)) {
KConfigDialogManager::changedMap()->insert("ColorEditWidget", QByteArray(SIGNAL(colorChanged(QColor))));
}
#endif

so support for the old variant would be only used when running against an older KDE Frameworks, and this again only built in if also compiled against an older version. Note: KCoreAddons::version() needs at least KDE Frameworks 5.20 though.

For the class OtherColorEditWidget from the previous example for the support of also older KDE Frameworks versions the change signal would be registered by this:

KConfigDialogManager::changedMap()->insert("OtherColorEditWidget", QByteArray(SIGNAL(colorSelected(QColor))));
OtherColorEditWidget *myWidget = new OtherColorEditWidget;
myWidget->setProperty("kcfg_propertyNotify", QByteArray(SIGNAL(colorSelected(QColor))));

Here for KDE Framework versions before 5.32 the "kcfg_propertyNotify" property would be ignored and the signal taken from KConfigDialogManager::changedMap(), while for newer versions it is taken from that property, which then overrides the latter. But as it is the same signal, nothing will break.

Again, using KConfigDialogManager::changedMap could be made to depend on the version, so for newer versions any global conflicts are avoided:

#include <kconfigwidgets_version.h>
#include <kcoreaddons.h>
// [...]
#if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5,32,0)
if (KCoreAddons::version() < QT_VERSION_CHECK(5,32,0)) {
KConfigDialogManager::changedMap()->insert("OtherColorEditWidget", QByteArray(SIGNAL(colorSelected(QColor))));
}
#endif
OtherColorEditWidget *myWidget = new OtherColorEditWidget;
myWidget->setProperty("kcfg_propertyNotify", QByteArray(SIGNAL(colorSelected(QColor))));
Author
Benjamin C Meyer <ben+kdelibs at meyerhome dot net>
Waldo Bastian basti[email protected][email protected][email protected]de.or[email protected]g

Definition at line 199 of file kconfigdialogmanager.h.

Constructor & Destructor Documentation

◆ KConfigDialogManager() [1/2]

KConfigDialogManager::KConfigDialogManager ( QWidget parent,
KCoreConfigSkeleton conf 
)

Constructor.

Parameters
parentDialog widget to manage
confObject that contains settings

Definition at line 31 of file kconfigdialogmanager.cpp.

◆ KConfigDialogManager() [2/2]

KConfigDialogManager::KConfigDialogManager ( QWidget parent,
KConfigSkeleton conf 
)

Constructor.

Parameters
parentDialog widget to manage
confObject that contains settings
Deprecated:
since 5.84, use KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf)

Definition at line 41 of file kconfigdialogmanager.cpp.

◆ ~KConfigDialogManager()

KConfigDialogManager::~KConfigDialogManager ( )
overridedefault

Destructor.

Member Function Documentation

◆ addWidget()

void KConfigDialogManager::addWidget ( QWidget widget)

Add additional widgets to manage.

Parameters
widgetAdditional widget to manage, including all its children

Definition at line 128 of file kconfigdialogmanager.cpp.

◆ changedMap()

QHash< QString, QByteArray > * KConfigDialogManager::changedMap ( )
static

Retrieve the map between widgets class names and signals that are listened to detect changes in the configuration values.

Deprecated:
Since 5.32, rely on the property change signal noted by NOTIFY of the used property in the class definition instead of setting it in this map. Or set the "kcfg_propertyNotify" property on the widget instance.

Definition at line 112 of file kconfigdialogmanager.cpp.

◆ getCustomProperty()

QByteArray KConfigDialogManager::getCustomProperty ( const QWidget widget) const
protected

Find the property to use for a widget by querying the "kcfg_property" property of the widget.

Like a widget can use a property other than the USER property.

Since
4.3

Definition at line 434 of file kconfigdialogmanager.cpp.

◆ getCustomPropertyChangedSignal()

QByteArray KConfigDialogManager::getCustomPropertyChangedSignal ( const QWidget widget) const
protected

Find the changed signal of the property to use for a widget by querying the "kcfg_propertyNotify" property of the widget.

Like a widget can use a property change signal other than the one for USER property, if there even is one.

Since
5.32

Definition at line 464 of file kconfigdialogmanager.cpp.

◆ getUserProperty()

QByteArray KConfigDialogManager::getUserProperty ( const QWidget widget) const
protected

Finds the USER property name using Qt's MetaProperty system, and caches it in the property map (the cache could be retrieved by propertyMap() ).

Definition at line 405 of file kconfigdialogmanager.cpp.

◆ getUserPropertyChangedSignal()

QByteArray KConfigDialogManager::getUserPropertyChangedSignal ( const QWidget widget) const
protected

Finds the changed signal of the USER property using Qt's MetaProperty system.

Since
5.32

Definition at line 447 of file kconfigdialogmanager.cpp.

◆ hasChanged()

bool KConfigDialogManager::hasChanged ( ) const

Returns whether the current state of the known widgets are different from the state in the config object.

Definition at line 549 of file kconfigdialogmanager.cpp.

◆ init()

void KConfigDialogManager::init ( bool  trackChanges)
protected
Parameters
trackChanges- If any changes by the widgets should be tracked set true. This causes the emitting the modified() signal when something changes. TODO:
Returns
bool - True if any setting was changed from the default.

Definition at line 119 of file kconfigdialogmanager.cpp.

◆ initMaps()

void KConfigDialogManager::initMaps ( )
staticprotected

Initializes the property maps.

Definition at line 54 of file kconfigdialogmanager.cpp.

◆ isDefault()

bool KConfigDialogManager::isDefault ( ) const

Returns whether the current state of the known widgets are the same as the default state in the config object.

Definition at line 571 of file kconfigdialogmanager.cpp.

◆ parseChildren()

bool KConfigDialogManager::parseChildren ( const QWidget widget,
bool  trackChanges 
)
protected

Recursive function that finds all known children.

Goes through the children of widget and if any are known and not being ignored, stores them in currentGroup. Also checks if the widget should be disabled because it is set immutable.

Parameters
widget- Parent of the children to look at.
trackChanges- If true then tracks any changes to the children of widget that are known.
Returns
bool - If a widget was set to something other than its default.

Definition at line 198 of file kconfigdialogmanager.cpp.

◆ property()

QVariant KConfigDialogManager::property ( QWidget w) const
protected

Retrieve a property.

Definition at line 515 of file kconfigdialogmanager.cpp.

◆ propertyMap()

QHash< QString, QByteArray > * KConfigDialogManager::propertyMap ( )
static

Retrieve the map between widgets class names and the USER properties used for the configuration values.

Definition at line 105 of file kconfigdialogmanager.cpp.

◆ setDefaultsIndicatorsVisible

void KConfigDialogManager::setDefaultsIndicatorsVisible ( bool  enabled)
slot

Show or hide an indicator when settings have changed from their default value.

Update all widgets to show or hide the indicator accordingly.

Since
5.73

Definition at line 371 of file kconfigdialogmanager.cpp.

◆ setProperty()

void KConfigDialogManager::setProperty ( QWidget w,
const QVariant v 
)
protected

Set a property.

Definition at line 477 of file kconfigdialogmanager.cpp.

◆ settingsChanged [1/2]

void KConfigDialogManager::settingsChanged ( )
signal

One or more of the settings have been saved (such as when the user clicks on the Apply button).

This is only emitted by updateSettings() whenever one or more setting were changed and consequently saved.

◆ settingsChanged [2/2]

void KConfigDialogManager::settingsChanged ( QWidget widget)
signal

TODO: Verify One or more of the settings have been changed.

Parameters
widget- The widget group (pass in via addWidget()) that contains the one or more modified setting.
See also
settingsChanged()
Deprecated:
since 5.82, use the KConfigDialogManager::settingsChanged() signal instead.

◆ setupWidget()

void KConfigDialogManager::setupWidget ( QWidget widget,
KConfigSkeletonItem item 
)
protected

Setup secondary widget properties.

Definition at line 133 of file kconfigdialogmanager.cpp.

◆ updateSettings

void KConfigDialogManager::updateSettings ( )
slot

Traverse the specified widgets, saving the settings of all known widgets in the settings object.

Example use: User clicks Ok or Apply button in a configure dialog.

Definition at line 376 of file kconfigdialogmanager.cpp.

◆ updateWidgets

void KConfigDialogManager::updateWidgets ( )
slot

Traverse the specified widgets, sets the state of all known widgets according to the state in the settings object.

Example use: Initialisation of dialog. Example use: User clicks Reset button in a configure dialog.

Definition at line 324 of file kconfigdialogmanager.cpp.

◆ updateWidgetsDefault

void KConfigDialogManager::updateWidgetsDefault ( )
slot

Traverse the specified widgets, sets the state of all known widgets according to the default state in the settings object.

Example use: User clicks Defaults button in a configure dialog.

Definition at line 363 of file kconfigdialogmanager.cpp.

◆ widgetModified

void KConfigDialogManager::widgetModified ( )
signal

If retrieveSettings() was told to track changes then if any known setting was changed this signal will be emitted.

Note that a settings can be modified several times and might go back to the original saved state. hasChanged() will tell you if anything has actually changed from the saved values.


The documentation for this class was generated from the following files:
static QHash< QString, QByteArray > * propertyMap()
Retrieve the map between widgets class names and the USER properties used for the configuration value...
Q_PROPERTY(...)
static QHash< QString, QByteArray > * changedMap()
Retrieve the map between widgets class names and signals that are listened to detect changes in the c...
KCOREADDONS_EXPORT unsigned int version()
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat May 21 2022 04:10:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.