mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 17:33:24 +00:00
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>
This commit is contained in:
parent
e39063f6df
commit
4ae87da58c
2 changed files with 18 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -79,9 +79,11 @@ private:
|
|||
bool workToBeDone() override;
|
||||
void undoit() override;
|
||||
void redoit() override;
|
||||
void post() const; // Called to fix up dives should a gas-change have happened.
|
||||
|
||||
OwningEventPtr eventToAdd; // for undo
|
||||
event *eventToRemove; // for redo
|
||||
int cylinder; // affected cylinder (if removing gas switch). <0: not a gas switch.
|
||||
};
|
||||
|
||||
class AddGasSwitch : public EventBase {
|
||||
|
|
Loading…
Add table
Reference in a new issue