diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2021-01-10 10:25:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-10 10:25:37 +0100 |
| commit | 80e44a9e3ade61695b4807a3a900d2866138ecac (patch) | |
| tree | 1ef9904664d8d34dba6692bbf5325aea8c199d08 /src/settings.cpp | |
| parent | eaec140f7c823012c09536175d8917dddcacdb7c (diff) | |
| parent | 4a0ce804ea486744e5f6140a0ce4538d99e21ce3 (diff) | |
Merge pull request #1338 from Holt59/collapsible-separators
Collapsible separators (and refactoring).
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index f5ad83a7..e04cd0c1 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -24,12 +24,14 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "instancemanager.h" #include "shared/appconfig.h" #include "env.h" +#include "modelutils.h" #include "envmetrics.h" #include <expanderwidget.h> #include <utility.h> #include <iplugingame.h> using namespace MOBase; +using namespace MOShared; EndorsementState endorsementStateFromString(const QString& s) @@ -1063,6 +1065,52 @@ WidgetSettings::WidgetSettings(QSettings& s, bool globalInstance) } } +void WidgetSettings::saveTreeCheckState(const QTreeView* tv, int role) +{ + QVariantList data; + for (auto index : flatIndex(tv->model())) { + data.append(index.data(role)); + } + set(m_Settings, "Widgets", indexSettingName(tv), data); +} + +void WidgetSettings::restoreTreeCheckState(QTreeView* tv, int role) const +{ + if (auto states = getOptional<QVariantList>(m_Settings, "Widgets", indexSettingName(tv))) { + auto allIndex = flatIndex(tv->model()); + MOBase::log::debug("restoreTreeCheckState: {}, {}", states->size(), allIndex.size()); + if (states->size() != allIndex.size()) { + return; + } + for (int i = 0; i < states->size(); ++i) { + tv->model()->setData(allIndex[i], states->at(i), role); + } + } +} + +void WidgetSettings::saveTreeExpandState(const QTreeView* tv, int role) +{ + QVariantList expanded; + for (auto index : flatIndex(tv->model())) { + if (tv->isExpanded(index)) { + expanded.append(index.data(role)); + } + } + set(m_Settings, "Widgets", indexSettingName(tv), expanded); +} + +void WidgetSettings::restoreTreeExpandState(QTreeView* tv, int role) const +{ + if (auto expanded = getOptional<QVariantList>(m_Settings, "Widgets", indexSettingName(tv))) { + tv->collapseAll(); + for (auto index : flatIndex(tv->model())) { + if (expanded->contains(index.data(role))) { + tv->expand(index); + } + } + } +} + std::optional<int> WidgetSettings::index(const QComboBox* cb) const { return getOptional<int>(m_Settings, "Widgets", indexSettingName(cb)); @@ -2127,6 +2175,26 @@ void InterfaceSettings::setStyleName(const QString& name) set(m_Settings, "Settings", "style", name); } +bool InterfaceSettings::collapsibleSeparators() const +{ + return get<bool>(m_Settings, "Settings", "collapsible_separators", true); +} + +void InterfaceSettings::setCollapsibleSeparators(bool b) +{ + set(m_Settings, "Settings", "collapsible_separators", b); +} + +bool InterfaceSettings::collapsibleSeparatorsConflicts() const +{ + return get<bool>(m_Settings, "Settings", "collapsible_separators_conflicts", true); +} + +void InterfaceSettings::setCollapsibleSeparatorsConflicts(bool b) +{ + set(m_Settings, "Settings", "collapsible_separators_conflicts", b); +} + bool InterfaceSettings::compactDownloads() const { return get<bool>(m_Settings, "Settings", "compact_downloads", false); |
