GUI: fix withSelectedIndexes not to skip rows in hierarchies

This commit is contained in:
Moritz Bunkus 2014-09-20 21:16:08 +02:00
parent c5c8dd5671
commit f911c28809
2 changed files with 14 additions and 6 deletions

View File

@ -62,14 +62,20 @@ resizeViewColumnsToContents(QTreeView *view) {
void
withSelectedIndexes(QAbstractItemView *view,
std::function<void(QModelIndex const &)> worker) {
auto rowsSeen = QSet<int>{};
for (auto const &range : view->selectionModel()->selection())
withSelectedIndexes(view->selectionModel(), worker);
}
void
withSelectedIndexes(QItemSelectionModel *selectionModel,
std::function<void(QModelIndex const &)> worker) {
auto rowsSeen = QMap< std::pair<QModelIndex, int>, bool >{};
for (auto const &range : selectionModel->selection())
for (auto const &index : range.indexes()) {
auto row = index.row();
if (rowsSeen.contains(row))
auto seenIdx = std::make_pair(index.parent(), index.row());
if (rowsSeen[seenIdx])
continue;
rowsSeen << row;
worker(index.sibling(row, 0));
rowsSeen[seenIdx] = true;
worker(index.sibling(index.row(), 0));
}
}

View File

@ -10,6 +10,7 @@ class QAbstractItemView;
class QComboBox;
class QDateTime;
class QIcon;
class QItemSelectionModel;
class QModelIndex;
class QTreeView;
class QString;
@ -40,6 +41,7 @@ enum MtxGuiRoles {
};
void resizeViewColumnsToContents(QTreeView *view);
void withSelectedIndexes(QItemSelectionModel *selectionModel, std::function<void(QModelIndex const &)> worker);
void withSelectedIndexes(QAbstractItemView *view, std::function<void(QModelIndex const &)> worker);
// String stuff