summaryrefslogtreecommitdiffstats
path: root/commands/command_event.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-03 22:34:50 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commit30c7499a3c656784cc45825b4b1b2fca61081308 (patch)
tree32f8ad2c085e3a1706ed0994c0f39eadde39830d /commands/command_event.cpp
parent3aa1bb5bfae9a7ebf8f5e6cdbf751afcafdb4baf (diff)
downloadsubsurface-30c7499a3c656784cc45825b4b1b2fca61081308.tar.gz
undo: implement addBookmark undo command
Create a new translation unit for event-related undo commands. Create a base class of commands that add events and one subclass that adds a bookmark event. Use this command in the profile-widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_event.cpp')
-rw-r--r--commands/command_event.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/commands/command_event.cpp b/commands/command_event.cpp
new file mode 100644
index 000000000..ea35402e4
--- /dev/null
+++ b/commands/command_event.cpp
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "command_event.h"
+#include "core/dive.h"
+#include "core/subsurface-qt/divelistnotifier.h"
+#include "core/libdivecomputer.h"
+
+namespace Command {
+
+AddEventBase::AddEventBase(struct dive *dIn, int dcNrIn, struct event *ev) :
+ d(dIn), dcNr(dcNrIn), eventToAdd(ev)
+{
+}
+
+bool AddEventBase::workToBeDone()
+{
+ return true;
+}
+
+void AddEventBase::redo()
+{
+ struct divecomputer *dc = get_dive_dc(d, dcNr);
+ eventToRemove = eventToAdd.get();
+ add_event_to_dc(dc, eventToAdd.release()); // return ownership to backend
+ invalidate_dive_cache(d);
+}
+
+void AddEventBase::undo()
+{
+ struct divecomputer *dc = get_dive_dc(d, dcNr);
+ remove_event_from_dc(dc, eventToRemove);
+ eventToAdd.reset(eventToRemove); // take ownership of event
+ eventToRemove = nullptr;
+ invalidate_dive_cache(d);
+}
+
+AddEventBookmark::AddEventBookmark(struct dive *d, int dcNr, int seconds) :
+ AddEventBase(d, dcNr, create_event(seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"))
+{
+ setText(tr("Add bookmark"));
+}
+
+} // namespace Command