1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +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/calibrationpoint.h \
src/map/color.h \
src/data/exifparser.h
src/data/exifparser.h \
src/data/imageinfo.h
SOURCES += src/main.cpp \
src/common/coordinates.cpp \
src/common/rectc.cpp \

View File

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

View File

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

View File

@ -1,5 +1,6 @@
#include <QDataStream>
#include <QFileInfo>
#include <QImageReader>
#include "common/tifffile.h"
#include "exifparser.h"
@ -200,9 +201,12 @@ bool EXIFParser::parseTIFF(QFile *file, QVector<Waypoint> &waypoints)
return false;
}
file->reset();
ImageInfo img(file->fileName(), QImageReader(file).size());
Waypoint wp(c);
wp.setName(QFileInfo(file->fileName()).baseName());
wp.setImage(file->fileName());
wp.setImage(img);
wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude),
GPSIFD.value(GPSAltitudeRef)));
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 <QDebug>
#include "common/coordinates.h"
#include "imageinfo.h"
class Waypoint
{
@ -17,7 +18,7 @@ public:
const Coordinates &coordinates() const {return _coordinates;}
const QString &name() const {return _name;}
const QString &description() const {return _description;}
const QString &image() const {return _image;}
const ImageInfo &image() const {return _image;}
const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;}
@ -28,7 +29,7 @@ public:
{_description = description;}
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
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);}
@ -40,7 +41,7 @@ private:
Coordinates _coordinates;
QString _name;
QString _description;
QString _image;
ImageInfo _image;
QDateTime _timestamp;
qreal _elevation;
};