mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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:
parent
d293e968e9
commit
bf60d29e99
1 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue