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

Optimized file access

This commit is contained in:
Martin Tůma 2019-03-15 19:39:52 +01:00
parent 2575ecf1d8
commit 3176a42aa5
6 changed files with 55 additions and 30 deletions

View File

@ -162,7 +162,8 @@ HEADERS += src/common/config.h \
src/map/rmap.h \ src/map/rmap.h \
src/map/calibrationpoint.h \ src/map/calibrationpoint.h \
src/map/color.h \ src/map/color.h \
src/data/exifparser.h src/data/exifparser.h \
src/data/imageinfo.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/common/coordinates.cpp \ src/common/coordinates.cpp \
src/common/rectc.cpp \ src/common/rectc.cpp \

View File

@ -9,33 +9,27 @@ void ToolTip::insert(const QString &key, const QString &value)
_list.append(KV(key, value)); _list.append(KV(key, value));
} }
QString ToolTip::toString() QString ToolTip::toString() const
{ {
QString html; QString html;
if (!_img.isNull()) { if (_img.isValid()) {
QImageReader r(_img);
QSize size(r.size());
if (size.isValid()) {
int width, height; int width, height;
if (_img.size().width() > _img.size().height()) {
if (size.width() > size.height()) { width = qMin(_img.size().width(), THUMBNAIL_MAX_SIZE);
width = qMin(size.width(), THUMBNAIL_MAX_SIZE); qreal ratio = _img.size().width() / (qreal)_img.size().height();
qreal ratio = (qreal)size.width() / (qreal)size.height();
height = (int)(width / ratio); height = (int)(width / ratio);
} else { } else {
height = qMin(size.height(), THUMBNAIL_MAX_SIZE); height = qMin(_img.size().height(), THUMBNAIL_MAX_SIZE);
qreal ratio = (qreal)size.height() / (qreal)size.width(); qreal ratio = _img.size().height() / (qreal)_img.size().width();
width = (int)(height / ratio); width = (int)(height / ratio);
} }
html += "<div align=\"center\">"; html += "<div align=\"center\">";
html += QString("<img src=\"file:%0\" width=\"%1\" height=\"%2\"/>") html += QString("<img src=\"file:%0\" width=\"%1\" height=\"%2\"/>")
.arg(_img, QString::number(width), QString::number(height)); .arg(_img.path(), QString::number(width), QString::number(height));
html += "</div>"; html += "</div>";
} }
}
if (!_list.isEmpty()) { if (!_list.isEmpty()) {
html += "<table>"; html += "<table>";

View File

@ -4,17 +4,18 @@
#include <QString> #include <QString>
#include <QList> #include <QList>
#include "common/kv.h" #include "common/kv.h"
#include "data/imageinfo.h"
class ToolTip class ToolTip
{ {
public: public:
void insert(const QString &key, const QString &value); void insert(const QString &key, const QString &value);
void setImage(const QString &img) {_img = img;} void setImage(const ImageInfo &image) {_img = image;}
QString toString(); QString toString() const;
private: private:
QList<KV> _list; QList<KV> _list;
QString _img; ImageInfo _img;
}; };
#endif // TOOLTIP_H #endif // TOOLTIP_H

View File

@ -1,5 +1,6 @@
#include <QDataStream> #include <QDataStream>
#include <QFileInfo> #include <QFileInfo>
#include <QImageReader>
#include "common/tifffile.h" #include "common/tifffile.h"
#include "exifparser.h" #include "exifparser.h"
@ -200,9 +201,12 @@ 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(QFileInfo(file->fileName()).baseName()); wp.setName(QFileInfo(file->fileName()).baseName());
wp.setImage(file->fileName()); wp.setImage(img);
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,

24
src/data/imageinfo.h Normal file
View File

@ -0,0 +1,24 @@
#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();}
private:
QString _path;
QSize _size;
};
#endif // IMAGEINFO_H

View File

@ -6,6 +6,7 @@
#include <QHash> #include <QHash>
#include <QDebug> #include <QDebug>
#include "common/coordinates.h" #include "common/coordinates.h"
#include "imageinfo.h"
class Waypoint class Waypoint
{ {
@ -17,7 +18,7 @@ public:
const Coordinates &coordinates() const {return _coordinates;} const Coordinates &coordinates() const {return _coordinates;}
const QString &name() const {return _name;} const QString &name() const {return _name;}
const QString &description() const {return _description;} const QString &description() const {return _description;}
const QString &image() const {return _image;} const ImageInfo &image() const {return _image;}
const QDateTime &timestamp() const {return _timestamp;} const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;} qreal elevation() const {return _elevation;}
@ -28,7 +29,7 @@ public:
{_description = description;} {_description = description;}
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 setImage(const QString &image) {_image = image;} void setImage(const ImageInfo &image) {_image = image;}
bool hasElevation() const {return !std::isnan(_elevation);} bool hasElevation() const {return !std::isnan(_elevation);}
@ -40,7 +41,7 @@ private:
Coordinates _coordinates; Coordinates _coordinates;
QString _name; QString _name;
QString _description; QString _description;
QString _image; ImageInfo _image;
QDateTime _timestamp; QDateTime _timestamp;
qreal _elevation; qreal _elevation;
}; };