Undo: implement undo of manual dive-creation

Play manual addition of dives via an UndoCommand. Since this does in
large parts the same thing as undo/redo of dive deletion (just the
other way round and only a single instead of multiple dive), factor
out the functions that add/delete dives and take care of trips.

The UI-interaction is just mindless copy&paste and will have to
be adapted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-19 22:35:25 +02:00 committed by Dirk Hohndel
parent 61467ea0d5
commit 12df9faaa2
7 changed files with 1064 additions and 64 deletions

View file

@ -148,6 +148,29 @@ struct TripDeleter {
typedef std::unique_ptr<dive, DiveDeleter> OwningDivePtr;
typedef std::unique_ptr<dive_trip, TripDeleter> OwningTripPtr;
// This helper structure describes a dive that we want to add.
// Potentially it also adds a trip (if deletion of the dive resulted in deletion of the trip)
struct DiveToAdd {
OwningDivePtr dive; // Dive to add
OwningTripPtr tripToAdd; // Not-null if we also have to add a dive
dive_trip *trip; // Trip the dive belongs to, may be null
int idx; // Position in divelist
};
class UndoAddDive : public QUndoCommand {
public:
UndoAddDive(dive *dive); // Warning: old dive will be erased (moved in C++-speak)!
private:
void undo() override;
void redo() override;
// For redo
DiveToAdd diveToAdd;
// For undo
dive *diveToRemove;
};
class UndoDeleteDive : public QUndoCommand {
Q_DECLARE_TR_FUNCTIONS(Command)
public:
@ -159,12 +182,6 @@ private:
// For redo
QVector<struct dive*> divesToDelete;
// For undo
struct DiveToAdd {
OwningDivePtr dive; // Dive to add
dive_trip *trip; // Trip, may be null
int idx; // Position in divelist
};
std::vector<OwningTripPtr> tripsToAdd;
std::vector<DiveToAdd> divesToAdd;
};