KCMUtils

kcmodule.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Michael Goffioul <kdeprint@swing.be>
3 SPDX-FileCopyrightText: 2004 Frans Englich <frans.englich@telia.com>
4 SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "kcmodule.h"
10#include "kabstractconfigmodule.h"
11#include "kcmutils_debug.h"
12
13#include <QVBoxLayout>
14
15#include <KConfigDialogManager>
16#include <KConfigSkeleton>
17#include <KLocalizedString>
18#include <KPluginMetaData>
19
20class KCModuleProxyInternal : public QWidget
21{
23public:
24 KCModuleProxyInternal(QWidget *parent)
26 {
27 }
28};
29
30class KCModulePrivate
31{
32public:
33 KCModulePrivate(QWidget *parentWidget)
34 : _needsAuthorization(false)
35 , _unmanagedWidgetChangeState(false)
36 , _unmanagedWidgetDefaultState(false)
37 , _unmanagedWidgetDefaultStateCalled(false)
38 , parentWidget(parentWidget)
39 {
40 }
41
42 void authStatusChanged(int status);
43
44 QList<KConfigDialogManager *> managers;
45
46 bool _needsAuthorization : 1;
47
48 // this member is used to record the state on non-automatically
49 // managed widgets, allowing for mixed KConfigXT-drive and manual
50 // widgets to coexist peacefully and do the correct thing with
51 // the changed(bool) signal
52 bool _unmanagedWidgetChangeState : 1;
53 bool _unmanagedWidgetDefaultState : 1;
54 bool _unmanagedWidgetDefaultStateCalled : 1;
55 QVBoxLayout *m_topLayout = nullptr; /* Contains QScrollView view, and root stuff */
56 QWidget *parentWidget;
57 KCModuleProxyInternal *m_proxyInternal = nullptr;
58};
59
61 : KAbstractConfigModule(parent, data)
62 , d(new KCModulePrivate(parent))
63{
65 for (auto manager : std::as_const(d->managers)) {
66 manager->setDefaultsIndicatorsVisible(defaultsIndicatorsVisible());
67 }
68 });
69}
70
72{
73 KConfigDialogManager *manager = new KConfigDialogManager(widget, config);
74 manager->setDefaultsIndicatorsVisible(defaultsIndicatorsVisible());
75 manager->setObjectName(objectName());
77 connect(manager, &QObject::destroyed, this, [this, manager]() {
78 d->managers.removeOne(manager);
79 });
80 d->managers.append(manager);
81 return manager;
82}
83
85{
86 qDeleteAll(d->managers);
87 d->managers.clear();
88}
89
91{
93 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
94 manager->updateWidgets();
95 }
97}
98
100{
102 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
103 manager->updateSettings();
104 }
105}
106
108{
110 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
111 manager->updateWidgetsDefault();
112 }
113}
114
116{
117 if (!d->m_proxyInternal) {
118 d->m_topLayout = new QVBoxLayout(d->parentWidget);
119 d->m_proxyInternal = new KCModuleProxyInternal(d->parentWidget);
120 d->m_topLayout->addWidget(d->m_proxyInternal);
121 }
122 return d->m_proxyInternal;
123}
124
126{
127 setNeedsSave(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
128 if (d->_unmanagedWidgetDefaultStateCalled) {
129 setRepresentsDefaults(d->_unmanagedWidgetDefaultState && managedWidgetDefaultState());
130 } else {
131 setRepresentsDefaults(!d->managers.isEmpty() && managedWidgetDefaultState());
132 }
133}
134
136{
137 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
138 if (manager->hasChanged()) {
139 return true;
140 }
141 }
142
143 return false;
144}
145
147{
148 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
149 if (!manager->isDefault()) {
150 return false;
151 }
152 }
153
154 return true;
155}
156
158{
159 d->_unmanagedWidgetChangeState = changed;
161}
162
164{
165 d->_unmanagedWidgetDefaultStateCalled = true;
166 d->_unmanagedWidgetDefaultState = defaulted;
168}
169
171{
172 return d->managers;
173}
174
175#include "kcmodule.moc"
176#include "moc_kcmodule.cpp"
virtual void defaults()
Sets the configuration to default values.
void setNeedsSave(bool needs)
Set this property to true when the user changes something in the module, signaling that a save (such ...
virtual void save()
The save method stores the config information as shown in the user interface in the config files.
Q_SIGNAL void defaultsIndicatorsVisibleChanged()
Emitted when kcm need to display indicators for field with non default value.
virtual void load()
Load the configuration data into the module.
void setRepresentsDefaults(bool defaults)
Set this property to true when the user sets the state of the module to the default settings (e....
bool managedWidgetChangeState() const
Returns the changed state of automatically managed widgets in this dialog.
Definition kcmodule.cpp:135
virtual QWidget * widget()
Get the associated widget that can be embedded The returned widget should be used as a parent for wid...
Definition kcmodule.cpp:115
void defaults() override
Sets the configuration to default values.
Definition kcmodule.cpp:107
~KCModule() override
Destroys the module.
Definition kcmodule.cpp:84
KConfigDialogManager * addConfig(KCoreConfigSkeleton *config, QWidget *widget)
Adds a KCoreConfigskeleton config to watch the widget widget.
Definition kcmodule.cpp:71
void load() override
Load the configuration data into the module.
Definition kcmodule.cpp:90
QList< KConfigDialogManager * > configs() const
Definition kcmodule.cpp:170
bool managedWidgetDefaultState() const
Returns the defaulted state of automatically managed widgets in this dialog.
Definition kcmodule.cpp:146
void unmanagedWidgetChangeState(bool)
Call this method when your manually managed widgets change state between changed and not changed.
Definition kcmodule.cpp:157
void widgetChanged()
A managed widget was changed, the widget settings and the current settings are compared and a corresp...
Definition kcmodule.cpp:125
KCModule(QWidget *parent, const KPluginMetaData &data)
Base class for all QWidgets configuration modules.
Definition kcmodule.cpp:60
void unmanagedWidgetDefaultState(bool)
Call this method when your manually managed widgets change state between defaulted and not defaulted.
Definition kcmodule.cpp:163
void save() override
The save method stores the config information as shown in the user interface in the config files.
Definition kcmodule.cpp:99
void setDefaultsIndicatorsVisible(bool enabled)
Q_SCRIPTABLE CaptureState status()
Q_OBJECTQ_OBJECT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
QObject * parent() const const
void setObjectName(QAnyStringView name)
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:54:07 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.