summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/undocommands.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-19 22:35:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commit12df9faaa2037b5155ebb84a7f6f6102491a0091 (patch)
tree33dcf0e400f669d088f1b20652e9c0c6f69aae2b /desktop-widgets/undocommands.h
parent61467ea0d59b04f141a68452ee16c70760421d72 (diff)
downloadsubsurface-12df9faaa2037b5155ebb84a7f6f6102491a0091.tar.gz
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>
Diffstat (limited to 'desktop-widgets/undocommands.h')
-rw-r--r--desktop-widgets/undocommands.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/desktop-widgets/undocommands.h b/desktop-widgets/undocommands.h
index bbc1f05bd..4c4073454 100644
--- a/desktop-widgets/undocommands.h
+++ b/desktop-widgets/undocommands.h
@@ -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;
};