summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-14 08:26:50 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit021aa4bd5742c575e56f36fd057e11679aaa35a5 (patch)
treed1380c7813cf5856929d14ec4492e57bcddacae1
parent4d183e0d75a3ae5b536abb6ea254ba224d713f72 (diff)
downloadsubsurface-021aa4bd5742c575e56f36fd057e11679aaa35a5.tar.gz
Undo: implement undo of dive site country editing
Simply copy the code of notes editing, but use the taxonomy_* functions to read and set the value. Moreover, replace the three TAXONOMY_n field ids by a single TAXONOMY id. We will probably never show one column per taxonomy field, but rather a single column with a string derived from all taxonomy fields. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-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
-rw-r--r--qt-models/divelocationmodel.cpp4
-rw-r--r--qt-models/divelocationmodel.h2
8 files changed, 54 insertions, 20 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();
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index 03b5f20fe..14d06f70f 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -97,9 +97,7 @@ QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, i
case COORDS: return "TODO";
case DESCRIPTION: return ds->description;
case NOTES: return ds->name;
- case TAXONOMY_1: return "TODO";
- case TAXONOMY_2: return "TODO";
- case TAXONOMY_3: return "TODO";
+ case TAXONOMY: return "TODO";
}
break;
case Qt::ToolTipRole:
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index a7743f9c9..9714054aa 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -17,7 +17,7 @@ class LocationInformationModel : public QAbstractTableModel {
public:
// Common columns, roles and accessor function for all dive-site models.
// Thus, different views can connect to different models.
- enum Columns { REMOVE, NAME, DESCRIPTION, NUM_DIVES, COORDS, NOTES, LATITUDE, LONGITUDE, DIVESITE, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
+ enum Columns { REMOVE, NAME, DESCRIPTION, NUM_DIVES, COORDS, NOTES, LATITUDE, LONGITUDE, DIVESITE, TAXONOMY, COLUMNS};
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);