28#include <QMetaProperty>
30#include <QRadioButton>
43class KConfigDialogManager::Private {
51 static int debugArea() {
static int s_area = KDebug::registerArea(
"kdeui (KConfigDialogManager)");
return s_area; }
65 bool insideGroupBox : 1;
66 bool trackChanges : 1;
70 :
QObject(parent), d(new Private(this))
78 :
QObject(parent), d(new Private(this))
92 if ( s_propertyMap->isEmpty() ) {
93 s_propertyMap->insert(
"KButtonGroup",
"current" );
94 s_propertyMap->insert(
"KColorButton",
"color" );
95 s_propertyMap->insert(
"KColorCombo",
"color" );
100 if( s_changedMap->isEmpty() )
103 s_changedMap->insert(
"QCheckBox", SIGNAL(stateChanged(
int)));
104 s_changedMap->insert(
"QPushButton", SIGNAL(clicked(
bool)));
105 s_changedMap->insert(
"QRadioButton", SIGNAL(toggled(
bool)));
109 s_changedMap->insert(
"QGroupBox", SIGNAL(toggled(
bool)));
110 s_changedMap->insert(
"QComboBox", SIGNAL(activated(
int)));
113 s_changedMap->insert(
"QDateEdit", SIGNAL(dateChanged(QDate)));
114 s_changedMap->insert(
"QTimeEdit", SIGNAL(timeChanged(QTime)));
115 s_changedMap->insert(
"QDateTimeEdit", SIGNAL(dateTimeChanged(QDateTime)));
116 s_changedMap->insert(
"QDial", SIGNAL(valueChanged(
int)));
117 s_changedMap->insert(
"QDoubleSpinBox", SIGNAL(valueChanged(
double)));
118 s_changedMap->insert(
"QLineEdit", SIGNAL(textChanged(QString)));
119 s_changedMap->insert(
"QSlider", SIGNAL(valueChanged(
int)));
120 s_changedMap->insert(
"QSpinBox", SIGNAL(valueChanged(
int)));
121 s_changedMap->insert(
"QTextEdit", SIGNAL(textChanged()));
122 s_changedMap->insert(
"QTextBrowser", SIGNAL(sourceChanged(QString)));
123 s_changedMap->insert(
"QPlainTextEdit", SIGNAL(textChanged()));
124 s_changedMap->insert(
"QTabWidget", SIGNAL(currentChanged(
int)));
127 s_changedMap->insert(
"KComboBox", SIGNAL(activated(
int)));
128 s_changedMap->insert(
"KFontComboBox", SIGNAL(activated(
int)));
129 s_changedMap->insert(
"KFontRequester", SIGNAL(fontSelected(QFont)));
130 s_changedMap->insert(
"KFontChooser", SIGNAL(fontSelected(QFont)));
131 s_changedMap->insert(
"KHistoryCombo", SIGNAL(activated(
int)));
132 s_changedMap->insert(
"KColorCombo", SIGNAL(activated(QColor)));
134 s_changedMap->insert(
"KColorButton", SIGNAL(changed(QColor)));
135 s_changedMap->insert(
"KDatePicker", SIGNAL(dateSelected(QDate)));
136 s_changedMap->insert(
"KDateWidget", SIGNAL(changed(QDate)));
137 s_changedMap->insert(
"KDateTimeWidget", SIGNAL(valueChanged(QDateTime)));
138 s_changedMap->insert(
"KEditListBox", SIGNAL(changed()));
139 s_changedMap->insert(
"KEditListWidget", SIGNAL(changed()));
140 s_changedMap->insert(
"KListWidget", SIGNAL(itemSelectionChanged()));
141 s_changedMap->insert(
"KLineEdit", SIGNAL(textChanged(QString)));
142 s_changedMap->insert(
"KPasswordEdit", SIGNAL(textChanged(QString)));
143 s_changedMap->insert(
"KRestrictedLine", SIGNAL(textChanged(QString)));
144 s_changedMap->insert(
"KTextBrowser", SIGNAL(sourceChanged(QString)));
145 s_changedMap->insert(
"KTextEdit", SIGNAL(textChanged()));
146 s_changedMap->insert(
"KUrlRequester", SIGNAL(textChanged(QString)));
147 s_changedMap->insert(
"KUrlComboRequester", SIGNAL(textChanged(QString)));
148 s_changedMap->insert(
"KUrlComboBox", SIGNAL(urlActivated(
KUrl)));
149 s_changedMap->insert(
"KIntNumInput", SIGNAL(valueChanged(
int)));
150 s_changedMap->insert(
"KIntSpinBox", SIGNAL(valueChanged(
int)));
151 s_changedMap->insert(
"KDoubleNumInput", SIGNAL(valueChanged(
double)));
152 s_changedMap->insert(
"KButtonGroup", SIGNAL(changed(
int)));
159 return s_propertyMap;
171 d->trackChanges = trackChanges;
184 QVariant minValue = item->
minValue();
185 if (minValue.isValid())
188 if (widget->metaObject()->indexOfProperty(
"minValue") != -1)
189 widget->setProperty(
"minValue", minValue);
190 if (widget->metaObject()->indexOfProperty(
"minimum") != -1)
191 widget->setProperty(
"minimum", minValue);
193 QVariant maxValue = item->
maxValue();
194 if (maxValue.isValid())
197 if (widget->metaObject()->indexOfProperty(
"maxValue") != -1)
198 widget->setProperty(
"maxValue", maxValue);
199 if (widget->metaObject()->indexOfProperty(
"maximum") != -1)
200 widget->setProperty(
"maximum", maxValue);
203 if (widget->whatsThis().isEmpty())
206 if ( !whatsThis.isEmpty() )
208 widget->setWhatsThis(whatsThis );
212 if (widget->toolTip().isEmpty())
214 QString toolTip = item->
toolTip();
215 if ( !toolTip.isEmpty() )
217 widget->setToolTip(toolTip);
227 bool valueChanged =
false;
229 if(listOfChildren.count()==0)
232 foreach (
QObject *
object, listOfChildren )
234 if(!object->isWidgetType())
239 QString widgetName = childWidget->objectName();
240 bool bParseChildren =
true;
241 bool bSaveInsideGroupBox = d->insideGroupBox;
243 if (widgetName.startsWith(QLatin1String(
"kcfg_")))
246 QString configId = widgetName.mid(5);
250 d->knownWidget.insert(configId, childWidget);
254 if ( d->trackChanges ) {
257 if (changedIt == s_changedMap->constEnd())
263 if ( childWidget->metaObject()->superClass() )
264 changedIt = s_changedMap->constFind(childWidget->metaObject()->superClass()->className());
266 changedIt = s_changedMap->constFind(0);
269 if (changedIt == s_changedMap->constEnd())
271 kWarning(d->debugArea()) <<
"Don't know how to monitor widget '" << childWidget->metaObject()->className() <<
"' for changes!";
275 connect(childWidget, *changedIt,
278 QComboBox *cb = qobject_cast<QComboBox *>(childWidget);
279 if (cb && cb->isEditable())
280 connect(cb, SIGNAL(editTextChanged(QString)),
284 QGroupBox *gb = qobject_cast<QGroupBox *>(childWidget);
286 bParseChildren =
false;
288 d->insideGroupBox =
true;
292 kWarning(d->debugArea()) <<
"A widget named '" << widgetName <<
"' was found but there is no setting named '" << configId <<
"'";
295 else if (
QLabel *label = qobject_cast<QLabel*>(childWidget))
297 QWidget *buddy = label->buddy();
300 QString buddyName = buddy->objectName();
301 if (buddyName.startsWith(QLatin1String(
"kcfg_")))
304 QString configId = buddyName.mid(5);
305 d->buddyWidget.insert(configId, childWidget);
309 else if (!widgetName.isEmpty() && d->trackChanges)
312 if (changedIt != s_changedMap->constEnd())
314 if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) &&
315 !qobject_cast<QGroupBox*>(childWidget) &&!qobject_cast<QTabWidget*>(childWidget) )
316 kDebug(d->debugArea()) <<
"Widget '" << widgetName <<
"' (" << childWidget->metaObject()->className() <<
") remains unmanaged.";
327 d->insideGroupBox = bSaveInsideGroupBox;
334 bool changed =
false;
335 bool bSignalsBlocked = signalsBlocked();
339 QHashIterator<QString, QWidget *> it( d->knownWidget );
340 while(it.hasNext()) {
347 kWarning(d->debugArea()) <<
"The setting '" << it.key() <<
"' has disappeared!";
359 widget->setEnabled(
false);
360 QWidget *buddy = d->buddyWidget.value(it.key(), 0);
362 buddy->setEnabled(
false);
365 blockSignals(bSignalsBlocked);
373 bool bUseDefaults = d->m_conf->useDefaults(
true);
375 d->m_conf->useDefaults(bUseDefaults);
380 bool changed =
false;
383 QHashIterator<QString, QWidget *> it( d->knownWidget );
384 while(it.hasNext()) {
390 kWarning(d->debugArea()) <<
"The setting '" << it.key() <<
"' has disappeared!";
394 QVariant fromWidget =
property(widget);
395 if(!item->
isEqual( fromWidget )) {
402 d->m_conf->writeConfig();
409 if (!s_propertyMap->contains(widget->metaObject()->className())) {
410 const QMetaObject *metaObject = widget->metaObject();
411 const QMetaProperty user = metaObject->userProperty();
412 if ( user.isValid() ) {
413 s_propertyMap->insert( widget->metaObject()->className(), user.name() );
421 const QComboBox *cb = qobject_cast<const QComboBox *>(widget);
423 const char *qcomboUserPropertyName = cb->QComboBox::metaObject()->userProperty().name();
424 const int qcomboUserPropertyIndex = qcomboUserPropertyName ? cb->QComboBox::metaObject()->indexOfProperty(qcomboUserPropertyName) : -1;
425 const char *widgetUserPropertyName = widget->metaObject()->userProperty().name();
426 const int widgetUserPropertyIndex = widgetUserPropertyName ? cb->metaObject()->indexOfProperty(widgetUserPropertyName) : -1;
428 if (qcomboUserPropertyIndex == widgetUserPropertyIndex) {
433 return s_propertyMap->value( widget->metaObject()->className() );
438 QVariant prop(widget->property(
"kcfg_property"));
439 if (prop.isValid()) {
440 if (!prop.canConvert(QVariant::ByteArray)) {
441 kWarning(d->debugArea()) <<
"kcfg_property on" << widget->metaObject()->className()
442 <<
"is not of type ByteArray";
444 return prop.toByteArray();
462 if (userproperty.isEmpty()) {
465 if (userproperty.isEmpty()) {
466 QComboBox *cb = qobject_cast<QComboBox *>(w);
468 if (cb->isEditable()) {
469 int i = cb->findText(v.toString());
471 cb->setCurrentIndex(i);
473 cb->setEditText(v.toString());
476 cb->setCurrentIndex(v.toInt());
481 if (userproperty.isEmpty()) {
482 kWarning(d->debugArea()) << w->metaObject()->className() <<
" widget not handled!";
486 w->setProperty(userproperty, v);
496 if (userproperty.isEmpty()) {
499 if (userproperty.isEmpty()) {
500 QComboBox *cb = qobject_cast<QComboBox *>(w);
502 if (cb->isEditable()) {
503 return QVariant(cb->currentText());
505 return QVariant(cb->currentIndex());
509 if (userproperty.isEmpty()) {
510 kWarning(d->debugArea()) << w->metaObject()->className() <<
" widget not handled!";
514 return w->property(userproperty);
520 QHashIterator<QString, QWidget *> it( d->knownWidget) ;
521 while(it.hasNext()) {
527 kWarning(d->debugArea()) <<
"The setting '" << it.key() <<
"' has disappeared!";
541 bool bUseDefaults = d->m_conf->useDefaults(
true);
543 d->m_conf->useDefaults(bUseDefaults);
547#include "kconfigdialogmanager.moc"
Provides a means of automatically retrieving, saving and resetting KConfigSkeleton based settings in ...
void setupWidget(QWidget *widget, KConfigSkeletonItem *item)
Setup secondary widget properties.
void updateWidgetsDefault()
Traverse the specified widgets, sets the state of all known widgets according to the default state in...
QVariant property(QWidget *w) const
Retrieve a property.
static void initMaps()
Initializes the property maps.
QByteArray getCustomProperty(const QWidget *widget) const
Find the property to use for a widget by querying the kcfg_property property of the widget.
QByteArray getUserProperty(const QWidget *widget) const
Finds the USER property name using Qt's MetaProperty system, and caches it in the property map (the c...
~KConfigDialogManager()
Destructor.
static QHash< QString, QByteArray > * changedMap()
Retrieve the widget change map.
void widgetModified()
If retrieveSettings() was told to track changes then if any known setting was changed this signal wil...
static QHash< QString, QByteArray > * propertyMap()
Retrieve the property map.
void settingsChanged()
One or more of the settings have been saved (such as when the user clicks on the Apply button).
void updateWidgets()
Traverse the specified widgets, sets the state of all known widgets according to the state in the set...
KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf)
Constructor.
void setProperty(QWidget *w, const QVariant &v)
Set a property.
void addWidget(QWidget *widget)
Add additional widgets to manage.
bool hasChanged() const
Returns whether the current state of the known widgets are different from the state in the config obj...
bool parseChildren(const QWidget *widget, bool trackChanges)
Recursive function that finds all known children.
void updateSettings()
Traverse the specified widgets, saving the settings of all known widgets in the settings object.
bool isDefault() const
Returns whether the current state of the known widgets are the same as the default state in the confi...
void init(bool trackChanges)
virtual bool isEqual(const QVariant &p) const=0
virtual QVariant minValue() const
QString whatsThis() const
virtual void setProperty(const QVariant &p)=0
virtual QVariant maxValue() const
virtual QVariant property() const=0
Class for handling preferences settings for an application.
#define K_GLOBAL_STATIC(TYPE, NAME)
QHash< QString, QByteArray > MyHash