From 0cca36377b01fc10063ecc67f5471ce80d133991 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 25 Aug 2018 16:42:35 +0200 Subject: Dive list: retain selection on moval of dives The current code cheats when it comes to move dives inside a trip or move dives between trips: Instead of using the *MoveRows() functionality, the dives are removed from and re-added to the respective trips. This loses the selection. Therefore, remember which of the moved dives are selected and select them manually after they are re-added. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'qt-models/divetripmodel.cpp') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 761a2ffa6..b6c69af0f 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -1075,6 +1075,16 @@ void DiveTripModel::divesChanged(dive_trip *trip, const QVector &divesIn } } +QVector filterSelectedDives(const QVector &dives) +{ + QVector res; + res.reserve(dives.size()); + for (dive *d: dives) + if (d->selected) + res.append(d); + return res; +} + void DiveTripModel::divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector &dives) { // Move dives between trips. This is an "interesting" problem, as we might @@ -1090,8 +1100,12 @@ void DiveTripModel::divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool return; // Cheating! + // Unfortunately, removing the dives means that their selection is lost. + // Thus, remember the selection and re-add it later. + QVector selectedDives = filterSelectedDives(dives); divesAdded(to, createTo, dives); divesDeleted(from, deleteFrom, dives); + divesSelected(to, selectedDives); } void DiveTripModel::divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector &dives) @@ -1104,8 +1118,12 @@ void DiveTripModel::divesTimeChanged(dive_trip *trip, timestamp_t delta, const Q // moved by the same delta. // Cheating! + // Unfortunately, removing the dives means that their selection is lost. + // Thus, remember the selection and re-add it later. + QVector selectedDives = filterSelectedDives(dives); divesDeleted(trip, false, dives); divesAdded(trip, false, dives); + divesSelected(trip, selectedDives); } void DiveTripModel::divesSelected(dive_trip *trip, const QVector &dives) -- cgit v1.2.3-70-g09d2