summaryrefslogtreecommitdiffstats
path: root/commands/command_event.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-06 23:20:58 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commit4ae87da58cda895f3573704966ef2e0dd8161864 (patch)
tree80f4367ea5b4a85d7b549598af45b1dd9919d3f2 /commands/command_event.cpp
parente39063f6df269facaad1430229d8b330385f68ff (diff)
downloadsubsurface-4ae87da58cda895f3573704966ef2e0dd8161864.tar.gz
undo: reload dive on removal of gas-switch
If a gas-switch is removed we have to perform the same action as if a gas-switch is added: fixup the dive and signal the changed cylinder and stats. Adapt the RemoveEvent command accordingly. Copy the code of the AddGasSwitch command and simplify for the fact that only ony cylinder can be affected. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_event.cpp')
-rw-r--r--commands/command_event.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/commands/command_event.cpp b/commands/command_event.cpp
index 2b9176af5..391dfe0a9 100644
--- a/commands/command_event.cpp
+++ b/commands/command_event.cpp
@@ -106,7 +106,9 @@ void RenameEvent::undoit()
}
RemoveEvent::RemoveEvent(struct dive *d, int dcNr, struct event *ev) : EventBase(d, dcNr),
- eventToRemove(ev)
+ eventToRemove(ev),
+ cylinder(ev->type == SAMPLE_EVENT_GASCHANGE2 || ev->type == SAMPLE_EVENT_GASCHANGE ?
+ ev->gas.index : -1)
{
setText(tr("Remove %1 event").arg(ev->name));
}
@@ -131,6 +133,19 @@ void RemoveEvent::undoit()
add_event_to_dc(dc, eventToAdd.release()); // return ownership to backend
}
+void RemoveEvent::post() const
+{
+ if (cylinder < 0)
+ return;
+
+ fixup_dive(d);
+ emit diveListNotifier.cylinderEdited(d, cylinder);
+
+ // TODO: This is silly we send a DURATION change event so that the statistics are recalculated.
+ // We should instead define a proper DiveField that expresses the change caused by a gas switch.
+ emit diveListNotifier.divesChanged(QVector<dive *>{ d }, DiveField::DURATION | DiveField::DEPTH);
+}
+
AddGasSwitch::AddGasSwitch(struct dive *d, int dcNr, int seconds, int tank) : EventBase(d, dcNr)
{
// If there is a gas change at this time stamp, remove it before adding the new one.