1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Read the image size only when actually needed

This commit is contained in:
Martin Tůma 2021-10-04 21:00:29 +02:00
parent 06dac47550
commit 3cfa5456e9
8 changed files with 19 additions and 55 deletions

View File

@ -226,7 +226,6 @@ HEADERS += src/common/config.h \
src/data/demloader.h \ src/data/demloader.h \
src/data/area.h \ src/data/area.h \
src/data/exifparser.h \ src/data/exifparser.h \
src/data/imageinfo.h \
src/data/csv.h \ src/data/csv.h \
src/data/cupparser.h \ src/data/cupparser.h \
src/data/gpiparser.h \ src/data/gpiparser.h \

View File

@ -2,38 +2,37 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileInfo> #include <QFileInfo>
#include <QMouseEvent> #include <QMouseEvent>
#include "data/imageinfo.h"
#include "thumbnail.h" #include "thumbnail.h"
static QSize thumbnailSize(const ImageInfo &img, int limit) static QSize thumbnailSize(const QSize &size, int limit)
{ {
int width, height; int width, height;
if (img.size().width() > img.size().height()) { if (size.width() > size.height()) {
width = qMin(img.size().width(), limit); width = qMin(size.width(), limit);
qreal ratio = img.size().width() / (qreal)img.size().height(); qreal ratio = size.width() / (qreal)size.height();
height = (int)(width / ratio); height = (int)(width / ratio);
} else { } else {
height = qMin(img.size().height(), limit); height = qMin(size.height(), limit);
qreal ratio = img.size().height() / (qreal)img.size().width(); qreal ratio = size.height() / (qreal)size.width();
width = (int)(height / ratio); width = (int)(height / ratio);
} }
return QSize(width, height); return QSize(width, height);
} }
Thumbnail::Thumbnail(const ImageInfo &img, int size, QWidget *parent) Thumbnail::Thumbnail(const QString &path, int limit, QWidget *parent)
: QLabel(parent) : QLabel(parent)
{ {
QImageReader reader(img.path()); QImageReader reader(path);
reader.setAutoTransform(true); reader.setAutoTransform(true);
reader.setScaledSize(thumbnailSize(img, size)); reader.setScaledSize(thumbnailSize(reader.size(), limit));
setPixmap(QPixmap::fromImage(reader.read())); setPixmap(QPixmap::fromImage(reader.read()));
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
_path = QFileInfo(img.path()).absoluteFilePath(); _path = QFileInfo(path).absoluteFilePath();
} }
void Thumbnail::mousePressEvent(QMouseEvent *event) void Thumbnail::mousePressEvent(QMouseEvent *event)

View File

@ -8,7 +8,7 @@ class ImageInfo;
class Thumbnail : public QLabel class Thumbnail : public QLabel
{ {
public: public:
Thumbnail(const ImageInfo &img, int size, QWidget *parent = 0); Thumbnail(const QString &path, int limit, QWidget *parent = 0);
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);

View File

@ -5,13 +5,12 @@
#include <QList> #include <QList>
#include <QVector> #include <QVector>
#include "common/kv.h" #include "common/kv.h"
#include "data/imageinfo.h"
class ToolTip class ToolTip
{ {
public: public:
const QList<KV<QString, QString> > &list() const {return _list;} const QList<KV<QString, QString> > &list() const {return _list;}
const QVector<ImageInfo> &images() const {return _images;} const QVector<QString> &images() const {return _images;}
bool isEmpty() const bool isEmpty() const
{ {
@ -31,14 +30,14 @@ public:
{ {
_list.append(KV<QString, QString>(key, value)); _list.append(KV<QString, QString>(key, value));
} }
void setImages(const QVector<ImageInfo> &images) void setImages(const QVector<QString> &images)
{ {
_images = images; _images = images;
} }
private: private:
QList<KV<QString, QString> > _list; QList<KV<QString, QString> > _list;
QVector<ImageInfo> _images; QVector<QString> _images;
}; };
#endif // TOOLTIP_H #endif // TOOLTIP_H

View File

@ -207,12 +207,9 @@ bool EXIFParser::parseTIFF(QFile *file, QVector<Waypoint> &waypoints)
return false; return false;
} }
file->reset();
ImageInfo img(file->fileName(), QImageReader(file).size());
Waypoint wp(c); Waypoint wp(c);
wp.setName(Util::file2name(file->fileName())); wp.setName(Util::file2name(file->fileName()));
wp.addImage(img); wp.addImage(file->fileName());
wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude), wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude),
GPSIFD.value(GPSAltitudeRef))); GPSIFD.value(GPSAltitudeRef)));
wp.setTimestamp(QDateTime(QDate::fromString(text(tiff, wp.setTimestamp(QDateTime(QDate::fromString(text(tiff,

View File

@ -434,7 +434,7 @@ static quint32 readImageInfo(DataStream &stream, Waypoint &waypoint,
imgFile.write(ba); imgFile.write(ba);
imgFile.close(); imgFile.close();
waypoint.addImage(ImageInfo(imgFile.fileName(), ir.size())); waypoint.addImage(imgFile.fileName());
} }
if (size + 5 != rh.size) if (size + 5 != rh.size)

View File

@ -1,29 +0,0 @@
#ifndef IMAGEINFO_H
#define IMAGEINFO_H
#include <QString>
#include <QSize>
class ImageInfo
{
public:
ImageInfo() {}
ImageInfo(const QString &path, const QSize &size)
: _path(path), _size(size) {}
const QString &path() const {return _path;}
const QSize &size() const {return _size;}
bool isValid() const {return _size.isValid() && !_path.isEmpty();}
bool operator==(const ImageInfo &other) const
{
return (_path == other._path);
}
private:
QString _path;
QSize _size;
};
#endif // IMAGEINFO_H

View File

@ -8,7 +8,6 @@
#include <QDebug> #include <QDebug>
#include "common/config.h" #include "common/config.h"
#include "common/coordinates.h" #include "common/coordinates.h"
#include "imageinfo.h"
#include "link.h" #include "link.h"
class Waypoint class Waypoint
@ -25,7 +24,7 @@ public:
const QString &comment() const {return _comment;} const QString &comment() const {return _comment;}
const QString &address() const {return _address;} const QString &address() const {return _address;}
const QString &phone() const {return _phone;} const QString &phone() const {return _phone;}
const QVector<ImageInfo> &images() const {return _images;} const QVector<QString> &images() const {return _images;}
const QVector<Link> &links() const {return _links;} const QVector<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;} const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;} qreal elevation() const {return _elevation;}
@ -42,7 +41,7 @@ public:
void setPhone(const QString &phone) {_phone = phone;} void setPhone(const QString &phone) {_phone = phone;}
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;} void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;} void setElevation(qreal elevation) {_elevation = elevation;}
void addImage(const ImageInfo &image) {_images.append(image);} void addImage(const QString &path) {_images.append(path);}
void addLink(const Link &link) {_links.append(link);} void addLink(const Link &link) {_links.append(link);}
bool hasElevation() const {return !std::isnan(_elevation);} bool hasElevation() const {return !std::isnan(_elevation);}
@ -62,7 +61,7 @@ private:
QString _comment; QString _comment;
QString _address; QString _address;
QString _phone; QString _phone;
QVector<ImageInfo> _images; QVector<QString> _images;
QVector<Link> _links; QVector<Link> _links;
QDateTime _timestamp; QDateTime _timestamp;
qreal _elevation; qreal _elevation;