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>
This commit is contained in:
parent
b6d5dacd51
commit
99b2de85b5
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user