kdeui: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-04 05:52:56 +03:00
parent 942e50f279
commit c23e68ad4d
2 changed files with 406 additions and 429 deletions

View file

@ -43,141 +43,146 @@ K_GLOBAL_STATIC(MyHash, s_changedMap)
// see kdebug.areas
static const int s_kconfigdialogmanagerarea = 300;
class KConfigDialogManager::Private {
class KConfigDialogManager::Private
{
public:
Private(KConfigDialogManager *q)
: q(q),
insideGroupBox(false)
{
}
public:
Private(KConfigDialogManager *q) : q(q), insideGroupBox(false) { }
KConfigDialogManager *q;
public:
KConfigDialogManager *q;
/**
* KConfigSkeleton object used to store settings
*/
KCoreConfigSkeleton *m_conf;
/**
* KConfigSkeleton object used to store settings
*/
KCoreConfigSkeleton *m_conf;
/**
* Dialog being managed
*/
QWidget* m_dialog;
/**
* Dialog being managed
*/
QWidget *m_dialog;
QHash<QString, QWidget *> knownWidget;
QHash<QString, QWidget *> buddyWidget;
bool insideGroupBox : 1;
bool trackChanges : 1;
QHash<QString, QWidget*> knownWidget;
QHash<QString, QWidget*> buddyWidget;
bool insideGroupBox;
bool trackChanges;
};
KConfigDialogManager::KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf)
: QObject(parent), d(new Private(this))
: QObject(parent),
d(new Private(this))
{
d->m_conf = conf;
d->m_dialog = parent;
init(true);
d->m_conf = conf;
d->m_dialog = parent;
init(true);
}
KConfigDialogManager::KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf)
: QObject(parent), d(new Private(this))
: QObject(parent),
d(new Private(this))
{
d->m_conf = conf;
d->m_dialog = parent;
init(true);
d->m_conf = conf;
d->m_dialog = parent;
init(true);
}
KConfigDialogManager::~KConfigDialogManager()
{
delete d;
delete d;
}
void KConfigDialogManager::initMaps()
{
if ( s_propertyMap->isEmpty() ) {
s_propertyMap->insert("QCheckBox", "checked");
s_propertyMap->insert("QPushButton", "toggled");
s_propertyMap->insert("QRadioButton", "checked");
s_propertyMap->insert("QGroupBox", "text");
// s_propertyMap->insert("QComboBox", "currentText");
s_propertyMap->insert("QDateEdit", "date");
s_propertyMap->insert("QDateTimeEdit", "dateTime");
s_propertyMap->insert("QDial", "value");
s_propertyMap->insert("QDoubleSpinBox", "value");
s_propertyMap->insert("QLineEdit", "text");
s_propertyMap->insert("QSlider", "value");
s_propertyMap->insert("QSpinBox", "value");
s_propertyMap->insert("QTextEdit", "html");
s_propertyMap->insert("QTextBrowser", "html");
s_propertyMap->insert("QPlainTextEdit", "plainText");
// s_propertyMap->insert( "QTabWidget", "");
if (s_propertyMap->isEmpty()) {
s_propertyMap->insert("QCheckBox", "checked");
s_propertyMap->insert("QPushButton", "toggled");
s_propertyMap->insert("QRadioButton", "checked");
s_propertyMap->insert("QGroupBox", "text");
// s_propertyMap->insert("QComboBox", "currentText");
s_propertyMap->insert("QDateEdit", "date");
s_propertyMap->insert("QDateTimeEdit", "dateTime");
s_propertyMap->insert("QDial", "value");
s_propertyMap->insert("QDoubleSpinBox", "value");
s_propertyMap->insert("QLineEdit", "text");
s_propertyMap->insert("QSlider", "value");
s_propertyMap->insert("QSpinBox", "value");
s_propertyMap->insert("QTextEdit", "html");
s_propertyMap->insert("QTextBrowser", "html");
s_propertyMap->insert("QPlainTextEdit", "plainText");
// s_propertyMap->insert( "QTabWidget", "");
// s_propertyMap->insert("KComboBox", "currentText");
s_propertyMap->insert("KFontRequester", "font");
s_propertyMap->insert("KHistoryCombo", "historyItems");
s_propertyMap->insert("KColorCombo", "color");
s_propertyMap->insert("KColorButton", "color");
s_propertyMap->insert("KCalendarWidget", "selectedDate");
s_propertyMap->insert("KTimeEdit", "time");
s_propertyMap->insert("KEditListWidget", "items");
// s_propertyMap->insert("KListWidget", "");
s_propertyMap->insert("KLineEdit", "text");
s_propertyMap->insert("KRestrictedLine", "text");
s_propertyMap->insert("KTextEdit", "html");
s_propertyMap->insert("KUrlRequester", "text");
s_propertyMap->insert("KUrlComboRequester", "text");
s_propertyMap->insert("KUrlComboBox", "urls");
s_propertyMap->insert("KIntNumInput", "value");
s_propertyMap->insert("KDoubleNumInput", "value");
s_propertyMap->insert("KButtonGroup", "current");
}
// s_propertyMap->insert("KComboBox", "currentText");
s_propertyMap->insert("KFontRequester", "font");
s_propertyMap->insert("KHistoryCombo", "historyItems");
s_propertyMap->insert("KColorCombo", "color");
s_propertyMap->insert("KColorButton", "color");
s_propertyMap->insert("KCalendarWidget", "selectedDate");
s_propertyMap->insert("KTimeEdit", "time");
s_propertyMap->insert("KEditListWidget", "items");
// s_propertyMap->insert("KListWidget", "");
s_propertyMap->insert("KLineEdit", "text");
s_propertyMap->insert("KRestrictedLine", "text");
s_propertyMap->insert("KTextEdit", "html");
s_propertyMap->insert("KUrlRequester", "text");
s_propertyMap->insert("KUrlComboRequester", "text");
s_propertyMap->insert("KUrlComboBox", "urls");
s_propertyMap->insert("KIntNumInput", "value");
s_propertyMap->insert("KDoubleNumInput", "value");
s_propertyMap->insert("KButtonGroup", "current");
}
if( s_changedMap->isEmpty() )
{
// Katie
s_changedMap->insert("QCheckBox", SIGNAL(stateChanged(int)));
s_changedMap->insert("QPushButton", SIGNAL(clicked(bool)));
s_changedMap->insert("QRadioButton", SIGNAL(toggled(bool)));
// can only store one thing so can't have a ButtonGroup that is checkable
// s_changedMap->insert("QButtonGroup", SIGNAL(buttonClicked(int)));
s_changedMap->insert("QGroupBox", SIGNAL(toggled(bool)));
s_changedMap->insert("QComboBox", SIGNAL(activated(int)));
// s_changedMap->insert("QComboBox", SIGNAL(textChanged(QString)));
s_changedMap->insert("QDateEdit", SIGNAL(dateChanged(QDate)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(dateTimeChanged(QDateTime)));
s_changedMap->insert("QDial", SIGNAL(valueChanged(int)));
s_changedMap->insert("QDoubleSpinBox", SIGNAL(valueChanged(double)));
s_changedMap->insert("QLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("QSlider", SIGNAL(valueChanged(int)));
s_changedMap->insert("QSpinBox", SIGNAL(valueChanged(int)));
s_changedMap->insert("QTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QTextBrowser", SIGNAL(sourceChanged(QString)));
s_changedMap->insert("QPlainTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QTabWidget", SIGNAL(currentChanged(int)));
if (s_changedMap->isEmpty()) {
// Katie
s_changedMap->insert("QCheckBox", SIGNAL(stateChanged(int)));
s_changedMap->insert("QPushButton", SIGNAL(clicked(bool)));
s_changedMap->insert("QRadioButton", SIGNAL(toggled(bool)));
// can only store one thing so can't have a ButtonGroup that is checkable
// s_changedMap->insert("QButtonGroup", SIGNAL(buttonClicked(int)));
s_changedMap->insert("QGroupBox", SIGNAL(toggled(bool)));
s_changedMap->insert("QComboBox", SIGNAL(activated(int)));
// s_changedMap->insert("QComboBox", SIGNAL(textChanged(QString)));
s_changedMap->insert("QDateEdit", SIGNAL(dateChanged(QDate)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(dateTimeChanged(QDateTime)));
s_changedMap->insert("QDial", SIGNAL(valueChanged(int)));
s_changedMap->insert("QDoubleSpinBox", SIGNAL(valueChanged(double)));
s_changedMap->insert("QLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("QSlider", SIGNAL(valueChanged(int)));
s_changedMap->insert("QSpinBox", SIGNAL(valueChanged(int)));
s_changedMap->insert("QTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QTextBrowser", SIGNAL(sourceChanged(QString)));
s_changedMap->insert("QPlainTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QTabWidget", SIGNAL(currentChanged(int)));
// KDE
s_changedMap->insert("KComboBox", SIGNAL(activated(int)));
s_changedMap->insert("KFontRequester", SIGNAL(fontSelected(QFont)));
s_changedMap->insert("KHistoryCombo", SIGNAL(activated(int)));
s_changedMap->insert("KColorCombo", SIGNAL(activated(QColor)));
s_changedMap->insert("KColorButton", SIGNAL(changed(QColor)));
s_changedMap->insert("KCalendarWidget", SIGNAL(activated(QDate)));
s_changedMap->insert("KTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("KEditListWidget", SIGNAL(changed()));
s_changedMap->insert("KListWidget", SIGNAL(itemSelectionChanged()));
s_changedMap->insert("KLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("KRestrictedLine", SIGNAL(textChanged(QString)));
s_changedMap->insert("KTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("KUrlRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboBox", SIGNAL(urlActivated(KUrl)));
s_changedMap->insert("KIntNumInput", SIGNAL(valueChanged(int)));
s_changedMap->insert("KDoubleNumInput", SIGNAL(valueChanged(double)));
s_changedMap->insert("KButtonGroup", SIGNAL(changed(int)));
}
// KDE
s_changedMap->insert("KComboBox", SIGNAL(activated(int)));
s_changedMap->insert("KFontRequester", SIGNAL(fontSelected(QFont)));
s_changedMap->insert("KHistoryCombo", SIGNAL(activated(int)));
s_changedMap->insert("KColorCombo", SIGNAL(activated(QColor)));
s_changedMap->insert("KColorButton", SIGNAL(changed(QColor)));
s_changedMap->insert("KCalendarWidget", SIGNAL(activated(QDate)));
s_changedMap->insert("KTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("KEditListWidget", SIGNAL(changed()));
s_changedMap->insert("KListWidget", SIGNAL(itemSelectionChanged()));
s_changedMap->insert("KLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("KRestrictedLine", SIGNAL(textChanged(QString)));
s_changedMap->insert("KTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("KUrlRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboBox", SIGNAL(urlActivated(KUrl)));
s_changedMap->insert("KIntNumInput", SIGNAL(valueChanged(int)));
s_changedMap->insert("KDoubleNumInput", SIGNAL(valueChanged(double)));
s_changedMap->insert("KButtonGroup", SIGNAL(changed(int)));
}
}
QHash<QString, QByteArray> *KConfigDialogManager::propertyMap()
{
initMaps();
return s_propertyMap;
initMaps();
return s_propertyMap;
}
QHash<QString, QByteArray> *KConfigDialogManager::changedMap()
@ -188,212 +193,201 @@ QHash<QString, QByteArray> *KConfigDialogManager::changedMap()
void KConfigDialogManager::init(bool trackChanges)
{
initMaps();
d->trackChanges = trackChanges;
initMaps();
d->trackChanges = trackChanges;
// Go through all of the children of the widgets and find all known widgets
(void) parseChildren(d->m_dialog, trackChanges);
// Go through all of the children of the widgets and find all known widgets
(void) parseChildren(d->m_dialog, trackChanges);
}
void KConfigDialogManager::addWidget(QWidget *widget)
{
(void) parseChildren(widget, true);
(void) parseChildren(widget, true);
}
void KConfigDialogManager::setupWidget(QWidget *widget, KConfigSkeletonItem *item)
{
QVariant minValue = item->minValue();
if (minValue.isValid())
{
// Only q3datetimeedit is using this property we can remove it if we stop supporting Qt3Support
if (widget->metaObject()->indexOfProperty("minValue") != -1)
widget->setProperty("minValue", minValue);
if (widget->metaObject()->indexOfProperty("minimum") != -1)
widget->setProperty("minimum", minValue);
}
QVariant maxValue = item->maxValue();
if (maxValue.isValid())
{
// Only q3datetimeedit is using that property we can remove it if we stop supporting Qt3Support
if (widget->metaObject()->indexOfProperty("maxValue") != -1)
widget->setProperty("maxValue", maxValue);
if (widget->metaObject()->indexOfProperty("maximum") != -1)
widget->setProperty("maximum", maxValue);
}
if (widget->whatsThis().isEmpty())
{
QString whatsThis = item->whatsThis();
if ( !whatsThis.isEmpty() )
{
widget->setWhatsThis(whatsThis );
QVariant minValue = item->minValue();
if (minValue.isValid()) {
// Only q3datetimeedit is using this property we can remove it if we stop supporting Qt3Support
if (widget->metaObject()->indexOfProperty("minValue") != -1) {
widget->setProperty("minValue", minValue);
}
if (widget->metaObject()->indexOfProperty("minimum") != -1) {
widget->setProperty("minimum", minValue);
}
}
}
if (widget->toolTip().isEmpty())
{
QString toolTip = item->toolTip();
if ( !toolTip.isEmpty() )
{
widget->setToolTip(toolTip);
QVariant maxValue = item->maxValue();
if (maxValue.isValid()) {
// Only q3datetimeedit is using that property we can remove it if we stop supporting Qt3Support
if (widget->metaObject()->indexOfProperty("maxValue") != -1) {
widget->setProperty("maxValue", maxValue);
}
if (widget->metaObject()->indexOfProperty("maximum") != -1) {
widget->setProperty("maximum", maxValue);
}
}
}
if(!item->isEqual( property(widget) ))
setProperty( widget, item->property() );
if (widget->whatsThis().isEmpty()) {
QString whatsThis = item->whatsThis();
if (!whatsThis.isEmpty()) {
widget->setWhatsThis(whatsThis);
}
}
if (widget->toolTip().isEmpty()) {
QString toolTip = item->toolTip();
if (!toolTip.isEmpty()) {
widget->setToolTip(toolTip);
}
}
if (!item->isEqual(property(widget))) {
setProperty(widget, item->property());
}
}
bool KConfigDialogManager::parseChildren(const QWidget *widget, bool trackChanges)
{
bool valueChanged = false;
const QList<QObject*> listOfChildren = widget->children();
if(listOfChildren.count()==0) //?? XXX
return valueChanged;
bool valueChanged = false;
const QList<QObject*> listOfChildren = widget->children();
if (listOfChildren.count() == 0) {
return valueChanged;
}
foreach ( QObject *object, listOfChildren )
{
if(!object->isWidgetType())
continue; // Skip non-widgets
QWidget *childWidget = static_cast<QWidget *>(object);
QString widgetName = childWidget->objectName();
bool bParseChildren = true;
bool bSaveInsideGroupBox = d->insideGroupBox;
if (widgetName.startsWith(QLatin1String("kcfg_")))
{
// This is one of our widgets!
QString configId = widgetName.mid(5);
KConfigSkeletonItem *item = d->m_conf->findItem(configId);
if (item)
{
d->knownWidget.insert(configId, childWidget);
setupWidget(childWidget, item);
if ( d->trackChanges ) {
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
if (changedIt == s_changedMap->constEnd())
{
// If the class name of the widget wasn't in the monitored widgets map, then look for
// it again using the super class name. This fixes a problem with using QtRuby/Korundum
// widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, even
// though it was a 'QWidget'.
if ( childWidget->metaObject()->superClass() )
changedIt = s_changedMap->constFind(childWidget->metaObject()->superClass()->className());
else
changedIt = s_changedMap->constFind(QString());
}
if (changedIt == s_changedMap->constEnd())
{
kWarning(s_kconfigdialogmanagerarea) << "Don't know how to monitor widget '" << childWidget->metaObject()->className() << "' for changes!";
}
else
{
connect(childWidget, *changedIt,
this, SIGNAL(widgetModified()));
QComboBox *cb = qobject_cast<QComboBox *>(childWidget);
if (cb && cb->isEditable())
connect(cb, SIGNAL(editTextChanged(QString)),
this, SIGNAL(widgetModified()));
}
foreach (QObject *object, listOfChildren) {
if(!object->isWidgetType()) {
// Skip non-widgets
continue;
}
QWidget *childWidget = static_cast<QWidget *>(object);
QString widgetName = childWidget->objectName();
bool bParseChildren = true;
bool bSaveInsideGroupBox = d->insideGroupBox;
if (widgetName.startsWith(QLatin1String("kcfg_"))) {
// This is one of our widgets!
QString configId = widgetName.mid(5);
KConfigSkeletonItem *item = d->m_conf->findItem(configId);
if (item) {
d->knownWidget.insert(configId, childWidget);
setupWidget(childWidget, item);
if (d->trackChanges) {
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
if (changedIt == s_changedMap->constEnd()) {
// If the class name of the widget wasn't in the monitored widgets map, then look for
// it again using the super class name. This fixes a problem with using QtRuby/Korundum
// widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, even
// though it was a 'QWidget'.
if ( childWidget->metaObject()->superClass()) {
changedIt = s_changedMap->constFind(childWidget->metaObject()->superClass()->className());
} else {
changedIt = s_changedMap->constFind(QString());
}
}
if (changedIt == s_changedMap->constEnd()) {
kWarning(s_kconfigdialogmanagerarea) << "Don't know how to monitor widget '" << childWidget->metaObject()->className() << "' for changes!";
} else {
connect(childWidget, *changedIt, this, SIGNAL(widgetModified()));
QComboBox *cb = qobject_cast<QComboBox *>(childWidget);
if (cb && cb->isEditable())
connect(cb, SIGNAL(editTextChanged(QString)), this, SIGNAL(widgetModified()));
}
}
QGroupBox *gb = qobject_cast<QGroupBox *>(childWidget);
if (!gb) {
bParseChildren = false;
} else {
d->insideGroupBox = true;
}
} else {
kWarning(s_kconfigdialogmanagerarea) << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'";
}
} else if (QLabel *label = qobject_cast<QLabel*>(childWidget)) {
QWidget *buddy = label->buddy();
if (!buddy) {
continue;
}
QString buddyName = buddy->objectName();
if (buddyName.startsWith(QLatin1String("kcfg_"))) {
// This is one of our widgets!
QString configId = buddyName.mid(5);
d->buddyWidget.insert(configId, childWidget);
}
}
QGroupBox *gb = qobject_cast<QGroupBox *>(childWidget);
if (!gb)
bParseChildren = false;
else
d->insideGroupBox = true;
}
else
{
kWarning(s_kconfigdialogmanagerarea) << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'";
}
}
else if (QLabel *label = qobject_cast<QLabel*>(childWidget))
{
QWidget *buddy = label->buddy();
if (!buddy)
continue;
QString buddyName = buddy->objectName();
if (buddyName.startsWith(QLatin1String("kcfg_")))
{
// This is one of our widgets!
QString configId = buddyName.mid(5);
d->buddyWidget.insert(configId, childWidget);
}
}
#ifndef NDEBUG
else if (!widgetName.isEmpty() && d->trackChanges)
{
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
if (changedIt != s_changedMap->constEnd())
{
if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) &&
!qobject_cast<QGroupBox*>(childWidget) &&!qobject_cast<QTabWidget*>(childWidget) )
kDebug(s_kconfigdialogmanagerarea) << "Widget '" << widgetName << "' (" << childWidget->metaObject()->className() << ") remains unmanaged.";
}
}
else if (!widgetName.isEmpty() && d->trackChanges) {
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
if (changedIt != s_changedMap->constEnd()) {
if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) &&
!qobject_cast<QGroupBox*>(childWidget) &&!qobject_cast<QTabWidget*>(childWidget)) {
kDebug(s_kconfigdialogmanagerarea) << "Widget '" << widgetName << "' (" << childWidget->metaObject()->className() << ") remains unmanaged.";
}
}
}
}
#endif
if(bParseChildren)
{
// this widget is not known as something we can store.
// Maybe we can store one of its children.
valueChanged |= parseChildren(childWidget, trackChanges);
if (bParseChildren) {
// this widget is not known as something we can store.
// Maybe we can store one of its children.
valueChanged |= parseChildren(childWidget, trackChanges);
}
d->insideGroupBox = bSaveInsideGroupBox;
}
d->insideGroupBox = bSaveInsideGroupBox;
}
return valueChanged;
return valueChanged;
}
void KConfigDialogManager::updateWidgets()
{
bool changed = false;
bool bSignalsBlocked = signalsBlocked();
blockSignals(true);
bool changed = false;
bool bSignalsBlocked = signalsBlocked();
blockSignals(true);
QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget );
while(it.hasNext()) {
it.next();
widget = it.value();
QWidget *widget;
QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) {
it.next();
widget = it.value();
KConfigSkeletonItem *item = d->m_conf->findItem(it.key());
if (!item)
{
kWarning(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' has disappeared!";
continue;
}
KConfigSkeletonItem* item = d->m_conf->findItem(it.key());
if (!item) {
kWarning(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' has disappeared!";
continue;
}
if(!item->isEqual( property(widget) ))
{
setProperty( widget, item->property() );
// kDebug(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' [" << widget->className() << "] has changed";
changed = true;
}
if (item->isImmutable())
{
widget->setEnabled(false);
QWidget *buddy = d->buddyWidget.value(it.key(), 0);
if (buddy)
buddy->setEnabled(false);
}
}
blockSignals(bSignalsBlocked);
if (!item->isEqual(property(widget))) {
setProperty(widget, item->property());
// kDebug(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' [" << widget->className() << "] has changed";
changed = true;
}
if (item->isImmutable()) {
widget->setEnabled(false);
QWidget *buddy = d->buddyWidget.value(it.key(), 0);
if (buddy) {
buddy->setEnabled(false);
}
}
}
blockSignals(bSignalsBlocked);
if (changed)
QTimer::singleShot(0, this, SIGNAL(widgetModified()));
if (changed) {
QTimer::singleShot(0, this, SIGNAL(widgetModified()));
}
}
void KConfigDialogManager::updateWidgetsDefault()
{
bool bUseDefaults = d->m_conf->useDefaults(true);
updateWidgets();
d->m_conf->useDefaults(bUseDefaults);
bool bUseDefaults = d->m_conf->useDefaults(true);
updateWidgets();
d->m_conf->useDefaults(bUseDefaults);
}
void KConfigDialogManager::updateSettings()
@ -401,7 +395,7 @@ void KConfigDialogManager::updateSettings()
bool changed = false;
QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget );
QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) {
it.next();
widget = it.value();
@ -413,13 +407,12 @@ void KConfigDialogManager::updateSettings()
}
QVariant fromWidget = property(widget);
if(!item->isEqual( fromWidget )) {
if(!item->isEqual(fromWidget)) {
item->setProperty( fromWidget );
changed = true;
}
}
if (changed)
{
if (changed) {
d->m_conf->writeConfig();
emit settingsChanged();
}
@ -441,15 +434,6 @@ QByteArray KConfigDialogManager::getCustomProperty(const QWidget *widget) const
void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
{
/* QButtonGroup *bg = qobject_cast<QButtonGroup *>(w);
if (bg)
{
QAbstractButton *b = bg->button(v.toInt());
if (b)
b->setDown(true);
return;
}*/
QByteArray customproperty = getCustomProperty(w);
if (customproperty.isEmpty()) {
customproperty = s_propertyMap->value(w->metaObject()->className());
@ -480,10 +464,6 @@ void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
QVariant KConfigDialogManager::property(QWidget *w) const
{
/* QButtonGroup *bg = qobject_cast<QButtonGroup *>(w);
if (bg && bg->checkedButton())
return QVariant(bg->id(bg->checkedButton()));*/
QByteArray customproperty = getCustomProperty(w);
if (customproperty.isEmpty()) {
customproperty = s_propertyMap->value(w->metaObject()->className());
@ -509,7 +489,7 @@ QVariant KConfigDialogManager::property(QWidget *w) const
bool KConfigDialogManager::hasChanged() const
{
QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget) ;
QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) {
it.next();
widget = it.value();
@ -520,7 +500,7 @@ bool KConfigDialogManager::hasChanged() const
continue;
}
if(!item->isEqual( property(widget) )) {
if(!item->isEqual( property(widget))) {
// kDebug(s_kconfigdialogmanagerarea) << "Widget for '" << it.key() << "' has changed.";
return true;
}
@ -530,10 +510,10 @@ bool KConfigDialogManager::hasChanged() const
bool KConfigDialogManager::isDefault() const
{
bool bUseDefaults = d->m_conf->useDefaults(true);
bool result = !hasChanged();
d->m_conf->useDefaults(bUseDefaults);
return result;
bool bUseDefaults = d->m_conf->useDefaults(true);
bool result = !hasChanged();
d->m_conf->useDefaults(bUseDefaults);
return result;
}
#include "moc_kconfigdialogmanager.cpp"

View file

@ -82,132 +82,129 @@ class KConfigSkeletonItem;
* @author Benjamin C Meyer <ben+kdelibs at meyerhome dot net>
* @author Waldo Bastian <bastian@kde.org>
*/
class KDEUI_EXPORT KConfigDialogManager : public QObject {
Q_OBJECT
class KDEUI_EXPORT KConfigDialogManager : public QObject
{
Q_OBJECT
Q_SIGNALS:
/**
* 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.
*/
void settingsChanged();
/**
* 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.
*/
void settingsChanged();
/**
* TODO: Verify
* One or more of the settings have been changed.
* @param widget - The widget group (pass in via addWidget()) that
* contains the one or more modified setting.
* @see settingsChanged()
*/
void settingsChanged( QWidget *widget );
/**
* 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.
*/
void widgetModified();
/**
* TODO: Verify
* One or more of the settings have been changed.
* @param widget - The widget group (pass in via addWidget()) that
* contains the one or more modified setting.
* @see settingsChanged()
*/
void settingsChanged(QWidget *widget);
/**
* 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.
*/
void widgetModified();
public:
/**
* Constructor.
* @param parent Dialog widget to manage
* @param conf Object that contains settings
*/
KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf);
/**
* Constructor.
* @param parent Dialog widget to manage
* @param conf Object that contains settings
*/
KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf);
/**
* Constructor.
* @param parent Dialog widget to manage
* @param conf Object that contains settings
*/
KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf);
/**
* Constructor.
* @param parent Dialog widget to manage
* @param conf Object that contains settings
*/
KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf);
/**
* Destructor.
*/
~KConfigDialogManager();
/**
* Destructor.
*/
~KConfigDialogManager();
/**
* Add additional widgets to manage
* @param widget Additional widget to manage, inlcuding all its children
*/
void addWidget(QWidget *widget);
/**
* Add additional widgets to manage
* @param widget Additional widget to manage, inlcuding all its children
*/
void addWidget(QWidget *widget);
/**
* Returns whether the current state of the known widgets are
* different from the state in the config object.
*/
bool hasChanged() const;
/**
* Returns whether the current state of the known widgets are
* different from the state in the config object.
*/
bool hasChanged() const;
/**
* Returns whether the current state of the known widgets are
* the same as the default state in the config object.
*/
bool isDefault() const;
/**
* Returns whether the current state of the known widgets are
* the same as the default state in the config object.
*/
bool isDefault() const;
/**
* Retrieve the property map
*/
static QHash<QString, QByteArray> *propertyMap();
/**
* Retrieve the property map
*/
static QHash<QString, QByteArray>* propertyMap();
/**
* Retrieve the widget change map
*/
static QHash<QString, QByteArray> *changedMap();
static QHash<QString, QByteArray>* changedMap();
public Q_SLOTS:
/**
* 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.
*/
void updateSettings();
/**
* 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.
*/
void updateSettings();
/**
* 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.
*/
void updateWidgets();
/**
* 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.
*/
void updateWidgets();
/**
* 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.
*/
void updateWidgetsDefault();
/**
* 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.
*/
void updateWidgetsDefault();
protected:
/**
* @param trackChanges - If any changes by the widgets should be tracked
* set true. This causes the emitting the modified() signal when
* something changes.
* TODO: @return bool - True if any setting was changed from the default.
*/
void init(bool trackChanges);
/**
* @param trackChanges - If any changes by the widgets should be tracked
* set true. This causes the emitting the modified() signal when
* something changes.
* TODO: @return bool - True if any setting was changed from the default.
*/
void init(bool trackChanges);
/**
* 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.
* @param widget - Parent of the children to look at.
* @param trackChanges - If true then tracks any changes to the children of
* widget that are known.
* @return bool - If a widget was set to something other than its default.
*/
/**
* 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.
* @param widget - Parent of the children to look at.
* @param trackChanges - If true then tracks any changes to the children of
* widget that are known.
* @return bool - If a widget was set to something other than its default.
*/
bool parseChildren(const QWidget *widget, bool trackChanges);
/**
@ -217,36 +214,36 @@ protected:
*/
QByteArray getCustomProperty(const QWidget *widget) const;
/**
* Set a property
*/
void setProperty(QWidget *w, const QVariant &v);
/**
* Set a property
*/
void setProperty(QWidget *w, const QVariant &v);
/**
* Retrieve a property
*/
QVariant property(QWidget *w) const;
/**
* Retrieve a property
*/
QVariant property(QWidget *w) const;
/**
* Setup secondary widget properties
*/
void setupWidget(QWidget *widget, KConfigSkeletonItem *item);
/**
* Setup secondary widget properties
*/
void setupWidget(QWidget *widget, KConfigSkeletonItem *item);
/**
* Initializes the property maps
*/
static void initMaps();
/**
* Initializes the property maps
*/
static void initMaps();
private:
class Private;
friend class Private;
class Private;
friend class Private;
/**
* KConfigDialogManager Private class.
*/
Private *const d;
Q_DISABLE_COPY(KConfigDialogManager)
/**
* KConfigDialogManager Private class.
*/
Private *const d;
Q_DISABLE_COPY(KConfigDialogManager)
};
#endif // KCONFIGDIALOGMANAGER_H