summaryrefslogtreecommitdiffstats
path: root/commands/command_event.h
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.h
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.h')
-rw-r--r--commands/command_event.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/commands/command_event.h b/commands/command_event.h
new file mode 100644
index 000000000..6e387d543
--- /dev/null
+++ b/commands/command_event.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+// Note: this header file is used by the undo-machinery and should not be included elsewhere.
+
+#ifndef COMMAND_EVENT_H
+#define COMMAND_EVENT_H
+
+#include "command_base.h"
+
+
+// We put everything in a namespace, so that we can shorten names without polluting the global namespace
+namespace Command {
+
+// Events are a strange thing: they contain there own description which means
+// that on changing the description a new object must be allocated. Moreover,
+// it means that these objects can't be collected in a table.
+// Therefore, the undo commands work on events as they do with dives: using
+// owning pointers. See comments in command_base.h
+
+class AddEventBase : public Base {
+public:
+ AddEventBase(struct dive *d, int dcNr, struct event *ev); // Takes ownership of event!
+private:
+ bool workToBeDone() override;
+ void undo() override;
+ void redo() override;
+
+ // Note: we store dive and the divecomputer-number instead of a pointer to the divecomputer.
+ // Since one divecomputer is integrated into the dive structure, pointers to divecomputers
+ // are probably not stable.
+ struct dive *d;
+ int dcNr;
+
+ OwningEventPtr eventToAdd; // for redo
+ event *eventToRemove; // for undo
+};
+
+class AddEventBookmark : public AddEventBase {
+public:
+ AddEventBookmark(struct dive *d, int dcNr, int seconds);
+};
+
+} // namespace Command
+
+#endif // COMMAND_EVENT_H