summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-06-28 20:11:39 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-06-29 13:30:48 +0800
commitbf60d29e99a7d201850766d9195a052599dfd018 (patch)
tree542ed73b80cd5b4007d5ee87552bca9bf914530a
parentd293e968e9398b0b34ae0aa104451e8ea25c4f7f (diff)
downloadsubsurface-4.8.0.tar.gz
Dive pictures: adjust rowDDEnd and rowDDStart on picture deletionv4.8.0
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>
-rw-r--r--qt-models/divepicturemodel.cpp14
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);
}
}