mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Clean up divelist dive selection
Since we have a "selectDive()" method, let's just use it rather than opencoding it. Similarly for "unselectDives()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4d937051ca
commit
4b405caa2c
1 changed files with 4 additions and 15 deletions
|
@ -91,7 +91,7 @@ void DiveListView::headerClicked(int i)
|
||||||
QItemSelection oldSelection = selectionModel()->selection();
|
QItemSelection oldSelection = selectionModel()->selection();
|
||||||
QList<struct dive*> currentSelectedDives;
|
QList<struct dive*> currentSelectedDives;
|
||||||
DiveTripModel::Layout newLayout;
|
DiveTripModel::Layout newLayout;
|
||||||
bool scrolled = false;
|
bool first = true;
|
||||||
|
|
||||||
newLayout = i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
newLayout = i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ void DiveListView::headerClicked(int i)
|
||||||
currentSelectedDives.push_back(d);
|
currentSelectedDives.push_back(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionModel()->clearSelection();
|
unselectDives();
|
||||||
|
|
||||||
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
|
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
|
||||||
if (currentLayout == newLayout) {
|
if (currentLayout == newLayout) {
|
||||||
|
@ -119,19 +119,8 @@ void DiveListView::headerClicked(int i)
|
||||||
|
|
||||||
// repopulat the selections.
|
// repopulat the selections.
|
||||||
Q_FOREACH(struct dive *d, currentSelectedDives) {
|
Q_FOREACH(struct dive *d, currentSelectedDives) {
|
||||||
QModelIndexList match = m->match(m->index(0,0), TreeItemDT::NR, d->number, 1, Qt::MatchRecursive);
|
selectDive(d, first);
|
||||||
QModelIndex idx = match.first();
|
first = false;
|
||||||
|
|
||||||
if (newLayout == DiveTripModel::TREE) {
|
|
||||||
QModelIndex parent = idx.parent();
|
|
||||||
if (parent.isValid())
|
|
||||||
expand(parent);
|
|
||||||
}
|
|
||||||
selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
|
||||||
if (!scrolled) {
|
|
||||||
scrollTo(idx, PositionAtCenter);
|
|
||||||
scrolled = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue