1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-25 04:05:53 +01:00
GPXSee/src/map/maplist.cpp

140 lines
3.1 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"
#include "maplist.h"
2018-05-22 22:40:15 +02:00
bool MapList::loadMap(Map* map, const QString &path, bool dir)
{
2017-07-27 19:47:46 +02:00
if (map->isValid()) {
_maps.append(map);
return true;
} else {
if (dir)
_errorString += path + ": " + map->errorString() + "\n";
else
_errorString = map->errorString();
2017-07-27 19:47:46 +02:00
return false;
}
}
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
}
bool MapList::loadFile(const QString &path, bool *atlas, 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();
2019-02-13 00:45:34 +01:00
Map *map;
2018-01-14 23:46:39 +01:00
if (Atlas::isAtlas(path)) {
*atlas = true;
2019-02-13 00:45:34 +01:00
map = new Atlas(path, this);
} else if (suffix == "xml") {
if (!(map = loadSource(path, dir)))
return false;
} 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();
2018-05-22 22:40:15 +02:00
bool atlas = 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)) {
if (!loadFile(fi.absoluteFilePath(), &atlas, true))
ret = false;
if (atlas)
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")
2019-05-10 18:56:19 +02:00
+ " (*.img *.jnx *.map *.mbtiles *.rmap *.rtmap *.tar *.tba *.tif *.tiff *.xml);;"
+ tr("Garmin IMG maps") + " (*.img);;"
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;
2019-05-10 18:56:19 +02:00
filter << "*.img" << "*.jnx" << "*.map" << "*.tba" << "*.tar" << "*.xml"
<< "*.tif" << "*.tiff" << "*.mbtiles" << "*.rmap" << "*.rtmap" << "*.img";
2017-07-27 19:47:46 +02:00
return filter;
}