summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--commands/command_event.cpp15
-rw-r--r--commands/command_event.h10
-rw-r--r--core/profile.c2
4 files changed, 23 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b058cb61..52718ab07 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
- undo: save to git after editing weights [#3159]
+- undo: reset dive-mode on undo of set-point addition
- desktop: complete rewrite of the statistics code, significantly expanding capabilities
- desktop: add preferences option to disable default cylinder types
- mobile: add ability to show fundamentally the same statistics as on the desktop
diff --git a/commands/command_event.cpp b/commands/command_event.cpp
index 5c71aaebd..4e29b452c 100644
--- a/commands/command_event.cpp
+++ b/commands/command_event.cpp
@@ -74,11 +74,24 @@ AddEventDivemodeSwitch::AddEventDivemodeSwitch(struct dive *d, int dcNr, int sec
}
AddEventSetpointChange::AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2) :
- AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_PO2, 0, pO2.mbar, QT_TRANSLATE_NOOP("gettextFromC", "SP change")))
+ AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_PO2, 0, pO2.mbar, QT_TRANSLATE_NOOP("gettextFromC", "SP change"))),
+ divemode(CCR)
{
setText(Command::Base::tr("Add set point change")); // TODO: format pO2 value in bar or psi.
}
+void AddEventSetpointChange::undoit()
+{
+ AddEventBase::undoit();
+ std::swap(get_dive_dc(d, dcNr)->divemode, divemode);
+}
+
+void AddEventSetpointChange::redoit()
+{
+ AddEventBase::redoit();
+ std::swap(get_dive_dc(d, dcNr)->divemode, divemode);
+}
+
RenameEvent::RenameEvent(struct dive *d, int dcNr, struct event *ev, const char *name) : EventBase(d, dcNr),
eventToAdd(clone_event_rename(ev, name)),
eventToRemove(ev)
diff --git a/commands/command_event.h b/commands/command_event.h
index b9662ecd4..fbf48c425 100644
--- a/commands/command_event.h
+++ b/commands/command_event.h
@@ -5,6 +5,7 @@
#define COMMAND_EVENT_H
#include "command_base.h"
+#include "core/divemode.h"
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {
@@ -35,10 +36,11 @@ private:
class AddEventBase : public EventBase {
public:
AddEventBase(struct dive *d, int dcNr, struct event *ev); // Takes ownership of event!
-private:
- bool workToBeDone() override;
+protected:
void undoit() override;
void redoit() override;
+private:
+ bool workToBeDone() override;
OwningEventPtr eventToAdd; // for redo
event *eventToRemove; // for undo
@@ -57,6 +59,10 @@ public:
class AddEventSetpointChange : public AddEventBase {
public:
AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
+private:
+ divemode_t divemode; // Wonderful: this may change the divemode of the dive to CCR
+ void undoit() override;
+ void redoit() override;
};
class RenameEvent : public EventBase {
diff --git a/core/profile.c b/core/profile.c
index e32a4bcd7..18c588b2a 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -345,8 +345,6 @@ static void check_setpoint_events(const struct dive *dive, struct divecomputer *
do {
i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
setpoint.mbar = ev->value;
- if (setpoint.mbar)
- dc->divemode = CCR;
ev = get_next_event(ev->next, "SP change");
} while (ev);
set_setpoint(pi, i, setpoint.mbar, INT_MAX);