summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/command.cpp5
-rw-r--r--desktop-widgets/command.h1
-rw-r--r--desktop-widgets/command_divesite.cpp26
-rw-r--r--desktop-widgets/command_divesite.h13
-rw-r--r--desktop-widgets/locationinformation.cpp21
-rw-r--r--desktop-widgets/locationinformation.h2
6 files changed, 52 insertions, 16 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index f476a66d0..fff60ddea 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -98,6 +98,11 @@ void editDiveSiteNotes(dive_site *ds, const QString &value)
execute(new EditDiveSiteNotes(ds, value));
}
+void editDiveSiteCountry(dive_site *ds, const QString &value)
+{
+ execute(new EditDiveSiteCountry(ds, value));
+}
+
void addDiveSite(const QString &name)
{
execute(new AddDiveSite(name));
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index 38b97121b..77209a6bb 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -44,6 +44,7 @@ void deleteDiveSites(const QVector <dive_site *> &sites);
void editDiveSiteName(dive_site *ds, const QString &value);
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 addDiveSite(const QString &name);
} // namespace Command
diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp
index 5d32a902d..5534bc5bb 100644
--- a/desktop-widgets/command_divesite.cpp
+++ b/desktop-widgets/command_divesite.cpp
@@ -4,6 +4,7 @@
#include "core/divesite.h"
#include "core/subsurface-qt/DiveListNotifier.h"
#include "core/qthelper.h"
+#include "core/subsurface-string.h"
#include "qt-models/divelocationmodel.h"
namespace Command {
@@ -182,4 +183,29 @@ void EditDiveSiteNotes::undo()
redo();
}
+EditDiveSiteCountry::EditDiveSiteCountry(dive_site *dsIn, const QString &country) : ds(dsIn),
+ value(country)
+{
+ setText(tr("Edit dive site country"));
+}
+
+bool EditDiveSiteCountry::workToBeDone()
+{
+ return !same_string(qPrintable(value), taxonomy_get_country(&ds->taxonomy));
+}
+
+void EditDiveSiteCountry::redo()
+{
+ QString old = taxonomy_get_country(&ds->taxonomy);
+ taxonomy_set_country(&ds->taxonomy, copy_qstring(value), taxonomy_origin::GEOMANUAL);
+ value = old;
+ emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site.
+}
+
+void EditDiveSiteCountry::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 ef3b2506f..f05bc765d 100644
--- a/desktop-widgets/command_divesite.h
+++ b/desktop-widgets/command_divesite.h
@@ -79,6 +79,19 @@ private:
QString value; // Value to be set
};
+
+class EditDiveSiteCountry : public Base {
+public:
+ EditDiveSiteCountry(dive_site *ds, const QString &country);
+private:
+ bool workToBeDone() override;
+ void undo() override;
+ void redo() override;
+
+ dive_site *ds;
+ QString value; // Value to be set
+};
+
} // namespace Command
#endif // COMMAND_DIVESITE_H
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index f02b45bd0..19d2befd2 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -139,6 +139,9 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
case LocationInformationModel::NOTES:
ui.diveSiteNotes->setText(diveSite->notes);
return;
+ case LocationInformationModel::TAXONOMY:
+ ui.diveSiteCountry->setText(taxonomy_get_country(&diveSite->taxonomy));
+ return;
default:
return;
}
@@ -183,18 +186,6 @@ void LocationInformationWidget::acceptChanges()
return;
}
- char *uiString;
- uiString = copy_qstring(ui.diveSiteCountry->text());
- // if the user entered a different country, first update the local taxonomy
- // this below will get copied into the diveSite
- if (!same_string(uiString, taxonomy_get_country(&taxonomy)) &&
- !empty_string(uiString))
- taxonomy_set_country(&taxonomy, uiString, taxonomy_origin::GEOMANUAL);
- else
- free(uiString);
- // now update the diveSite
- copy_taxonomy(&taxonomy, &diveSite->taxonomy);
-
if (!ui.diveSiteCoordinates->text().isEmpty())
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
mark_divelist_changed(true);
@@ -277,10 +268,10 @@ void LocationInformationWidget::on_diveSiteCoordinates_textChanged(const QString
}
}
-void LocationInformationWidget::on_diveSiteCountry_textChanged(const QString& text)
+void LocationInformationWidget::on_diveSiteCountry_editingFinished()
{
- if (!same_string(qPrintable(text), taxonomy_get_country(&taxonomy)))
- markChangedWidget(ui.diveSiteCountry);
+ if (diveSite)
+ Command::editDiveSiteCountry(diveSite, ui.diveSiteCountry->text());
}
void LocationInformationWidget::on_diveSiteDescription_editingFinished()
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index 86b82c3e3..04be64654 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -29,7 +29,7 @@ public slots:
void enableEdition();
void resetState();
void resetPallete();
- void on_diveSiteCountry_textChanged(const QString& text);
+ void on_diveSiteCountry_editingFinished();
void on_diveSiteCoordinates_textChanged(const QString& text);
void on_diveSiteDescription_editingFinished();
void on_diveSiteName_editingFinished();