diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-01-28 18:35:27 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | f11ac405933f2bc124dcff05ec44dd6860cf712c (patch) | |
tree | 502d7f9880076455324bb762e011555f7f452ae2 /desktop-widgets/command_edit.cpp | |
parent | 45ef87954669c765cb7b317384066c6eb88dc5d3 (diff) | |
download | subsurface-f11ac405933f2bc124dcff05ec44dd6860cf712c.tar.gz |
Undo: implement undo of dive mode editing
Add a new UndoCommand for dive mode editing. This one is a bit
special, as the mode is associated with a dive computer (DC),
not a dive. Thus the edit command has an additional parameter,
viz. the index of the DC.
This does not fit properly to the EditBase class, as this class
isn't aware of additional parameters and therefore this parameter
is not sent via signals. At the moment this doesn't matter. In
any case, the semantics of editing are weird and therefore let's
do the simple thing (derive from EditBase) and let's see what
the future brings.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_edit.cpp')
-rw-r--r-- | desktop-widgets/command_edit.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index aab3dc791..5ead59998 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -76,6 +76,9 @@ void EditBase<T>::redo() undo(); } +// Implementation of virtual functions + +// ***** Notes ***** void EditNotes::set(struct dive *d, QString s) const { free(d->notes); @@ -97,4 +100,43 @@ DiveField EditNotes::fieldId() const return DiveField::NOTES; } +// ***** Mode ***** +// Editing the dive mode has very peculiar semantics for historic reasons: +// Since the dive-mode depends on the dive computer, the i-th dive computer +// of each dive will be edited. If the dive has less than i dive computers, +// the default dive computer will be edited. +// The index "i" will be stored as an additional payload with the command. +// Thus, we need an explicit constructor. Since the actual handling is done +// by the base class, which knows nothing about this index, it will not be +// sent via signals. Currently this is not needed. Should it turn out to +// become necessary, then we might either +// - Not derive EditMode from EditBase. +// - Change the semantics of the mode-editing. +// The future will tell. +EditMode::EditMode(const QVector<dive *> &dives, int indexIn, int newValue, int oldValue) + : EditBase(dives, newValue, oldValue), index(indexIn) +{ +} + +void EditMode::set(struct dive *d, int i) const +{ + get_dive_dc(d, index)->divemode = (enum divemode_t)i; + update_setpoint_events(d, get_dive_dc(d, index)); +} + +int EditMode::data(struct dive *d) const +{ + return get_dive_dc(d, index)->divemode; +} + +QString EditMode::fieldName() const +{ + return tr("dive mode"); +} + +DiveField EditMode::fieldId() const +{ + return DiveField::MODE; +} + } // namespace Command |