diff options
-rw-r--r-- | dive.c | 23 | ||||
-rw-r--r-- | dive.h | 1 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 10 |
3 files changed, 31 insertions, 3 deletions
@@ -75,6 +75,29 @@ void remove_event(struct event* event) } } +/* since the name is an array as part of the structure (how silly is that?) we + * have to actually remove the existing event and replace it with a new one. + * WARNING, WARNING... this may end up freeing event in case that event is indeed + * WARNING, WARNING... part of this divecomputer on this dive! */ +void update_event_name(struct dive *d, struct event* event, char *name) +{ + if (!d || !event) + return; + struct divecomputer *dc = get_dive_dc(d, dc_number); + if (!dc) + return; + struct event **removep = &dc->events; + struct event *remove; + while ((*removep)->next && !same_event(*removep, event)) + removep = &(*removep)->next; + if (!same_event(*removep, event)) + return; + remove = *removep; + *removep = (*removep)->next; + add_event(dc, event->time.seconds, event->type, event->flags, event->value, name); + free(remove); +} + /* this returns a pointer to static variable - so use it right away after calling */ struct gasmix *get_gasmix_from_event(struct event *ev) { @@ -624,6 +624,7 @@ extern void fill_default_cylinder(cylinder_t *cyl); extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx); extern void add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name); extern void remove_event(struct event *event); +extern void update_event_name(struct dive *d, struct event* event, char *name); extern void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration); extern int get_cylinder_index(struct dive *dive, struct event *ev); extern int nr_cylinders(struct dive *dive); diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index dfe514f28..6c1991aee 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -1093,10 +1093,14 @@ void ProfileWidget2::editName() lengthWarning.exec(); return; } - strcpy(event->name, newName.toUtf8()); - remember_event(event->name); + // order is important! first update the current dive (by matching the unchanged event), + // then update the displayed dive (as event is part of the events on displayed dive + // and will be freed as part of changing the name! + update_event_name(current_dive, event, newName.toUtf8().data()); + update_event_name(&displayed_dive, event, newName.toUtf8().data()); + mark_divelist_changed(true); + replot(); } - replot(); } void ProfileWidget2::disconnectTemporaryConnections() |