diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-11-24 07:50:13 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-09 20:58:04 -0800 |
commit | 825fcc854788750d0d1afc4a6d1cdae9e85e738e (patch) | |
tree | 0f3a1b4dce0e39d559e547fb7a27ab7e9dc7a8fa | |
parent | f8327ed51bc2298e2c7ef69a1ef0f82509e8d8d4 (diff) | |
download | subsurface-825fcc854788750d0d1afc4a6d1cdae9e85e738e.tar.gz |
Dive list: add table parameter to autogroup_dives()
Currently autogroup_dives() groups all dives in the global dive
list. Add a table parameter so that dives in any table can be
grouped. Thus it will be possible to pre-group dives on import,
which will be used for undo of import.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/divelist.c | 24 | ||||
-rw-r--r-- | core/divelist.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 2 |
3 files changed, 15 insertions, 13 deletions
diff --git a/core/divelist.c b/core/divelist.c index 8934624c4..320713bc7 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -23,7 +23,7 @@ * struct dive_trip *unregister_dive_from_trip(struct dive *dive) * void add_dive_to_trip(struct dive *dive, dive_trip_t *trip) * dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive) - * dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated) + * dive_trip_t *get_dives_to_autogroup(sruct dive_table *table, int start, int *from, int *to, bool *allocated) * dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated) * void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b) * dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b) @@ -984,15 +984,16 @@ dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated) * manually injects the new trips. If there are no dives to be autogrouped, * return NULL. */ -dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated) +dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *from, int *to, bool *allocated) { int i; - struct dive *dive, *lastdive = NULL; + struct dive *lastdive = NULL; /* Find first dive that should be merged and remember any previous * dive that could be merged into. */ - for (i = start; (dive = get_dive(i)) != NULL; i++) { + for (i = start; i < table->nr; i++) { + struct dive *dive = table->dives[i]; dive_trip_t *trip; if (dive->divetrip) { @@ -1022,7 +1023,8 @@ dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocat // Now, find all dives that will be added to this trip lastdive = dive; *from = i; - for (*to = *from + 1; (dive = get_dive(*to)) != NULL; (*to)++) { + for (*to = *from + 1; *to < table->nr; (*to)++) { + dive = table->dives[*to]; if (dive->divetrip || dive->notrip || dive->when >= lastdive->when + TRIP_THRESHOLD) break; @@ -1038,10 +1040,10 @@ dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocat } /* - * Walk the dives from the oldest dive, and see if we can autogroup them. - * But only do this when the user selected autogrouping. + * Walk the dives from the oldest dive in the given tabe, and see if we + * can autogroup them. But only do this when the user selected autogrouping. */ -static void autogroup_dives(void) +static void autogroup_dives(struct dive_table *table) { int from, to; dive_trip_t *trip; @@ -1051,7 +1053,7 @@ static void autogroup_dives(void) if (!autogroup) return; - for (i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) { + for (i = 0; (trip = get_dives_to_autogroup(&dive_table, i, &from, &to, &alloc)) != NULL; i = to) { /* If this was newly allocated, add trip to list */ if (alloc) insert_trip(trip); @@ -1355,7 +1357,7 @@ void process_loaded_dives() sort_table(&dive_table); /* Autogroup dives if desired by user. */ - autogroup_dives(); + autogroup_dives(&dive_table); } /* @@ -1505,7 +1507,7 @@ void process_imported_dives(struct dive_table *import_table, bool prefer_importe try_to_renumber(preexisting); /* Autogroup dives if desired by user. */ - autogroup_dives(); + autogroup_dives(&dive_table); /* We might have deleted the old selected dive. * Choose the newest dive as selected (if any) */ diff --git a/core/divelist.h b/core/divelist.h index c276c941a..620de42d8 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -33,7 +33,7 @@ extern void remove_dive_from_trip(struct dive *dive); extern dive_trip_t *alloc_trip(void); extern dive_trip_t *create_trip_from_dive(struct dive *dive); extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive); -extern dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated); +extern dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *from, int *to, bool *allocated); extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated); extern bool consecutive_selected(); extern void select_dive(struct dive *dive); diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 7bab098fc..b5cbc12ee 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -724,7 +724,7 @@ AutogroupDives::AutogroupDives() dive_trip *trip; bool alloc; int from, to; - for(int i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) { + for(int i = 0; (trip = get_dives_to_autogroup(&dive_table, i, &from, &to, &alloc)) != NULL; i = to) { // If this is an allocated trip, take ownership if (alloc) divesToMove.tripsToAdd.emplace_back(trip); |