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.cpp27
-rw-r--r--commands/command_event.h12
4 files changed, 45 insertions, 0 deletions
diff --git a/commands/command.cpp b/commands/command.cpp
index 44eb4b8f0..09e85f3b2 100644
--- a/commands/command.cpp
+++ b/commands/command.cpp
@@ -344,4 +344,9 @@ void addEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO
execute(new AddEventSetpointChange(d, dcNr, seconds, pO2));
}
+void renameEvent(struct dive *d, int dcNr, struct event *ev, const char *name)
+{
+ execute(new RenameEvent(d, dcNr, ev, name));
+}
+
} // namespace Command
diff --git a/commands/command.h b/commands/command.h
index aa7c75ab3..eeb400bc4 100644
--- a/commands/command.h
+++ b/commands/command.h
@@ -109,6 +109,7 @@ void editTripNotes(dive_trip *trip, const QString &s);
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);
} // namespace Command
diff --git a/commands/command_event.cpp b/commands/command_event.cpp
index 7ecd4f070..1114182aa 100644
--- a/commands/command_event.cpp
+++ b/commands/command_event.cpp
@@ -70,4 +70,31 @@ AddEventSetpointChange::AddEventSetpointChange(struct dive *d, int dcNr, int sec
setText(tr("Add set point change")); // TODO: format pO2 value in bar or psi.
}
+RenameEvent::RenameEvent(struct dive *d, int dcNr, struct event *ev, const char *name) : EventBase(d, dcNr),
+ eventToAdd(clone_event_rename(ev, name)),
+ eventToRemove(ev)
+{
+ setText(tr("Rename bookmark to %1").arg(name));
+}
+
+bool RenameEvent::workToBeDone()
+{
+ return true;
+}
+
+void RenameEvent::redoit()
+{
+ struct divecomputer *dc = get_dive_dc(d, dcNr);
+ swap_event(dc, eventToRemove, eventToAdd.get());
+ event *tmp = eventToRemove;
+ eventToRemove = eventToAdd.release();
+ eventToAdd.reset(tmp);
+}
+
+void RenameEvent::undoit()
+{
+ // Undo and redo do the same thing - they simply swap events
+ redoit();
+}
+
} // namespace Command
diff --git a/commands/command_event.h b/commands/command_event.h
index a674e258b..ddfe6f7d4 100644
--- a/commands/command_event.h
+++ b/commands/command_event.h
@@ -58,6 +58,18 @@ public:
AddEventSetpointChange(struct dive *d, int dcNr, int seconds, pressure_t pO2);
};
+class RenameEvent : public EventBase {
+public:
+ RenameEvent(struct dive *d, int dcNr, struct event *ev, const char *name);
+private:
+ bool workToBeDone() override;
+ void undoit() override;
+ void redoit() override;
+
+ OwningEventPtr eventToAdd; // for undo and redo
+ event *eventToRemove; // for undo and redo
+};
+
} // namespace Command
#endif // COMMAND_EVENT_H