core: turn picture-table into std::vector<>

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-30 15:00:28 +02:00 committed by bstoeger
parent 3cb04d230b
commit 9e3e0a5a05
29 changed files with 170 additions and 316 deletions

View file

@ -13,13 +13,6 @@
#include <QFileInfo>
#include <QPainter>
PictureEntry::PictureEntry(dive *dIn, const PictureObj &p) : d(dIn),
filename(p.filename),
offsetSeconds(p.offset.seconds),
length({ 0 })
{
}
PictureEntry::PictureEntry(dive *dIn, const picture &p) : d(dIn),
filename(p.filename),
offsetSeconds(p.offset.seconds),
@ -91,8 +84,8 @@ void DivePictureModel::updateDivePictures()
for (struct dive *dive: getDiveSelection()) {
size_t first = pictures.size();
FOR_EACH_PICTURE(dive)
pictures.push_back(PictureEntry(dive, *picture));
for (auto &picture: dive->pictures)
pictures.push_back(PictureEntry(dive, picture));
// Sort pictures of this dive by offset.
// Thus, the list will be sorted by (dive, offset).
@ -197,7 +190,7 @@ void DivePictureModel::picturesRemoved(dive *d, QVector<QString> filenamesIn)
}
// Assumes that pics is sorted!
void DivePictureModel::picturesAdded(dive *d, QVector<PictureObj> picsIn)
void DivePictureModel::picturesAdded(dive *d, QVector<picture> picsIn)
{
// We only display pictures of selected dives
if (!d->selected || picsIn.empty())
@ -206,7 +199,7 @@ void DivePictureModel::picturesAdded(dive *d, QVector<PictureObj> picsIn)
// Convert the picture-data into our own format
std::vector<PictureEntry> pics;
pics.reserve(picsIn.size());
for (const PictureObj &pic: picsIn)
for (const picture &pic: picsIn)
pics.push_back(PictureEntry(d, pic));
// Insert batch-wise to avoid too many reloads

View file

@ -2,8 +2,7 @@
#ifndef DIVEPICTUREMODEL_H
#define DIVEPICTUREMODEL_H
#include "core/units.h"
#include "core/pictureobj.h"
#include "core/picture.h"
#include <QAbstractTableModel>
#include <QImage>
@ -17,7 +16,6 @@ struct PictureEntry {
QImage image;
int offsetSeconds;
duration_t length;
PictureEntry(dive *, const PictureObj &);
PictureEntry(dive *, const picture &);
bool operator<(const PictureEntry &) const;
};
@ -36,7 +34,7 @@ public slots:
void updateThumbnail(QString filename, QImage thumbnail, duration_t duration);
void pictureOffsetChanged(dive *d, const QString filename, offset_t offset);
void picturesRemoved(dive *d, QVector<QString> filenames);
void picturesAdded(dive *d, QVector<PictureObj> pics);
void picturesAdded(dive *d, QVector<picture> pics);
private:
DivePictureModel();
std::vector<PictureEntry> pictures;

View file

@ -147,8 +147,8 @@ static int countPhotos(const struct dive *d)
const int bufperiod = 120; // A 2-min buffer period. Photos within 2 min of dive are assumed as
int diveTotaltime = dive_endtime(d) - d->when; // taken during the dive, not before/after.
int pic_offset, icon_index = 0;
FOR_EACH_PICTURE (d) { // Step through each of the pictures for this dive:
pic_offset = picture->offset.seconds;
for (auto &picture: d->pictures) { // Step through each of the pictures for this dive:
pic_offset = picture.offset.seconds;
if ((pic_offset < -bufperiod) | (pic_offset > diveTotaltime+bufperiod)) {
icon_index |= 0x02; // If picture is before/after the dive
// then set the appropriate bit ...
@ -378,7 +378,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
case PHOTOS:
// If there are photos, show one of the three photo icons: fish= photos during dive;
// sun=photos before/after dive; sun+fish=photos during dive as well as before/after
if (d->pictures.nr > 0)
if (!d->pictures.empty())
return getPhotoIcon(countPhotos(d));
break;
}