1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Unified path -> name conversion

This commit is contained in:
Martin Tůma 2021-01-17 19:33:06 +01:00
parent 3033bc680d
commit 6d8ccd2216
18 changed files with 65 additions and 76 deletions

View File

@ -29,8 +29,8 @@ private:
Ticks::Ticks(double minValue, double maxValue, int maxCount) Ticks::Ticks(double minValue, double maxValue, int maxCount)
{ {
double range = niceNum(maxValue - minValue, false); double range = Util::niceNum(maxValue - minValue, false);
_d = niceNum(range / maxCount, false); _d = Util::niceNum(range / maxCount, false);
_min = ceil(minValue / _d) * _d; _min = ceil(minValue / _d) * _d;
_max = floor(maxValue / _d) * _d; _max = floor(maxValue / _d) * _d;
} }

View File

@ -61,9 +61,9 @@ void ScaleItem::computeScale()
qreal res = _res * pow(2, -_digitalZoom); qreal res = _res * pow(2, -_digitalZoom);
if (_units == Imperial) { if (_units == Imperial) {
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true); _length = Util::niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
if (_length >= MIINFT) { if (_length >= MIINFT) {
_length = niceNum((res * M2MI * SCALE_WIDTH) / SEGMENTS, true); _length = Util::niceNum((res * M2MI * SCALE_WIDTH) / SEGMENTS, true);
_width = (_length / (res * M2MI)); _width = (_length / (res * M2MI));
_scale = true; _scale = true;
} else { } else {
@ -71,9 +71,9 @@ void ScaleItem::computeScale()
_scale = false; _scale = false;
} }
} else if (_units == Nautical) { } else if (_units == Nautical) {
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true); _length = Util::niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
if (_length >= NMIINFT) { if (_length >= NMIINFT) {
_length = niceNum((res * M2NMI * SCALE_WIDTH) / SEGMENTS, true); _length = Util::niceNum((res * M2NMI * SCALE_WIDTH) / SEGMENTS, true);
_width = (_length / (res * M2NMI)); _width = (_length / (res * M2NMI));
_scale = true; _scale = true;
} else { } else {
@ -81,7 +81,7 @@ void ScaleItem::computeScale()
_scale = false; _scale = false;
} }
} else { } else {
_length = niceNum((res * SCALE_WIDTH) / SEGMENTS, true); _length = Util::niceNum((res * SCALE_WIDTH) / SEGMENTS, true);
if (_length >= KMINM) { if (_length >= KMINM) {
_length *= M2KM; _length *= M2KM;
_width = (_length / (res * M2KM)); _width = (_length / (res * M2KM));

View File

@ -1,9 +1,10 @@
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
#include <QFileInfo>
#include "util.h" #include "util.h"
int str2int(const char *str, int len) int Util::str2int(const char *str, int len)
{ {
int res = 0; int res = 0;
@ -17,7 +18,7 @@ int str2int(const char *str, int len)
return res; return res;
} }
double niceNum(double x, bool round) double Util::niceNum(double x, bool round)
{ {
int expv; int expv;
double f; double f;
@ -48,3 +49,9 @@ double niceNum(double x, bool round)
return nf * pow(10.0, expv); return nf * pow(10.0, expv);
} }
QString Util::file2name(const QString &path)
{
QFileInfo fi(path);
return fi.baseName().replace('_', ' ');
}

View File

@ -1,7 +1,13 @@
#ifndef UTIL_H #ifndef UTIL_H
#define UTIL_H #define UTIL_H
int str2int(const char *str, int len); #include <QString>
double niceNum(double x, bool round);
namespace Util
{
int str2int(const char *str, int len);
double niceNum(double x, bool round);
QString file2name(const QString &path);
}
#endif // UTIL_H #endif // UTIL_H

View File

@ -2,6 +2,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QImageReader> #include <QImageReader>
#include "common/tifffile.h" #include "common/tifffile.h"
#include "common/util.h"
#include "exifparser.h" #include "exifparser.h"
@ -211,7 +212,7 @@ bool EXIFParser::parseTIFF(QFile *file, QVector<Waypoint> &waypoints)
ImageInfo img(file->fileName(), QImageReader(file).size()); ImageInfo img(file->fileName(), QImageReader(file).size());
Waypoint wp(c); Waypoint wp(c);
wp.setName(QFileInfo(file->fileName()).baseName()); wp.setName(Util::file2name(file->fileName()));
wp.addImage(img); wp.addImage(img);
wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude), wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude),
GPSIFD.value(GPSAltitudeRef))); GPSIFD.value(GPSAltitudeRef)));

View File

@ -5,9 +5,9 @@
static bool readLat(const char *data, qreal &lat) static bool readLat(const char *data, qreal &lat)
{ {
int d = str2int(data, 2); int d = Util::str2int(data, 2);
int mi = str2int(data + 2, 2); int mi = Util::str2int(data + 2, 2);
int mf = str2int(data + 4, 3); int mf = Util::str2int(data + 4, 3);
if (d < 0 || mi < 0 || mf < 0) if (d < 0 || mi < 0 || mf < 0)
return false; return false;
@ -26,9 +26,9 @@ static bool readLat(const char *data, qreal &lat)
static bool readLon(const char *data, qreal &lon) static bool readLon(const char *data, qreal &lon)
{ {
int d = str2int(data, 3); int d = Util::str2int(data, 3);
int mi = str2int(data + 3, 2); int mi = Util::str2int(data + 3, 2);
int mf = str2int(data + 5, 3); int mf = Util::str2int(data + 5, 3);
if (d < 0 || mi < 0 || mf < 0) if (d < 0 || mi < 0 || mf < 0)
return false; return false;
@ -53,11 +53,11 @@ static bool readAltitude(const char *data, qreal &ele)
return false; return false;
if (data[6] == '-') { if (data[6] == '-') {
if ((ga = str2int(data + 7, 4)) < 0) if ((ga = Util::str2int(data + 7, 4)) < 0)
return false; return false;
ga = -ga; ga = -ga;
} else { } else {
if ((ga = str2int(data + 6, 5)) < 0) if ((ga = Util::str2int(data + 6, 5)) < 0)
return false; return false;
} }
@ -71,9 +71,9 @@ static bool readAltitude(const char *data, qreal &ele)
static bool readTimestamp(const char *data, QTime &time) static bool readTimestamp(const char *data, QTime &time)
{ {
int h = str2int(data, 2); int h = Util::str2int(data, 2);
int m = str2int(data + 2, 2); int m = Util::str2int(data + 2, 2);
int s = str2int(data + 4, 2); int s = Util::str2int(data + 4, 2);
if (h < 0 || m < 0 || s < 0) if (h < 0 || m < 0 || s < 0)
return false; return false;
@ -105,9 +105,9 @@ bool IGCParser::readHRecord(CTX &ctx, const char *line, int len)
int offset = (len < 16 || ::strncmp(line + 5, "DATE:", 5)) ? 5 : 10; int offset = (len < 16 || ::strncmp(line + 5, "DATE:", 5)) ? 5 : 10;
int d = str2int(line + offset, 2); int d = Util::str2int(line + offset, 2);
int m = str2int(line + offset + 2, 2); int m = Util::str2int(line + offset + 2, 2);
int y = str2int(line + offset + 4, 2); int y = Util::str2int(line + offset + 4, 2);
if (y < 0 || m < 0 || d < 0) { if (y < 0 || m < 0 || d < 0) {
_errorString = "Invalid date header format"; _errorString = "Invalid date header format";

View File

@ -71,14 +71,14 @@ bool NMEAParser::readTime(const char *data, int len, QTime &time)
if (len < 6) if (len < 6)
goto error; goto error;
h = str2int(data, 2); h = Util::str2int(data, 2);
m = str2int(data + 2, 2); m = Util::str2int(data + 2, 2);
s = str2int(data + 4, 2); s = Util::str2int(data + 4, 2);
if (h < 0 || m < 0 || s < 0) if (h < 0 || m < 0 || s < 0)
goto error; goto error;
if (len > 7 && data[6] == '.') { if (len > 7 && data[6] == '.') {
if ((ms = str2int(data + 7, len - 7)) < 0) if ((ms = Util::str2int(data + 7, len - 7)) < 0)
goto error; goto error;
} }
@ -106,9 +106,9 @@ bool NMEAParser::readDate(const char *data, int len, QDate &date)
if (len < 6) if (len < 6)
goto error; goto error;
d = str2int(data, 2); d = Util::str2int(data, 2);
m = str2int(data + 2, 2); m = Util::str2int(data + 2, 2);
y = str2int(data + 4, len - 4); y = Util::str2int(data + 4, len - 4);
if (d < 0 || m < 0 || y < 0) if (d < 0 || m < 0 || y < 0)
goto error; goto error;
@ -142,8 +142,8 @@ bool NMEAParser::readLat(const char *data, int len, qreal &lat)
if (len < 7 || data[4] != '.') if (len < 7 || data[4] != '.')
goto error; goto error;
d = str2int(data, 2); d = Util::str2int(data, 2);
mi = str2int(data + 2, 2); mi = Util::str2int(data + 2, 2);
mf = QString(QByteArray::fromRawData(data + 4, len - 4)).toFloat(&ok); mf = QString(QByteArray::fromRawData(data + 4, len - 4)).toFloat(&ok);
if (d < 0 || mi < 0 || !ok) if (d < 0 || mi < 0 || !ok)
goto error; goto error;
@ -192,8 +192,8 @@ bool NMEAParser::readLon(const char *data, int len, qreal &lon)
if (len < 8 || data[5] != '.') if (len < 8 || data[5] != '.')
goto error; goto error;
d = str2int(data, 3); d = Util::str2int(data, 3);
mi = str2int(data + 3, 2); mi = Util::str2int(data + 3, 2);
mf = QString(QByteArray::fromRawData(data + 5, len - 5)).toFloat(&ok); mf = QString(QByteArray::fromRawData(data + 5, len - 5)).toFloat(&ok);
if (d < 0 || mi < 0 || !ok) if (d < 0 || mi < 0 || !ok)
goto error; goto error;
@ -437,7 +437,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
case 2: case 2:
if (!(lp - vp)) if (!(lp - vp))
return true; return true;
if ((d = str2int(vp, lp - vp)) < 0) { if ((d = Util::str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid day"; _errorString = "Invalid day";
return false; return false;
} }
@ -445,7 +445,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
case 3: case 3:
if (!(lp - vp)) if (!(lp - vp))
return true; return true;
if ((m = str2int(vp, lp - vp)) < 0) { if ((m = Util::str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid month"; _errorString = "Invalid month";
return false; return false;
} }
@ -453,7 +453,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
case 4: case 4:
if (!(lp - vp)) if (!(lp - vp))
return true; return true;
if ((y = str2int(vp, lp - vp)) < 0) { if ((y = Util::str2int(vp, lp - vp)) < 0) {
_errorString = "Invalid year"; _errorString = "Invalid year";
return false; return false;
} }

View File

@ -11,10 +11,10 @@ static double sDMS2deg(double val)
QByteArray ba = qstr.toLatin1(); QByteArray ba = qstr.toLatin1();
const char *str = ba.constData(); const char *str = ba.constData();
decimal = strrchr(str, '.'); decimal = strrchr(str, '.');
int deg = str2int(str, decimal - str); int deg = Util::str2int(str, decimal - str);
int min = str2int(decimal + 1, 2); int min = Util::str2int(decimal + 1, 2);
int sec = str2int(decimal + 3, 2); int sec = Util::str2int(decimal + 3, 2);
int f = str2int(decimal + 5, 3); int f = Util::str2int(decimal + 5, 3);
angle = deg + min/60.0 + sec/3600.0 + (f/1000.0)/3600.0; angle = deg + min/60.0 + sec/3600.0 + (f/1000.0)/3600.0;

View File

@ -1,6 +1,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QPainter> #include <QPainter>
#include <QImageReader> #include <QImageReader>
#include "common/util.h"
#include "geotiff.h" #include "geotiff.h"
#include "image.h" #include "image.h"
#include "geotiffmap.h" #include "geotiffmap.h"
@ -33,12 +34,6 @@ GeoTIFFMap::~GeoTIFFMap()
delete _img; delete _img;
} }
QString GeoTIFFMap::name() const
{
QFileInfo fi(path());
return fi.fileName();
}
QPointF GeoTIFFMap::ll2xy(const Coordinates &c) QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
{ {
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio; return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;

View File

@ -15,8 +15,6 @@ public:
GeoTIFFMap(const QString &fileName, QObject *parent = 0); GeoTIFFMap(const QString &fileName, QObject *parent = 0);
~GeoTIFFMap(); ~GeoTIFFMap();
QString name() const;
QRectF bounds(); QRectF bounds();
QPointF ll2xy(const Coordinates &c); QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p); Coordinates xy2ll(const QPointF &p);

View File

@ -2,7 +2,7 @@
#include <QPainter> #include <QPainter>
#include <QFileInfo> #include <QFileInfo>
#include <QPixmapCache> #include <QPixmapCache>
#include "common/config.h" #include "common/util.h"
#include "rectd.h" #include "rectd.h"
#include "gcs.h" #include "gcs.h"
#include "pcs.h" #include "pcs.h"
@ -134,7 +134,6 @@ JNXMap::JNXMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _file(fileName), _zoom(0), _mapRatio(1.0), : Map(fileName, parent), _file(fileName), _zoom(0), _mapRatio(1.0),
_valid(false) _valid(false)
{ {
_name = QFileInfo(fileName).fileName();
_projection = Projection(GCS::gcs(4326)); _projection = Projection(GCS::gcs(4326));
if (!_file.open(QIODevice::ReadOnly)) { if (!_file.open(QIODevice::ReadOnly)) {

View File

@ -17,8 +17,6 @@ public:
public: public:
JNXMap(const QString &fileName, QObject *parent = 0); JNXMap(const QString &fileName, QObject *parent = 0);
QString name() const {return _name;}
QRectF bounds(); QRectF bounds();
RectC llBounds() {return _bounds;} RectC llBounds() {return _bounds;}
@ -66,7 +64,6 @@ private:
static bool cb(Tile *tile, void *context); static bool cb(Tile *tile, void *context);
static QPixmap pixmap(const Tile *tile, QFile *file); static QPixmap pixmap(const Tile *tile, QFile *file);
QString _name;
QFile _file; QFile _file;
QVector<Zoom> _zooms; QVector<Zoom> _zooms;
int _zoom; int _zoom;

View File

@ -18,6 +18,7 @@
#include <QBuffer> #include <QBuffer>
#include <QPainter> #include <QPainter>
#include <private/qzipreader_p.h> #include <private/qzipreader_p.h>
#include"common/util.h"
#include "pcs.h" #include "pcs.h"
#include "image.h" #include "image.h"
#include "kmzmap.h" #include "kmzmap.h"
@ -339,12 +340,6 @@ KMZMap::KMZMap(const QString &fileName, QObject *parent)
_valid = true; _valid = true;
} }
QString KMZMap::name() const
{
QFileInfo fi(path());
return fi.fileName();
}
QRectF KMZMap::bounds() QRectF KMZMap::bounds()
{ {
QRectF rect; QRectF rect;

View File

@ -17,8 +17,6 @@ class KMZMap : public Map
public: public:
KMZMap(const QString &fileName, QObject *parent = 0); KMZMap(const QString &fileName, QObject *parent = 0);
QString name() const;
QRectF bounds(); QRectF bounds();
int zoom() const {return _zoom;} int zoom() const {return _zoom;}

View File

@ -6,6 +6,7 @@
#include <QRectF> #include <QRectF>
#include <QFlags> #include <QFlags>
#include "common/rectc.h" #include "common/rectc.h"
#include "common/util.h"
class QPainter; class QPainter;
@ -28,7 +29,7 @@ public:
virtual ~Map() {} virtual ~Map() {}
const QString &path() const {return _path;} const QString &path() const {return _path;}
virtual QString name() const = 0; virtual QString name() const {return Util::file2name(path());}
virtual RectC llBounds(); virtual RectC llBounds();
virtual QRectF bounds() = 0; virtual QRectF bounds() = 0;

View File

@ -8,7 +8,7 @@
#include <QBuffer> #include <QBuffer>
#include <QtConcurrent> #include <QtConcurrent>
#include "common/rectc.h" #include "common/rectc.h"
#include "common/config.h" #include "common/util.h"
#include "osm.h" #include "osm.h"
#include "mbtilesmap.h" #include "mbtilesmap.h"
@ -147,7 +147,7 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
_name = query.value(0).toString(); _name = query.value(0).toString();
else { else {
qWarning("%s: missing map name", qPrintable(fileName)); qWarning("%s: missing map name", qPrintable(fileName));
_name = QFileInfo(fileName).fileName(); _name = Util::file2name(fileName);
} }
} }

View File

@ -256,12 +256,6 @@ RMap::RMap(const QString &fileName, QObject *parent)
_file.close(); _file.close();
} }
QString RMap::name() const
{
QFileInfo fi(path());
return fi.baseName();
}
QRectF RMap::bounds() QRectF RMap::bounds()
{ {
return QRectF(QPointF(0, 0), _zooms.at(_zoom).size / _mapRatio); return QRectF(QPointF(0, 0), _zooms.at(_zoom).size / _mapRatio);

View File

@ -14,8 +14,6 @@ class RMap : public Map
public: public:
RMap(const QString &fileName, QObject *parent = 0); RMap(const QString &fileName, QObject *parent = 0);
QString name() const;
QRectF bounds(); QRectF bounds();
int zoom() const {return _zoom;} int zoom() const {return _zoom;}