mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
302f6adb79
commit
014c04f8bd
7 changed files with 220 additions and 50 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue