Undo: make weight editing undoable

Implement the EditWeight undo command. Since there is common code
(storage of the old weight), this creates a common base class for
RemoveWeight and EditWeight. The model calls directly into the undo
command, which is somewhat unfortunate as it feels like a layering
violation. It's the easy thing to do for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-11-08 22:47:38 +01:00 committed by Dirk Hohndel
parent 029c9ccf02
commit 72c6b83866
10 changed files with 132 additions and 59 deletions

View file

@ -339,16 +339,32 @@ private:
bool workToBeDone() override;
};
class RemoveWeight : public EditDivesBase {
public:
RemoveWeight(int index, bool currentDiveOnly);
~RemoveWeight();
private:
class EditWeightBase : public EditDivesBase {
protected:
EditWeightBase(int index, bool currentDiveOnly);
~EditWeightBase();
weightsystem_t ws;
std::vector<int> indexes; // An index for each dive in the dives vector.
bool workToBeDone() override;
};
class RemoveWeight : public EditWeightBase {
public:
RemoveWeight(int index, bool currentDiveOnly);
private:
void undo() override;
void redo() override;
};
class EditWeight : public EditWeightBase {
public:
EditWeight(int index, weightsystem_t ws, bool currentDiveOnly); // Clones ws
~EditWeight();
private:
weightsystem_t new_ws;
void undo() override;
void redo() override;
bool workToBeDone() override;
};
} // namespace Command