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
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{
64}
65
67{
68 KConfigDialogManager *manager = new KConfigDialogManager(widget, config);
69 manager->setObjectName(objectName());
71 connect(manager, &QObject::destroyed, this, [this, manager]() {
72 d->managers.removeOne(manager);
73 });
74 d->managers.append(manager);
75 return manager;
76}
77
79{
80 qDeleteAll(d->managers);
81 d->managers.clear();
82}
83
85{
87 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
88 manager->updateWidgets();
89 }
91}
92
94{
96 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
97 manager->updateSettings();
98 }
99}
100
102{
104 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
105 manager->updateWidgetsDefault();
106 }
107}
108
110{
111 if (!d->m_proxyInternal) {
112 d->m_topLayout = new QVBoxLayout(d->parentWidget);
113 d->m_proxyInternal = new KCModuleProxyInternal(d->parentWidget);
114 d->m_topLayout->addWidget(d->m_proxyInternal);
115 }
116 return d->m_proxyInternal;
117}
118
120{
121 setNeedsSave(d->_unmanagedWidgetChangeState || managedWidgetChangeState());
122 if (d->_unmanagedWidgetDefaultStateCalled) {
123 setRepresentsDefaults(d->_unmanagedWidgetDefaultState && managedWidgetDefaultState());
124 } else {
125 setRepresentsDefaults(!d->managers.isEmpty() && managedWidgetDefaultState());
126 }
127}
128
130{
131 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
132 if (manager->hasChanged()) {
133 return true;
134 }
135 }
136
137 return false;
138}
139
141{
142 for (KConfigDialogManager *manager : std::as_const(d->managers)) {
143 if (!manager->isDefault()) {
144 return false;
145 }
146 }
147
148 return true;
149}
150
152{
153 d->_unmanagedWidgetChangeState = changed;
155}
156
158{
159 d->_unmanagedWidgetDefaultStateCalled = true;
160 d->_unmanagedWidgetDefaultState = defaulted;
162}
163
165{
166 return d->managers;
167}
168
169#include "kcmodule.moc"
170#include "moc_kcmodule.cpp"
Base class for QML and QWidgets config modules.
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.
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:129
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:109
void defaults() override
Sets the configuration to default values.
Definition kcmodule.cpp:101
~KCModule() override
Destroys the module.
Definition kcmodule.cpp:78
KConfigDialogManager * addConfig(KCoreConfigSkeleton *config, QWidget *widget)
Adds a KCoreConfigskeleton config to watch the widget widget.
Definition kcmodule.cpp:66
void load() override
Load the configuration data into the module.
Definition kcmodule.cpp:84
QList< KConfigDialogManager * > configs() const
Definition kcmodule.cpp:164
bool managedWidgetDefaultState() const
Returns the defaulted state of automatically managed widgets in this dialog.
Definition kcmodule.cpp:140
void unmanagedWidgetChangeState(bool)
Call this method when your manually managed widgets change state between changed and not changed.
Definition kcmodule.cpp:151
void widgetChanged()
A managed widget was changed, the widget settings and the current settings are compared and a corresp...
Definition kcmodule.cpp:119
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:157
void save() override
The save method stores the config information as shown in the user interface in the config files.
Definition kcmodule.cpp:93
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)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.