mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Do not make unnecessary checks when loading IMG maps and TrekBuddy atlases
This commit is contained in:
parent
ca0089e486
commit
e7d6c3f76a
@ -149,18 +149,3 @@ GMAPData::~GMAPData()
|
||||
{
|
||||
qDeleteAll(_files);
|
||||
}
|
||||
|
||||
bool GMAPData::isGMAP(const QString &path)
|
||||
{
|
||||
QFile file(path);
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
return false;
|
||||
|
||||
QXmlStreamReader reader(&file);
|
||||
if (reader.readNextStartElement()
|
||||
&& reader.name() == QLatin1String("MapProduct"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ public:
|
||||
GMAPData(const QString &fileName);
|
||||
~GMAPData();
|
||||
|
||||
static bool isGMAP(const QString &path);
|
||||
|
||||
private:
|
||||
bool readXML(const QString &path, QString &dataDir, QString &typFile,
|
||||
QString &baseMap);
|
||||
|
@ -77,25 +77,23 @@ void Atlas::computeBounds()
|
||||
QRectF(offsets.at(i), _maps.at(i)->bounds().size()));
|
||||
}
|
||||
|
||||
Atlas::Atlas(const QString &fileName, QObject *parent)
|
||||
Atlas::Atlas(const QString &fileName, bool TAR, QObject *parent)
|
||||
: Map(fileName, parent), _zoom(0), _mapIndex(-1), _valid(false)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
QByteArray ba;
|
||||
QString suffix = fi.suffix().toLower();
|
||||
Tar tar(fileName);
|
||||
|
||||
|
||||
_name = fi.dir().dirName();
|
||||
|
||||
if (suffix == "tar") {
|
||||
if (TAR) {
|
||||
if (!tar.open()) {
|
||||
_errorString = "Error reading tar file";
|
||||
return;
|
||||
}
|
||||
QString tbaFileName = fi.completeBaseName() + ".tba";
|
||||
ba = tar.file(tbaFileName);
|
||||
} else if (suffix == "tba") {
|
||||
} else {
|
||||
QFile tbaFile(fileName);
|
||||
if (!tbaFile.open(QIODevice::ReadOnly)) {
|
||||
_errorString = QString("Error opening tba file: %1")
|
||||
@ -293,10 +291,18 @@ void Atlas::unload()
|
||||
_maps.at(i)->unload();
|
||||
}
|
||||
|
||||
Map *Atlas::create(const QString &path, const Projection &, bool *isDir)
|
||||
Map *Atlas::createTAR(const QString &path, const Projection &, bool *isDir)
|
||||
{
|
||||
if (isDir)
|
||||
*isDir = true;
|
||||
|
||||
return new Atlas(path);
|
||||
return new Atlas(path, true);
|
||||
}
|
||||
|
||||
Map *Atlas::createTBA(const QString &path, const Projection &, bool *isDir)
|
||||
{
|
||||
if (isDir)
|
||||
*isDir = true;
|
||||
|
||||
return new Atlas(path, false);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class Atlas : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Atlas(const QString &fileName, QObject *parent = 0);
|
||||
Atlas(const QString &fileName, bool TAR, QObject *parent = 0);
|
||||
|
||||
QString name() const {return _name;}
|
||||
|
||||
@ -34,7 +34,8 @@ public:
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
|
||||
static Map *create(const QString &path, const Projection &, bool *isDir);
|
||||
static Map *createTAR(const QString &path, const Projection &, bool *isDir);
|
||||
static Map *createTBA(const QString &path, const Projection &, bool *isDir);
|
||||
|
||||
private:
|
||||
struct Zoom {
|
||||
|
@ -40,11 +40,11 @@ static QList<MapData*> overlays(const QString &fileName)
|
||||
return list;
|
||||
}
|
||||
|
||||
IMGMap::IMGMap(const QString &fileName, QObject *parent)
|
||||
IMGMap::IMGMap(const QString &fileName, bool GMAP, QObject *parent)
|
||||
: Map(fileName, parent), _projection(PCS::pcs(3857)), _tileRatio(1.0),
|
||||
_valid(false)
|
||||
{
|
||||
if (GMAPData::isGMAP(fileName))
|
||||
if (GMAP)
|
||||
_data.append(new GMAPData(fileName));
|
||||
else {
|
||||
_data.append(new IMGData(fileName));
|
||||
@ -291,10 +291,18 @@ void IMGMap::setOutputProjection(const Projection &projection)
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
Map* IMGMap::create(const QString &path, const Projection &, bool *isDir)
|
||||
Map* IMGMap::createIMG(const QString &path, const Projection &, bool *isDir)
|
||||
{
|
||||
if (isDir)
|
||||
*isDir = GMAPData::isGMAP(path);
|
||||
*isDir = false;
|
||||
|
||||
return new IMGMap(path);
|
||||
return new IMGMap(path, false);
|
||||
}
|
||||
|
||||
Map* IMGMap::createGMAP(const QString &path, const Projection &, bool *isDir)
|
||||
{
|
||||
if (isDir)
|
||||
*isDir = true;
|
||||
|
||||
return new IMGMap(path, true);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class IMGMap : public Map
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IMGMap(const QString &fileName, QObject *parent = 0);
|
||||
IMGMap(const QString &fileName, bool GMAP, QObject *parent = 0);
|
||||
~IMGMap() {qDeleteAll(_data);}
|
||||
|
||||
QString name() const {return _data.first()->name();}
|
||||
@ -79,7 +79,8 @@ public:
|
||||
bool isValid() const {return _valid;}
|
||||
QString errorString() const {return _errorString;}
|
||||
|
||||
static Map* create(const QString &path, const Projection &, bool *isDir);
|
||||
static Map* createIMG(const QString &path, const Projection &, bool *isDir);
|
||||
static Map* createGMAP(const QString &path, const Projection &, bool *isDir);
|
||||
|
||||
private slots:
|
||||
void jobFinished(IMGMapJob *job);
|
||||
|
@ -24,12 +24,12 @@ MapList::ParserMap MapList::parsers()
|
||||
{
|
||||
MapList::ParserMap map;
|
||||
|
||||
map.insert("tar", &Atlas::create);
|
||||
map.insert("tar", &Atlas::createTAR);
|
||||
map.insert("tar", &OziMap::create);
|
||||
map.insert("tba", &Atlas::create);
|
||||
map.insert("tba", &Atlas::createTBA);
|
||||
map.insert("xml", &MapSource::create);
|
||||
map.insert("xml", &IMGMap::create);
|
||||
map.insert("img", &IMGMap::create);
|
||||
map.insert("xml", &IMGMap::createGMAP);
|
||||
map.insert("img", &IMGMap::createIMG);
|
||||
map.insert("jnx", &JNXMap::create);
|
||||
map.insert("tif", &GeoTIFFMap::create);
|
||||
map.insert("tiff", &GeoTIFFMap::create);
|
||||
|
Loading…
Reference in New Issue
Block a user