diff options
-rw-r--r-- | core/divesite-helper.cpp | 10 | ||||
-rw-r--r-- | core/divesite.c | 22 | ||||
-rw-r--r-- | core/divesite.h | 2 | ||||
-rw-r--r-- | core/taxonomy.c | 22 | ||||
-rw-r--r-- | core/taxonomy.h | 1 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 20 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.h | 2 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 2 |
8 files changed, 44 insertions, 37 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(©->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, ©->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); diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 30146b5be..e76a45091 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -20,6 +20,7 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false) { memset(&displayed_dive_site, 0, sizeof(displayed_dive_site)); + memset(&taxonomy, 0, sizeof(taxonomy)); ui.setupUi(this); ui.diveSiteMessage->setCloseButtonVisible(false); @@ -97,7 +98,7 @@ void LocationInformationWidget::updateLabels() ui.diveSiteName->setText(displayed_dive_site.name); else ui.diveSiteName->clear(); - const char *country = taxonomy_get_country(&displayed_dive_site.taxonomy); + const char *country = taxonomy_get_country(&taxonomy); if (country) ui.diveSiteCountry->setText(country); else @@ -118,7 +119,7 @@ void LocationInformationWidget::updateLabels() ui.diveSiteCoordinates->clear(); } - ui.locationTags->setText(constructLocationTags(&displayed_dive_site, false)); + ui.locationTags->setText(constructLocationTags(&taxonomy, false)); } @@ -172,15 +173,15 @@ void LocationInformationWidget::acceptChanges() free(uiString); } uiString = copy_qstring(ui.diveSiteCountry->text()); - // if the user entered a different contriy, first update the taxonomy - // for the displayed dive site; this below will get copied into the currentDs - if (!same_string(uiString, taxonomy_get_country(&displayed_dive_site.taxonomy)) && + // if the user entered a different country, first update the local taxonomy + // this below will get copied into the currentDs + if (!same_string(uiString, taxonomy_get_country(&taxonomy)) && !empty_string(uiString)) - taxonomy_set_country(&displayed_dive_site.taxonomy, uiString, taxonomy_origin::GEOMANUAL); + taxonomy_set_country(&taxonomy, uiString, taxonomy_origin::GEOMANUAL); else free(uiString); // now update the currentDs (which we then later copy back ontop of displayed_dive_site - copy_dive_site_taxonomy(&displayed_dive_site, currentDs); + copy_taxonomy(&taxonomy, ¤tDs->taxonomy); uiString = copy_qstring(ui.diveSiteNotes->document()->toPlainText()); if (!same_string(uiString, currentDs->notes)) { @@ -214,6 +215,7 @@ void LocationInformationWidget::initFields(dive_site *ds) { if (ds) { copy_dive_site(ds, &displayed_dive_site); + copy_taxonomy(&ds->taxonomy, &taxonomy); filter_model.set(displayed_dive_site.uuid, displayed_dive_site.latitude, displayed_dive_site.longitude); updateLabels(); enableLocationButtons(dive_site_has_gps_location(&displayed_dive_site)); @@ -283,7 +285,7 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString void LocationInformationWidget::on_diveSiteCountry_textChanged(const QString& text) { - if (!same_string(qPrintable(text), taxonomy_get_country(&displayed_dive_site.taxonomy))) + if (!same_string(qPrintable(text), taxonomy_get_country(&taxonomy))) markChangedWidget(ui.diveSiteCountry); } @@ -317,7 +319,7 @@ void LocationInformationWidget::resetPallete() void LocationInformationWidget::reverseGeocode() { - reverseGeoLookup(displayed_dive_site.latitude, displayed_dive_site.longitude, &displayed_dive_site.taxonomy); + reverseGeoLookup(displayed_dive_site.latitude, displayed_dive_site.longitude, &taxonomy); updateLabels(); } diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index 3e0da4aa6..43115a05b 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -4,6 +4,7 @@ #include "core/units.h" #include "core/divesite.h" +#include "core/taxonomy.h" #include "ui_locationInformation.h" #include "qt-models/divelocationmodel.h" #include <stdint.h> @@ -52,6 +53,7 @@ private: QAction *acceptAction, *rejectAction; GPSLocationInformationModel filter_model; dive_site displayed_dive_site; + taxonomy_data taxonomy; }; class DiveLocationFilterProxyModel : public QSortFilterProxyModel { diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 322ec5943..32f390a7d 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -418,7 +418,7 @@ void MainTab::updateDiveInfo(bool clear) ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid); if (ds) { ui.location->setCurrentDiveSiteUuid(ds->uuid); - ui.locationTags->setText(constructLocationTags(ds, true)); + ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true)); } else { ui.location->clear(); ui.locationTags->clear(); |