diff options
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command.cpp | 5 | ||||
-rw-r--r-- | desktop-widgets/command.h | 1 | ||||
-rw-r--r-- | desktop-widgets/command_divesite.cpp | 31 | ||||
-rw-r--r-- | desktop-widgets/command_divesite.h | 13 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 14 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.h | 2 |
6 files changed, 57 insertions, 9 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index 4ba6c10e9..785443390 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -108,6 +108,11 @@ void editDiveSiteLocation(dive_site *ds, location_t value) execute(new EditDiveSiteLocation(ds, value)); } +void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value) +{ + execute(new EditDiveSiteTaxonomy(ds, value)); +} + void addDiveSite(const QString &name) { execute(new AddDiveSite(name)); diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index b41462ac9..d1a8326ea 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -46,6 +46,7 @@ void editDiveSiteDescription(dive_site *ds, const QString &value); void editDiveSiteNotes(dive_site *ds, const QString &value); void editDiveSiteCountry(dive_site *ds, const QString &value); void editDiveSiteLocation(dive_site *ds, location_t value); +void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value); // value is consumed (i.e. will be erased after call)! void addDiveSite(const QString &name); } // namespace Command diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp index 91a6dbe81..04ee3b212 100644 --- a/desktop-widgets/command_divesite.cpp +++ b/desktop-widgets/command_divesite.cpp @@ -235,4 +235,35 @@ void EditDiveSiteLocation::undo() redo(); } +EditDiveSiteTaxonomy::EditDiveSiteTaxonomy(dive_site *dsIn, taxonomy_data &taxonomy) : ds(dsIn), + value(taxonomy) +{ + // We did a dumb copy. Erase the source to remove double references to strings. + memset(&taxonomy, 0, sizeof(taxonomy)); + setText(tr("Edit dive site taxonomy")); +} + +EditDiveSiteTaxonomy::~EditDiveSiteTaxonomy() +{ + free_taxonomy(&value); +} + +bool EditDiveSiteTaxonomy::workToBeDone() +{ + // TODO: Apparently we have no way of comparing taxonomies? + return true; +} + +void EditDiveSiteTaxonomy::redo() +{ + std::swap(value, ds->taxonomy); + emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site. +} + +void EditDiveSiteTaxonomy::undo() +{ + // Undo and redo do the same + redo(); +} + } // namespace Command diff --git a/desktop-widgets/command_divesite.h b/desktop-widgets/command_divesite.h index bf6fb3dc4..b73cc1b5a 100644 --- a/desktop-widgets/command_divesite.h +++ b/desktop-widgets/command_divesite.h @@ -104,6 +104,19 @@ private: location_t value; // Value to be set }; +class EditDiveSiteTaxonomy : public Base { +public: + EditDiveSiteTaxonomy(dive_site *ds, taxonomy_data &taxonomy); + ~EditDiveSiteTaxonomy(); // free taxonomy +private: + bool workToBeDone() override; + void undo() override; + void redo() override; + + dive_site *ds; + taxonomy_data value; // Value to be set +}; + } // namespace Command #endif // COMMAND_DIVESITE_H diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 39bd6678f..244e85f8d 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -10,6 +10,7 @@ #include "desktop-widgets/modeldelegates.h" #include "core/subsurface-qt/DiveListNotifier.h" #include "command.h" +#include "core/taxonomy.h" #include <QDebug> #include <QShowEvent> @@ -21,7 +22,6 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), diveSite(nullptr) { - memset(&taxonomy, 0, sizeof(taxonomy)); ui.setupUi(this); ui.diveSiteMessage->setCloseButtonVisible(false); @@ -92,7 +92,7 @@ void LocationInformationWidget::updateLabels() ui.diveSiteName->setText(diveSite->name); else ui.diveSiteName->clear(); - const char *country = taxonomy_get_country(&taxonomy); + const char *country = taxonomy_get_country(&diveSite->taxonomy); if (country) ui.diveSiteCountry->setText(country); else @@ -110,7 +110,7 @@ void LocationInformationWidget::updateLabels() else ui.diveSiteCoordinates->clear(); - ui.locationTags->setText(constructLocationTags(&taxonomy, false)); + ui.locationTags->setText(constructLocationTags(&diveSite->taxonomy, false)); } void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field) @@ -129,6 +129,7 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field) return; case LocationInformationModel::TAXONOMY: ui.diveSiteCountry->setText(taxonomy_get_country(&diveSite->taxonomy)); + ui.locationTags->setText(constructLocationTags(&diveSite->taxonomy, false)); return; case LocationInformationModel::LOCATION: filter_model.setCoordinates(diveSite->location); @@ -178,7 +179,6 @@ void LocationInformationWidget::initFields(dive_site *ds) { diveSite = ds; if (ds) { - copy_taxonomy(&ds->taxonomy, &taxonomy); filter_model.set(ds, ds->location); updateLabels(); enableLocationButtons(dive_site_has_gps_location(ds)); @@ -187,7 +187,6 @@ void LocationInformationWidget::initFields(dive_site *ds) if (m) m->invalidate(); } else { - free_taxonomy(&taxonomy); filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } }); clearLabels(); } @@ -228,10 +227,11 @@ void LocationInformationWidget::on_diveSiteNotes_editingFinished() void LocationInformationWidget::reverseGeocode() { location_t location = parseGpsText(ui.diveSiteCoordinates->text()); - if (!has_location(&location)) + if (!diveSite || !has_location(&location)) return; + taxonomy_data taxonomy = { 0 }; reverseGeoLookup(location.lat, location.lon, &taxonomy); - ui.locationTags->setText(constructLocationTags(&taxonomy, false)); + Command::editDiveSiteTaxonomy(diveSite, taxonomy); } DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject*) diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index 550b8ba8e..8188893bf 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -4,7 +4,6 @@ #include "core/units.h" #include "core/divesite.h" -#include "core/taxonomy.h" #include "ui_locationinformation.h" #include "qt-models/divelocationmodel.h" #include <stdint.h> @@ -41,7 +40,6 @@ private: Ui::LocationInformation ui; GPSLocationInformationModel filter_model; dive_site *diveSite; - taxonomy_data taxonomy; }; class DiveLocationFilterProxyModel : public QSortFilterProxyModel { |