diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-05-19 21:18:39 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-05-21 22:17:28 +0300 |
commit | f47f2773fd4de5bfbb8d90e5e00dc18e0c18e5bb (patch) | |
tree | 2735961e5d272b79ce8ff81b8d6fd2197d00026b /qt-models/divepicturemodel.cpp | |
parent | 3c0c1801cd869f7a98c23356ab2ae4e373f55f31 (diff) | |
download | subsurface-f47f2773fd4de5bfbb8d90e5e00dc18e0c18e5bb.tar.gz |
Dive pictures: don't repopulate DivePictureModel on deletion
On deletion of a single or multiple pictures, the whole DivePictureModel
was repopulated, which was clearly visible in the UI, owing to the
reconstructing of all images in the profile plot.
To avoid this vexing behavior, implement proper deletion routines in
DivePictureModel and ProfileWidget2. Since this needs sensible erase()
semantics the QList<PictureEntry> member of DivePictureModel was
replaced by a QVector. A QVector should be the default anyway, unless
there are very specific reasons to use a QList (which actually is
a deque, not a classical linked list).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divepicturemodel.cpp')
-rw-r--r-- | qt-models/divepicturemodel.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index 3fa1a07f4..48fa652c9 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -149,7 +149,22 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrls) copy_dive(current_dive, &displayed_dive); mark_divelist_changed(true); - updateDivePictures(); + for (int i = 0; i < pictures.size(); ++i) { + // Find range [i j) of pictures to remove + if (std::find(fileUrls.begin(), fileUrls.end(), pictures[i].filename) == fileUrls.end()) + continue; + int j; + for (j = i + 1; j < pictures.size(); ++j) { + if (std::find(fileUrls.begin(), fileUrls.end(), pictures[j].filename) == fileUrls.end()) + break; + } + + // Qt's model-interface is surprisingly idiosyncratic: you don't pass [first last), but [first last] ranges. + // For example, an empty list would be [0 -1]. + beginRemoveRows(QModelIndex(), i, j - 1); + pictures.erase(pictures.begin() + i, pictures.begin() + j); + endRemoveRows(); + } } int DivePictureModel::rowCount(const QModelIndex &parent) const |