Planner: Fix Editing of Plans in Multi-Divecomputer Dives.

Currently editing of planned dives that have been merged with actual
(logged) dives only works if the 'Planned dive' divecomputer is the
first divecomputer, and this divecomputer is selected when clicking
'Edit planned dive'. In other cases the profile of the first
divecomputer is overlaid with the profile of the planned dive, and the
first divecomputer's profile is overwritten when saving the dive plan.
Fix this problem.

Triggered by @SeppoTakalo's comment (https://github.com/subsurface/subsurface/issues/1913#issuecomment-2075562119): Users don't like that planned dives show up as their own entries in the dive list, so being able to merge them with the actual dive after it has been executed is a good feature - but this wasn't working well until now.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-04-26 08:16:08 +12:00
parent a83349015a
commit 528532572f
11 changed files with 114 additions and 106 deletions

View file

@ -339,28 +339,27 @@ extern "C" void selective_copy_dive(const struct dive *s, struct dive *d, struct
}
#undef CONDITIONAL_COPY_STRING
/* copies all events from all dive computers before a given time
/* copies all events from the given dive computer before a given time
this is used when editing a dive in the planner to preserve the events
of the old dive */
extern "C" void copy_events_until(const struct dive *sd, struct dive *dd, int time)
extern "C" void copy_events_until(const struct dive *sd, struct dive *dd, int dcNr, int time)
{
if (!sd || !dd)
return;
const struct divecomputer *s = &sd->dc;
struct divecomputer *d = &dd->dc;
struct divecomputer *d = get_dive_dc(dd, dcNr);
while (s && d) {
const struct event *ev;
ev = s->events;
while (ev != NULL) {
// Don't add events the planner knows about
if (ev->time.seconds < time && !event_is_gaschange(ev) && !event_is_divemodechange(ev))
add_event(d, ev->time.seconds, ev->type, ev->flags, ev->value, ev->name);
ev = ev->next;
}
s = s->next;
d = d->next;
if (!s || !d)
return;
const struct event *ev;
ev = s->events;
while (ev != NULL) {
// Don't add events the planner knows about
if (ev->time.seconds < time && !event_is_gaschange(ev) && !event_is_divemodechange(ev))
add_event(d, ev->time.seconds, ev->type, ev->flags, ev->value, ev->name);
ev = ev->next;
}
}