desktop: use getDiveSelection to access selected dives

In the list view two functions were still manually collecting
the selected dives. Use getDiveSelection() there as well.

Careful: that means that the check for dives that are already
outside of a trip now has to be done in the RemoveDivesFromTrip
command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-11-24 20:17:27 +01:00 committed by Dirk Hohndel
parent 369c5b0dc6
commit 16f86f2f65
2 changed files with 9 additions and 18 deletions

View file

@ -740,8 +740,14 @@ void TripBase::undoit()
redoit(); redoit();
} }
RemoveDivesFromTrip::RemoveDivesFromTrip(const QVector<dive *> &divesToRemove) RemoveDivesFromTrip::RemoveDivesFromTrip(const QVector<dive *> &divesToRemoveIn)
{ {
// Filter out dives outside of trip. Note: This is in a separate loop to get the command-description right.
QVector<dive *> divesToRemove;
for (dive *d: divesToRemoveIn) {
if (d->divetrip)
divesToRemove.push_back(d);
}
setText(QStringLiteral("%1 [%2]").arg(Command::Base::tr("remove %n dive(s) from trip", "", divesToRemove.size())).arg(getListOfDives(divesToRemove))); setText(QStringLiteral("%1 [%2]").arg(Command::Base::tr("remove %n dive(s) from trip", "", divesToRemove.size())).arg(getListOfDives(divesToRemove)));
divesToMove.divesToMove.reserve(divesToRemove.size()); divesToMove.divesToMove.reserve(divesToRemove.size());
for (dive *d: divesToRemove) { for (dive *d: divesToRemove) {

View file

@ -679,15 +679,7 @@ void DiveListView::mergeTripBelow()
void DiveListView::removeFromTrip() void DiveListView::removeFromTrip()
{ {
//TODO: move this to C-code. Command::removeDivesFromTrip(stdToQt(getDiveSelection()));
int i;
struct dive *d;
QVector<dive *> divesToRemove;
for_each_dive (i, d) {
if (d->selected && d->divetrip)
divesToRemove.append(d);
}
Command::removeDivesFromTrip(divesToRemove);
} }
void DiveListView::newTripAbove() void DiveListView::newTripAbove()
@ -695,14 +687,7 @@ void DiveListView::newTripAbove()
struct dive *d = contextMenuIndex.data(DiveTripModelBase::DIVE_ROLE).value<struct dive *>(); struct dive *d = contextMenuIndex.data(DiveTripModelBase::DIVE_ROLE).value<struct dive *>();
if (!d) // shouldn't happen as we only are setting up this action if this is a dive if (!d) // shouldn't happen as we only are setting up this action if this is a dive
return; return;
//TODO: port to c-code. Command::createTrip(stdToQt(getDiveSelection()));
int idx;
QVector<dive *> dives;
for_each_dive (idx, d) {
if (d->selected)
dives.append(d);
}
Command::createTrip(dives);
} }
void DiveListView::addToTripBelow() void DiveListView::addToTripBelow()