diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-25 16:42:35 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 0cca36377b01fc10063ecc67f5471ce80d133991 (patch) | |
tree | ea578d41d66234cf848b0873f46f2140e1675107 /qt-models | |
parent | 3c6cdfd8c02e215f98986cbb74b33f58e47fe632 (diff) | |
download | subsurface-0cca36377b01fc10063ecc67f5471ce80d133991.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divetripmodel.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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<dive *> &divesIn } } +QVector<dive *> filterSelectedDives(const QVector<dive *> &dives) +{ + QVector<dive *> 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<dive *> &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<dive *> 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<dive *> &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<dive *> selectedDives = filterSelectedDives(dives); divesDeleted(trip, false, dives); divesAdded(trip, false, dives); + divesSelected(trip, selectedDives); } void DiveTripModel::divesSelected(dive_trip *trip, const QVector<dive *> &dives) |