Dive pictures: adjust rowDDEnd and rowDDStart on picture deletion

In DivePictureModel, rowDDEnd and rowDDStart specify the range of
pictures in the profile plot. Obviously, these have to be adjusted
when pictures are deleted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-06-28 20:11:39 +02:00 committed by Dirk Hohndel
parent d293e968e9
commit bf60d29e99

View file

@ -138,6 +138,14 @@ static bool removePictureFromSelectedDive(const char *fileUrl)
return false; 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) void DivePictureModel::removePictures(const QVector<QString> &fileUrls)
{ {
bool removed = false; bool removed = false;
@ -163,6 +171,12 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrls)
beginRemoveRows(QModelIndex(), i, j - 1); beginRemoveRows(QModelIndex(), i, j - 1);
pictures.erase(pictures.begin() + i, pictures.begin() + j); pictures.erase(pictures.begin() + i, pictures.begin() + j);
endRemoveRows(); 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);
} }
} }