2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-02-11 19:22:00 +00:00
|
|
|
#ifndef DIVESITE_H
|
|
|
|
#define DIVESITE_H
|
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "divelist.h"
|
2024-05-11 09:47:45 +00:00
|
|
|
#include "owning_table.h"
|
|
|
|
#include "taxonomy.h"
|
|
|
|
#include "units.h"
|
2015-02-11 19:22:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-10-16 13:52:13 +00:00
|
|
|
#include <QObject>
|
2015-02-12 09:59:16 +00:00
|
|
|
|
2015-02-11 19:22:00 +00:00
|
|
|
struct dive_site
|
|
|
|
{
|
2024-05-04 11:39:04 +00:00
|
|
|
uint32_t uuid = 0;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string name;
|
2024-05-04 12:41:04 +00:00
|
|
|
std::vector<dive *> dives;
|
2024-05-04 17:15:47 +00:00
|
|
|
location_t location;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string description;
|
|
|
|
std::string notes;
|
2024-05-04 11:39:04 +00:00
|
|
|
taxonomy_data taxonomy;
|
2024-05-11 13:01:37 +00:00
|
|
|
|
2024-05-04 11:39:04 +00:00
|
|
|
dive_site();
|
2024-05-04 15:18:08 +00:00
|
|
|
dive_site(const std::string &name);
|
|
|
|
dive_site(const std::string &name, const location_t *loc);
|
2024-05-11 09:47:45 +00:00
|
|
|
dive_site(uint32_t uuid);
|
2024-05-04 11:39:04 +00:00
|
|
|
~dive_site();
|
2024-05-11 13:01:37 +00:00
|
|
|
|
|
|
|
size_t nr_of_dives() const;
|
|
|
|
bool is_selected() const;
|
|
|
|
bool is_empty() const;
|
|
|
|
void merge(struct dive_site &b); // Note: b is consumed
|
|
|
|
void add_dive(struct dive *d);
|
2015-02-11 19:22:00 +00:00
|
|
|
};
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
inline int divesite_comp_uuid(const dive_site &ds1, const dive_site &ds2)
|
2015-02-11 19:22:00 +00:00
|
|
|
{
|
2024-05-11 09:47:45 +00:00
|
|
|
if (ds1.uuid == ds2.uuid)
|
|
|
|
return 0;
|
|
|
|
return ds1.uuid < ds2.uuid ? -1 : 1;
|
2015-02-11 19:22:00 +00:00
|
|
|
}
|
|
|
|
|
2024-05-11 09:47:45 +00:00
|
|
|
class dive_site_table : public sorted_owning_table<dive_site, &divesite_comp_uuid> {
|
|
|
|
public:
|
2024-05-11 12:22:33 +00:00
|
|
|
put_result register_site(std::unique_ptr<dive_site> site); // Creates or changes UUID if duplicate
|
|
|
|
dive_site *get_by_uuid(uint32_t uuid) const;
|
|
|
|
dive_site *alloc_or_get(uint32_t uuid);
|
|
|
|
dive_site *create(const std::string &name);
|
|
|
|
dive_site *create(const std::string &name, const location_t *);
|
|
|
|
dive_site *find_or_create(const std::string &name);
|
|
|
|
dive_site *get_by_name(const std::string &name) const;
|
|
|
|
dive_site *get_by_gps(const location_t *) const;
|
|
|
|
dive_site *get_by_gps_and_name(const std::string &name, const location_t *) const;
|
2024-05-11 13:18:37 +00:00
|
|
|
dive_site *get_by_gps_proximity(location_t, int distance) const;
|
2024-05-11 12:22:33 +00:00
|
|
|
void purge_empty();
|
2024-05-11 09:47:45 +00:00
|
|
|
};
|
2015-02-12 09:26:57 +00:00
|
|
|
|
2019-03-04 22:20:29 +00:00
|
|
|
struct dive_site *unregister_dive_from_dive_site(struct dive *d);
|
2024-05-11 13:01:37 +00:00
|
|
|
struct dive_site *get_same_dive_site(const struct dive_site &); // accesses global dive list
|
2015-10-07 22:34:02 +00:00
|
|
|
|
2018-10-28 20:16:42 +00: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 19:22:00 +00:00
|
|
|
#endif // DIVESITE_H
|