+
+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
+ key.prepend(settingsKey() + '/');
+ return key;
+}
+
+
+void SettingsPage::autoWidgetHasChanged()
+{
+ bool changed_ = false;
+ foreach(QObject *widget, _autoWidgets) {
+ QVariant curValue = widget->property(autoWidgetPropertyName(widget));
+ if (!curValue.isValid())
+ qWarning() << "SettingsPage::autoWidgetHasChanged(): Unknown property";
+
+ if (curValue != widget->property("storedValue")) {
+ changed_ = true;
+ break;
+ }
+ }
+
+ if (changed_ != _autoWidgetsChanged) {
+ bool old = hasChanged();
+ _autoWidgetsChanged = changed_;
+ if (hasChanged() != old)
+ emit changed(hasChanged());
+ }
+}
+
+
+void SettingsPage::load()
+{
+ UiSettings s("");
+ foreach(QObject *widget, _autoWidgets) {
+ 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);
+ }
+ bool old = hasChanged();
+ _autoWidgetsChanged = _changed = false;
+ if (hasChanged() != old)
+ emit changed(hasChanged());
+}
+
+
+void SettingsPage::save()
+{
+ UiSettings s("");
+ foreach(QObject *widget, _autoWidgets) {
+ QString key = autoWidgetSettingsKey(widget);
+ QVariant val = widget->property(autoWidgetPropertyName(widget));
+ widget->setProperty("storedValue", val);
+ if (key.isEmpty())
+ saveAutoWidgetValue(widget->objectName(), val);
+ else
+ s.setValue(key, val);
+ }
+ bool old = hasChanged();
+ _autoWidgetsChanged = _changed = false;
+ if (hasChanged() != old)
+ emit changed(hasChanged());
+}
+
+
+void SettingsPage::defaults()
+{
+ foreach(QObject *widget, _autoWidgets) {
+ QVariant val = widget->property("defaultValue");
+ widget->setProperty(autoWidgetPropertyName(widget), val);
+ }
+ 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;
+}