summary refs log tree commit diff
path: root/src/timeline/CommunitiesModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline/CommunitiesModel.cpp')
-rw-r--r--src/timeline/CommunitiesModel.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp

index fb8aac24..3c28463e 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp
@@ -40,6 +40,7 @@ CommunitiesModel::setData(const QModelIndex &index, const QVariant &value, int r const auto cindex = spaceOrder_.lastChild(index.row() - 2); emit dataChanged(index, this->index(cindex + 2), {Collapsed, Qt::DisplayRole}); + spaceOrder_.storeCollapsed(); return true; } else return false; @@ -276,6 +277,7 @@ CommunitiesModel::initializeSidebar() tags_.push_back(QString::fromStdString(t)); hiddentTagIds_ = UserSettings::instance()->hiddenTags(); + spaceOrder_.restoreCollapsed(); endResetModel(); emit tagsChanged(); @@ -284,6 +286,55 @@ CommunitiesModel::initializeSidebar() } void +CommunitiesModel::FlatTree::storeCollapsed() +{ + QList<QStringList> elements; + + int depth = -1; + + QStringList current; + + for (const auto &e : tree) { + if (e.depth > depth) { + current.push_back(e.name); + } else if (e.depth == depth) { + current.back() = e.name; + } else { + current.pop_back(); + current.back() = e.name; + } + + if (e.collapsed) + elements.push_back(current); + } + + UserSettings::instance()->setCollapsedSpaces(elements); +} +void +CommunitiesModel::FlatTree::restoreCollapsed() +{ + QList<QStringList> elements = UserSettings::instance()->collapsedSpaces(); + + int depth = -1; + + QStringList current; + + for (auto &e : tree) { + if (e.depth > depth) { + current.push_back(e.name); + } else if (e.depth == depth) { + current.back() = e.name; + } else { + current.pop_back(); + current.back() = e.name; + } + + if (elements.contains(current)) + e.collapsed = true; + } +} + +void CommunitiesModel::clear() { beginResetModel();