summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-13 11:52:59 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-13 21:41:41 -0400
commit8815f77ea086ba474df051144098b80739a0f3ae (patch)
treecd4546081961c4734ca850d72ce8c2f62ac91dc9 /core
parent5d3967ce846ed4876abeb43ebe2d919064050ed6 (diff)
downloadsubsurface-8815f77ea086ba474df051144098b80739a0f3ae.tar.gz
Dive site: use own copy of taxonomy in dive-site-edit widget
The dive-site-edit widget uses a copy of the to-be-edited site to compare with old values. Generally, this seems overkill (the original dive-site can be used for such a comparison). But one place where it can't simply be removed is the taxonomy, because the widget needs a place to store the unsaved data. Change the code to use an explicit taxonomy structure instead of the one provided in the copy. This should ultimately allow removal of the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/divesite-helper.cpp10
-rw-r--r--core/divesite.c22
-rw-r--r--core/divesite.h2
-rw-r--r--core/taxonomy.c22
-rw-r--r--core/taxonomy.h1
5 files changed, 30 insertions, 27 deletions
diff --git a/core/divesite-helper.cpp b/core/divesite-helper.cpp
index 55ebb3aba..bed0297ce 100644
--- a/core/divesite-helper.cpp
+++ b/core/divesite-helper.cpp
@@ -3,11 +3,11 @@
#include "pref.h"
#include "gettextfromc.h"
-QString constructLocationTags(struct dive_site *ds, bool for_maintab)
+QString constructLocationTags(struct taxonomy_data *taxonomy, bool for_maintab)
{
QString locationTag;
- if (!ds || !ds->taxonomy.nr)
+ if (!taxonomy->nr)
return locationTag;
/* Check if the user set any of the 3 geocoding categories */
@@ -33,9 +33,9 @@ QString constructLocationTags(struct dive_site *ds, bool for_maintab)
for (int i = 0; i < 3; i++) {
if (prefs.geocoding.category[i] == TC_NONE)
continue;
- for (int j = 0; j < ds->taxonomy.nr; j++) {
- if (ds->taxonomy.category[j].category == prefs.geocoding.category[i]) {
- QString tag = ds->taxonomy.category[j].value;
+ for (int j = 0; j < taxonomy->nr; j++) {
+ if (taxonomy->category[j].category == prefs.geocoding.category[i]) {
+ QString tag = taxonomy->category[j].value;
if (!tag.isEmpty()) {
locationTag += connector + tag;
connector = " / ";
diff --git a/core/divesite.c b/core/divesite.c
index e84ec1dcc..f634044c2 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -249,26 +249,6 @@ bool dive_site_is_empty(struct dive_site *ds)
ds->longitude.udeg == 0);
}
-void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy)
-{
- if (orig->taxonomy.category == NULL) {
- free_taxonomy(&copy->taxonomy);
- } else {
- if (copy->taxonomy.category == NULL)
- copy->taxonomy.category = alloc_taxonomy();
- for (int i = 0; i < TC_NR_CATEGORIES; i++) {
- if (i < copy->taxonomy.nr) {
- free((void *)copy->taxonomy.category[i].value);
- copy->taxonomy.category[i].value = NULL;
- }
- if (i < orig->taxonomy.nr) {
- copy->taxonomy.category[i] = orig->taxonomy.category[i];
- copy->taxonomy.category[i].value = copy_string(orig->taxonomy.category[i].value);
- }
- }
- copy->taxonomy.nr = orig->taxonomy.nr;
- }
-}
void copy_dive_site(struct dive_site *orig, struct dive_site *copy)
{
free(copy->name);
@@ -281,7 +261,7 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy)
copy->notes = copy_string(orig->notes);
copy->description = copy_string(orig->description);
copy->uuid = orig->uuid;
- copy_dive_site_taxonomy(orig, copy);
+ copy_taxonomy(&orig->taxonomy, &copy->taxonomy);
}
static void merge_string(char **a, char **b)
diff --git a/core/divesite.h b/core/divesite.h
index 5b6943c73..b38ef5c28 100644
--- a/core/divesite.h
+++ b/core/divesite.h
@@ -75,7 +75,7 @@ void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count);
#ifdef __cplusplus
}
-QString constructLocationTags(struct dive_site *ds, bool for_maintab);
+QString constructLocationTags(struct taxonomy_data *taxonomy, bool for_maintab);
#endif
diff --git a/core/taxonomy.c b/core/taxonomy.c
index 1689d1952..9592843f0 100644
--- a/core/taxonomy.c
+++ b/core/taxonomy.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "taxonomy.h"
#include "gettext.h"
+#include "subsurface-string.h"
#include <stdlib.h>
#include <stdio.h>
@@ -41,6 +42,27 @@ void free_taxonomy(struct taxonomy_data *t)
}
}
+void copy_taxonomy(struct taxonomy_data *orig, struct taxonomy_data *copy)
+{
+ if (orig->category == NULL) {
+ free_taxonomy(copy);
+ } else {
+ if (copy->category == NULL)
+ copy->category = alloc_taxonomy();
+ for (int i = 0; i < TC_NR_CATEGORIES; i++) {
+ if (i < copy->nr) {
+ free((void *)copy->category[i].value);
+ copy->category[i].value = NULL;
+ }
+ if (i < orig->nr) {
+ copy->category[i] = orig->category[i];
+ copy->category[i].value = copy_string(orig->category[i].value);
+ }
+ }
+ copy->nr = orig->nr;
+ }
+}
+
int taxonomy_index_for_category(struct taxonomy_data *t, enum taxonomy_category cat)
{
for (int i = 0; i < t->nr; i++)
diff --git a/core/taxonomy.h b/core/taxonomy.h
index 8c886c9ed..5f7f0cf43 100644
--- a/core/taxonomy.h
+++ b/core/taxonomy.h
@@ -41,6 +41,7 @@ struct taxonomy_data {
struct taxonomy *alloc_taxonomy();
void free_taxonomy(struct taxonomy_data *t);
+void copy_taxonomy(struct taxonomy_data *orig, struct taxonomy_data *copy);
int taxonomy_index_for_category(struct taxonomy_data *t, enum taxonomy_category cat);
const char *taxonomy_get_country(struct taxonomy_data *t);
void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum taxonomy_origin origin);