mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:43:24 +00:00
Dive list: move trip merging logic into divelist.c
This also fixes a couple of issues with the existing code: - removes a memory leak - treats null and "" the same Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
10e5675151
commit
e4b8cf89a1
3 changed files with 21 additions and 9 deletions
19
divelist.c
19
divelist.c
|
@ -864,6 +864,25 @@ void select_dives_in_trip(struct dive_trip *trip)
|
||||||
select_dive(get_divenr(dive));
|
select_dive(get_divenr(dive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This only gets called with non-NULL trips.
|
||||||
|
* It does not combine notes or location, just picks the first one
|
||||||
|
* (or the second one if the first one is empty */
|
||||||
|
void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b)
|
||||||
|
{
|
||||||
|
if (same_string(trip_a->location, "") && trip_b->location) {
|
||||||
|
free(trip_a->location);
|
||||||
|
trip_a->location = strdup(trip_b->location);
|
||||||
|
}
|
||||||
|
if (same_string(trip_a->notes, "") && trip_b->notes) {
|
||||||
|
free(trip_a->notes);
|
||||||
|
trip_a->notes = strdup(trip_b->notes);
|
||||||
|
}
|
||||||
|
/* this also removes the dives from trip_b and eventually
|
||||||
|
* calls delete_trip(trip_b) when the last dive has been moved */
|
||||||
|
while (trip_b->dives)
|
||||||
|
add_dive_to_trip(trip_b->dives, trip_a);
|
||||||
|
}
|
||||||
|
|
||||||
void mark_divelist_changed(int changed)
|
void mark_divelist_changed(int changed)
|
||||||
{
|
{
|
||||||
dive_list_changed = changed;
|
dive_list_changed = changed;
|
||||||
|
|
|
@ -32,6 +32,7 @@ extern void select_dive(int idx);
|
||||||
extern void deselect_dive(int idx);
|
extern void deselect_dive(int idx);
|
||||||
extern void select_dives_in_trip(struct dive_trip *trip);
|
extern void select_dives_in_trip(struct dive_trip *trip);
|
||||||
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
||||||
|
extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
||||||
extern void find_new_trip_start_time(dive_trip_t *trip);
|
extern void find_new_trip_start_time(dive_trip_t *trip);
|
||||||
extern struct dive *first_selected_dive();
|
extern struct dive *first_selected_dive();
|
||||||
extern struct dive *last_selected_dive();
|
extern struct dive *last_selected_dive();
|
||||||
|
|
|
@ -535,17 +535,9 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset)
|
||||||
|
|
||||||
dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
||||||
dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>();
|
||||||
// TODO: merge_trip on the C code? some part of this needs to stay ( getting the trips from the model,
|
|
||||||
// but not the algorithm.
|
|
||||||
if (trip_a == trip_b || !trip_a || !trip_b)
|
if (trip_a == trip_b || !trip_a || !trip_b)
|
||||||
return;
|
return;
|
||||||
|
combine_trips(trip_a, trip_b);
|
||||||
if (!trip_a->location && trip_b->location)
|
|
||||||
trip_a->location = strdup(trip_b->location);
|
|
||||||
if (!trip_a->notes && trip_b->notes)
|
|
||||||
trip_a->notes = strdup(trip_b->notes);
|
|
||||||
while (trip_b->dives)
|
|
||||||
add_dive_to_trip(trip_b->dives, trip_a);
|
|
||||||
rememberSelection();
|
rememberSelection();
|
||||||
reload(currentLayout, false);
|
reload(currentLayout, false);
|
||||||
fixMessyQtModelBehaviour();
|
fixMessyQtModelBehaviour();
|
||||||
|
|
Loading…
Add table
Reference in a new issue