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.cpp27
-rw-r--r--desktop-widgets/command_divesite.h12
-rw-r--r--desktop-widgets/locationinformation.cpp15
-rw-r--r--desktop-widgets/locationinformation.h1
6 files changed, 61 insertions, 0 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index 80a233404..82e5ebe07 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -83,4 +83,9 @@ void deleteDiveSites(const QVector <dive_site *> &sites)
execute(new DeleteDiveSites(sites));
}
+void editDiveSiteName(dive_site *ds, const QString &value)
+{
+ execute(new EditDiveSiteName(ds, value));
+}
+
} // namespace Command
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index 77920a81c..09fb45526 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -41,6 +41,7 @@ void mergeDives(const QVector <dive *> &dives);
// 3) Dive-site related commands
void deleteDiveSites(const QVector <dive_site *> &sites);
+void editDiveSiteName(dive_site *ds, const QString &value);
} // namespace Command
diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp
index d4c5d87b8..eafa18a76 100644
--- a/desktop-widgets/command_divesite.cpp
+++ b/desktop-widgets/command_divesite.cpp
@@ -3,6 +3,8 @@
#include "command_divesite.h"
#include "core/divesite.h"
#include "core/subsurface-qt/DiveListNotifier.h"
+#include "core/qthelper.h"
+#include "qt-models/divelocationmodel.h"
namespace Command {
@@ -80,4 +82,29 @@ void DeleteDiveSites::undo()
sitesToRemove = std::move(addDiveSites(sitesToAdd));
}
+EditDiveSiteName::EditDiveSiteName(dive_site *dsIn, const QString &name) : ds(dsIn),
+ value(name)
+{
+}
+
+bool EditDiveSiteName::workToBeDone()
+{
+ return value != QString(ds->name);
+}
+
+void EditDiveSiteName::redo()
+{
+ QString s = ds->name;
+ free(ds->name);
+ ds->name = copy_qstring(value);
+ value = s;
+ emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::NAME); // Inform frontend of changed dive site.
+}
+
+void EditDiveSiteName::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 9c4f93058..692e5c109 100644
--- a/desktop-widgets/command_divesite.h
+++ b/desktop-widgets/command_divesite.h
@@ -16,14 +16,26 @@ public:
DeleteDiveSites(const QVector<dive_site *> &sites);
private:
bool workToBeDone() override;
+ void undo() override;
+ void redo() override;
// For redo
std::vector<dive_site *> sitesToRemove;
// For undo
std::vector<OwningDiveSitePtr> sitesToAdd;
+};
+
+class EditDiveSiteName : public Base {
+public:
+ EditDiveSiteName(dive_site *ds, const QString &name);
+private:
+ bool workToBeDone() override;
void undo() override;
void redo() override;
+
+ dive_site *ds;
+ QString value; // Value to be set
};
} // namespace Command
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index ea52dd8c6..d827f5006 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -8,6 +8,7 @@
#include "qt-models/filtermodels.h"
#include "core/divesitehelpers.h"
#include "desktop-widgets/modeldelegates.h"
+#include "core/subsurface-qt/DiveListNotifier.h"
#include <QDebug>
#include <QShowEvent>
@@ -38,6 +39,8 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
connect(ui.diveSiteCoordinates, SIGNAL(returnPressed()), this, SLOT(updateLocationOnMap()));
ui.diveSiteCoordinates->installEventFilter(this);
+ connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &LocationInformationWidget::diveSiteChanged);
+
ui.diveSiteListView->setModel(&filter_model);
ui.diveSiteListView->setModelColumn(LocationInformationModel::NAME);
ui.diveSiteListView->installEventFilter(this);
@@ -121,6 +124,18 @@ void LocationInformationWidget::updateLabels()
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
}
+void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
+{
+ if (diveSite != ds)
+ return; // A different dive site was changed -> do nothing.
+ switch (field) {
+ case LocationInformationModel::NAME:
+ ui.diveSiteName->setText(diveSite->name);
+ default:
+ return;
+ }
+}
+
void LocationInformationWidget::clearLabels()
{
ui.diveSiteName->clear();
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index c741f49f3..3b297c741 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -39,6 +39,7 @@ public slots:
private slots:
void updateLabels();
void updateLocationOnMap();
+ void diveSiteChanged(struct dive_site *ds, int field);
signals:
void endEditDiveSite();
void nameChanged(const QString &oldName, const QString &newName);