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_divelist.cpp52
-rw-r--r--desktop-widgets/command_divelist.h17
4 files changed, 75 insertions, 0 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index e5244e92a..b6283ec8d 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -74,6 +74,11 @@ void splitDiveComputer(dive *d, int dc_num)
execute(new SplitDiveComputer(d, dc_num));
}
+void moveDiveComputerToFront(dive *d, int dc_num)
+{
+ execute(new MoveDiveComputerToFront(d, dc_num));
+}
+
void mergeDives(const QVector <dive *> &dives)
{
execute(new MergeDives(dives));
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index 2686255ee..543e3bcae 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -36,6 +36,7 @@ void autogroupDives();
void mergeTrips(dive_trip *trip1, dive_trip *trip2);
void splitDives(dive *d, duration_t time);
void splitDiveComputer(dive *d, int dc_num);
+void moveDiveComputerToFront(dive *d, int dc_num);
void mergeDives(const QVector <dive *> &dives);
// 3) Dive-site related commands
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp
index c49159f5a..4c4a7e7d3 100644
--- a/desktop-widgets/command_divelist.cpp
+++ b/desktop-widgets/command_divelist.cpp
@@ -9,6 +9,7 @@
#include "core/qthelper.h"
#include "core/subsurface-qt/DiveListNotifier.h"
#include "qt-models/filtermodels.h"
+#include "../profile-widget/profilewidget2.h"
#include <array>
@@ -802,6 +803,57 @@ SplitDiveComputer::SplitDiveComputer(dive *d, int dc_num) : SplitDivesBase(d, sp
setText(tr("split dive computer"));
}
+MoveDiveComputerToFront::MoveDiveComputerToFront(dive *d, int dc_num)
+{
+ setText(tr("move dive computer to front"));
+
+ dive *new_dive = make_first_dc(d, dc_num);
+ if (!new_dive)
+ return;
+
+ diveToRemove.dives.push_back(d);
+
+ // Currently, the core code selects the dive -> this is not what we want, as
+ // we manually manage the selection post-command.
+ // TODO: Reset selection in core.
+ new_dive->selected = false;
+
+ // Reset references to trip and site in the new dive, as the undo command
+ // will add the dive to the trip and site.
+ new_dive->divetrip = nullptr;
+ new_dive->dive_site = nullptr;
+
+ diveToAdd.dives.resize(1);
+ diveToAdd.dives[0].dive.reset(new_dive);
+ diveToAdd.dives[0].trip = d->divetrip;
+ diveToAdd.dives[0].site = d->dive_site;
+}
+
+bool MoveDiveComputerToFront::workToBeDone()
+{
+ return !diveToRemove.dives.empty() || !diveToAdd.dives.empty();
+}
+
+void MoveDiveComputerToFront::redoit()
+{
+ DivesAndSitesToRemove addedDive = addDives(diveToAdd);
+ diveToAdd = removeDives(diveToRemove);
+ diveToRemove = std::move(addedDive);
+
+ // Select added dive and make it current
+ restoreSelection(diveToRemove.dives, diveToRemove.dives[0]);
+
+ // Update the profile to show the first dive computer
+ dc_number = 0;
+ MainWindow::instance()->graphics->replot(current_dive);
+}
+
+void MoveDiveComputerToFront::undoit()
+{
+ // Undo and redo do the same
+ redoit();
+}
+
MergeDives::MergeDives(const QVector <dive *> &dives)
{
setText(tr("merge dive"));
diff --git a/desktop-widgets/command_divelist.h b/desktop-widgets/command_divelist.h
index 2d3ee8db1..d46697454 100644
--- a/desktop-widgets/command_divelist.h
+++ b/desktop-widgets/command_divelist.h
@@ -236,6 +236,23 @@ public:
SplitDiveComputer(dive *d, int dc_num);
};
+// When moving the dive computer to the front, we go the ineffective,
+// but easy way: We keep two full copies of the dive (before and after).
+// Removing and readding assures that the dive stays at the correct
+// position in the list (the dive computer list is used for sorting dives).
+class MoveDiveComputerToFront : public DiveListBase {
+public:
+ MoveDiveComputerToFront(dive *d, int dc_num);
+private:
+ void undoit() override;
+ void redoit() override;
+ bool workToBeDone() override;
+
+ // For redo and undo
+ DivesAndTripsToAdd diveToAdd;
+ DivesAndSitesToRemove diveToRemove;
+};
+
class MergeDives : public DiveListBase {
public:
MergeDives(const QVector<dive *> &dives);