aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-26 17:03:54 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-29 00:09:31 +0000
commit724055f0af4fb7cdb9f1570967fe4b34797f3419 (patch)
tree6aab8c34e7d0a6df1d6fe84bc5794e8eb5404b7d
parentacd44467c1100a1a774cc644921b1dc33dca1266 (diff)
downloadsubsurface-724055f0af4fb7cdb9f1570967fe4b34797f3419.tar.gz
Dive site: replace dive->dive_site_uuid by dive_site
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/datatrak.c6
-rw-r--r--core/dive.c22
-rw-r--r--core/dive.h2
-rw-r--r--core/divesite.c8
-rw-r--r--core/gpslocation.cpp4
-rw-r--r--core/import-cobalt.c2
-rw-r--r--core/import-divinglog.c2
-rw-r--r--core/libdivecomputer.c2
-rw-r--r--core/liquivision.c2
-rw-r--r--core/load-git.c10
-rw-r--r--core/parse-xml.c38
-rw-r--r--core/parse.c12
-rw-r--r--core/save-git.c12
-rw-r--r--core/save-xml.c11
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp4
-rw-r--r--core/uemis-downloader.c14
-rw-r--r--desktop-widgets/divelogexportdialog.cpp2
-rw-r--r--desktop-widgets/locationinformation.cpp4
-rw-r--r--desktop-widgets/subsurfacewebservices.cpp6
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp33
-rw-r--r--map-widget/qml/MapWidget.qml14
-rw-r--r--map-widget/qmlmapwidgethelper.cpp25
-rw-r--r--map-widget/qmlmapwidgethelper.h2
-rw-r--r--mobile-widgets/qmlmanager.cpp4
-rw-r--r--qt-models/filtermodels.cpp2
-rw-r--r--qt-models/maplocationmodel.cpp67
-rw-r--r--qt-models/maplocationmodel.h28
-rw-r--r--smtk-import/smartrak.c12
28 files changed, 181 insertions, 169 deletions
diff --git a/core/datatrak.c b/core/datatrak.c
index 98cfcb795..1c6cd8bb1 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -202,9 +202,9 @@ unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive)
*/
snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
ds = get_dive_site_by_name(buffer);
- dt_dive->dive_site_uuid = ds ? ds->uuid : 0;
- if (dt_dive->dive_site_uuid == 0)
- dt_dive->dive_site_uuid = create_dive_site(buffer, dt_dive->when)->uuid;
+ dt_dive->dive_site = ds;
+ if (!dt_dive->dive_site)
+ dt_dive->dive_site = create_dive_site(buffer, dt_dive->when);
free(locality);
locality = NULL;
free(dive_point);
diff --git a/core/dive.c b/core/dive.c
index 347dbdbfa..ae411d494 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -650,7 +650,7 @@ void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_compo
if (what.visibility)
d->visibility = s->visibility;
if (what.divesite)
- d->dive_site_uuid = s->dive_site_uuid;
+ d->dive_site = s->dive_site;
if (what.tags)
STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
if (what.cylinders)
@@ -3503,10 +3503,10 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset,
join_dive_computers(res, &res->dc, &a->dc, &b->dc, cylinders_map_a, cylinders_map_b, 0);
/* we take the first dive site, unless it's empty */
- if (a->dive_site_uuid && !dive_site_is_empty(get_dive_site_by_uuid(a->dive_site_uuid)))
- res->dive_site_uuid = a->dive_site_uuid;
+ if (a->dive_site && !dive_site_is_empty(a->dive_site))
+ res->dive_site = a->dive_site;
else
- res->dive_site_uuid = b->dive_site_uuid;
+ res->dive_site = b->dive_site;
fixup_dive(res);
return res;
}
@@ -4075,12 +4075,12 @@ unsigned int dive_get_picture_count(struct dive *dive)
void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
{
- struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ struct dive_site *ds = dive->dive_site;
if (!dive_site_has_gps_location(ds) && has_location(&picture->location)) {
if (ds) {
ds->location = picture->location;
} else {
- dive->dive_site_uuid = create_dive_site_with_gps("", &picture->location, dive->when)->uuid;
+ dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when);
invalidate_dive_cache(dive);
}
}
@@ -4333,14 +4333,12 @@ struct dive *get_dive_from_table(int nr, struct dive_table *dt)
struct dive_site *get_dive_site_for_dive(const struct dive *dive)
{
- if (dive)
- return get_dive_site_by_uuid(dive->dive_site_uuid);
- return NULL;
+ return dive->dive_site;
}
const char *get_dive_country(const struct dive *dive)
{
- struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ struct dive_site *ds = dive->dive_site;
if (ds) {
int idx = taxonomy_index_for_category(&ds->taxonomy, TC_COUNTRY);
if (idx >= 0)
@@ -4351,7 +4349,7 @@ const char *get_dive_country(const struct dive *dive)
const char *get_dive_location(const struct dive *dive)
{
- const struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ const struct dive_site *ds = dive->dive_site;
if (ds && ds->name)
return ds->name;
return NULL;
@@ -4432,7 +4430,7 @@ int dive_has_gps_location(const struct dive *dive)
{
if (!dive)
return false;
- return dive_site_has_gps_location(get_dive_site_by_uuid(dive->dive_site_uuid));
+ return dive_site_has_gps_location(dive->dive_site);
}
struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc, int time, const struct event **evp, struct gasmix gasmix)
diff --git a/core/dive.h b/core/dive.h
index 8415974e9..bca4e16b4 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -310,7 +310,7 @@ struct dive {
bool selected;
bool hidden_by_filter;
timestamp_t when;
- uint32_t dive_site_uuid;
+ struct dive_site *dive_site;
char *notes;
char *divemaster, *buddy;
int rating;
diff --git a/core/divesite.c b/core/divesite.c
index 79902d1ef..726dec42d 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -138,7 +138,7 @@ int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only)
if (!ds)
return 0;
for_each_dive(j, d) {
- if (d->dive_site_uuid == ds->uuid && (!select_only || d->selected)) {
+ if (d->dive_site == ds && (!select_only || d->selected)) {
nr++;
}
}
@@ -153,7 +153,7 @@ bool is_dive_site_used(struct dive_site *ds, bool select_only)
if (!ds)
return false;
for_each_dive(j, d) {
- if (d->dive_site_uuid == ds->uuid && (!select_only || d->selected)) {
+ if (d->dive_site == ds && (!select_only || d->selected)) {
found = true;
break;
}
@@ -318,9 +318,9 @@ void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int
continue;
for_each_dive(curr_dive, d) {
- if (d->dive_site_uuid != dive_sites[i]->uuid )
+ if (d->dive_site != dive_sites[i] )
continue;
- d->dive_site_uuid = ref->uuid;
+ d->dive_site = ref;
invalidate_dive_cache(d);
}
}
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index 3d27e28cc..e0b176f58 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -209,10 +209,10 @@ int GpsLocation::getGpsNum() const
static void copy_gps_location(struct gpsTracker &gps, struct dive *d)
{
- struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
+ struct dive_site *ds = d->dive_site;
if (!ds) {
ds = create_dive_site(qPrintable(gps.name), gps.when);
- d->dive_site_uuid = ds->uuid;
+ d->dive_site = ds;
}
ds->location = gps.location;
}
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index 9208ad696..48faf73c0 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -197,7 +197,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
return 1;
}
sprintf(tmp, "%s / %s", location, location_site);
- state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(tmp, state->cur_dive->when)->uuid;
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when);
free(tmp);
}
free(location);
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index d0e8786e6..66a9ba2c0 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -287,7 +287,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
state->cur_dive->when = (time_t)(atol(data[1]));
if (data[2])
- state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(data[2], state->cur_dive->when)->uuid;
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when);
if (data[3])
utf8_string(data[3], &state->cur_dive->buddy);
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index b22d5fed2..a2e2890b8 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -596,7 +596,7 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str)
parse_location(line, &location);
if (location.lat.udeg && location.lon.udeg)
- dive->dive_site_uuid = create_dive_site_with_gps(str->value, &location, time(NULL))->uuid;
+ dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL));
}
}
#endif
diff --git a/core/liquivision.c b/core/liquivision.c
index e5ad9fef0..bb3f2c7b4 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -227,7 +227,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
// now that we have the dive time we can store the divesite
// (we need the dive time to create deterministic uuids)
if (found_divesite) {
- dive->dive_site_uuid = find_or_create_dive_site_with_name(location, dive->when)->uuid;
+ dive->dive_site = find_or_create_dive_site_with_name(location, dive->when);
free(location);
}
//unsigned int end_time = array_uint32_le(buf + ptr);
diff --git a/core/load-git.c b/core/load-git.c
index b0d94f3cf..8483b9cf0 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -159,9 +159,9 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
if (!ds) {
ds = get_dive_site_by_gps(&location);
if (!ds)
- dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid;
+ dive->dive_site = create_dive_site_with_gps("", &location, dive->when);
else
- dive->dive_site_uuid = ds->uuid;
+ dive->dive_site = ds;
} else {
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
const char *coords = printGPSCoords(&location);
@@ -183,9 +183,9 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
if (!ds) {
ds = get_dive_site_by_name(name);
if (!ds)
- dive->dive_site_uuid = create_dive_site(name, dive->when)->uuid;
+ dive->dive_site = create_dive_site(name, dive->when);
else
- dive->dive_site_uuid = ds->uuid;
+ dive->dive_site = ds;
} else {
// we already had a dive site linked to the dive
if (empty_string(ds->name)) {
@@ -212,7 +212,7 @@ static void parse_dive_notes(char *line, struct membuffer *str, void *_dive)
{ UNUSED(line); struct dive *dive = _dive; dive->notes = get_utf8(str); }
static void parse_dive_divesiteid(char *line, struct membuffer *str, void *_dive)
-{ UNUSED(str); struct dive *dive = _dive; dive->dive_site_uuid = get_hex(line); }
+{ UNUSED(str); struct dive *dive = _dive; dive->dive_site = get_dive_site_by_uuid(get_hex(line)); }
/*
* We can have multiple tags in the membuffer. They are separated by
diff --git a/core/parse-xml.c b/core/parse-xml.c
index a49004bae..5f70fdc52 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -558,6 +558,13 @@ static void hex_value(char *buffer, uint32_t *i)
*i = strtoul(buffer, NULL, 16);
}
+static void dive_site(char *buffer, struct dive_site **ds)
+{
+ uint32_t uuid;
+ hex_value(buffer, &uuid);
+ *ds = get_dive_site_by_uuid(uuid);
+}
+
static void get_tripflag(char *buffer, tripflag_t *tf)
{
*tf = strcmp(buffer, "NOTRIP") ? TF_NONE : NO_TRIP;
@@ -965,10 +972,9 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
nonmatch("sample", name, buf);
}
-static void divinglog_place(char *place, uint32_t *uuid, struct parser_state *state)
+static void divinglog_place(char *place, struct dive_site **ds, struct parser_state *state)
{
char buffer[1024];
- struct dive_site *ds;
snprintf(buffer, sizeof(buffer),
"%s%s%s%s%s",
@@ -977,11 +983,9 @@ static void divinglog_place(char *place, uint32_t *uuid, struct parser_state *st
state->city ? state->city : "",
state->country ? ", " : "",
state->country ? state->country : "");
- ds = get_dive_site_by_name(buffer);
- if (ds)
- *uuid = ds->uuid;
- else
- *uuid = create_dive_site(buffer, state->cur_dive->when)->uuid;
+ *ds = get_dive_site_by_name(buffer);
+ if (!*ds)
+ *ds = create_dive_site(buffer, state->cur_dive->when);
// TODO: capture the country / city info in the taxonomy instead
free(state->city);
@@ -1006,7 +1010,7 @@ static int divinglog_dive_match(struct dive *dive, const char *name, char *buf,
MATCH("names.buddy", utf8_string, &dive->buddy) ||
MATCH("name.country", utf8_string, &state->country) ||
MATCH("name.city", utf8_string, &state->city) ||
- MATCH_STATE("name.place", divinglog_place, &dive->dive_site_uuid) ||
+ MATCH_STATE("name.place", divinglog_place, &dive->dive_site) ||
0;
}
@@ -1133,7 +1137,7 @@ static void gps_lat(char *buffer, struct dive *dive)
location.lat = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid;
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when);
} else {
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
@@ -1149,7 +1153,7 @@ static void gps_long(char *buffer, struct dive *dive)
location.lon = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid;
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when);
} else {
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
@@ -1174,12 +1178,11 @@ static void gps_location(char *buffer, struct dive_site *ds)
static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *state)
{
- struct dive_site *ds = NULL;
+ struct dive_site *ds = dive->dive_site;
location_t location;
- uint32_t uuid = dive->dive_site_uuid;
parse_location(buffer, &location);
- if (uuid == 0) {
+ if (!ds) {
// check if we have a dive site within 20 meters of that gps fix
ds = get_dive_site_by_gps_proximity(&location, 20);
@@ -1187,12 +1190,11 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
// found a site nearby; in case it turns out this one had a different name let's
// remember the original coordinates so we can create the correct dive site later
state->cur_location = location;
- dive->dive_site_uuid = ds->uuid;
+ dive->dive_site = ds;
} else {
- dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid;
+ dive->dive_site = create_dive_site_with_gps("", &location, dive->when);
}
} else {
- ds = get_dive_site_by_uuid(uuid);
if (dive_site_has_gps_location(ds) &&
has_location(&location) && !same_location(&ds->location, &location)) {
// Houston, we have a problem
@@ -1233,7 +1235,7 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
default:
break;
}
- if (MATCH("divesiteid", hex_value, &dive->dive_site_uuid))
+ if (MATCH("divesiteid", dive_site, &dive->dive_site))
return;
if (MATCH("number", get_index, &dive->number))
return;
@@ -2120,7 +2122,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
/* Measure GPS */
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
- state.cur_dive->dive_site_uuid = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when)->uuid;
+ state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when);
break;
default:
break;
diff --git a/core/parse.c b/core/parse.c
index 8da7322a0..56e2e1b6f 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -163,7 +163,7 @@ void event_end(struct parser_state *state)
bool is_dive(struct parser_state *state)
{
return state->cur_dive &&
- (state->cur_dive->dive_site_uuid || state->cur_dive->when || state->cur_dive->dc.samples);
+ (state->cur_dive->dive_site || state->cur_dive->when || state->cur_dive->dc.samples);
}
void reset_dc_info(struct divecomputer *dc, struct parser_state *state)
@@ -417,7 +417,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
char *to_free = NULL;
int size = trimspace(buffer);
if(size) {
- struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ struct dive_site *ds = dive->dive_site;
if (!ds) {
// if the dive doesn't have a uuid, check if there's already a dive site by this name
ds = get_dive_site_by_name(buffer);
@@ -433,10 +433,10 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
// way around
struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location);
if (exact_match) {
- dive->dive_site_uuid = exact_match->uuid;
+ dive->dive_site = exact_match;
} else {
struct dive_site *newds = create_dive_site(buffer, dive->when);
- dive->dive_site_uuid = newds->uuid;
+ dive->dive_site = newds;
if (has_location(&state->cur_location)) {
// we started this uuid with GPS data, so lets use those
newds->location = state->cur_location;
@@ -447,10 +447,10 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
}
} else {
// add the existing dive site to the current dive
- dive->dive_site_uuid = ds->uuid;
+ dive->dive_site = ds;
}
} else {
- dive->dive_site_uuid = create_dive_site(buffer, dive->when)->uuid;
+ dive->dive_site = create_dive_site(buffer, dive->when);
}
}
free(to_free);
diff --git a/core/save-git.c b/core/save-git.c
index b118cff3d..413c66211 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -431,17 +431,15 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b)
SAVE("visibility", visibility);
cond_put_format(dive->tripflag == NO_TRIP, b, "notrip\n");
save_tags(b, dive->tag_list);
- cond_put_format(dive->dive_site_uuid && get_dive_site_by_uuid(dive->dive_site_uuid),
- b, "divesiteid %08x\n", dive->dive_site_uuid);
- if (verbose && dive->dive_site_uuid && !get_dive_site_by_uuid(dive->dive_site_uuid))
- fprintf(stderr, "removed reference to non-existant dive site with uuid %08x\n", dive->dive_site_uuid);
+ cond_put_format(!!dive->dive_site, b, "divesiteid %08x\n", dive->dive_site->uuid);
+ if (verbose && dive->dive_site)
+ fprintf(stderr, "removed reference to non-existant dive site with uuid %08x\n", dive->dive_site->uuid);
save_overview(b, dive);
save_cylinder_info(b, dive);
save_weightsystem_info(b, dive);
save_dive_temperature(b, dive);
}
-
/*
* libgit2 has a "git_treebuilder" concept, but it's broken, and can not
* be used to do a flat tree (like the git "index") nor a recursive tree.
@@ -887,8 +885,8 @@ static void save_divesites(git_repository *repo, struct dir *tree)
int j;
struct dive *d;
for_each_dive(j, d) {
- if (d->dive_site_uuid == ds->uuid)
- d->dive_site_uuid = 0;
+ if (d->dive_site == ds)
+ d->dive_site = NULL;
}
delete_dive_site(ds);
i--; // since we just deleted that one
diff --git a/core/save-xml.c b/core/save-xml.c
index 7393b84cb..4a85053ab 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -483,11 +483,8 @@ void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize)
if (dive->visibility)
put_format(b, " visibility='%d'", dive->visibility);
save_tags(b, dive->tag_list);
- if (dive->dive_site_uuid) {
- if (get_dive_site_by_uuid(dive->dive_site_uuid) != NULL)
- put_format(b, " divesiteid='%8x'", dive->dive_site_uuid);
- else if (verbose)
- fprintf(stderr, "removed reference to non-existant dive site with uuid %08x\n", dive->dive_site_uuid);
+ if (dive->dive_site) {
+ put_format(b, " divesiteid='%8x'", dive->dive_site->uuid);
}
show_date(b, dive->when);
if (dive->dc.duration.seconds > 0)
@@ -602,8 +599,8 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi
struct dive_site *ds = get_dive_site(i);
if (dive_site_is_empty(ds) || !is_dive_site_used(ds, false)) {
for_each_dive(j, d) {
- if (d->dive_site_uuid == ds->uuid)
- d->dive_site_uuid = 0;
+ if (d->dive_site == ds)
+ d->dive_site = NULL;
}
delete_dive_site(ds);
i--; // since we just deleted that one
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index b1d319c37..a1233c3ea 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -112,7 +112,7 @@ QString DiveObjectHelper::location() const
QString DiveObjectHelper::gps() const
{
- struct dive_site *ds = get_dive_site_by_uuid(m_dive->dive_site_uuid);
+ struct dive_site *ds = m_dive->dive_site;
return ds ? QString(printGPSCoords(&ds->location)) : QString();
}
@@ -129,7 +129,7 @@ QString DiveObjectHelper::gps_decimal() const
QVariant DiveObjectHelper::dive_site() const
{
- return QVariant::fromValue((uintptr_t)get_dive_site_by_uuid(m_dive->dive_site_uuid));
+ return QVariant::fromValue((uintptr_t)m_dive->dive_site);
}
QString DiveObjectHelper::duration() const
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 2b44a9852..5caa10498 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -993,11 +993,11 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
int divespot_id = atoi(val);
if (divespot_id != -1) {
struct dive_site *ds = create_dive_site("from Uemis", dive->when);
- dive->dive_site_uuid = ds->uuid;
+ dive->dive_site = ds;
uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds);
}
#if UEMIS_DEBUG & 2
- fprintf(debugfile, "Created divesite %d for diveid : %d\n", dive->dive_site_uuid, dive->dc.diveid);
+ fprintf(debugfile, "Created divesite %d for diveid : %d\n", dive->dive_site->uuid, dive->dc.diveid);
#endif
} else if (dive) {
parse_tag(dive, tag, val);
@@ -1175,11 +1175,11 @@ static bool load_uemis_divespot(const char *mountpath, int divespot_id)
static void get_uemis_divespot(const char *mountpath, int divespot_id, struct dive *dive)
{
- struct dive_site *nds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ struct dive_site *nds = dive->dive_site;
if (is_divespot_mappable(divespot_id)) {
struct dive_site *ds = get_dive_site_by_divespot_id(divespot_id);
- dive->dive_site_uuid = ds ? ds->uuid : 0;
+ dive->dive_site = ds;
} else if (nds && nds->name && strstr(nds->name,"from Uemis")) {
if (load_uemis_divespot(mountpath, divespot_id)) {
/* get the divesite based on the diveid, this should give us
@@ -1195,15 +1195,15 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
if (nds->uuid != ods->uuid) {
delete_dive_site(nds);
- dive->dive_site_uuid = ods->uuid;
+ dive->dive_site = ods;
}
}
- add_to_divespot_mapping(divespot_id, get_dive_site_by_uuid(dive->dive_site_uuid));
+ add_to_divespot_mapping(divespot_id, dive->dive_site);
} else {
/* if we can't load the dive site details, delete the site we
* created in process_raw_buffer
*/
- delete_dive_site(get_dive_site_by_uuid(dive->dive_site_uuid));
+ delete_dive_site(dive->dive_site);
}
}
}
diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp
index 928256df4..5c337f0a5 100644
--- a/desktop-widgets/divelogexportdialog.cpp
+++ b/desktop-widgets/divelogexportdialog.cpp
@@ -286,7 +286,7 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o
struct tm tm;
utc_mkdate(dive->when, &tm);
- dive_site *site = get_dive_site_by_uuid(dive->dive_site_uuid);
+ dive_site *site = dive->dive_site;
QRegExp ct("countrytag: (\\w+)");
QString country;
if (ct.indexIn(site->notes) >= 0)
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index e48c46008..2b57c122c 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -206,7 +206,7 @@ void LocationInformationWidget::acceptChanges()
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
if (dive_site_is_empty(diveSite)) {
LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite));
- displayed_dive.dive_site_uuid = 0;
+ displayed_dive.dive_site = nullptr;
diveSite = nullptr;
}
mark_divelist_changed(true);
@@ -386,7 +386,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
return new_ds_value[index.row()];
case Qt::ToolTipRole:
- return displayed_dive.dive_site_uuid ?
+ return displayed_dive.dive_site ?
tr("Create a new dive site, copying relevant information from the current dive.") :
tr("Create a new dive site with this name");
case Qt::DecorationRole:
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp
index 7e67366eb..2acc7451e 100644
--- a/desktop-widgets/subsurfacewebservices.cpp
+++ b/desktop-widgets/subsurfacewebservices.cpp
@@ -45,7 +45,7 @@ static void copy_gps_location(struct dive *from, struct dive *to)
struct dive_site *gds = get_dive_site_for_dive(from);
if (!ds) {
// simply link to the one created for the fake dive
- to->dive_site_uuid = gds->uuid;
+ to->dive_site = gds;
} else {
ds->latitude = gds->latitude;
ds->longitude = gds->longitude;
@@ -198,10 +198,10 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
/* make sure the buffer is empty and add the dive */
mb.len = 0;
- struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
+ struct dive_site *ds = dive->dive_site;
if (ds) {
- put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site_uuid);
+ put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site->uuid);
put_quoted(&mb, ds->name, 1, 0);
put_format(&mb, "'");
put_location(&mb, &ds->location, " gps='", "'");
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 7d5df7488..1c0914e7f 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -222,7 +222,7 @@ MainTab::~MainTab()
void MainTab::setCurrentLocationIndex()
{
if (current_dive) {
- struct dive_site *ds = get_dive_site_by_uuid(current_dive->dive_site_uuid);
+ struct dive_site *ds = current_dive->dive_site;
if (ds)
ui.location->setCurrentDiveSite(ds);
else
@@ -415,7 +415,7 @@ void MainTab::updateDiveInfo(bool clear)
if (!clear) {
struct dive_site *ds = NULL;
- ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
+ ds = displayed_dive.dive_site;
if (ds) {
ui.location->setCurrentDiveSite(ds);
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
@@ -605,7 +605,7 @@ void MainTab::updateDiveInfo(bool clear)
ui.cylinders->view()->hideColumn(CylindersModel::USE);
if (verbose)
- qDebug() << "Set the current dive site:" << displayed_dive.dive_site_uuid;
+ qDebug() << "Set the current dive site:" << displayed_dive.dive_site->uuid;
emit diveSiteChanged();
}
@@ -678,8 +678,7 @@ struct dive_site *MainTab::updateDiveSite(struct dive_site *pickedDs, dive *d)
if (!pickedDs)
return 0;
- const uint32_t origUuid = d->dive_site_uuid;
- struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
+ struct dive_site *origDs = d->dive_site;
bool createdNewDive = false;
if (pickedDs == origDs)
@@ -706,7 +705,7 @@ struct dive_site *MainTab::updateDiveSite(struct dive_site *pickedDs, dive *d)
}
}
- d->dive_site_uuid = pickedDs->uuid;
+ d->dive_site = pickedDs;
qDebug() << "Setting the dive site id on the dive:" << pickedDs->uuid;
return pickedDs;
}
@@ -808,8 +807,8 @@ void MainTab::acceptChanges()
if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin)
MODIFY_DIVES(selectedDives, EDIT_VALUE(watertemp.mkelvin));
- if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
- MODIFY_DIVES(selectedDives, EDIT_VALUE(dive_site_uuid));
+ if (displayed_dive.dive_site != cd->dive_site)
+ MODIFY_DIVES(selectedDives, EDIT_VALUE(dive_site));
// three text fields are somewhat special and are represented as tags
// in the UI - they need somewhat smarter handling
@@ -877,10 +876,10 @@ void MainTab::acceptChanges()
}
// update the dive site for the selected dives that had the same dive site as the current dive
- struct dive_site *oldDs = get_dive_site_by_uuid(cd->dive_site_uuid);
- struct dive_site *newDs = 0;
+ struct dive_site *oldDs = cd->dive_site;
+ struct dive_site *newDs = nullptr;
MODIFY_DIVES(selectedDives,
- if (mydive->dive_site_uuid == current_dive->dive_site_uuid)
+ if (mydive->dive_site == current_dive->dive_site)
newDs = updateDiveSite(!newDs ? ui.location->currDiveSite() : newDs, mydive);
);
if (oldDs && !is_dive_site_used(oldDs, false)) {
@@ -893,7 +892,7 @@ void MainTab::acceptChanges()
// code below triggers an update of the display without re-initializing displayed_dive
// so let's make sure here that our data is consistent now that we have handled the
// dive sites
- displayed_dive.dive_site_uuid = current_dive->dive_site_uuid;
+ displayed_dive.dive_site = current_dive->dive_site;
// each dive that was selected might have had the temperatures in its active divecomputer changed
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
@@ -1009,7 +1008,7 @@ void MainTab::rejectChanges()
}
// the user could have edited the location and then canceled the edit
// let's get the correct location back in view
- MapWidget::instance()->centerOnDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid));
+ MapWidget::instance()->centerOnDiveSite(displayed_dive.dive_site);
// show the profile and dive info
MainWindow::instance()->graphics->replot();
MainWindow::instance()->setEnabledToolbar(true);
@@ -1325,7 +1324,7 @@ void MainTab::on_location_textChanged()
// we don't want to act on the edit until editing is finished,
// but we want to mark the field so it's obvious it is being edited
QString currentLocation;
- struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
+ struct dive_site *ds = displayed_dive.dive_site;
if (ds)
currentLocation = ds->name;
if (ui.location->text() != currentLocation)
@@ -1338,12 +1337,12 @@ void MainTab::on_location_diveSiteSelected()
return;
if (ui.location->text().isEmpty()) {
- displayed_dive.dive_site_uuid = 0;
+ displayed_dive.dive_site = nullptr;
markChangedWidget(ui.location);
emit diveSiteChanged();
return;
} else {
- if (ui.location->currDiveSite() != get_dive_site_by_uuid(displayed_dive.dive_site_uuid)) {
+ if (ui.location->currDiveSite() != displayed_dive.dive_site) {
markChangedWidget(ui.location);
} else {
QPalette p;
@@ -1480,7 +1479,7 @@ void MainTab::showAndTriggerEditSelective(struct dive_components what)
if (what.visibility)
ui.visibility->setCurrentStars(displayed_dive.visibility);
if (what.divesite)
- ui.location->setCurrentDiveSite(get_dive_site_by_uuid(displayed_dive.dive_site_uuid));
+ ui.location->setCurrentDiveSite(displayed_dive.dive_site);
if (what.tags) {
ui.tagWidget->setText(get_taglist_string(displayed_dive.tag_list));
}
diff --git a/map-widget/qml/MapWidget.qml b/map-widget/qml/MapWidget.qml
index 77e52ab56..77fd2141c 100644
--- a/map-widget/qml/MapWidget.qml
+++ b/map-widget/qml/MapWidget.qml
@@ -56,26 +56,26 @@ Item {
anchorPoint.x: 0
anchorPoint.y: mapItemImage.height
coordinate: model.coordinate
- z: mapHelper.model.selectedUuid === model.uuid ? mapHelper.model.count - 1 : 0
+ z: mapHelper.model.selectedDs === model.divesite ? mapHelper.model.count - 1 : 0
sourceItem: Image {
id: mapItemImage
- source: "qrc:///dive-location-marker" + (mapHelper.model.selectedUuid === model.uuid ? "-selected" : (mapHelper.editMode ? "-inactive" : "")) + "-icon"
+ source: "qrc:///dive-location-marker" + (mapHelper.model.selectedDs === model.divesite ? "-selected" : (mapHelper.editMode ? "-inactive" : "")) + "-icon"
SequentialAnimation {
id: mapItemImageAnimation
PropertyAnimation { target: mapItemImage; property: "scale"; from: 1.0; to: 0.7; duration: 120 }
PropertyAnimation { target: mapItemImage; property: "scale"; from: 0.7; to: 1.0; duration: 80 }
}
MouseArea {
- drag.target: (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) ? mapItem : undefined
+ drag.target: (mapHelper.editMode && mapHelper.model.selectedDs === model.divesite) ? mapItem : undefined
anchors.fill: parent
onClicked: {
if (!mapHelper.editMode)
- mapHelper.model.setSelectedUuid(model.uuid, true)
+ mapHelper.model.setSelected(model.divesite, true)
}
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
onReleased: {
- if (mapHelper.editMode && mapHelper.model.selectedUuid === model.uuid) {
- mapHelper.updateCurrentDiveSiteCoordinatesFromMap(mapHelper.model.selectedUuid, mapItem.coordinate)
+ if (mapHelper.editMode && mapHelper.model.selectedDs === model.divesite) {
+ mapHelper.updateCurrentDiveSiteCoordinatesFromMap(mapHelper.model.selectedDs, mapItem.coordinate)
}
}
}
@@ -94,7 +94,7 @@ Item {
id: mapItemText
text: model.name
font.pointSize: 11.0
- color: mapHelper.model.selectedUuid === model.uuid ? "white" : "lightgrey"
+ color: mapHelper.model.selectedDs === model.divesite ? "white" : "lightgrey"
}
}
}
diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp
index 4bfa4ea31..011433818 100644
--- a/map-widget/qmlmapwidgethelper.cpp
+++ b/map-widget/qmlmapwidgethelper.cpp
@@ -41,11 +41,11 @@ void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
{
if (!ds || !dive_site_has_gps_location(ds)) {
// dive site with no GPS
- m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false);
+ m_mapLocationModel->setSelected(ds, false);
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
} else {
// dive site with GPS
- m_mapLocationModel->setSelectedUuid(ds->uuid, false);
+ m_mapLocationModel->setSelected(ds, false);
QGeoCoordinate dsCoord (ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001);
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
}
@@ -72,15 +72,14 @@ void MapWidgetHelper::centerOnSelectedDiveSite()
if (selDS.isEmpty()) {
// no selected dives with GPS coordinates
- m_mapLocationModel->setSelectedUuid(0, false);
+ m_mapLocationModel->setSelected(nullptr, false);
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
-
} else if (selDS.size() == 1) {
centerOnDiveSite(selDS[0]);
} else if (selDS.size() > 1) {
/* more than one dive sites with GPS selected.
* find the most top-left and bottom-right dive sites on the map coordinate system. */
- m_mapLocationModel->setSelectedUuid(selDS[0]->uuid, false);
+ m_mapLocationModel->setSelected(selDS[0], false);
qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0;
bool start = true;
for(struct dive_site *dss: selDS) {
@@ -143,7 +142,7 @@ void MapWidgetHelper::reloadMapLocations()
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
continue;
}
- location = new MapLocation(ds->uuid, dsCoord, name);
+ location = new MapLocation(ds, dsCoord, name);
locationList.append(location);
locations.append(ds);
locationNameMap[name] = location;
@@ -169,7 +168,7 @@ void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
m_selectedDiveIds.append(idx);
}
#else // the mobile version doesn't support multi-dive selection
- if (ds->uuid == location->uuid())
+ if (ds == location->divesite())
m_selectedDiveIds.append(dive->id); // use id here instead of index
}
int last; // get latest dive chronologically
@@ -200,7 +199,7 @@ void MapWidgetHelper::selectVisibleLocations()
Q_ARG(QGeoCoordinate, dsCoord));
if (!qIsNaN(point.x())) {
if (!selectedFirst) {
- m_mapLocationModel->setSelectedUuid(ds->uuid, false);
+ m_mapLocationModel->setSelected(ds, false);
selectedFirst = true;
}
#ifndef SUBSURFACE_MOBILE // indexes on desktop
@@ -262,9 +261,9 @@ void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool form
prefs.coordinates_traditional = savep;
}
-void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(quint32 uuid, QGeoCoordinate coord)
+void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord)
{
- MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid);
+ MapLocation *loc = m_mapLocationModel->getMapLocation(ds);
if (loc)
loc->setCoordinate(coord);
location_t location = mk_location(coord);
@@ -278,7 +277,7 @@ void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const loca
const qreal latitude_r = location.lat.udeg * 0.000001;
const qreal longitude_r = location.lon.udeg * 0.000001;
QGeoCoordinate coord(latitude_r, longitude_r);
- m_mapLocationModel->updateMapLocationCoordinates(ds->uuid, coord);
+ m_mapLocationModel->updateMapLocationCoordinates(ds, coord);
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(coord)));
}
@@ -295,12 +294,12 @@ void MapWidgetHelper::enterEditMode(struct dive_site *ds)
return;
m_editMode = true;
- MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(ds->uuid);
+ MapLocation *exists = m_mapLocationModel->getMapLocation(ds);
QGeoCoordinate coord;
// if divesite doesn't exist in the model, add a new MapLocation.
if (!exists) {
coord = m_map->property("center").value<QGeoCoordinate>();
- m_mapLocationModel->add(new MapLocation(ds->uuid, coord, QString(ds->name)));
+ m_mapLocationModel->add(new MapLocation(ds, coord, QString(ds->name)));
} else {
coord = exists->coordinate();
}
diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h
index 8fad3aed2..9300bf3bc 100644
--- a/map-widget/qmlmapwidgethelper.h
+++ b/map-widget/qmlmapwidgethelper.h
@@ -34,7 +34,7 @@ public:
Q_INVOKABLE void reloadMapLocations();
Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional);
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
- Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(quint32 uuid, QGeoCoordinate coord);
+ Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
Q_INVOKABLE void selectVisibleLocations();
void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &);
void enterEditMode(struct dive_site *ds);
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 0a10c640e..81c8f324f 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -760,7 +760,7 @@ static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, doub
if (ds) {
ds->location = location;
} else {
- d->dive_site_uuid = create_dive_site_with_gps(locationtext, &location, d->when)->uuid;
+ d->dive_site = create_dive_site_with_gps(locationtext, &location, d->when);
}
}
@@ -881,7 +881,7 @@ bool QMLManager::checkLocation(DiveObjectHelper *myDive, struct dive *d, QString
if (!ds && !location.isEmpty()) {
ds = create_dive_site(qPrintable(location), d->when);
}
- d->dive_site_uuid = ds ? ds->uuid : 0;
+ d->dive_site = ds;
}
// now make sure that the GPS coordinates match - if the user changed the name but not
// the GPS coordinates, this still does the right thing as the now new dive site will
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 9e9c6de60..1d6830ee0 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -589,7 +589,7 @@ void MultiFilterSortModel::divesDeleted(const QVector<dive *> &dives)
bool MultiFilterSortModel::showDive(const struct dive *d) const
{
if (curr_dive_site) {
- dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
+ dive_site *ds = d->dive_site;
if (!ds)
return false;
return same_string(ds->name, curr_dive_site->name) || ds->uuid == curr_dive_site->uuid;
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 45759a57f..ab34a7b16 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -1,26 +1,31 @@
// SPDX-License-Identifier: GPL-2.0
#include <QDebug>
#include "maplocationmodel.h"
+#include "core/divesite.h"
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
-const char *MapLocation::PROPERTY_NAME_UUID = "uuid";
+const char *MapLocation::PROPERTY_NAME_DIVESITE = "divesite";
const char *MapLocation::PROPERTY_NAME_NAME = "name";
-MapLocation::MapLocation()
+MapLocation::MapLocation() : m_ds(nullptr)
{
- m_uuid = 0;
}
-MapLocation::MapLocation(quint32 uuid, QGeoCoordinate coord, QString name) :
- m_uuid(uuid), m_coordinate(coord), m_name(name)
+MapLocation::MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name) :
+ m_ds(ds), m_coordinate(coord), m_name(name)
{
}
QVariant MapLocation::getRole(int role) const
{
switch (role) {
- case Roles::RoleUuid:
- return QVariant::fromValue(m_uuid);
+ case Roles::RoleDivesite:
+ // To pass the dive site as an opaque object to QML, we convert it to uintptr_t.
+ // This type is guaranteed to hold a full pointer, therefore false equivalence
+ // owing to truncation can happen. The more logical type would of course be void *,
+ // but in tests all QVariant<void *> compared equal. It is unclear whether this is
+ // a bug in a certain version of QML or QML is inredibly broken by design.
+ return QVariant::fromValue((uintptr_t)m_ds);
case Roles::RoleCoordinate:
return QVariant::fromValue(m_coordinate);
case Roles::RoleName:
@@ -46,17 +51,23 @@ void MapLocation::setCoordinateNoEmit(QGeoCoordinate coord)
m_coordinate = coord;
}
-quint32 MapLocation::uuid()
+struct dive_site *MapLocation::divesite()
{
- return m_uuid;
+ return m_ds;
}
-MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
+QVariant MapLocation::divesiteVariant()
{
- m_roles[MapLocation::Roles::RoleUuid] = MapLocation::PROPERTY_NAME_UUID;
+ // See comment on uintptr_t above
+ return QVariant::fromValue((uintptr_t)m_ds);
+}
+
+MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent),
+ m_selectedDs(nullptr)
+{
+ m_roles[MapLocation::Roles::RoleDivesite] = MapLocation::PROPERTY_NAME_DIVESITE;
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
- m_selectedUuid = 0;
}
MapLocationModel::~MapLocationModel()
@@ -120,36 +131,44 @@ void MapLocationModel::clear()
endRemoveRows();
}
-void MapLocationModel::setSelectedUuid(QVariant uuid, QVariant fromClick)
+void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
+{
+ m_selectedDs = ds;
+ emit selectedDsChanged();
+ if (fromClick)
+ emit selectedLocationChanged(getMapLocation(m_selectedDs));
+}
+
+void MapLocationModel::setSelected(QVariant divesite, QVariant fromClick)
{
- m_selectedUuid = qvariant_cast<quint32>(uuid);
+ // See comment on uintptr_t above
+ struct dive_site *ds = (struct dive_site *)qvariant_cast<uintptr_t>(divesite);
const bool fromClickBool = qvariant_cast<bool>(fromClick);
- emit selectedUuidChanged();
- if (fromClickBool)
- emit selectedLocationChanged(getMapLocationForUuid(m_selectedUuid));
+ setSelected(ds, fromClickBool);
}
-quint32 MapLocationModel::selectedUuid()
+QVariant MapLocationModel::selectedDs()
{
- return m_selectedUuid;
+ // See comment on uintptr_t above
+ return QVariant::fromValue((uintptr_t)m_selectedDs);
}
-MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)
+MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
{
MapLocation *location;
foreach(location, m_mapLocations) {
- if (uuid == location->uuid())
+ if (ds == location->divesite())
return location;
}
return NULL;
}
-void MapLocationModel::updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord)
+void MapLocationModel::updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord)
{
MapLocation *location;
int row = 0;
foreach(location, m_mapLocations) {
- if (uuid == location->uuid()) {
+ if (ds == location->divesite()) {
location->setCoordinateNoEmit(coord);
emit dataChanged(createIndex(0, row), createIndex(0, row));
return;
@@ -157,5 +176,5 @@ void MapLocationModel::updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate
row++;
}
// should not happen, as this should be called only when editing an existing marker
- qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << uuid;
+ qWarning() << "MapLocationModel::updateMapLocationCoordinates(): cannot find MapLocation for uuid:" << (ds ? ds->uuid : 0);
}
diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h
index e198773a5..33a22366f 100644
--- a/qt-models/maplocationmodel.h
+++ b/qt-models/maplocationmodel.h
@@ -12,32 +12,33 @@
class MapLocation : public QObject
{
Q_OBJECT
- Q_PROPERTY(quint32 uuid READ uuid)
+ Q_PROPERTY(QVariant divesite READ divesiteVariant)
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged)
Q_PROPERTY(QString name MEMBER m_name)
public:
static const char *PROPERTY_NAME_COORDINATE;
- static const char *PROPERTY_NAME_UUID;
+ static const char *PROPERTY_NAME_DIVESITE;
static const char *PROPERTY_NAME_NAME;
explicit MapLocation();
- explicit MapLocation(quint32 uuid, QGeoCoordinate coord, QString name);
+ explicit MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name);
QVariant getRole(int role) const;
QGeoCoordinate coordinate();
void setCoordinate(QGeoCoordinate coord);
void setCoordinateNoEmit(QGeoCoordinate coord);
- quint32 uuid();
+ QVariant divesiteVariant();
+ struct dive_site *divesite();
enum Roles {
- RoleUuid = Qt::UserRole + 1,
+ RoleDivesite = Qt::UserRole + 1,
RoleCoordinate,
RoleName
};
private:
- quint32 m_uuid;
+ struct dive_site *m_ds;
QGeoCoordinate m_coordinate;
QString m_name;
@@ -49,7 +50,7 @@ class MapLocationModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
- Q_PROPERTY(quint32 selectedUuid READ selectedUuid NOTIFY selectedUuidChanged)
+ Q_PROPERTY(QVariant selectedDs READ selectedDs NOTIFY selectedDsChanged)
public:
MapLocationModel(QObject *parent = NULL);
@@ -62,10 +63,11 @@ public:
void add(MapLocation *);
void addList(QVector<MapLocation *>);
void clear();
- MapLocation *getMapLocationForUuid(quint32 uuid);
- void updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord);
- Q_INVOKABLE void setSelectedUuid(QVariant uuid, QVariant fromClick = true);
- quint32 selectedUuid();
+ MapLocation *getMapLocation(const struct dive_site *ds);
+ void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
+ void setSelected(struct dive_site *ds, bool fromClick = true);
+ Q_INVOKABLE void setSelected(QVariant divesite, QVariant fromClick = true);
+ QVariant selectedDs();
protected:
QHash<int, QByteArray> roleNames() const override;
@@ -73,11 +75,11 @@ protected:
private:
QVector<MapLocation *> m_mapLocations;
QHash<int, QByteArray> m_roles;
- quint32 m_selectedUuid;
+ struct dive_site *m_selectedDs;
signals:
void countChanged(int c);
- void selectedUuidChanged();
+ void selectedDsChanged();
void selectedLocationChanged(MapLocation *);
};
diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c
index d97e8b69f..d998ef544 100644
--- a/smtk-import/smartrak.c
+++ b/smtk-import/smartrak.c
@@ -315,7 +315,7 @@ static void smtk_wreck_site(MdbHandle *mdb, char *site_idx, struct dive_site *ds
* Location format:
* | Idx | Text | Province | Country | Depth |
*/
-static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, uint32_t *location)
+static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, struct dive_site **location)
{
MdbTableDef *table;
MdbColumn *col[MDB_MAX_COLS];
@@ -376,13 +376,11 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, uin
ds = get_dive_site_by_name(str);
if (!ds) {
if (!has_location(&loc))
- *location = create_dive_site(str, when)->uuid;
+ ds = create_dive_site(str, when);
else
- *location = create_dive_site_with_gps(str, &loc, when)->uuid;
- ds = get_dive_site_by_uuid(*location);
- } else {
- *location = ds->uuid;
+ ds = create_dive_site_with_gps(str, &loc, when);
}
+ *location = ds;
smtk_free(bound_values, table->num_cols);
/* Insert site notes */
@@ -1065,7 +1063,7 @@ void smartrak_import(const char *file, struct dive_table *divetable)
smtkdive->visibility = strtod(col[coln(VISIBILITY)]->bind_ptr, NULL) > 25 ? 5 : lrint(strtod(col[13]->bind_ptr, NULL) / 5);
smtkdive->weightsystem[0].weight.grams = lrint(strtod(col[coln(WEIGHT)]->bind_ptr, NULL) * 1000);
smtkdive->suit = copy_string(suit_list[atoi(col[coln(SUITIDX)]->bind_ptr) - 1]);
- smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, smtkdive->when, &smtkdive->dive_site_uuid);
+ smtk_build_location(mdb_clon, col[coln(SITEIDX)]->bind_ptr, smtkdive->when, &smtkdive->dive_site);
smtkdive->buddy = smtk_locate_buddy(mdb_clon, col[0]->bind_ptr, buddy_list);
smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Type", "TypeRelation", type_list, true);
smtk_parse_relations(mdb_clon, smtkdive, col[0]->bind_ptr, "Activity", "ActivityRelation", activity_list, false);