mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Undo: update filter flag when dives change
The filter code is strange: it actually only checks the dive->hidden_by_filter flag. Thus, before propagating the dive changed signal, this flag has to be updated. Do this in the DiveTripModel. Ultimately, this should be refactored. Moreover, if the filter-flag changed notify the frontend of a changed trip so that the trip is hidden / unhidden. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e7063b6b08
commit
9afea37e15
4 changed files with 46 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "core/qthelper.h"
|
||||
#include "core/subsurface-string.h"
|
||||
#include "qt-models/divelocationmodel.h"
|
||||
#include "qt-models/filtermodels.h"
|
||||
|
||||
namespace Command {
|
||||
|
||||
|
@ -17,13 +18,16 @@ namespace Command {
|
|||
static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sites)
|
||||
{
|
||||
std::vector<dive_site *> res;
|
||||
std::vector<dive *> changedDives;
|
||||
res.reserve(sites.size());
|
||||
|
||||
for (OwningDiveSitePtr &ds: sites) {
|
||||
// Readd the dives that belonged to this site
|
||||
for (int i = 0; i < ds->dives.nr; ++i) {
|
||||
// TODO: send dive site changed signal
|
||||
ds->dives.dives[i]->dive_site = ds.get();
|
||||
struct dive *d = ds->dives.dives[i];
|
||||
d->dive_site = ds.get();
|
||||
changedDives.push_back(d);
|
||||
}
|
||||
|
||||
// Add dive site to core, but remember a non-owning pointer first.
|
||||
|
@ -32,6 +36,10 @@ static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sit
|
|||
emit diveListNotifier.diveSiteAdded(res.back(), idx); // Inform frontend of new dive site.
|
||||
}
|
||||
|
||||
processByTrip(changedDives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
|
||||
emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
|
||||
});
|
||||
|
||||
// Clear vector of unused owning pointers
|
||||
sites.clear();
|
||||
|
||||
|
@ -44,13 +52,15 @@ static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sit
|
|||
static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &sites)
|
||||
{
|
||||
std::vector<OwningDiveSitePtr> res;
|
||||
std::vector<dive *> changedDives;
|
||||
res.reserve(sites.size());
|
||||
|
||||
for (dive_site *ds: sites) {
|
||||
// Reset the dive_site field of the affected dives
|
||||
for (int i = 0; i < ds->dives.nr; ++i) {
|
||||
// TODO: send dive site changed signal
|
||||
ds->dives.dives[i]->dive_site = nullptr;
|
||||
struct dive *d = ds->dives.dives[i];
|
||||
d->dive_site = nullptr;
|
||||
changedDives.push_back(d);
|
||||
}
|
||||
|
||||
// Remove dive site from core and take ownership.
|
||||
|
@ -59,6 +69,10 @@ static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &
|
|||
emit diveListNotifier.diveSiteDeleted(ds, idx); // Inform frontend of removed dive site.
|
||||
}
|
||||
|
||||
processByTrip(changedDives, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
|
||||
emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
|
||||
});
|
||||
|
||||
sites.clear();
|
||||
|
||||
return res;
|
||||
|
@ -344,6 +358,7 @@ void MergeDiveSites::undo()
|
|||
}
|
||||
|
||||
sitesToRemove = std::move(addDiveSites(sitesToAdd));
|
||||
|
||||
processByTrip(divesChanged, [&](dive_trip *trip, const QVector<dive *> &divesInTrip) {
|
||||
emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue