summaryrefslogtreecommitdiffstats
path: root/commands/command_divelist.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-17 17:41:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-19 21:13:40 -0800
commit6d6d10f03a92a9bac5394fc226c398af61f29d66 (patch)
tree55cc04e1ddfc0174973f6ad7e496aa80e07523f9 /commands/command_divelist.cpp
parent2d09819ddfc6bbb4eb9bd7127485f42c839fd85b (diff)
downloadsubsurface-6d6d10f03a92a9bac5394fc226c398af61f29d66.tar.gz
Filter: move calculation of shown dives to undo command
The filter-model was catching dives-added / dives-deleted signals from the models to keep track of the number of shown dives. To simplify the data flow, do this directly in the undo-command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_divelist.cpp')
-rw-r--r--commands/command_divelist.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp
index 4b4ef4ab8..9943651eb 100644
--- a/commands/command_divelist.cpp
+++ b/commands/command_divelist.cpp
@@ -40,6 +40,9 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<OwningTripPtr> &t
if (idx < 0)
qWarning("Deletion of unknown dive!");
+ if (!d->hidden_by_filter)
+ --shown_dives;
+
res.dive.reset(unregister_dive(idx)); // Remove dive from backend
return res;
@@ -67,6 +70,8 @@ dive *DiveListBase::addDive(DiveToAdd &d)
// Set the filter flag according to current filter settings
bool show = MultiFilterSortModel::instance()->showDive(res);
res->hidden_by_filter = !show;
+ if (show)
+ ++shown_dives;
int idx = dive_table_get_insertion_index(&dive_table, res);
add_to_dive_table(&dive_table, idx, res); // Return ownership to backend
@@ -118,6 +123,9 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
divesToAdd.reserve(divesAndSitesToDelete.dives.size());
sitesToAdd.reserve(divesAndSitesToDelete.sites.size());
+ // Remember old number of shown dives
+ int oldShown = shown_dives;
+
// Make sure that the dive list is sorted. The added dives will be sent in a signal
// and the recipients assume that the dives are sorted the same way as they are
// in the core list.
@@ -149,6 +157,10 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
{ return ptr.get() == trip; }) != tripsToAdd.end();
emit diveListNotifier.divesDeleted(trip, deleteTrip, divesInTrip);
});
+
+ if (oldShown != shown_dives)
+ emit diveListNotifier.numShownChanged();
+
return { std::move(divesToAdd), std::move(tripsToAdd), std::move(sitesToAdd) };
}
@@ -172,6 +184,9 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
[](const DiveToAdd &d, const DiveToAdd &d2)
{ return dive_less_than(d.dive.get(), d2.dive.get()); });
+ // Remember old number of shown dives
+ int oldShown = shown_dives;
+
// Now, add the dives
// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
// that is closer to classical C-style.
@@ -207,6 +222,10 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
// Finally, emit the signal
emit diveListNotifier.divesAdded(trip, createTrip, divesInTrip);
});
+
+ if (oldShown != shown_dives)
+ emit diveListNotifier.numShownChanged();
+
return { res, sites };
}