From 0f712305c840bc509fa8f00eebf2a2a4bbf28bfd Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 24 Aug 2019 13:04:10 -0400 Subject: added settings for QTabWidget, checkable QAbstractButton and ExpanderWidget removed directInterface() from mod info conflicts --- src/settings.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'src/settings.cpp') diff --git a/src/settings.cpp b/src/settings.cpp index 9001ac65..844ee81e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see . #include "serverinfo.h" #include "executableslist.h" #include "appconfig.h" +#include "expanderwidget.h" #include #include #include @@ -107,6 +108,11 @@ QString widgetName(const QHeaderView* w) return widgetNameWithTopLevel(w->parentWidget()); } +QString widgetName(const ExpanderWidget* w) +{ + return widgetNameWithTopLevel(w->button()); +} + QString widgetName(const QWidget* w) { return widgetNameWithTopLevel(w); @@ -140,6 +146,19 @@ QString indexSettingName(const QWidget* widget) return widgetNameWithTopLevel(widget) + "_index"; } +QString checkedSettingName(const QAbstractButton* b) +{ + return widgetNameWithTopLevel(b) + "_checked"; +} + +void warnIfNotCheckable(const QAbstractButton* b) +{ + if (!b->isCheckable()) { + log::warn( + "button '{}' used in the settings as a checkbox or radio button " + "but is not checkable", b->objectName()); + } +} Settings *Settings::s_Instance = nullptr; @@ -1048,7 +1067,7 @@ void Settings::resetQuestionButtons() m_Settings.endGroup(); } -std::optional Settings::getIndex(QComboBox* cb) const +std::optional Settings::getIndex(const QComboBox* cb) const { return getOptional(m_Settings, indexSettingName(cb)); } @@ -1065,6 +1084,44 @@ void Settings::restoreIndex(QComboBox* cb, std::optional def) const } } +std::optional Settings::getIndex(const QTabWidget* w) const +{ + return getOptional(m_Settings, indexSettingName(w)); +} + +void Settings::saveIndex(const QTabWidget* w) +{ + m_Settings.setValue(indexSettingName(w), w->currentIndex()); +} + +void Settings::restoreIndex(QTabWidget* w, std::optional def) const +{ + if (auto v=getOptional(m_Settings, indexSettingName(w), def)) { + w->setCurrentIndex(*v); + } +} + +std::optional Settings::getChecked(const QAbstractButton* w) const +{ + warnIfNotCheckable(w); + return getOptional(m_Settings, checkedSettingName(w)); +} + +void Settings::saveChecked(const QAbstractButton* w) +{ + warnIfNotCheckable(w); + m_Settings.setValue(checkedSettingName(w), w->isChecked()); +} + +void Settings::restoreChecked(QAbstractButton* w, std::optional def) const +{ + warnIfNotCheckable(w); + + if (auto v=getOptional(m_Settings, checkedSettingName(w), def)) { + w->setChecked(*v); + } +} + GeometrySettings& Settings::geometry() { return m_Geometry; @@ -1184,6 +1241,21 @@ bool GeometrySettings::restoreState(QSplitter* w) const return false; } +void GeometrySettings::saveState(const ExpanderWidget* expander) +{ + m_Settings.setValue(stateSettingName(expander), expander->saveState()); +} + +bool GeometrySettings::restoreState(ExpanderWidget* expander) const +{ + if (auto v=getOptional(m_Settings, stateSettingName(expander))) { + expander->restoreState(*v); + return true; + } + + return false; +} + void GeometrySettings::saveVisibility(const QWidget* w) { m_Settings.setValue(visibilitySettingName(w), w->isVisible()); -- cgit v1.3.1