summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-02 14:50:12 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-02 14:50:12 -0400
commita94c84d5982a10cd9adfd421aed41cf159dd3303 (patch)
treeedbaea3f89cad4e03f4ed2126de3e0c4bb07c2a7 /qt-ui/divelistview.cpp
parent7c427dcc020064e0ea867c77ee86db6e1f4755bb (diff)
downloadsubsurface-a94c84d5982a10cd9adfd421aed41cf159dd3303.tar.gz
Undo/redo of dive deletion needs to handle trips as well
If we delete dives that were part of a trip, that trip may get deleted as well. So if we undo that operation we need to bring back the trip, too. This also deals with a bug in the original code that did the delete both in calling code (in divelistview.cpp) and in the redo function. Because of the nature of the delete this didn't really matter but it is of course wrong and with the new code it would in fact cause an issue. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp11
1 files changed, 2 insertions, 9 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 51720a317..d2386ecf1 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -776,23 +776,16 @@ void DiveListView::deleteDive()
if (!d)
return;
- //TODO: port this to C-code.
int i;
- // after a dive is deleted the ones following it move forward in the dive_table
- // so instead of using the for_each_dive macro I'm using an explicit for loop
- // to make this easier to understand
int lastDiveNr = -1;
QList<struct dive*> deletedDives; //a list of all deleted dives to be stored in the undo command
for_each_dive (i, d) {
if (!d->selected)
continue;
- struct dive* undo_entry = alloc_dive();
- copy_dive(get_dive(i), undo_entry);
- deletedDives.append(undo_entry);
- delete_single_dive(i);
- i--; // so the next dive isn't skipped... it's now #i
+ deletedDives.append(d);
lastDiveNr = i;
}
+ // the actual dive deletion is happening in the redo command that is implicitly triggered
UndoDeleteDive *undoEntry = new UndoDeleteDive(deletedDives);
MainWindow::instance()->undoStack->push(undoEntry);
if (amount_selected == 0) {