2017-04-27 20:24:53 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-02-11 11:22:00 -08:00
|
|
|
#ifndef DIVESITE_H
|
|
|
|
#define DIVESITE_H
|
|
|
|
|
2020-05-01 13:43:52 +02:00
|
|
|
#include "divelist.h"
|
2024-05-11 11:47:45 +02:00
|
|
|
#include "owning_table.h"
|
|
|
|
#include "taxonomy.h"
|
|
|
|
#include "units.h"
|
2015-02-11 11:22:00 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-10-16 15:52:13 +02:00
|
|
|
#include <QObject>
|
2015-02-12 01:59:16 -08:00
|
|
|
|
2015-02-11 11:22:00 -08:00
|
|
|
struct dive_site
|
|
|
|
{
|
2024-05-04 13:39:04 +02:00
|
|
|
uint32_t uuid = 0;
|
2024-05-04 17:18:08 +02:00
|
|
|
std::string name;
|
2024-05-04 14:41:04 +02:00
|
|
|
std::vector<dive *> dives;
|
2024-05-04 19:15:47 +02:00
|
|
|
location_t location;
|
2024-05-04 17:18:08 +02:00
|
|
|
std::string description;
|
|
|
|
std::string notes;
|
2024-05-04 13:39:04 +02:00
|
|
|
taxonomy_data taxonomy;
|
|
|
|
dive_site();
|
2024-05-04 17:18:08 +02:00
|
|
|
dive_site(const std::string &name);
|
|
|
|
dive_site(const std::string &name, const location_t *loc);
|
2024-05-11 11:47:45 +02:00
|
|
|
dive_site(uint32_t uuid);
|
2024-05-04 13:39:04 +02:00
|
|
|
~dive_site();
|
2015-02-11 11:22:00 -08:00
|
|
|
};
|
|
|
|
|
2024-05-11 11:47:45 +02:00
|
|
|
inline int divesite_comp_uuid(const dive_site &ds1, const dive_site &ds2)
|
2015-02-11 11:22:00 -08:00
|
|
|
{
|
2024-05-11 11:47:45 +02:00
|
|
|
if (ds1.uuid == ds2.uuid)
|
|
|
|
return 0;
|
|
|
|
return ds1.uuid < ds2.uuid ? -1 : 1;
|
2015-02-11 11:22:00 -08:00
|
|
|
}
|
|
|
|
|
2024-05-11 11:47:45 +02:00
|
|
|
class dive_site_table : public sorted_owning_table<dive_site, &divesite_comp_uuid> {
|
|
|
|
public:
|
|
|
|
put_result register_site(std::unique_ptr<dive_site> site);
|
|
|
|
};
|
2015-02-12 01:26:57 -08:00
|
|
|
|
2024-05-11 11:47:45 +02:00
|
|
|
int get_divesite_idx(const struct dive_site *ds, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_dive_site_by_uuid(uint32_t uuid, dive_site_table &ds_table);
|
|
|
|
struct dive_site *alloc_or_get_dive_site(uint32_t uuid, dive_site_table &ds_table);
|
2024-05-04 14:41:04 +02:00
|
|
|
size_t nr_of_dives_at_dive_site(const struct dive_site &ds);
|
|
|
|
bool is_dive_site_selected(const struct dive_site &ds);
|
2024-05-11 11:47:45 +02:00
|
|
|
struct dive_site *create_dive_site(const std::string &name, dive_site_table &ds_table);
|
|
|
|
struct dive_site *create_dive_site_with_gps(const std::string &name, const location_t *, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_dive_site_by_name(const std::string &name, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_dive_site_by_gps(const location_t *, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_dive_site_by_gps_and_name(const std::string &name, const location_t *, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance, dive_site_table &ds_table);
|
|
|
|
struct dive_site *get_same_dive_site(const struct dive_site &);
|
2015-02-13 22:53:03 -08:00
|
|
|
bool dive_site_is_empty(struct dive_site *ds);
|
2017-02-19 14:11:37 -08:00
|
|
|
void merge_dive_site(struct dive_site *a, struct dive_site *b);
|
2018-10-20 14:12:15 -04:00
|
|
|
unsigned int get_distance(const location_t *loc1, const location_t *loc2);
|
2024-05-11 11:47:45 +02:00
|
|
|
struct dive_site *find_or_create_dive_site_with_name(const std::string &name, dive_site_table &ds_table);
|
|
|
|
void purge_empty_dive_sites(dive_site_table &ds_table);
|
2019-03-04 23:20:29 +01:00
|
|
|
void add_dive_to_dive_site(struct dive *d, struct dive_site *ds);
|
|
|
|
struct dive_site *unregister_dive_from_dive_site(struct dive *d);
|
2024-05-04 14:55:10 +02:00
|
|
|
std::string constructLocationTags(const taxonomy_data &taxonomy, bool for_maintab);
|
2015-10-07 19:34:02 -03:00
|
|
|
|
2018-10-28 21:16:42 +01:00
|
|
|
/* Make pointer-to-dive_site a "Qt metatype" so that we can pass it through QVariants */
|
|
|
|
Q_DECLARE_METATYPE(dive_site *);
|
|
|
|
|
2015-02-11 11:22:00 -08:00
|
|
|
#endif // DIVESITE_H
|