1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/map/maplist.cpp

151 lines
3.4 KiB
C++
Raw Normal View History

#include <QFileInfo>
#include <QDir>
#include "atlas.h"
#include "ozimap.h"
2018-05-22 22:40:15 +02:00
#include "jnxmap.h"
#include "geotiffmap.h"
2018-01-29 00:19:57 +01:00
#include "mapsource.h"
2018-09-20 07:59:47 +02:00
#include "mbtilesmap.h"
2019-03-02 16:51:14 +01:00
#include "rmap.h"
2019-05-10 18:56:19 +02:00
#include "imgmap.h"
2020-02-09 23:24:48 +01:00
#include "IMG/gmap.h"
#include "maplist.h"
2020-02-09 23:24:48 +01:00
bool MapList::loadMap(Map *map, const QString &path, bool dir)
{
2020-02-09 23:24:48 +01:00
if (map && map->isValid()) {
2017-07-27 19:47:46 +02:00
_maps.append(map);
return true;
2020-02-09 23:24:48 +01:00
} else if (map) {
if (dir)
_errorString += path + ": " + map->errorString() + "\n";
else
_errorString = map->errorString();
2017-07-27 19:47:46 +02:00
return false;
2020-02-09 23:24:48 +01:00
} else {
if (dir)
_errorString += path + ": " + "Unknown map format\n";
else
_errorString = "Unknown map format";
return false;
2017-07-27 19:47:46 +02:00
}
}
2019-02-13 00:45:34 +01:00
Map *MapList::loadSource(const QString &path, bool dir)
2017-07-27 19:47:46 +02:00
{
2018-05-22 22:40:15 +02:00
QString err;
Map *map = MapSource::loadMap(path, err);
2018-05-22 22:40:15 +02:00
if (!map) {
if (dir)
2018-05-22 22:40:15 +02:00
_errorString += path + ": " + err + "\n";
else
2018-05-22 22:40:15 +02:00
_errorString = err;
2019-02-13 00:45:34 +01:00
} else
map->setParent(this);
2018-05-22 22:40:15 +02:00
2019-02-13 00:45:34 +01:00
return map;
2017-07-27 19:47:46 +02:00
}
2020-02-09 23:24:48 +01:00
bool MapList::loadFile(const QString &path, bool *terminate, bool dir)
2017-07-27 19:47:46 +02:00
{
2018-01-14 23:46:39 +01:00
QFileInfo fi(path);
QString suffix = fi.suffix().toLower();
2020-02-09 23:24:48 +01:00
Map *map = 0;
2018-01-14 23:46:39 +01:00
if (Atlas::isAtlas(path)) {
2020-02-09 23:24:48 +01:00
*terminate = true;
2019-02-13 00:45:34 +01:00
map = new Atlas(path, this);
} else if (suffix == "xml") {
2020-02-09 23:24:48 +01:00
if (MapSource::isMap(path) && !(map = loadSource(path, dir)))
2019-02-13 00:45:34 +01:00
return false;
2020-02-09 23:24:48 +01:00
else if (GMAP::isGMAP(path)) {
*terminate = true;
map = new IMGMap(path);
}
2019-02-13 00:45:34 +01:00
} else if (suffix == "jnx")
map = new JNXMap(path, this);
else if (suffix == "tif" || suffix == "tiff")
2019-02-13 00:45:34 +01:00
map = new GeoTIFFMap(path, this);
2018-09-20 07:59:47 +02:00
else if (suffix == "mbtiles")
2019-02-13 00:45:34 +01:00
map = new MBTilesMap(path, this);
2019-03-07 22:58:43 +01:00
else if (suffix == "rmap" || suffix == "rtmap")
2019-03-02 16:51:14 +01:00
map = new RMap(path, this);
2019-05-10 18:56:19 +02:00
else if (suffix == "img")
map = new IMGMap(path, this);
2018-05-22 22:40:15 +02:00
else
2019-02-13 00:45:34 +01:00
map = new OziMap(path, this);
if (!loadMap(map, path, dir)) {
delete map;
return false;
}
return true;
2017-07-27 19:47:46 +02:00
}
2018-02-10 09:57:21 +01:00
bool MapList::loadDirR(const QString &path)
2017-07-27 19:47:46 +02:00
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
md.setSorting(QDir::DirsLast);
QFileInfoList ml = md.entryInfoList();
2018-05-22 22:40:15 +02:00
bool ret = true;
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower();
2020-02-09 23:24:48 +01:00
bool terminate = false;
if (fi.isDir() && fi.fileName() != "set") {
2018-02-10 09:57:21 +01:00
if (!loadDirR(fi.absoluteFilePath()))
ret = false;
} else if (filter().contains("*." + suffix)) {
2020-02-09 23:24:48 +01:00
if (!loadFile(fi.absoluteFilePath(), &terminate, true))
ret = false;
2020-02-09 23:24:48 +01:00
if (terminate)
break;
}
}
return ret;
}
2018-02-10 09:57:21 +01:00
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);
}
2017-07-27 19:47:46 +02:00
QString MapList::formats()
{
2018-02-04 15:30:54 +01:00
return
2018-09-20 07:59:47 +02:00
tr("Supported files")
+ " (*.gmap *.gmapi *.img *.jnx *.map *.mbtiles *.rmap *.rtmap *.tar *.tba *.tif *.tiff *.xml);;"
+ tr("Garmin IMG maps") + " (*.gmap *.gmapi *.img *.xml);;"
2018-05-22 22:40:15 +02:00
+ tr("Garmin JNX maps") + " (*.jnx);;"
2018-02-04 15:30:54 +01:00
+ tr("OziExplorer maps") + " (*.map);;"
2019-05-10 18:56:19 +02:00
+ tr("MBTiles maps") + " (*.mbtiles);;"
2018-02-04 15:30:54 +01:00
+ tr("TrekBuddy maps/atlases") + " (*.tar *.tba);;"
+ tr("GeoTIFF images") + " (*.tif *.tiff);;"
2019-03-07 22:58:43 +01:00
+ tr("TwoNav maps") + " (*.rmap *.rtmap);;"
2018-02-04 15:30:54 +01:00
+ tr("Online map sources") + " (*.xml)";
2017-07-27 19:47:46 +02:00
}
QStringList MapList::filter()
{
QStringList filter;
filter << "*.img" << "*.jnx" << "*.map" << "*.mbtiles" << "*.rmap"
<< "*.rtmap" << "*.tar" << "*.tba" << "*.tif" << "*.tiff" << "*.xml";
2017-07-27 19:47:46 +02:00
return filter;
}