mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
Be more careful when restoring a selection in the presence of filters
Try really hard to ensure there remains a valid selection. Only if none of the dives are selectable should we give up. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7cb307cf73
commit
02567ec790
1 changed files with 13 additions and 0 deletions
|
@ -313,6 +313,7 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
|
||||||
|
|
||||||
void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
||||||
{
|
{
|
||||||
|
int firstInList, newSelection;
|
||||||
if (!newDiveSelection.count())
|
if (!newDiveSelection.count())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -321,9 +322,21 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
||||||
// becomes the selected_dive that we scroll to
|
// becomes the selected_dive that we scroll to
|
||||||
QList<int> sortedSelection = newDiveSelection;
|
QList<int> sortedSelection = newDiveSelection;
|
||||||
qSort(sortedSelection.begin(), sortedSelection.end());
|
qSort(sortedSelection.begin(), sortedSelection.end());
|
||||||
|
newSelection = firstInList = sortedSelection.first();
|
||||||
|
|
||||||
while (!sortedSelection.isEmpty())
|
while (!sortedSelection.isEmpty())
|
||||||
selectDive(sortedSelection.takeLast());
|
selectDive(sortedSelection.takeLast());
|
||||||
|
|
||||||
|
while (selected_dive == -1) {
|
||||||
|
// that can happen if we restored a selection after edit
|
||||||
|
// and the only selected dive is no longer visible because of a filter
|
||||||
|
newSelection--;
|
||||||
|
if (newSelection < 0)
|
||||||
|
newSelection = dive_table.nr - 1;
|
||||||
|
if (newSelection == firstInList)
|
||||||
|
break;
|
||||||
|
selectDive(newSelection);
|
||||||
|
}
|
||||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||||
QModelIndexList idxList = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive);
|
QModelIndexList idxList = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive);
|
||||||
if (!idxList.isEmpty()) {
|
if (!idxList.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue