core/trip handling: add helper function to get trip from id

In the QML code we pass ids around. I had assumed that there already was a reverse
lookup function, but I wasn't able to find it. So I added it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-02-20 13:20:03 -08:00
parent 3464e776e2
commit 0cd275af67
2 changed files with 11 additions and 0 deletions

View file

@ -195,6 +195,16 @@ dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated)
return trip; return trip;
} }
/* lookup of trip in main trip_table based on its id */
dive_trip_t *get_trip_by_uniq_id(int tripId)
{
for (int i = 0; i < trip_table.nr; i++) {
if (trip_table.trips[i]->id == tripId)
return trip_table.trips[i];
}
return NULL;
}
/* Check if two trips overlap time-wise up to trip threshold. */ /* Check if two trips overlap time-wise up to trip threshold. */
bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2) bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2)
{ {

View file

@ -45,6 +45,7 @@ extern dive_trip_t *create_trip_from_dive(struct dive *dive);
extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive, struct trip_table *trip_table_arg); extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive, struct trip_table *trip_table_arg);
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_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 dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated);
extern dive_trip_t *get_trip_by_uniq_id(int tripId);
extern bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2); extern bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2);
extern void select_dives_in_trip(struct dive_trip *trip); extern void select_dives_in_trip(struct dive_trip *trip);