Undo: make editing of dive number undoable

When pressing F2 in the dive list, the number can be edited.
Make this action undoable by implementing a EditNumber command.

This command is differs from the other undo commands, as not the
currently selected dives are changed. This means that the EditCommand
needs an alternative constructor taking a single dive. This constructor
was implemented in the base class so that all edit commands can now
be called with a single dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-07-17 15:49:45 +02:00 committed by Dirk Hohndel
parent 658ac2bb78
commit 726d08c2f7
5 changed files with 55 additions and 2 deletions

View file

@ -29,6 +29,7 @@ namespace Command {
class EditDivesBase : public Base {
protected:
EditDivesBase(bool currentDiveOnly);
EditDivesBase(dive *d);
std::vector<dive *> dives; // Dives to be edited.
// On undo, we set the selection and current dive at the time of the operation.
@ -50,6 +51,7 @@ protected:
public:
EditBase(T newValue, bool currentDiveOnly);
EditBase(T newValue, dive *d);
protected:
// Get and set functions to be overriden by sub-classes.
@ -174,6 +176,15 @@ public:
DiveField fieldId() const override;
};
class EditNumber : public EditBase<int> {
public:
using EditBase<int>::EditBase; // Use constructor of base class.
void set(struct dive *d, int number) const override;
int data(struct dive *d) const override;
QString fieldName() const override;
DiveField fieldId() const override;
};
// Fields that work with tag-lists (tags, buddies, divemasters) work differently and therefore
// have their own base class. In this case, it's not a template, as all these lists are base
// on strings.