summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/divelist.c19
-rw-r--r--core/divelist.h2
-rw-r--r--qt-models/divetripmodel.cpp1
-rw-r--r--qt-models/filtermodels.cpp16
4 files changed, 18 insertions, 20 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 4367b8708..6405dfd51 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -900,13 +900,19 @@ void deselect_dive(struct dive *dive)
}
int shown_dives = 0;
-void filter_dive(struct dive *d, bool shown)
+bool filter_dive(struct dive *d, bool shown)
{
+ bool old_shown, changed;
if (!d)
- return;
+ return false;
+ old_shown = !d->hidden_by_filter;
d->hidden_by_filter = !shown;
if (!shown && d->selected)
deselect_dive(d);
+ changed = old_shown != shown;
+ if (changed)
+ shown_dives += shown - old_shown;
+ return changed;
}
void mark_divelist_changed(bool changed)
@@ -927,9 +933,13 @@ void process_loaded_dives()
int i;
struct dive *dive;
- /* Register dive computer nick names */
- for_each_dive(i, dive)
+ /* Register dive computer nick names and count shown dives. */
+ shown_dives = 0;
+ for_each_dive(i, dive) {
+ if (!dive->hidden_by_filter)
+ shown_dives++;
set_dc_nickname(dive);
+ }
sort_dive_table(&dive_table);
sort_trip_table(&trip_table);
@@ -1448,6 +1458,7 @@ void clear_dive_file_data()
while (dive_table.nr)
delete_single_dive(0);
current_dive = NULL;
+ shown_dives = 0;
while (dive_site_table.nr)
delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table);
if (trip_table.nr != 0) {
diff --git a/core/divelist.h b/core/divelist.h
index c0f70ccb6..efab389ee 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -44,7 +44,7 @@ extern int remove_dive(const struct dive *dive, struct dive_table *table);
extern bool consecutive_selected();
extern void select_dive(struct dive *dive);
extern void deselect_dive(struct dive *dive);
-extern void filter_dive(struct dive *d, bool shown);
+extern bool filter_dive(struct dive *d, bool shown); /* returns true if status changed */
extern struct dive *first_selected_dive();
extern struct dive *last_selected_dive();
extern int get_dive_nr_at_idx(int idx);
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 7f9ca9e32..7ee09d2a7 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -1377,7 +1377,6 @@ void DiveTripModelList::filterFinished()
// In list mode, we don't have to change anything after filter finished.
}
-
// Simple sorting helper for sorting against a criterium and if
// that is undefined against a different criterium.
// Return true if diff1 < 0, false if diff1 > 0.
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index b04fce127..53b9e2e45 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -57,8 +57,6 @@ void MultiFilterSortModel::myInvalidate()
// as a consequence of the filterFinished signal right after the local scope.
auto marker = diveListNotifier.enterCommand();
- shown_dives = 0;
-
DiveFilter *filter = DiveFilter::instance();
for (int i = 0; i < m->rowCount(QModelIndex()); ++i) {
QModelIndex idx = m->index(i, 0, QModelIndex());
@@ -75,18 +73,14 @@ void MultiFilterSortModel::myInvalidate()
continue;
}
bool show = filter->showDive(d);
- if (show) {
- shown_dives++;
+ if (show)
showTrip = true;
- }
m->setData(idx2, show, DiveTripModelBase::SHOWN_ROLE);
}
m->setData(idx, showTrip, DiveTripModelBase::SHOWN_ROLE);
} else {
dive *d = m->data(idx, DiveTripModelBase::DIVE_ROLE).value<dive *>();
bool show = (d != NULL) && filter->showDive(d);
- if (show)
- shown_dives++;
m->setData(idx, show, DiveTripModelBase::SHOWN_ROLE);
}
}
@@ -103,14 +97,8 @@ void MultiFilterSortModel::myInvalidate()
bool MultiFilterSortModel::updateDive(struct dive *d)
{
- bool oldStatus = !d->hidden_by_filter;
bool newStatus = DiveFilter::instance()->showDive(d);
- bool changed = oldStatus != newStatus;
- if (changed) {
- filter_dive(d, newStatus);
- shown_dives += newStatus - oldStatus;
- }
- return changed;
+ return filter_dive(d, newStatus);
}
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const