diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-02 21:19:29 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-12-05 10:14:25 -0800 |
commit | 147a36647ce6148ef2eccbe393faa658d0fe6834 (patch) | |
tree | 853ff1272cfdb8859a81a60f886dbf55dbd29bbc /commands/command_edit.cpp | |
parent | 76a5a38f5e8aad339061f534df8130b426079a03 (diff) | |
download | subsurface-147a36647ce6148ef2eccbe393faa658d0fe6834.tar.gz |
Undo: make adding of weights an undoable action
Introduce an AddWeight undo command. This is modelled after the
numerous dive-edit undo commands. The redo and undo actions are
connected to the WeightModel via two new signals, weightAdded
and weightRemoved.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_edit.cpp')
-rw-r--r-- | commands/command_edit.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 5e02ed80e..541eac61a 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -953,4 +953,36 @@ void ReplanDive::redo() undo(); } +// ***** Add Weight ***** +AddWeight::AddWeight(bool currentDiveOnly) : + EditDivesBase(currentDiveOnly) +{ + //: remove the part in parentheses for %n = 1 + setText(tr("Add weight (%n dive(s))", "", dives.size())); +} + +bool AddWeight::workToBeDone() +{ + return true; +} + +void AddWeight::undo() +{ + for (dive *d: dives) { + if (d->weightsystems.nr <= 0) + continue; + remove_weightsystem(d, d->weightsystems.nr - 1); + emit diveListNotifier.weightRemoved(d, d->weightsystems.nr); + } +} + +void AddWeight::redo() +{ + weightsystem_t ws { {0}, "" }; + for (dive *d: dives) { + add_cloned_weightsystem(&d->weightsystems, ws); + emit diveListNotifier.weightAdded(d, d->weightsystems.nr - 1); + } +} + } // namespace Command |