summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/command.cpp5
-rw-r--r--commands/command.h1
-rw-r--r--commands/command_event.cpp26
-rw-r--r--commands/command_event.h12
4 files changed, 44 insertions, 0 deletions
diff --git a/commands/command.cpp b/commands/command.cpp
index 09e85f3b2..54f9b22f9 100644
--- a/commands/command.cpp
+++ b/commands/command.cpp
@@ -349,4 +349,9 @@ void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name)
execute(new RenameEvent(d, dcNr, ev, name));
}
+void removeEvent(struct dive *d, int dcNr, struct event *ev)
+{
+ execute(new RemoveEvent(d, dcNr, ev));
+}
+
} // namespace Command
diff --git a/commands/command.h b/commands/command.h
index eeb400bc4..82931747c 100644
--- a/commands/command.h
+++ b/commands/command.h
@@ -110,6 +110,7 @@ void addEventBookmark(struct dive *d, int dcNr, int seconds);
void addEventDivemodeSwitch(struct dive *d, int dcNr, int seconds, int divemode);
void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name);
+void removeEvent(struct dive *d, int dcNr, struct event *ev);
} // namespace Command
diff --git a/commands/command_event.cpp b/commands/command_event.cpp
index 1114182aa..e32edfc41 100644
--- a/commands/command_event.cpp
+++ b/commands/command_event.cpp
@@ -97,4 +97,30 @@ void RenameEvent::undoit()
redoit();
}
+RemoveEvent::RemoveEvent(struct dive *d, int dcNr, struct event *ev) : EventBase(d, dcNr),
+ eventToRemove(ev)
+{
+ setText(tr("Remove %1 event").arg(ev->name));
+}
+
+bool RemoveEvent::workToBeDone()
+{
+ return true;
+}
+
+void RemoveEvent::redoit()
+{
+ struct divecomputer *dc = get_dive_dc(d, dcNr);
+ remove_event_from_dc(dc, eventToRemove);
+ eventToAdd.reset(eventToRemove); // take ownership of event
+ eventToRemove = nullptr;
+}
+
+void RemoveEvent::undoit()
+{
+ struct divecomputer *dc = get_dive_dc(d, dcNr);
+ eventToRemove = eventToAdd.get();
+ add_event_to_dc(dc, eventToAdd.release()); // return ownership to backend
+}
+
} // namespace Command
diff --git a/commands/command_event.h b/commands/command_event.h
index ddfe6f7d4..eec5cb262 100644
--- a/commands/command_event.h
+++ b/commands/command_event.h
@@ -70,6 +70,18 @@ private:
event *eventToRemove; // for undo and redo
};
+class RemoveEvent : public EventBase {
+public:
+ RemoveEvent(struct dive *d, int dcNr, struct event *ev);
+private:
+ bool workToBeDone() override;
+ void undoit() override;
+ void redoit() override;
+
+ OwningEventPtr eventToAdd; // for undo
+ event *eventToRemove; // for redo
+};
+
} // namespace Command
#endif // COMMAND_EVENT_H