diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-09-23 21:22:48 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | f427226b3b605523bc8285dbdaaa7f6993af6e6a (patch) | |
tree | e025722f92883fbac72b3584d6b4fb301bb8a40d /desktop-widgets/divelistview.cpp | |
parent | 4fbb8ef399a356e0b1a7393311c22ca68c50a14d (diff) | |
download | subsurface-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/divelistview.cpp')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index e6cbbc78f..27b7e3ed9 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -671,7 +671,8 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset) dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>(); if (trip_a == trip_b || !trip_a || !trip_b) return; - combine_trips(trip_a, trip_b); + UndoMergeTrips *undoCommand = new UndoMergeTrips(trip_a, trip_b); + MainWindow::instance()->undoStack->push(undoCommand); rememberSelection(); reload(currentLayout, false); restoreSelection(); @@ -694,7 +695,7 @@ void DiveListView::removeFromTrip() //TODO: move this to C-code. int i; struct dive *d; - QVector<struct dive *> divesToRemove; + QVector<dive *> divesToRemove; for_each_dive (i, d) { if (d->selected && d->divetrip) divesToRemove.append(d); @@ -717,15 +718,16 @@ void DiveListView::newTripAbove() if (!d) // shouldn't happen as we only are setting up this action if this is a dive return; //TODO: port to c-code. - dive_trip_t *trip; int idx; rememberSelection(); - trip = create_and_hookup_trip_from_dive(d); + QVector<dive *> dives; for_each_dive (idx, d) { if (d->selected) - add_dive_to_trip(d, trip); + dives.append(d); } - trip->expanded = 1; + UndoCreateTrip *undoCommand = new UndoCreateTrip(dives); + MainWindow::instance()->undoStack->push(undoCommand); + reload(currentLayout, false); mark_divelist_changed(true); restoreSelection(); @@ -764,16 +766,16 @@ void DiveListView::addToTrip(int delta) rememberSelection(); - add_dive_to_trip(d, trip); + QVector<dive *> dives; if (d->selected) { // there are possibly other selected dives that we should add int idx; for_each_dive (idx, d) { if (d->selected) - add_dive_to_trip(d, trip); + dives.append(d); } } - trip->expanded = 1; - mark_divelist_changed(true); + UndoAddDivesToTrip *undoEntry = new UndoAddDivesToTrip(dives, trip); + MainWindow::instance()->undoStack->push(undoEntry); reload(currentLayout, false); restoreSelection(); |