diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-21 18:28:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 014c04f8bd30740e7711f3b3a01619fd27b5b613 (patch) | |
tree | 0f7e505cc36e377bed4e24fb6f94adc93db22fb2 /desktop-widgets/divelistview.cpp | |
parent | 302f6adb79681da3fe53336f1e4c7525f46fd47d (diff) | |
download | subsurface-014c04f8bd30740e7711f3b3a01619fd27b5b613.tar.gz |
Undo: implement rudimentary support for undo of dive-merging
For this, an output-parameter was added to the backend merge_dives()
function. When non-zero, instead of adding the merged dive to
the preferred trip, the preferred trip is returned to the caller.
Since the new UndoObject, just like the delete-dives UndoObject,
needs to remove/readd a set of dives, the corresponding functionality
was split-off in a helper function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 938a4e3e5..e6cbbc78f 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -611,21 +611,32 @@ static bool can_merge(const struct dive *a, const struct dive *b, enum asked_use void DiveListView::mergeDives() { int i; - struct dive *dive, *maindive = NULL; + struct dive *d; enum asked_user have_asked = NOTYET; - for_each_dive (i, dive) { - if (dive->selected) { - if (!can_merge(maindive, dive, &have_asked)) { - maindive = dive; - } else { - maindive = merge_two_dives(maindive, dive); - i--; // otherwise we skip a dive in the freshly changed list - } + // Collect a vector of batches of dives to merge (i.e. a vector of vector of dives) + QVector<QVector<dive *>> merge_batches; + QVector<dive *> current_batch; + for_each_dive (i, d) { + if (!d->selected) + continue; + if (current_batch.empty()) { + current_batch.append(d); + } else if (can_merge(current_batch.back(), d, &have_asked)) { + current_batch.append(d); + } else { + if (current_batch.count() > 1) + merge_batches.append(current_batch); + current_batch.clear(); } } - MainWindow::instance()->refreshProfile(); - MainWindow::instance()->refreshDisplay(); + if (current_batch.count() > 1) + merge_batches.append(current_batch); + + for (const QVector<dive *> &batch: merge_batches) { + UndoMergeDives *undoCommand = new UndoMergeDives(batch); + MainWindow::instance()->undoStack->push(undoCommand); + } } void DiveListView::splitDives() |