diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-09-30 00:01:24 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-03 10:01:13 -0700 |
commit | 00abc04913d8aef45be4e30f23d5ebc9914c8d54 (patch) | |
tree | 1a9d51c8680a6edb9278191510278d6ac8a62def /desktop-widgets/divelistview.cpp | |
parent | 7b196a5ef90ee96435ea762c7045ef47a6811a28 (diff) | |
download | subsurface-00abc04913d8aef45be4e30f23d5ebc9914c8d54.tar.gz |
cleanup: use getDiveSelection() to loop over selected dives
getDiveSelection() returns a vector of the selected dives.
Use that instead of looping over the dive table and checking
manually.
This removes a few lines of code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 0a95005a6..6fb1de077 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -609,16 +609,12 @@ static bool can_merge(const struct dive *a, const struct dive *b, enum asked_use void DiveListView::mergeDives() { - int i; - struct dive *d; enum asked_user have_asked = NOTYET; // 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; + for (dive *d: getDiveSelection()) { if (current_batch.empty()) { current_batch.append(d); } else if (can_merge(current_batch.back(), d, &have_asked)) { @@ -638,16 +634,7 @@ void DiveListView::mergeDives() void DiveListView::splitDives() { - int i; - struct dive *dive; - - // Let's collect the dives to be split first, so that we don't catch newly inserted dives! - QVector<struct dive *> dives; - for_each_dive (i, dive) { - if (dive->selected) - dives.append(dive); - } - for (struct dive *d: dives) + for (struct dive *d: getDiveSelection()) Command::splitDives(d, duration_t{-1}); } @@ -748,15 +735,7 @@ void DiveListView::addToTrip(int delta) // no dive, no trip? get me out of here return; - 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) - dives.append(d); - } - } - Command::addDivesToTrip(dives, trip); + Command::addDivesToTrip(QVector<dive *>::fromStdVector(getDiveSelection()), trip); } void DiveListView::markDiveInvalid() @@ -775,13 +754,7 @@ void DiveListView::deleteDive() if (!d) return; - int i; - QVector<struct dive*> deletedDives; - for_each_dive (i, d) { - if (d->selected) - deletedDives.append(d); - } - Command::deleteDive(deletedDives); + Command::deleteDive(QVector<dive *>::fromStdVector(getDiveSelection())); } void DiveListView::contextMenuEvent(QContextMenuEvent *event) |