2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-29 17:42:57 +00:00
|
|
|
#ifndef DIVEPICTUREMODEL_H
|
|
|
|
#define DIVEPICTUREMODEL_H
|
|
|
|
|
2018-07-15 15:56:18 +00:00
|
|
|
#include "core/units.h"
|
2020-04-17 21:18:58 +00:00
|
|
|
#include "core/pictureobj.h"
|
2018-07-15 15:56:18 +00:00
|
|
|
|
2015-05-29 17:42:57 +00:00
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <QImage>
|
|
|
|
|
pictures: turn QString into std::string for filenames
For undo of picture manipulation, it will be crucial that the
model and the core have the same order of pictures. The first
sort criterion will be time, the second filename in the case
that two pictures have, for whatever reason, the same timestamp.
However in the core we us C-strings and thus sort byte-wise
using strcmp. In the Qt-part we use QStrings, which sort according
to unicode encoding. To enable consistent sorting, change the
Qt-part to std::string, which uses a C-style 0-terminated string
as its backing store.
One might argue that in general filenames should use system-encoding
and therefore use std::string instead of QString. However, a
broader conversion to std::string turned out to be very painful,
since Qt is (deliberately?) difficult to use with std::string.
Notable all the file-manipulation functions don't take std::string
by default. Thus, this commit only converts the internal data
of DivePictureModel, but continues to use QString for the Qt-facing
interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 07:47:55 +00:00
|
|
|
// 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.
|
2020-04-14 20:14:23 +00:00
|
|
|
struct dive;
|
2017-12-09 23:07:46 +00:00
|
|
|
struct PictureEntry {
|
2020-04-14 20:14:23 +00:00
|
|
|
dive *d;
|
pictures: turn QString into std::string for filenames
For undo of picture manipulation, it will be crucial that the
model and the core have the same order of pictures. The first
sort criterion will be time, the second filename in the case
that two pictures have, for whatever reason, the same timestamp.
However in the core we us C-strings and thus sort byte-wise
using strcmp. In the Qt-part we use QStrings, which sort according
to unicode encoding. To enable consistent sorting, change the
Qt-part to std::string, which uses a C-style 0-terminated string
as its backing store.
One might argue that in general filenames should use system-encoding
and therefore use std::string instead of QString. However, a
broader conversion to std::string turned out to be very painful,
since Qt is (deliberately?) difficult to use with std::string.
Notable all the file-manipulation functions don't take std::string
by default. Thus, this commit only converts the internal data
of DivePictureModel, but continues to use QString for the Qt-facing
interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 07:47:55 +00:00
|
|
|
std::string filename;
|
2015-05-29 17:42:57 +00:00
|
|
|
QImage image;
|
|
|
|
int offsetSeconds;
|
2019-04-14 14:19:23 +00:00
|
|
|
duration_t length;
|
2020-04-17 21:18:58 +00:00
|
|
|
PictureEntry(dive *, const PictureObj &);
|
|
|
|
PictureEntry(dive *, const picture &);
|
|
|
|
bool operator<(const PictureEntry &) const;
|
2015-05-29 17:42:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DivePictureModel : public QAbstractTableModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static DivePictureModel *instance();
|
2018-09-29 20:13:44 +00:00
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2018-07-31 05:41:19 +00:00
|
|
|
void updateDivePictures();
|
2020-04-17 21:18:58 +00:00
|
|
|
void removePictures(const QModelIndexList &);
|
2017-12-17 15:17:38 +00:00
|
|
|
public slots:
|
|
|
|
void setZoomLevel(int level);
|
2018-07-15 15:56:18 +00:00
|
|
|
void updateThumbnail(QString filename, QImage thumbnail, duration_t duration);
|
2020-04-14 20:07:00 +00:00
|
|
|
void pictureOffsetChanged(dive *d, const QString filename, offset_t offset);
|
2020-04-17 21:18:58 +00:00
|
|
|
void picturesRemoved(dive *d, QVector<QString> filenames);
|
|
|
|
void picturesAdded(dive *d, QVector<PictureObj> pics);
|
2017-12-17 13:49:40 +00:00
|
|
|
private:
|
2015-05-29 17:42:57 +00:00
|
|
|
DivePictureModel();
|
2020-04-17 20:43:43 +00:00
|
|
|
std::vector<PictureEntry> pictures;
|
pictures: turn QString into std::string for filenames
For undo of picture manipulation, it will be crucial that the
model and the core have the same order of pictures. The first
sort criterion will be time, the second filename in the case
that two pictures have, for whatever reason, the same timestamp.
However in the core we us C-strings and thus sort byte-wise
using strcmp. In the Qt-part we use QStrings, which sort according
to unicode encoding. To enable consistent sorting, change the
Qt-part to std::string, which uses a C-style 0-terminated string
as its backing store.
One might argue that in general filenames should use system-encoding
and therefore use std::string instead of QString. However, a
broader conversion to std::string turned out to be very painful,
since Qt is (deliberately?) difficult to use with std::string.
Notable all the file-manipulation functions don't take std::string
by default. Thus, this commit only converts the internal data
of DivePictureModel, but continues to use QString for the Qt-facing
interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 07:47:55 +00:00
|
|
|
int findPictureId(const std::string &filename); // Return -1 if not found
|
2017-12-17 15:17:38 +00:00
|
|
|
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
|
2018-04-11 04:56:46 +00:00
|
|
|
int size;
|
2017-12-17 15:17:38 +00:00
|
|
|
void updateThumbnails();
|
2018-04-11 04:56:46 +00:00
|
|
|
void updateZoom();
|
2015-05-29 17:42:57 +00:00
|
|
|
};
|
|
|
|
|
2015-08-06 13:14:18 +00:00
|
|
|
#endif
|