X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fsettingspage.cpp;h=0476f9678cfad9d16ea9b6c64ed728eb6a066857;hb=342b6d8a5869e438362914f3848e639ac6c70bbc;hp=b91fc64bb30bd16cc88ee5083b14c4dda5efcc4a;hpb=ae6ccecd44b12527894574b878ed32600bedd156;p=quassel.git diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index b91fc64b..0476f967 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -25,8 +25,6 @@ #include #include -#include - #include "uisettings.h" SettingsPage::SettingsPage(const QString &category, const QString &title, QWidget *parent) @@ -53,7 +51,7 @@ void SettingsPage::load(QCheckBox *box, bool checked) { } bool SettingsPage::hasChanged(QCheckBox *box) { - return box->property("StoredValue").toBool() == box->isChecked(); + return box->property("StoredValue").toBool() != box->isChecked(); } @@ -63,7 +61,7 @@ void SettingsPage::load(QComboBox *box, int index) { } bool SettingsPage::hasChanged(QComboBox *box) { - return box->property("StoredValue").toInt() == box->currentIndex(); + return box->property("StoredValue").toInt() != box->currentIndex(); } void SettingsPage::load(QSpinBox *box, int value) { @@ -72,7 +70,7 @@ void SettingsPage::load(QSpinBox *box, int value) { } bool SettingsPage::hasChanged(QSpinBox *box) { - return box->property("StoredValue").toInt() == box->value(); + return box->property("StoredValue").toInt() != box->value(); } /*** Auto child widget handling ***/ @@ -80,15 +78,12 @@ bool SettingsPage::hasChanged(QSpinBox *box) { void SettingsPage::initAutoWidgets() { _autoWidgets.clear(); - if(settingsKey().isNull()) - return; - // find all descendants that should be considered auto widgets // we need to climb the QObject tree recursively findAutoWidgets(this, &_autoWidgets); foreach(QObject *widget, _autoWidgets) { - if(widget->inherits("QAbstractButton")) + if(widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) connect(widget, SIGNAL(toggled(bool)), SLOT(autoWidgetHasChanged())); else if(widget->inherits("QLineEdit") || widget->inherits("QTextEdit")) connect(widget, SIGNAL(textChanged(const QString &)), SLOT(autoWidgetHasChanged())); @@ -103,7 +98,7 @@ void SettingsPage::initAutoWidgets() { void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const { foreach(QObject *child, parent->children()) { - if(!child->property("settingsKey").toString().isEmpty()) + if(child->property("settingsKey").isValid()) autoList->append(child); findAutoWidgets(child, autoList); } @@ -111,7 +106,7 @@ void SettingsPage::findAutoWidgets(QObject *parent, QObjectList *autoList) const QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { QByteArray prop; - if(widget->inherits("QAbstractButton")) + if(widget->inherits("QAbstractButton") || widget->inherits("QGroupBox")) prop = "checked"; else if(widget->inherits("QLineEdit") || widget->inherits("QTextEdit")) prop = "text"; @@ -127,6 +122,8 @@ QByteArray SettingsPage::autoWidgetPropertyName(QObject *widget) const { QString SettingsPage::autoWidgetSettingsKey(QObject *widget) const { QString key = widget->property("settingsKey").toString(); + if(key.isEmpty()) + return QString(""); if(key.startsWith('/')) key.remove(0, 1); else @@ -158,7 +155,14 @@ void SettingsPage::autoWidgetHasChanged() { void SettingsPage::load() { UiSettings s(""); foreach(QObject *widget, _autoWidgets) { - QVariant val = s.value(autoWidgetSettingsKey(widget), widget->property("defaultValue")); + QString key = autoWidgetSettingsKey(widget); + QVariant val; + if(key.isEmpty()) + val = loadAutoWidgetValue(widget->objectName()); + else + val = s.value(key, QVariant()); + if(!val.isValid()) + val = widget->property("defaultValue"); widget->setProperty(autoWidgetPropertyName(widget), val); widget->setProperty("storedValue", val); } @@ -171,9 +175,13 @@ void SettingsPage::load() { void SettingsPage::save() { UiSettings s(""); foreach(QObject *widget, _autoWidgets) { + QString key = autoWidgetSettingsKey(widget); QVariant val = widget->property(autoWidgetPropertyName(widget)); widget->setProperty("storedValue", val); - s.setValue(autoWidgetSettingsKey(widget), val); + if(key.isEmpty()) + saveAutoWidgetValue(widget->objectName(), val); + else + s.setValue(key, val); } bool old = hasChanged(); _autoWidgetsChanged = _changed = false; @@ -188,3 +196,13 @@ void SettingsPage::defaults() { } autoWidgetHasChanged(); } + +QVariant SettingsPage::loadAutoWidgetValue(const QString &widgetName) { + qWarning() << "Could not load value for SettingsPage widget" << widgetName; + return QVariant(); +} + +void SettingsPage::saveAutoWidgetValue(const QString &widgetName, const QVariant &) { + qWarning() << "Could not save value for SettingsPage widget" << widgetName; +} +