From 7860ce8acc90c310bc78a2d8149ebecc5ed810c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 31 Dec 2023 10:05:02 +0100 Subject: [PATCH] Use the info we already have for calibration file type distinction --- src/map/atlas.cpp | 25 +++++++++++++++++-------- src/map/maplist.cpp | 2 +- src/map/ozimap.cpp | 39 +++++++++++++++++++++------------------ src/map/ozimap.h | 12 +++++++----- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/map/atlas.cpp b/src/map/atlas.cpp index 288b9449..ebe738ca 100644 --- a/src/map/atlas.cpp +++ b/src/map/atlas.cpp @@ -27,19 +27,25 @@ static bool yCmp(OziMap *m1, OziMap *m2) return TL(m1).y() > TL(m2).y(); } -static QString calibrationFile(const QString &path) +static QString calibrationFile(const QString &path, OziMap::CalibrationType &type) { QDir dir(path); - QFileInfoList files = dir.entryInfoList(QDir::Files); + QFileInfoList files(dir.entryInfoList(QDir::Files)); for (int i = 0; i < files.size(); i++) { const QFileInfo &fi = files.at(i); QString suffix(fi.suffix().toLower()); - if (suffix == "map" || suffix == "gmi") + if (suffix == "map") { + type = OziMap::MAP; return fi.absoluteFilePath(); + } else if (suffix == "gmi") { + type = OziMap::GMI; + return fi.absoluteFilePath(); + } } + type = OziMap::Unknown; return QString(); } @@ -141,16 +147,19 @@ Atlas::Atlas(const QString &fileName, bool TAR, const Projection &proj, QFileInfoList maps = zdir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); for (int i = 0; i < maps.count(); i++) { + QString path(maps.at(i).absoluteFilePath()); OziMap *map; + if (TAR) - map = new OziMap(maps.at(i).absoluteFilePath(), tar, proj, this); + map = new OziMap(path, tar, proj, this); else { - QString cf(calibrationFile(maps.at(i).absoluteFilePath())); + OziMap::CalibrationType type; + QString cf(calibrationFile(path, type)); if (cf.isNull()) { - _errorString = "No calibration file found"; - return; + qWarning("%s: no calibration file found", qPrintable(path)); + continue; } - map = new OziMap(cf, proj, this); + map = new OziMap(cf, type, proj, this); } if (map->isValid()) diff --git a/src/map/maplist.cpp b/src/map/maplist.cpp index 61867c75..d19f8010 100644 --- a/src/map/maplist.cpp +++ b/src/map/maplist.cpp @@ -43,7 +43,7 @@ MapList::ParserMap MapList::parsers() map.insert("rtmap", &RMap::create); map.insert("map", &MapsforgeMap::create); map.insert("map", &OziMap::createMAP); - map.insert("gmi", &OziMap::createMAP); + map.insert("gmi", &OziMap::createGMI); map.insert("kap", &BSBMap::create); map.insert("kmz", &KMZMap::create); map.insert("aqm", &AQMMap::create); diff --git a/src/map/ozimap.cpp b/src/map/ozimap.cpp index 1d93b50b..6b6e8e2e 100644 --- a/src/map/ozimap.cpp +++ b/src/map/ozimap.cpp @@ -54,16 +54,12 @@ QString OziMap::calibrationFile(const QStringList &files, const QString path, return QString(); } -OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent) - : Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), - _valid(false) +OziMap::OziMap(const QString &fileName, CalibrationType type, + const Projection &proj, QObject *parent) : Map(fileName, parent), _img(0), + _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0), _valid(false) { - QFileInfo fi(fileName); - QString suffix(fi.suffix().toLower()); - - if (suffix == "tar") { - CalibrationType type; - + // TAR maps + if (type == Unknown) { _tar = new Tar(fileName); if (!_tar->open()) { _errorString = "Error reading tar file: " + _tar->errorString(); @@ -110,10 +106,12 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent) return; _tar->close(); + + // regular MAP or GMI maps } else { QFile file(fileName); - if (suffix == "map") { + if (type == MAP) { MapFile mf(file); if (!mf.isValid()) { _errorString = mf.errorString(); @@ -125,7 +123,7 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent) _projection = mf.projection(); _transform = mf.transform(); } - } else if (suffix == "gmi") { + } else if (type == GMI) { GmiFile gmi(file); if (!gmi.isValid()) { _errorString = gmi.errorString(); @@ -138,11 +136,9 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent) _projection = proj; computeTransform(); } - } else { - _errorString = "Unknown file type"; - return; } + QFileInfo fi(fileName); QDir set(fi.absolutePath() + "/" + "set"); if (set.exists()) { if (!setTileInfo(set.entryList(), set.absolutePath())) @@ -373,8 +369,7 @@ void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const pixmap = QPixmap(tileName); if (pixmap.isNull()) - qWarning("%s: error loading tile image", qPrintable( - _tile.path.arg(QString::number(x), QString::number(y)))); + qWarning("%s: error loading tile image", qPrintable(tileName)); else { pixmap.setDevicePixelRatio(_mapRatio); QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height()); @@ -512,7 +507,7 @@ Map *OziMap::createTAR(const QString &path, const Projection &proj, bool *isDir) if (isDir) *isDir = false; - return new OziMap(path, proj); + return new OziMap(path, Unknown, proj); } Map *OziMap::createMAP(const QString &path, const Projection &proj, bool *isDir) @@ -520,5 +515,13 @@ Map *OziMap::createMAP(const QString &path, const Projection &proj, bool *isDir) if (isDir) *isDir = false; - return new OziMap(path, proj); + return new OziMap(path, MAP, proj); +} + +Map *OziMap::createGMI(const QString &path, const Projection &proj, bool *isDir) +{ + if (isDir) + *isDir = false; + + return new OziMap(path, GMI, proj); } diff --git a/src/map/ozimap.h b/src/map/ozimap.h index aeb9b3b0..aafe90fb 100644 --- a/src/map/ozimap.h +++ b/src/map/ozimap.h @@ -15,7 +15,11 @@ class OziMap : public Map Q_OBJECT public: - OziMap(const QString &fileName, const Projection &proj, + enum CalibrationType { + Unknown, MAP, GMI + }; + + OziMap(const QString &fileName, CalibrationType type, const Projection &proj, QObject *parent = 0); OziMap(const QString &dirName, Tar &tar, const Projection &proj, QObject *parent = 0); @@ -54,12 +58,10 @@ public: bool *isDir); static Map *createMAP(const QString &path, const Projection &proj, bool *isDir); + static Map *createGMI(const QString &path, const Projection &proj, + bool *isDir); private: - enum CalibrationType { - Unknown, MAP, GMI - }; - struct ImageInfo { QSize size; QString path;