mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Core: unify insert_trip() and insert_trip_dont_merge()
There were two versions of the insert_trip() function: one would merge trips if a trip with the same date already existed, the other wouldn't. The latter was introduced with the dive-list undo work. The problem is that the "date" of a trip (i.e. the first dive) seems ill-defined as this is a volatile value. Moreover in the context of making dive-import undoable this is a very dangerous notion, as the caller needs control over when the dives are added to a trip. Therefore, unify these two functions and never merge trips. The decision on merging dives now has to made by the caller. This will be implemented in a future commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c48056300d
commit
0618aa737f
6 changed files with 14 additions and 49 deletions
|
@ -421,8 +421,7 @@ extern void delete_single_dive(int idx);
|
||||||
extern int dive_get_insertion_index(struct dive *dive);
|
extern int dive_get_insertion_index(struct dive *dive);
|
||||||
extern void add_single_dive(int idx, struct dive *dive);
|
extern void add_single_dive(int idx, struct dive *dive);
|
||||||
|
|
||||||
extern void insert_trip(dive_trip_t **trip);
|
extern void insert_trip(dive_trip_t *trip);
|
||||||
extern void insert_trip_dont_merge(dive_trip_t *trip);
|
|
||||||
extern void unregister_trip(dive_trip_t *trip);
|
extern void unregister_trip(dive_trip_t *trip);
|
||||||
extern void free_trip(dive_trip_t *trip);
|
extern void free_trip(dive_trip_t *trip);
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
* int init_decompression(struct dive *dive)
|
* int init_decompression(struct dive *dive)
|
||||||
* void update_cylinder_related_info(struct dive *dive)
|
* void update_cylinder_related_info(struct dive *dive)
|
||||||
* void dump_trip_list(void)
|
* void dump_trip_list(void)
|
||||||
* void insert_trip(dive_trip_t **dive_trip_p)
|
* void insert_trip(dive_trip_t *dive_trip_p)
|
||||||
* void insert_trip_dont_merge(dive_trip_t *dive_trip_p)
|
|
||||||
* void unregister_trip(dive_trip_t *trip)
|
* void unregister_trip(dive_trip_t *trip)
|
||||||
* void free_trip(dive_trip_t *trip)
|
* void free_trip(dive_trip_t *trip)
|
||||||
* void remove_dive_from_trip(struct dive *dive)
|
* void remove_dive_from_trip(struct dive *dive)
|
||||||
|
@ -742,44 +741,8 @@ void dump_trip_list(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* insert the trip into the dive_trip_list - but ensure you don't have
|
/* insert the trip into the dive_trip_list */
|
||||||
* two trips for the same date; but if you have, make sure you don't
|
void insert_trip(dive_trip_t *dive_trip)
|
||||||
* keep the one with less information */
|
|
||||||
void insert_trip(dive_trip_t **dive_trip_p)
|
|
||||||
{
|
|
||||||
dive_trip_t *dive_trip = *dive_trip_p;
|
|
||||||
dive_trip_t **p = &dive_trip_list;
|
|
||||||
dive_trip_t *trip;
|
|
||||||
struct dive *divep;
|
|
||||||
|
|
||||||
/* Walk the dive trip list looking for the right location.. */
|
|
||||||
while ((trip = *p) != NULL && trip->when < dive_trip->when)
|
|
||||||
p = &trip->next;
|
|
||||||
|
|
||||||
if (trip && trip->when == dive_trip->when) {
|
|
||||||
if (!trip->location)
|
|
||||||
trip->location = dive_trip->location;
|
|
||||||
if (!trip->notes)
|
|
||||||
trip->notes = dive_trip->notes;
|
|
||||||
divep = dive_trip->dives;
|
|
||||||
while (divep) {
|
|
||||||
add_dive_to_trip(divep, trip);
|
|
||||||
divep = divep->next;
|
|
||||||
}
|
|
||||||
*dive_trip_p = trip;
|
|
||||||
} else {
|
|
||||||
dive_trip->next = trip;
|
|
||||||
*p = dive_trip;
|
|
||||||
}
|
|
||||||
#ifdef DEBUG_TRIP
|
|
||||||
dump_trip_list();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* same as insert_trip, but don't merge trips with the same date.
|
|
||||||
* this is cruical for the merge undo-command, because there we
|
|
||||||
* add a new trip with the same date and then remove the old one. */
|
|
||||||
void insert_trip_dont_merge(dive_trip_t *dive_trip)
|
|
||||||
{
|
{
|
||||||
dive_trip_t **p = &dive_trip_list;
|
dive_trip_t **p = &dive_trip_list;
|
||||||
dive_trip_t *trip;
|
dive_trip_t *trip;
|
||||||
|
@ -790,6 +753,9 @@ void insert_trip_dont_merge(dive_trip_t *dive_trip)
|
||||||
|
|
||||||
dive_trip->next = trip;
|
dive_trip->next = trip;
|
||||||
*p = dive_trip;
|
*p = dive_trip;
|
||||||
|
#ifdef DEBUG_TRIP
|
||||||
|
dump_trip_list();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free resources associated with a trip structure */
|
/* free resources associated with a trip structure */
|
||||||
|
@ -957,7 +923,7 @@ dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive)
|
||||||
dive_trip_t *dive_trip = alloc_trip();
|
dive_trip_t *dive_trip = alloc_trip();
|
||||||
|
|
||||||
dive_trip = create_trip_from_dive(dive);
|
dive_trip = create_trip_from_dive(dive);
|
||||||
insert_trip(&dive_trip);
|
insert_trip(dive_trip);
|
||||||
|
|
||||||
dive->tripflag = IN_TRIP;
|
dive->tripflag = IN_TRIP;
|
||||||
add_dive_to_trip(dive, dive_trip);
|
add_dive_to_trip(dive, dive_trip);
|
||||||
|
@ -1072,7 +1038,7 @@ void autogroup_dives(void)
|
||||||
for(i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) {
|
for(i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) {
|
||||||
/* If this was newly allocated, add trip to list */
|
/* If this was newly allocated, add trip to list */
|
||||||
if (alloc)
|
if (alloc)
|
||||||
insert_trip(&trip);
|
insert_trip(trip);
|
||||||
for (j = from; j < to; ++j)
|
for (j = from; j < to; ++j)
|
||||||
add_dive_to_trip(get_dive(j), trip);
|
add_dive_to_trip(get_dive(j), trip);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1176,7 +1176,7 @@ static void finish_active_trip(void)
|
||||||
|
|
||||||
if (trip) {
|
if (trip) {
|
||||||
active_trip = NULL;
|
active_trip = NULL;
|
||||||
insert_trip(&trip);
|
insert_trip(trip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,7 @@ void trip_end(struct parser_state *state)
|
||||||
{
|
{
|
||||||
if (!state->cur_trip)
|
if (!state->cur_trip)
|
||||||
return;
|
return;
|
||||||
insert_trip(&state->cur_trip);
|
insert_trip(state->cur_trip);
|
||||||
state->cur_trip = NULL;
|
state->cur_trip = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d)
|
||||||
dive *DiveListBase::addDive(DiveToAdd &d)
|
dive *DiveListBase::addDive(DiveToAdd &d)
|
||||||
{
|
{
|
||||||
if (d.tripToAdd)
|
if (d.tripToAdd)
|
||||||
insert_trip_dont_merge(d.tripToAdd.release()); // Return ownership to backend
|
insert_trip(d.tripToAdd.release()); // Return ownership to backend
|
||||||
if (d.trip)
|
if (d.trip)
|
||||||
add_dive_to_trip(d.dive.get(), d.trip);
|
add_dive_to_trip(d.dive.get(), d.trip);
|
||||||
dive *res = d.dive.release(); // Give up ownership of dive
|
dive *res = d.dive.release(); // Give up ownership of dive
|
||||||
|
@ -259,7 +259,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives)
|
||||||
for (OwningTripPtr &trip: dives.tripsToAdd) {
|
for (OwningTripPtr &trip: dives.tripsToAdd) {
|
||||||
dive_trip *t = trip.release(); // Give up ownership
|
dive_trip *t = trip.release(); // Give up ownership
|
||||||
createdTrips.push_back(t);
|
createdTrips.push_back(t);
|
||||||
insert_trip_dont_merge(t); // Return ownership to backend
|
insert_trip(t); // Return ownership to backend
|
||||||
}
|
}
|
||||||
dives.tripsToAdd.clear();
|
dives.tripsToAdd.clear();
|
||||||
|
|
||||||
|
|
|
@ -1270,7 +1270,7 @@ bool QMLManager::undoDelete(int id)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (deletedTrip)
|
if (deletedTrip)
|
||||||
insert_trip(&deletedTrip);
|
insert_trip(deletedTrip);
|
||||||
if (deletedDive->divetrip) {
|
if (deletedDive->divetrip) {
|
||||||
struct dive_trip *trip = deletedDive->divetrip;
|
struct dive_trip *trip = deletedDive->divetrip;
|
||||||
tripflag_t tripflag = deletedDive->tripflag; // this gets overwritten in add_dive_to_trip()
|
tripflag_t tripflag = deletedDive->tripflag; // this gets overwritten in add_dive_to_trip()
|
||||||
|
|
Loading…
Add table
Reference in a new issue