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

Use the info we already have for calibration file type distinction

This commit is contained in:
Martin Tůma 2023-12-31 10:05:02 +01:00
parent 2541797e7d
commit 7860ce8acc
4 changed files with 46 additions and 32 deletions

View File

@ -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())

View File

@ -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);

View File

@ -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);
}

View File

@ -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;