summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/undocommands.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-09-23 21:22:48 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commitf427226b3b605523bc8285dbdaaa7f6993af6e6a (patch)
treee025722f92883fbac72b3584d6b4fb301bb8a40d /desktop-widgets/undocommands.h
parent4fbb8ef399a356e0b1a7393311c22ca68c50a14d (diff)
downloadsubsurface-f427226b3b605523bc8285dbdaaa7f6993af6e6a.tar.gz
Undo: make diverse trip-related operations undo-able
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips and MergeTrips basically all did the same thing as RemoveDivesFromTrip, which was already implemented. Thus, factor our the common functionality and hook it up to make all these functions undo-able. Don't do the autogroup-call everytime the dive-list is rebuilt (that would create innumberable undo-actions), but only on dive-load / import or if expressly asked by the user [by switching the autogroup flag]. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/undocommands.h')
-rw-r--r--desktop-widgets/undocommands.h56
1 files changed, 45 insertions, 11 deletions
diff --git a/desktop-widgets/undocommands.h b/desktop-widgets/undocommands.h
index da30c27a0..11c35bb40 100644
--- a/desktop-widgets/undocommands.h
+++ b/desktop-widgets/undocommands.h
@@ -157,9 +157,27 @@ struct DiveToAdd {
int idx; // Position in divelist
};
+// This helper structure describes a dive that should be moved to / removed from
+// a trip. If the "trip" member is null, the dive is removed from its trip (if
+// it is in a trip, that is)
+struct DiveToTrip
+{
+ struct dive *dive;
+ dive_trip *trip;
+};
+
+// This helper structure describes a number of dives to add to /remove from /
+// move between trips.
+// It has ownership of the trips (if any) that have to be added before hand.
+struct DivesToTrip
+{
+ std::vector<DiveToTrip> divesToMove; // If dive_trip is null, remove from trip
+ std::vector<OwningTripPtr> tripsToAdd;
+};
+
class UndoAddDive : public QUndoCommand {
public:
- UndoAddDive(dive *dive); // Warning: old dive will be erased (moved in C++-speak)!
+ UndoAddDive(dive *dive);
private:
void undo() override;
void redo() override;
@@ -211,20 +229,36 @@ private:
QVector<QPair<int, int>> divesToRenumber;
};
-class UndoRemoveDivesFromTrip : public QUndoCommand {
+// The classes UndoRemoveDivesFromTrip, UndoRemoveAutogenTrips, UndoCreateTrip,
+// UndoAutogroupDives and UndoMergeTrips all do the same thing, just the intialization
+// differs. Therefore, define a base class with the proper data-structures, redo()
+// and undo() functions and derive to specialize the initialization.
+class UndoTripBase : public QUndoCommand {
Q_DECLARE_TR_FUNCTIONS(Command)
-public:
- UndoRemoveDivesFromTrip(const QVector<dive *> &divesToRemove);
-private:
+protected:
void undo() override;
void redo() override;
- // For redo
- QVector<dive *> divesToRemove;
-
- // For undo
- std::vector<std::pair<dive *, dive_trip *>> divesToAdd;
- std::vector<OwningTripPtr> tripsToAdd;
+ // For redo and undo
+ DivesToTrip divesToMove;
+};
+struct UndoRemoveDivesFromTrip : public UndoTripBase {
+ UndoRemoveDivesFromTrip(const QVector<dive *> &divesToRemove);
+};
+struct UndoRemoveAutogenTrips : public UndoTripBase {
+ UndoRemoveAutogenTrips();
+};
+struct UndoAddDivesToTrip : public UndoTripBase {
+ UndoAddDivesToTrip(const QVector<dive *> &divesToAdd, dive_trip *trip);
+};
+struct UndoCreateTrip : public UndoTripBase {
+ UndoCreateTrip(const QVector<dive *> &divesToAdd);
+};
+struct UndoAutogroupDives : public UndoTripBase {
+ UndoAutogroupDives();
+};
+struct UndoMergeTrips : public UndoTripBase {
+ UndoMergeTrips(dive_trip *trip1, dive_trip *trip2);
};
class UndoSplitDives : public QUndoCommand {