diff options
-rw-r--r-- | qt-models/divepicturemodel.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index 8c66f5974..541f88027 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -138,6 +138,14 @@ static bool removePictureFromSelectedDive(const char *fileUrl) return false; } +// Calculate how many items of a range are before the given index +static int rangeBefore(int rangeFrom, int rangeTo, int index) +{ + if (rangeTo <= rangeFrom) + return 0; + return std::min(rangeTo, index) - std::min(rangeFrom, index); +} + void DivePictureModel::removePictures(const QVector<QString> &fileUrls) { bool removed = false; @@ -163,6 +171,12 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrls) beginRemoveRows(QModelIndex(), i, j - 1); pictures.erase(pictures.begin() + i, pictures.begin() + j); endRemoveRows(); + + // After removing pictures, we have to adjust rowDDStart and rowDDEnd. + // Calculate the part of the range that is before rowDDStart and rowDDEnd, + // respectively and subtract accordingly. + rowDDStart -= rangeBefore(i, j, rowDDStart); + rowDDEnd -= rangeBefore(i, j, rowDDEnd); } } |