summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_divelist.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-26 22:06:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-09 20:58:04 -0800
commit7df8d8c888cb8e1cdb12a171a4715c8f5af7c80d (patch)
tree1a397c5d9c448a8b6c0c3d5771fd7d981bc0b763 /desktop-widgets/command_divelist.h
parent517fb7a462c207e32cc7c5ed50e1e9b1f359dbd8 (diff)
downloadsubsurface-7df8d8c888cb8e1cdb12a171a4715c8f5af7c80d.tar.gz
Undo commands: refactor dive-trip handling
Trips were added to the core with the first dive of that trip. With the recent changes that keep trips ordered by first dive, this became counter-productive. Keeping a consistent state at all times would mean resorting the trip table for every dive that is added. Instead, add all dives to a trip and *then* add the trip to the core. Change the data-structures to not register trips-to-be-added with individual dives, but keep them in a separate vector for each undo command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_divelist.h')
-rw-r--r--desktop-widgets/command_divelist.h33
1 files changed, 19 insertions, 14 deletions
diff --git a/desktop-widgets/command_divelist.h b/desktop-widgets/command_divelist.h
index 29c9c6e7b..77116c302 100644
--- a/desktop-widgets/command_divelist.h
+++ b/desktop-widgets/command_divelist.h
@@ -15,11 +15,16 @@ namespace Command {
// 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
};
+// Multiple trips and dives that have to be added for a command
+struct DivesAndTripsToAdd {
+ std::vector<DiveToAdd> dives;
+ std::vector<OwningTripPtr> trips;
+};
+
// 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)
@@ -29,7 +34,7 @@ struct DiveToTrip
dive_trip *trip;
};
-// This helper structure describes a number of dives to add to /remove from /
+// 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
@@ -51,10 +56,10 @@ protected:
// These are helper functions to add / remove dive from the C-core structures,
// which set the selectionChanged flag if the added / removed dive was selected.
- DiveToAdd removeDive(struct dive *d);
+ DiveToAdd removeDive(struct dive *d, std::vector<OwningTripPtr> &tripsToAdd);
dive *addDive(DiveToAdd &d);
- std::vector<DiveToAdd> removeDives(std::vector<dive *> &divesToDelete);
- std::vector<dive *> addDives(std::vector<DiveToAdd> &divesToAdd);
+ DivesAndTripsToAdd removeDives(std::vector<dive *> &divesToDelete);
+ std::vector<dive *> addDives(DivesAndTripsToAdd &toAdd);
// Set the selection to a given state. Set the selectionChanged flag if anything changed.
void restoreSelection(const std::vector<dive *> &selection, dive *currentDive);
@@ -89,9 +94,9 @@ private:
bool workToBeDone() override;
// For redo
- // Note: we use a vector even though we add only a single dive, so
+ // Note: we a multi-dive structure even though we add only a single dive, so
// that we can reuse the multi-dive functions of the other commands.
- std::vector<DiveToAdd> divesToAdd;
+ DivesAndTripsToAdd divesToAdd;
// For undo
std::vector<dive *> divesToRemove;
@@ -111,7 +116,7 @@ private:
std::vector<struct dive*> divesToDelete;
std::vector<OwningTripPtr> tripsToAdd;
- std::vector<DiveToAdd> divesToAdd;
+ DivesAndTripsToAdd divesToAdd;
};
class ShiftTime : public DiveListBase {
@@ -185,13 +190,13 @@ private:
// Note: we use a vector even though we split only a single dive, so
// that we can reuse the multi-dive functions of the other commands.
std::vector<dive *> diveToSplit;
- std::vector<DiveToAdd> splitDives;
+ DivesAndTripsToAdd splitDives;
// For undo
// For each dive to unsplit, we remove two dives from and add one into the backend
- // Note: we use a vector even though we unsplit only a single dive, so
+ // Note: we use a multi-dive structure even though we unsplit only a single dive, so
// that we can reuse the multi-dive functions of the other commands.
- std::vector<DiveToAdd> unsplitDive;
+ DivesAndTripsToAdd unsplitDive;
std::vector<dive *> divesToUnsplit;
};
@@ -205,9 +210,9 @@ private:
// For redo
// Add one and remove a batch of dives
- // Note: we use a vector even though we add only a single dive, so
+ // Note: we use a multi-dives structure even though we add only a single dive, so
// that we can reuse the multi-dive functions of the other commands.
- std::vector<DiveToAdd> mergedDive;
+ DivesAndTripsToAdd mergedDive;
std::vector<dive *> divesToMerge;
// For undo
@@ -215,7 +220,7 @@ private:
// Note: we use a vector even though we remove only a single dive, so
// that we can reuse the multi-dive functions of the other commands.
std::vector<dive *> diveToUnmerge;
- std::vector<DiveToAdd> unmergedDives;
+ DivesAndTripsToAdd unmergedDives;
// For undo and redo
QVector<QPair<dive *, int>> divesToRenumber;