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:
parent
3033bc680d
commit
6d8ccd2216
@ -29,8 +29,8 @@ private:
|
||||
|
||||
Ticks::Ticks(double minValue, double maxValue, int maxCount)
|
||||
{
|
||||
double range = niceNum(maxValue - minValue, false);
|
||||
_d = niceNum(range / maxCount, false);
|
||||
double range = Util::niceNum(maxValue - minValue, false);
|
||||
_d = Util::niceNum(range / maxCount, false);
|
||||
_min = ceil(minValue / _d) * _d;
|
||||
_max = floor(maxValue / _d) * _d;
|
||||
}
|
||||
|
@ -61,9 +61,9 @@ void ScaleItem::computeScale()
|
||||
qreal res = _res * pow(2, -_digitalZoom);
|
||||
|
||||
if (_units == Imperial) {
|
||||
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_length = Util::niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
|
||||
if (_length >= MIINFT) {
|
||||
_length = niceNum((res * M2MI * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_length = Util::niceNum((res * M2MI * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_width = (_length / (res * M2MI));
|
||||
_scale = true;
|
||||
} else {
|
||||
@ -71,9 +71,9 @@ void ScaleItem::computeScale()
|
||||
_scale = false;
|
||||
}
|
||||
} else if (_units == Nautical) {
|
||||
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_length = Util::niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, true);
|
||||
if (_length >= NMIINFT) {
|
||||
_length = niceNum((res * M2NMI * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_length = Util::niceNum((res * M2NMI * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_width = (_length / (res * M2NMI));
|
||||
_scale = true;
|
||||
} else {
|
||||
@ -81,7 +81,7 @@ void ScaleItem::computeScale()
|
||||
_scale = false;
|
||||
}
|
||||
} else {
|
||||
_length = niceNum((res * SCALE_WIDTH) / SEGMENTS, true);
|
||||
_length = Util::niceNum((res * SCALE_WIDTH) / SEGMENTS, true);
|
||||
if (_length >= KMINM) {
|
||||
_length *= M2KM;
|
||||
_width = (_length / (res * M2KM));
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <QFileInfo>
|
||||
#include "util.h"
|
||||
|
||||
|
||||
int str2int(const char *str, int len)
|
||||
int Util::str2int(const char *str, int len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
@ -17,7 +18,7 @@ int str2int(const char *str, int len)
|
||||
return res;
|
||||
}
|
||||
|
||||
double niceNum(double x, bool round)
|
||||
double Util::niceNum(double x, bool round)
|
||||
{
|
||||
int expv;
|
||||
double f;
|
||||
@ -48,3 +49,9 @@ double niceNum(double x, bool round)
|
||||
|
||||
return nf * pow(10.0, expv);
|
||||
}
|
||||
|
||||
QString Util::file2name(const QString &path)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
return fi.baseName().replace('_', ' ');
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Util
|
||||
{
|
||||
int str2int(const char *str, int len);
|
||||
double niceNum(double x, bool round);
|
||||
QString file2name(const QString &path);
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QImageReader>
|
||||
#include "common/tifffile.h"
|
||||
#include "common/util.h"
|
||||
#include "exifparser.h"
|
||||
|
||||
|
||||
@ -211,7 +212,7 @@ bool EXIFParser::parseTIFF(QFile *file, QVector<Waypoint> &waypoints)
|
||||
ImageInfo img(file->fileName(), QImageReader(file).size());
|
||||
|
||||
Waypoint wp(c);
|
||||
wp.setName(QFileInfo(file->fileName()).baseName());
|
||||
wp.setName(Util::file2name(file->fileName()));
|
||||
wp.addImage(img);
|
||||
wp.setElevation(altitude(tiff, GPSIFD.value(GPSAltitude),
|
||||
GPSIFD.value(GPSAltitudeRef)));
|
||||
|
@ -5,9 +5,9 @@
|
||||
|
||||
static bool readLat(const char *data, qreal &lat)
|
||||
{
|
||||
int d = str2int(data, 2);
|
||||
int mi = str2int(data + 2, 2);
|
||||
int mf = str2int(data + 4, 3);
|
||||
int d = Util::str2int(data, 2);
|
||||
int mi = Util::str2int(data + 2, 2);
|
||||
int mf = Util::str2int(data + 4, 3);
|
||||
if (d < 0 || mi < 0 || mf < 0)
|
||||
return false;
|
||||
|
||||
@ -26,9 +26,9 @@ static bool readLat(const char *data, qreal &lat)
|
||||
|
||||
static bool readLon(const char *data, qreal &lon)
|
||||
{
|
||||
int d = str2int(data, 3);
|
||||
int mi = str2int(data + 3, 2);
|
||||
int mf = str2int(data + 5, 3);
|
||||
int d = Util::str2int(data, 3);
|
||||
int mi = Util::str2int(data + 3, 2);
|
||||
int mf = Util::str2int(data + 5, 3);
|
||||
if (d < 0 || mi < 0 || mf < 0)
|
||||
return false;
|
||||
|
||||
@ -53,11 +53,11 @@ static bool readAltitude(const char *data, qreal &ele)
|
||||
return false;
|
||||
|
||||
if (data[6] == '-') {
|
||||
if ((ga = str2int(data + 7, 4)) < 0)
|
||||
if ((ga = Util::str2int(data + 7, 4)) < 0)
|
||||
return false;
|
||||
ga = -ga;
|
||||
} else {
|
||||
if ((ga = str2int(data + 6, 5)) < 0)
|
||||
if ((ga = Util::str2int(data + 6, 5)) < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -71,9 +71,9 @@ static bool readAltitude(const char *data, qreal &ele)
|
||||
|
||||
static bool readTimestamp(const char *data, QTime &time)
|
||||
{
|
||||
int h = str2int(data, 2);
|
||||
int m = str2int(data + 2, 2);
|
||||
int s = str2int(data + 4, 2);
|
||||
int h = Util::str2int(data, 2);
|
||||
int m = Util::str2int(data + 2, 2);
|
||||
int s = Util::str2int(data + 4, 2);
|
||||
|
||||
if (h < 0 || m < 0 || s < 0)
|
||||
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 d = str2int(line + offset, 2);
|
||||
int m = str2int(line + offset + 2, 2);
|
||||
int y = str2int(line + offset + 4, 2);
|
||||
int d = Util::str2int(line + offset, 2);
|
||||
int m = Util::str2int(line + offset + 2, 2);
|
||||
int y = Util::str2int(line + offset + 4, 2);
|
||||
|
||||
if (y < 0 || m < 0 || d < 0) {
|
||||
_errorString = "Invalid date header format";
|
||||
|
@ -71,14 +71,14 @@ bool NMEAParser::readTime(const char *data, int len, QTime &time)
|
||||
if (len < 6)
|
||||
goto error;
|
||||
|
||||
h = str2int(data, 2);
|
||||
m = str2int(data + 2, 2);
|
||||
s = str2int(data + 4, 2);
|
||||
h = Util::str2int(data, 2);
|
||||
m = Util::str2int(data + 2, 2);
|
||||
s = Util::str2int(data + 4, 2);
|
||||
if (h < 0 || m < 0 || s < 0)
|
||||
goto error;
|
||||
|
||||
if (len > 7 && data[6] == '.') {
|
||||
if ((ms = str2int(data + 7, len - 7)) < 0)
|
||||
if ((ms = Util::str2int(data + 7, len - 7)) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -106,9 +106,9 @@ bool NMEAParser::readDate(const char *data, int len, QDate &date)
|
||||
if (len < 6)
|
||||
goto error;
|
||||
|
||||
d = str2int(data, 2);
|
||||
m = str2int(data + 2, 2);
|
||||
y = str2int(data + 4, len - 4);
|
||||
d = Util::str2int(data, 2);
|
||||
m = Util::str2int(data + 2, 2);
|
||||
y = Util::str2int(data + 4, len - 4);
|
||||
if (d < 0 || m < 0 || y < 0)
|
||||
goto error;
|
||||
|
||||
@ -142,8 +142,8 @@ bool NMEAParser::readLat(const char *data, int len, qreal &lat)
|
||||
if (len < 7 || data[4] != '.')
|
||||
goto error;
|
||||
|
||||
d = str2int(data, 2);
|
||||
mi = str2int(data + 2, 2);
|
||||
d = Util::str2int(data, 2);
|
||||
mi = Util::str2int(data + 2, 2);
|
||||
mf = QString(QByteArray::fromRawData(data + 4, len - 4)).toFloat(&ok);
|
||||
if (d < 0 || mi < 0 || !ok)
|
||||
goto error;
|
||||
@ -192,8 +192,8 @@ bool NMEAParser::readLon(const char *data, int len, qreal &lon)
|
||||
if (len < 8 || data[5] != '.')
|
||||
goto error;
|
||||
|
||||
d = str2int(data, 3);
|
||||
mi = str2int(data + 3, 2);
|
||||
d = Util::str2int(data, 3);
|
||||
mi = Util::str2int(data + 3, 2);
|
||||
mf = QString(QByteArray::fromRawData(data + 5, len - 5)).toFloat(&ok);
|
||||
if (d < 0 || mi < 0 || !ok)
|
||||
goto error;
|
||||
@ -437,7 +437,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
|
||||
case 2:
|
||||
if (!(lp - vp))
|
||||
return true;
|
||||
if ((d = str2int(vp, lp - vp)) < 0) {
|
||||
if ((d = Util::str2int(vp, lp - vp)) < 0) {
|
||||
_errorString = "Invalid day";
|
||||
return false;
|
||||
}
|
||||
@ -445,7 +445,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
|
||||
case 3:
|
||||
if (!(lp - vp))
|
||||
return true;
|
||||
if ((m = str2int(vp, lp - vp)) < 0) {
|
||||
if ((m = Util::str2int(vp, lp - vp)) < 0) {
|
||||
_errorString = "Invalid month";
|
||||
return false;
|
||||
}
|
||||
@ -453,7 +453,7 @@ bool NMEAParser::readZDA(CTX &ctx, const char *line, int len)
|
||||
case 4:
|
||||
if (!(lp - vp))
|
||||
return true;
|
||||
if ((y = str2int(vp, lp - vp)) < 0) {
|
||||
if ((y = Util::str2int(vp, lp - vp)) < 0) {
|
||||
_errorString = "Invalid year";
|
||||
return false;
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ static double sDMS2deg(double val)
|
||||
QByteArray ba = qstr.toLatin1();
|
||||
const char *str = ba.constData();
|
||||
decimal = strrchr(str, '.');
|
||||
int deg = str2int(str, decimal - str);
|
||||
int min = str2int(decimal + 1, 2);
|
||||
int sec = str2int(decimal + 3, 2);
|
||||
int f = str2int(decimal + 5, 3);
|
||||
int deg = Util::str2int(str, decimal - str);
|
||||
int min = Util::str2int(decimal + 1, 2);
|
||||
int sec = Util::str2int(decimal + 3, 2);
|
||||
int f = Util::str2int(decimal + 5, 3);
|
||||
|
||||
angle = deg + min/60.0 + sec/3600.0 + (f/1000.0)/3600.0;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QImageReader>
|
||||
#include "common/util.h"
|
||||
#include "geotiff.h"
|
||||
#include "image.h"
|
||||
#include "geotiffmap.h"
|
||||
@ -33,12 +34,6 @@ GeoTIFFMap::~GeoTIFFMap()
|
||||
delete _img;
|
||||
}
|
||||
|
||||
QString GeoTIFFMap::name() const
|
||||
{
|
||||
QFileInfo fi(path());
|
||||
return fi.fileName();
|
||||
}
|
||||
|
||||
QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
|
||||
|
@ -15,8 +15,6 @@ public:
|
||||
GeoTIFFMap(const QString &fileName, QObject *parent = 0);
|
||||
~GeoTIFFMap();
|
||||
|
||||
QString name() const;
|
||||
|
||||
QRectF bounds();
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QPixmapCache>
|
||||
#include "common/config.h"
|
||||
#include "common/util.h"
|
||||
#include "rectd.h"
|
||||
#include "gcs.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),
|
||||
_valid(false)
|
||||
{
|
||||
_name = QFileInfo(fileName).fileName();
|
||||
_projection = Projection(GCS::gcs(4326));
|
||||
|
||||
if (!_file.open(QIODevice::ReadOnly)) {
|
||||
|
@ -17,8 +17,6 @@ public:
|
||||
public:
|
||||
JNXMap(const QString &fileName, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
QRectF bounds();
|
||||
RectC llBounds() {return _bounds;}
|
||||
|
||||
@ -66,7 +64,6 @@ private:
|
||||
static bool cb(Tile *tile, void *context);
|
||||
static QPixmap pixmap(const Tile *tile, QFile *file);
|
||||
|
||||
QString _name;
|
||||
QFile _file;
|
||||
QVector<Zoom> _zooms;
|
||||
int _zoom;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <QBuffer>
|
||||
#include <QPainter>
|
||||
#include <private/qzipreader_p.h>
|
||||
#include"common/util.h"
|
||||
#include "pcs.h"
|
||||
#include "image.h"
|
||||
#include "kmzmap.h"
|
||||
@ -339,12 +340,6 @@ KMZMap::KMZMap(const QString &fileName, QObject *parent)
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
QString KMZMap::name() const
|
||||
{
|
||||
QFileInfo fi(path());
|
||||
return fi.fileName();
|
||||
}
|
||||
|
||||
QRectF KMZMap::bounds()
|
||||
{
|
||||
QRectF rect;
|
||||
|
@ -17,8 +17,6 @@ class KMZMap : public Map
|
||||
public:
|
||||
KMZMap(const QString &fileName, QObject *parent = 0);
|
||||
|
||||
QString name() const;
|
||||
|
||||
QRectF bounds();
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QRectF>
|
||||
#include <QFlags>
|
||||
#include "common/rectc.h"
|
||||
#include "common/util.h"
|
||||
|
||||
|
||||
class QPainter;
|
||||
@ -28,7 +29,7 @@ public:
|
||||
virtual ~Map() {}
|
||||
|
||||
const QString &path() const {return _path;}
|
||||
virtual QString name() const = 0;
|
||||
virtual QString name() const {return Util::file2name(path());}
|
||||
|
||||
virtual RectC llBounds();
|
||||
virtual QRectF bounds() = 0;
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <QBuffer>
|
||||
#include <QtConcurrent>
|
||||
#include "common/rectc.h"
|
||||
#include "common/config.h"
|
||||
#include "common/util.h"
|
||||
#include "osm.h"
|
||||
#include "mbtilesmap.h"
|
||||
|
||||
@ -147,7 +147,7 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
_name = query.value(0).toString();
|
||||
else {
|
||||
qWarning("%s: missing map name", qPrintable(fileName));
|
||||
_name = QFileInfo(fileName).fileName();
|
||||
_name = Util::file2name(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,12 +256,6 @@ RMap::RMap(const QString &fileName, QObject *parent)
|
||||
_file.close();
|
||||
}
|
||||
|
||||
QString RMap::name() const
|
||||
{
|
||||
QFileInfo fi(path());
|
||||
return fi.baseName();
|
||||
}
|
||||
|
||||
QRectF RMap::bounds()
|
||||
{
|
||||
return QRectF(QPointF(0, 0), _zooms.at(_zoom).size / _mapRatio);
|
||||
|
@ -14,8 +14,6 @@ class RMap : public Map
|
||||
public:
|
||||
RMap(const QString &fileName, QObject *parent = 0);
|
||||
|
||||
QString name() const;
|
||||
|
||||
QRectF bounds();
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
|
Loading…
Reference in New Issue
Block a user