summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp20
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp
index 648df6395..5b65015da 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "TabDiveSite.h"
+#include "core/subsurface-qt/DiveListNotifier.h"
+#include "core/divesite.h"
#include "qt-models/divelocationmodel.h"
#include "desktop-widgets/command.h"
@@ -31,5 +33,23 @@ void TabDiveSite::clear()
void TabDiveSite::add()
{
+ // This is mighty dirty: We hook into the "dive site added" signal and
+ // select the name field of the added dive site when the command sends
+ // the signal. This works only because we know that the model added the
+ // connection first. Very subtle!
+ // After the command has finished, the signal is disconnected so that dive
+ // site names are not selected on regular redo / undo.
+ connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &TabDiveSite::diveSiteAdded);
Command::addDiveSite(tr("New dive site"));
+ disconnect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &TabDiveSite::diveSiteAdded);
+}
+
+void TabDiveSite::diveSiteAdded(struct dive_site *, int idx)
+{
+ if (idx < 0)
+ return;
+ QModelIndex globalIdx = LocationInformationModel::instance()->index(idx, LocationInformationModel::NAME);
+ QModelIndex localIdx = model.mapFromSource(globalIdx);
+ ui.diveSites->view()->setCurrentIndex(localIdx);
+ ui.diveSites->view()->edit(localIdx);
}
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.h b/desktop-widgets/tab-widgets/TabDiveSite.h
index 2538166b4..32badadc3 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.h
+++ b/desktop-widgets/tab-widgets/TabDiveSite.h
@@ -14,6 +14,7 @@ public:
void clear() override;
private slots:
void add();
+ void diveSiteAdded(struct dive_site *, int idx);
private:
Ui::TabDiveSite ui;
DiveSiteSortedModel model;