X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fsettingspage.cpp;h=0476f9678cfad9d16ea9b6c64ed728eb6a066857;hb=0edcf393c9aaab06f7db904bea1da0b7352f1ed7;hp=577f1683f14901a3927f844709b0eae27b2c616d;hpb=553fb640622542592d353ba2af06d5baef6a5915;p=quassel.git diff --git a/src/uisupport/settingspage.cpp b/src/uisupport/settingspage.cpp index 577f1683..0476f967 100644 --- a/src/uisupport/settingspage.cpp +++ b/src/uisupport/settingspage.cpp @@ -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,9 +78,6 @@ 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); @@ -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); } @@ -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; +} +