core: remove dive_site member from merge_result

All callers were just using that member to set the dive_site
in the resulting dive. We might just do that in the called
function [merge_dives()].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-08-31 09:38:37 +02:00 committed by Michael Keller
parent 5b46d8cc33
commit 27a89b0232
3 changed files with 6 additions and 10 deletions

View file

@ -922,7 +922,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
return;
}
auto [d, trip, site] = divelog.dives.merge_dives(*dives[0], *dives[1], dives[1]->when - dives[0]->when, false);
auto [d, trip] = divelog.dives.merge_dives(*dives[0], *dives[1], dives[1]->when - dives[0]->when, false);
// Currently, the core code selects the dive -> this is not what we want, as
// we manually manage the selection post-command.
@ -932,11 +932,10 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
// Set the preferred dive trip, so that for subsequent merges the better trip can be selected
d->divetrip = trip;
for (int i = 2; i < dives.count(); ++i) {
auto [d2, trip, site] = divelog.dives.merge_dives(*d, *dives[i], dives[i]->when - d->when, false);
auto [d2, trip] = divelog.dives.merge_dives(*d, *dives[i], dives[i]->when - d->when, false);
d = std::move(d2);
// Set the preferred dive trip and site, so that for subsequent merges the better trip and site can be selected
d->divetrip = trip;
d->dive_site = site;
}
// The merged dive gets the number of the first dive with a non-zero number

View file

@ -1175,14 +1175,13 @@ merge_result dive_table::merge_dives(const struct dive &a_in, const struct dive
res.trip = get_preferred_trip(a, b);
/* we take the first dive site, unless it's empty */
res.site = a->dive_site && !a->dive_site->is_empty() ? a->dive_site : b->dive_site;
if (res.site && !res.site->has_gps_location() && b->dive_site && b->dive_site->has_gps_location()) {
res.dive->dive_site = a->dive_site && !a->dive_site->is_empty() ? a->dive_site : b->dive_site;
if (res.dive->dive_site && !res.dive->dive_site->has_gps_location() && b->dive_site && b->dive_site->has_gps_location()) {
/* we picked the first dive site and that didn't have GPS data, but the new dive has
* GPS data (that could be a download from a GPS enabled dive computer).
* Keep the dive site, but add the GPS data */
res.site->location = b->dive_site->location;
res.dive->dive_site->location = b->dive_site->location;
}
res.dive->dive_site = res.site;
fixup_dive(*res.dive);
return res;
@ -1206,8 +1205,7 @@ struct std::unique_ptr<dive> dive_table::try_to_merge(const struct dive &a, cons
if (!a.likely_same(b))
return {};
auto [res, trip, site] = merge_dives(a, b, 0, prefer_downloaded);
res->dive_site = site; /* Caller has to call site->add_dive()! */
auto [res, trip] = merge_dives(a, b, 0, prefer_downloaded);
return std::move(res);
}

View file

@ -18,7 +18,6 @@ int comp_dives_ptr(const struct dive *a, const struct dive *b);
struct merge_result {
std::unique_ptr<struct dive> dive;
dive_trip *trip;
dive_site *site;
};
struct dive_table : public sorted_owning_table<dive, &comp_dives> {