diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-12-28 14:25:47 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-02 15:38:15 +0100 |
| commit | 9db6a9d7931edbb08e74cd1e110794f47d46df3e (patch) | |
| tree | e060bb6ed23a12796ed5c883661aad2501cb56e4 /src/settings.cpp | |
| parent | 4636d7bd5d092ff47146248232cd73c8d0254d7a (diff) | |
Save collapse state of separator.
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index f5ad83a7..04cfafc9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1063,6 +1063,41 @@ WidgetSettings::WidgetSettings(QSettings& s, bool globalInstance) } } +std::vector<QModelIndex> WidgetSettings::allIndex(const QAbstractItemModel* model, int column, const QModelIndex& parent) const +{ + std::vector<QModelIndex> index; + for (std::size_t i = 0; i < model->rowCount(parent); ++i) { + index.push_back(model->index(i, column, parent)); + + auto cindex = allIndex(model, column, index.back()); + index.insert(index.end(), cindex.begin(), cindex.end()); + } + return index; +} + +void WidgetSettings::saveTreeState(const QTreeView* tv, int role) +{ + QVariantList expanded; + for (auto index : allIndex(tv->model())) { + if (tv->isExpanded(index)) { + expanded.append(index.data(role)); + } + } + set(m_Settings, "Widgets", indexSettingName(tv), expanded); +} + +void WidgetSettings::restoreTreeState(QTreeView* tv, int role) const +{ + if (auto expanded = getOptional<QVariantList>(m_Settings, "Widgets", indexSettingName(tv))) { + tv->collapseAll(); + for (auto index : allIndex(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)); |
