diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-11-26 22:08:29 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-12-06 21:56:35 +0100 |
commit | 99b2de85b5f71ad7bfd57bda5f0fb3b595b2b94f (patch) | |
tree | ea4f1087d2cf9fca2df660d8a040c7cc55b51960 | |
parent | b6d5dacd51bb7fcab417c40a7aa48f0a63693621 (diff) | |
download | subsurface-99b2de85b5f71ad7bfd57bda5f0fb3b595b2b94f.tar.gz |
Dive list: fix off-by-two bug in DiveTripModel
Commit 911edfca712a046944de6d033cc4b8dd50cedfc3 changed the dive list
on desktop to update positions of trips when adding/removing dives.
A very unlikely case, but necessary for consistency.
For a trip to be moveable down, its index has to be one-less than
the maximum index, which is "items - 1". The code was doubly wrong:
it forget the "1" and checked for less-or-equal instead less-than.
Thus this was effectively an off-by-two error. Fix it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | qt-models/divetripmodel.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index ae7641ba2..7a76ffbdb 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -696,12 +696,13 @@ void DiveTripModel::topLevelChanged(int idx) // If that didn't change, try to move forward if (newIdx == idx) { - while (newIdx <= (int)items.size() && !dive_or_trip_less_than(items[idx].d_or_t, items[newIdx + 1].d_or_t)) + ++newIdx; + while (newIdx < (int)items.size() && !dive_or_trip_less_than(items[idx].d_or_t, items[newIdx].d_or_t)) ++newIdx; } // If index changed, move items - if (newIdx != idx) { + if (newIdx != idx && newIdx != idx + 1) { beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), newIdx); moveInVector(items, idx, idx + 1, newIdx); endMoveRows(); |