mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
fe82cb32b9
commit
9962d47b56
2 changed files with 7 additions and 8 deletions
|
@ -52,7 +52,7 @@ void DivePictureModel::updateThumbnails()
|
||||||
void DivePictureModel::updateDivePictures()
|
void DivePictureModel::updateDivePictures()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
if (!pictures.isEmpty()) {
|
if (!pictures.empty()) {
|
||||||
pictures.clear();
|
pictures.clear();
|
||||||
Thumbnailer::instance()->clearWorkQueue();
|
Thumbnailer::instance()->clearWorkQueue();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ void DivePictureModel::updateDivePictures()
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
for_each_dive (i, dive) {
|
for_each_dive (i, dive) {
|
||||||
if (dive->selected) {
|
if (dive->selected) {
|
||||||
int first = pictures.count();
|
size_t first = pictures.size();
|
||||||
FOR_EACH_PICTURE(dive)
|
FOR_EACH_PICTURE(dive)
|
||||||
pictures.push_back({ dive, picture->filename, {}, picture->offset.seconds, {.seconds = 0}});
|
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);
|
copy_dive(current_dive, &displayed_dive);
|
||||||
mark_divelist_changed(true);
|
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
|
// Find range [i j) of pictures to remove
|
||||||
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[i].filename) == fileUrls.end())
|
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[i].filename) == fileUrls.end())
|
||||||
continue;
|
continue;
|
||||||
int j;
|
size_t j;
|
||||||
for (j = i + 1; j < pictures.size(); ++j) {
|
for (j = i + 1; j < pictures.size(); ++j) {
|
||||||
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[j].filename) == fileUrls.end())
|
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[j].filename) == fileUrls.end())
|
||||||
break;
|
break;
|
||||||
|
@ -162,12 +162,12 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrlsIn)
|
||||||
|
|
||||||
int DivePictureModel::rowCount(const QModelIndex&) const
|
int DivePictureModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
return pictures.count();
|
return (int)pictures.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DivePictureModel::findPictureId(const std::string &filename)
|
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)
|
if (pictures[i].filename == filename)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QFuture>
|
|
||||||
|
|
||||||
// We use std::string instead of QString to use the same character-encoding
|
// We use std::string instead of QString to use the same character-encoding
|
||||||
// as in the C core (UTF-8). This is crucial to guarantee the same sort-order.
|
// as in the C core (UTF-8). This is crucial to guarantee the same sort-order.
|
||||||
|
@ -36,7 +35,7 @@ public slots:
|
||||||
void pictureOffsetChanged(dive *d, const QString filename, offset_t offset);
|
void pictureOffsetChanged(dive *d, const QString filename, offset_t offset);
|
||||||
private:
|
private:
|
||||||
DivePictureModel();
|
DivePictureModel();
|
||||||
QVector<PictureEntry> pictures;
|
std::vector<PictureEntry> pictures;
|
||||||
int findPictureId(const std::string &filename); // Return -1 if not found
|
int findPictureId(const std::string &filename); // Return -1 if not found
|
||||||
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
|
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
|
||||||
int size;
|
int size;
|
||||||
|
|
Loading…
Add table
Reference in a new issue