mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Cleanup the map loading code
This commit is contained in:
parent
8d06ab6208
commit
eb9767f2dd
@ -112,7 +112,7 @@ void GUI::loadMaps()
|
|||||||
QString mapDir(ProgramPaths::mapDir());
|
QString mapDir(ProgramPaths::mapDir());
|
||||||
|
|
||||||
if (!mapDir.isNull() && !_ml->loadDir(mapDir))
|
if (!mapDir.isNull() && !_ml->loadDir(mapDir))
|
||||||
qWarning("%s", qPrintable(_ml->errorString()));
|
qWarning("%s", qPrintable(_ml->errorPath() + ": " + _ml->errorString()));
|
||||||
|
|
||||||
_map = new EmptyMap(this);
|
_map = new EmptyMap(this);
|
||||||
}
|
}
|
||||||
|
@ -12,56 +12,50 @@
|
|||||||
#include "maplist.h"
|
#include "maplist.h"
|
||||||
|
|
||||||
|
|
||||||
bool MapList::loadMap(Map *map, const QString &path, bool dir)
|
bool MapList::loadMap(Map *map, const QString &path)
|
||||||
{
|
{
|
||||||
if (map && map->isValid()) {
|
if (map && map->isValid()) {
|
||||||
_maps.append(map);
|
_maps.append(map);
|
||||||
return true;
|
return true;
|
||||||
} else if (map) {
|
} else if (map) {
|
||||||
if (dir)
|
_errorPath = path;
|
||||||
_errorString += path + ": " + map->errorString() + "\n";
|
_errorString = map->errorString();
|
||||||
else
|
|
||||||
_errorString = map->errorString();
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (dir)
|
_errorString = path;
|
||||||
_errorString += path + ": " + "Unknown map format\n";
|
_errorString = "Unknown file format";
|
||||||
else
|
|
||||||
_errorString = "Unknown map format";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map *MapList::loadSource(const QString &path, bool dir)
|
Map *MapList::loadSource(const QString &path)
|
||||||
{
|
{
|
||||||
QString err;
|
Map *map = MapSource::loadMap(path, _errorString);
|
||||||
Map *map = MapSource::loadMap(path, err);
|
|
||||||
|
|
||||||
if (!map) {
|
if (!map)
|
||||||
if (dir)
|
_errorPath = path;
|
||||||
_errorString += path + ": " + err + "\n";
|
else
|
||||||
else
|
|
||||||
_errorString = err;
|
|
||||||
} else
|
|
||||||
map->setParent(this);
|
map->setParent(this);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapList::loadFile(const QString &path, bool *terminate, bool dir)
|
bool MapList::loadFile(const QString &path, bool *terminate)
|
||||||
{
|
{
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
QString suffix = fi.suffix().toLower();
|
QString suffix = fi.suffix().toLower();
|
||||||
Map *map = 0;
|
Map *map = 0;
|
||||||
|
|
||||||
if (Atlas::isAtlas(path)) {
|
if (Atlas::isAtlas(path)) {
|
||||||
*terminate = true;
|
if (terminate)
|
||||||
|
*terminate = true;
|
||||||
map = new Atlas(path, this);
|
map = new Atlas(path, this);
|
||||||
} else if (suffix == "xml") {
|
} else if (suffix == "xml") {
|
||||||
if (MapSource::isMap(path) && !(map = loadSource(path, dir)))
|
if (MapSource::isMap(path) && !(map = loadSource(path)))
|
||||||
return false;
|
return false;
|
||||||
else if (GMAP::isGMAP(path)) {
|
else if (GMAP::isGMAP(path)) {
|
||||||
*terminate = true;
|
if (terminate)
|
||||||
|
*terminate = true;
|
||||||
map = new IMGMap(path);
|
map = new IMGMap(path);
|
||||||
}
|
}
|
||||||
} else if (suffix == "jnx")
|
} else if (suffix == "jnx")
|
||||||
@ -74,10 +68,10 @@ bool MapList::loadFile(const QString &path, bool *terminate, bool dir)
|
|||||||
map = new RMap(path, this);
|
map = new RMap(path, this);
|
||||||
else if (suffix == "img")
|
else if (suffix == "img")
|
||||||
map = new IMGMap(path, this);
|
map = new IMGMap(path, this);
|
||||||
else
|
else if (suffix == "map" || suffix == "tar")
|
||||||
map = new OziMap(path, this);
|
map = new OziMap(path, this);
|
||||||
|
|
||||||
if (!loadMap(map, path, dir)) {
|
if (!loadMap(map, path)) {
|
||||||
delete map;
|
delete map;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -85,7 +79,7 @@ bool MapList::loadFile(const QString &path, bool *terminate, bool dir)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapList::loadDirR(const QString &path)
|
bool MapList::loadDir(const QString &path)
|
||||||
{
|
{
|
||||||
QDir md(path);
|
QDir md(path);
|
||||||
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
@ -99,10 +93,10 @@ bool MapList::loadDirR(const QString &path)
|
|||||||
bool terminate = false;
|
bool terminate = false;
|
||||||
|
|
||||||
if (fi.isDir() && fi.fileName() != "set") {
|
if (fi.isDir() && fi.fileName() != "set") {
|
||||||
if (!loadDirR(fi.absoluteFilePath()))
|
if (!loadDir(fi.absoluteFilePath()))
|
||||||
ret = false;
|
ret = false;
|
||||||
} else if (filter().contains("*." + suffix)) {
|
} else if (filter().contains("*." + suffix)) {
|
||||||
if (!loadFile(fi.absoluteFilePath(), &terminate, true))
|
if (!loadFile(fi.absoluteFilePath(), &terminate))
|
||||||
ret = false;
|
ret = false;
|
||||||
if (terminate)
|
if (terminate)
|
||||||
break;
|
break;
|
||||||
@ -112,25 +106,10 @@ bool MapList::loadDirR(const QString &path)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapList::loadFile(const QString &path)
|
|
||||||
{
|
|
||||||
bool atlas;
|
|
||||||
|
|
||||||
_errorString.clear();
|
|
||||||
return loadFile(path, &atlas, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MapList::loadDir(const QString &path)
|
|
||||||
{
|
|
||||||
_errorString.clear();
|
|
||||||
return loadDirR(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MapList::formats()
|
QString MapList::formats()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
tr("Supported files")
|
tr("Supported files") + " (" + filter().join(" ") + ");;"
|
||||||
+ " (*.gmap *.gmapi *.img *.jnx *.map *.mbtiles *.rmap *.rtmap *.tar *.tba *.tif *.tiff *.xml);;"
|
|
||||||
+ tr("Garmin IMG maps") + " (*.gmap *.gmapi *.img *.xml);;"
|
+ tr("Garmin IMG maps") + " (*.gmap *.gmapi *.img *.xml);;"
|
||||||
+ tr("Garmin JNX maps") + " (*.jnx);;"
|
+ tr("Garmin JNX maps") + " (*.jnx);;"
|
||||||
+ tr("OziExplorer maps") + " (*.map);;"
|
+ tr("OziExplorer maps") + " (*.map);;"
|
||||||
@ -144,7 +123,8 @@ QString MapList::formats()
|
|||||||
QStringList MapList::filter()
|
QStringList MapList::filter()
|
||||||
{
|
{
|
||||||
QStringList filter;
|
QStringList filter;
|
||||||
filter << "*.img" << "*.jnx" << "*.map" << "*.mbtiles" << "*.rmap"
|
filter << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.map"
|
||||||
<< "*.rtmap" << "*.tar" << "*.tba" << "*.tif" << "*.tiff" << "*.xml";
|
<< "*.mbtiles" << "*.rmap" << "*.rtmap" << "*.tar" << "*.tba" << "*.tif"
|
||||||
|
<< "*.tiff" << "*.xml";
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
@ -13,23 +13,24 @@ class MapList : public QObject
|
|||||||
public:
|
public:
|
||||||
MapList(QObject *parent = 0) : QObject(parent) {}
|
MapList(QObject *parent = 0) : QObject(parent) {}
|
||||||
|
|
||||||
bool loadFile(const QString &path);
|
bool loadFile(const QString &path, bool *terminate = 0);
|
||||||
bool loadDir(const QString &path);
|
bool loadDir(const QString &path);
|
||||||
|
|
||||||
const QList<Map*> &maps() const {return _maps;}
|
const QList<Map*> &maps() const {return _maps;}
|
||||||
|
|
||||||
const QString &errorString() const {return _errorString;}
|
const QString &errorString() const {return _errorString;}
|
||||||
|
const QString &errorPath() const {return _errorPath;}
|
||||||
|
|
||||||
static QString formats();
|
static QString formats();
|
||||||
static QStringList filter();
|
static QStringList filter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool loadFile(const QString &path, bool *terminate, bool dir);
|
Map *loadSource(const QString &path);
|
||||||
bool loadDirR(const QString &path);
|
bool loadMap(Map *map, const QString &path);
|
||||||
Map *loadSource(const QString &path, bool dir);
|
|
||||||
bool loadMap(Map *map, const QString &path, bool dir);
|
|
||||||
|
|
||||||
QList<Map*> _maps;
|
QList<Map*> _maps;
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
|
QString _errorPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPLIST_H
|
#endif // MAPLIST_H
|
||||||
|
Loading…
Reference in New Issue
Block a user