From 9db6a9d7931edbb08e74cd1e110794f47d46df3e Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Mon, 28 Dec 2020 14:25:47 +0100 Subject: Save collapse state of separator. --- src/settings.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/settings.cpp') 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 WidgetSettings::allIndex(const QAbstractItemModel* model, int column, const QModelIndex& parent) const +{ + std::vector 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(m_Settings, "Widgets", indexSettingName(tv))) { + tv->collapseAll(); + for (auto index : allIndex(tv->model())) { + if (expanded->contains(index.data(role))) { + tv->expand(index); + } + } + } +} + std::optional WidgetSettings::index(const QComboBox* cb) const { return getOptional(m_Settings, "Widgets", indexSettingName(cb)); -- cgit v1.3.1