| 89 | } |
| 90 | |
| 91 | QSet<QString> MainWindow::saveExpandedState() const { |
| 92 | QSet<QString> expanded; |
| 93 | std::function<void(const QModelIndex &, int)> walk = |
| 94 | [&](const QModelIndex &parent, int depth) { |
| 95 | for (int i = 0; i < m_model->rowCount(parent); ++i) { |
| 96 | QModelIndex idx = m_model->index(i, 0, parent); |
| 97 | if (m_tree->isExpanded(idx)) { |
| 98 | expanded.insert( |
| 99 | QString::number(depth) + ':' |
| 100 | + m_model->data(idx, Qt::DisplayRole).toString()); |
| 101 | walk(idx, depth + 1); |
| 102 | } |
| 103 | } |
| 104 | }; |
| 105 | walk(m_tree->rootIndex(), 0); |
| 106 | return expanded; |
| 107 | } |
| 108 | |
| 109 | void MainWindow::restoreExpandedState(const QSet<QString> &expanded) { |
| 110 | std::function<void(const QModelIndex &, int)> walk = |