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 | |
| parent | 4636d7bd5d092ff47146248232cd73c8d0254d7a (diff) | |
Save collapse state of separator.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 2 | ||||
| -rw-r--r-- | src/settings.cpp | 35 | ||||
| -rw-r--r-- | src/settings.h | 6 | ||||
| -rw-r--r-- | src/settingsutilities.h | 8 |
4 files changed, 51 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index df571a2d..65ab368d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2103,6 +2103,7 @@ void MainWindow::readSettings() s.widgets().restoreIndex(ui->groupCombo); s.widgets().restoreIndex(ui->tabWidget); + s.widgets().restoreTreeState(ui->modList); m_Filters->restoreState(s); @@ -2177,6 +2178,7 @@ void MainWindow::storeSettings() s.geometry().saveState(ui->downloadView->header()); s.geometry().saveState(ui->modList->header()); + s.widgets().saveTreeState(ui->modList); s.widgets().saveIndex(ui->groupCombo); s.widgets().saveIndex(ui->executablesListBox); s.widgets().saveIndex(ui->tabWidget); 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)); diff --git a/src/settings.h b/src/settings.h index 4d1258bf..3f60fc7b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -202,6 +202,12 @@ public: // WidgetSettings(QSettings& s, bool globalInstance); + // tree state - this saves the list of expanded items based on the given role + // + std::vector<QModelIndex> allIndex(const QAbstractItemModel* model, int column = 0, const QModelIndex& parent = QModelIndex()) const; + void saveTreeState(const QTreeView* tv, int role = Qt::DisplayRole); + void restoreTreeState(QTreeView* tv, int role = Qt::DisplayRole) const; + // selected index for a combobox // std::optional<int> index(const QComboBox* cb) const; diff --git a/src/settingsutilities.h b/src/settingsutilities.h index ac6aeb29..53eeff87 100644 --- a/src/settingsutilities.h +++ b/src/settingsutilities.h @@ -25,6 +25,14 @@ struct ValueConverter<T, std::enable_if_t<std::is_enum_v<T>>> } }; +template <> +struct ValueConverter<QVariantList> +{ + static QString convert(const QVariantList& t) + { + return QString("%1").arg(QVariant(t).toStringList().join(",")); + } +}; bool shouldLogSetting(const QString& displayName); |
