diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-17 22:43:43 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-06 13:58:09 -0700 |
commit | 9962d47b56eb15aba9339b22845566535c168483 (patch) | |
tree | 4101ffd5526b0a70b91e94216808cd4027ca14bc /qt-models/divepicturemodel.cpp | |
parent | fe82cb32b93e906b9bf53010538651b9c84df9db (diff) | |
download | subsurface-9962d47b56eb15aba9339b22845566535c168483.tar.gz |
media: turn DivePictureModel::pictures into std::vector
QVector doesn't have a function to insert a range of pictures,
which we will need for undo of image adding/deletion.
Moreover, std::vector gives us stronger guarantees. For example,
if capacity is large enough, it guarantees that there will be
no reallocation and thus iterators stay valid. I have not found
such a guarantee in the Qt docs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divepicturemodel.cpp')
-rw-r--r-- | qt-models/divepicturemodel.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index 548f8e7be..351396e5f 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -52,7 +52,7 @@ void DivePictureModel::updateThumbnails() void DivePictureModel::updateDivePictures() { beginResetModel(); - if (!pictures.isEmpty()) { + if (!pictures.empty()) { pictures.clear(); Thumbnailer::instance()->clearWorkQueue(); } @@ -61,7 +61,7 @@ void DivePictureModel::updateDivePictures() struct dive *dive; for_each_dive (i, dive) { if (dive->selected) { - int first = pictures.count(); + size_t first = pictures.size(); FOR_EACH_PICTURE(dive) pictures.push_back({ dive, picture->filename, {}, picture->offset.seconds, {.seconds = 0}}); @@ -141,11 +141,11 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrlsIn) copy_dive(current_dive, &displayed_dive); mark_divelist_changed(true); - for (int i = 0; i < pictures.size(); ++i) { + for (size_t 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; + size_t j; for (j = i + 1; j < pictures.size(); ++j) { if (std::find(fileUrls.begin(), fileUrls.end(), pictures[j].filename) == fileUrls.end()) break; @@ -162,12 +162,12 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrlsIn) int DivePictureModel::rowCount(const QModelIndex&) const { - return pictures.count(); + return (int)pictures.size(); } int DivePictureModel::findPictureId(const std::string &filename) { - for (int i = 0; i < pictures.size(); ++i) + for (int i = 0; i < (int)pictures.size(); ++i) if (pictures[i].filename == filename) return i; return -1; |