mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Deselect dives that are no longer shown as the dive list is filtered
This cleans up the way we ensure that all dives are handled as the dive list is filtered. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
71b6de0523
commit
0b31854031
4 changed files with 22 additions and 8 deletions
10
divelist.c
10
divelist.c
|
@ -873,6 +873,16 @@ void select_dives_in_trip(struct dive_trip *trip)
|
||||||
select_dive(get_divenr(dive));
|
select_dive(get_divenr(dive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void filter_dive(struct dive *d, bool shown)
|
||||||
|
{
|
||||||
|
if (!d)
|
||||||
|
return;
|
||||||
|
d->hidden_by_filter = !shown;
|
||||||
|
if (!shown && d->selected)
|
||||||
|
deselect_dive(get_divenr(d));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This only gets called with non-NULL trips.
|
/* This only gets called with non-NULL trips.
|
||||||
* It does not combine notes or location, just picks the first one
|
* It does not combine notes or location, just picks the first one
|
||||||
* (or the second one if the first one is empty */
|
* (or the second one if the first one is empty */
|
||||||
|
|
|
@ -32,6 +32,7 @@ extern void select_dive(int idx);
|
||||||
extern void deselect_dive(int idx);
|
extern void deselect_dive(int idx);
|
||||||
extern void select_dives_in_trip(struct dive_trip *trip);
|
extern void select_dives_in_trip(struct dive_trip *trip);
|
||||||
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
||||||
|
extern void filter_dive(struct dive *d, bool shown);
|
||||||
extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
||||||
extern void find_new_trip_start_time(dive_trip_t *trip);
|
extern void find_new_trip_start_time(dive_trip_t *trip);
|
||||||
extern struct dive *first_selected_dive();
|
extern struct dive *first_selected_dive();
|
||||||
|
|
|
@ -314,6 +314,8 @@ 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;
|
int firstInList, newSelection;
|
||||||
|
struct dive *d;
|
||||||
|
|
||||||
if (!newDiveSelection.count())
|
if (!newDiveSelection.count())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -335,7 +337,8 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
||||||
newSelection = dive_table.nr - 1;
|
newSelection = dive_table.nr - 1;
|
||||||
if (newSelection == firstInList)
|
if (newSelection == firstInList)
|
||||||
break;
|
break;
|
||||||
selectDive(newSelection);
|
if ((d = get_dive(newSelection)) != NULL && !d->hidden_by_filter)
|
||||||
|
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);
|
||||||
|
|
|
@ -2366,7 +2366,9 @@ bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent,
|
||||||
QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
|
QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
|
||||||
struct dive *d = (struct dive *)diveVariant.value<void *>();
|
struct dive *d = (struct dive *)diveVariant.value<void *>();
|
||||||
|
|
||||||
return doFilter(d, index0, sourceModel);
|
bool show = doFilter(d, index0, sourceModel);
|
||||||
|
filter_dive(d, show);
|
||||||
|
return show;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuddyFilterModel::BuddyFilterModel(QObject *parent) : QStringListModel(parent)
|
BuddyFilterModel::BuddyFilterModel(QObject *parent) : QStringListModel(parent)
|
||||||
|
@ -2628,11 +2630,7 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
|
||||||
shouldShow = false;
|
shouldShow = false;
|
||||||
}
|
}
|
||||||
// if it's a dive, mark it accordingly
|
// if it's a dive, mark it accordingly
|
||||||
if (d) {
|
filter_dive(d, shouldShow);
|
||||||
if (d->selected)
|
|
||||||
d->selected = shouldShow;
|
|
||||||
d->hidden_by_filter = !shouldShow;
|
|
||||||
}
|
|
||||||
return shouldShow;
|
return shouldShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2656,10 +2654,12 @@ void MultiFilterSortModel::myInvalidate()
|
||||||
} else {
|
} else {
|
||||||
// otherwise find the dives that should still be selected (the filter above unselected any
|
// otherwise find the dives that should still be selected (the filter above unselected any
|
||||||
// dive that's no longer visible) and select them again
|
// dive that's no longer visible) and select them again
|
||||||
|
QList<int>curSelectedDives;
|
||||||
for_each_dive (i, d) {
|
for_each_dive (i, d) {
|
||||||
if(d->selected)
|
if(d->selected)
|
||||||
dlv->selectDive(get_idx_by_uniq_id(d->id));
|
curSelectedDives.append(get_divenr(d));
|
||||||
}
|
}
|
||||||
|
dlv->selectDives(curSelectedDives);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue