2015-11-26 19:13:59 +01:00
|
|
|
#include <QFileInfo>
|
2017-04-21 21:15:58 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include "atlas.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#include "ozimap.h"
|
2018-05-22 22:40:15 +02:00
|
|
|
#include "jnxmap.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#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"
|
2015-11-23 23:19:57 +01:00
|
|
|
#include "maplist.h"
|
|
|
|
|
|
|
|
|
2018-05-22 22:40:15 +02:00
|
|
|
bool MapList::loadMap(Map* map, const QString &path, bool dir)
|
2017-04-21 21:15:58 +02:00
|
|
|
{
|
2017-07-27 19:47:46 +02:00
|
|
|
if (map->isValid()) {
|
|
|
|
_maps.append(map);
|
|
|
|
return true;
|
|
|
|
} else {
|
2018-01-28 22:56:08 +01:00
|
|
|
if (dir)
|
|
|
|
_errorString += path + ": " + map->errorString() + "\n";
|
|
|
|
else
|
|
|
|
_errorString = map->errorString();
|
2017-07-27 19:47:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 23:19:57 +01: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-01-14 23:03:27 +01:00
|
|
|
|
2018-05-22 22:40:15 +02:00
|
|
|
if (!map) {
|
2018-01-28 22:56:08 +01:00
|
|
|
if (dir)
|
2018-05-22 22:40:15 +02:00
|
|
|
_errorString += path + ": " + err + "\n";
|
2018-01-28 22:56:08 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-28 22:56:08 +01: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
|
|
|
|
2018-01-14 23:03:27 +01:00
|
|
|
if (Atlas::isAtlas(path)) {
|
2018-01-28 22:56:08 +01:00
|
|
|
*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);
|
2018-08-21 20:01:47 +02:00
|
|
|
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
|
|
|
{
|
2018-01-14 23:03:27 +01: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;
|
2018-01-14 23:03:27 +01:00
|
|
|
|
|
|
|
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;
|
2018-01-14 23:03:27 +01:00
|
|
|
|
|
|
|
if (fi.isDir() && fi.fileName() != "set") {
|
2018-02-10 09:57:21 +01:00
|
|
|
if (!loadDirR(fi.absoluteFilePath()))
|
2018-01-28 22:56:08 +01:00
|
|
|
ret = false;
|
2018-01-14 23:03:27 +01:00
|
|
|
} else if (filter().contains("*." + suffix)) {
|
2018-01-28 22:56:08 +01:00
|
|
|
if (!loadFile(fi.absoluteFilePath(), &atlas, true))
|
|
|
|
ret = false;
|
2018-01-14 23:03:27 +01:00
|
|
|
if (atlas)
|
|
|
|
break;
|
|
|
|
}
|
2017-04-21 21:15:58 +02:00
|
|
|
}
|
2018-01-14 23:03:27 +01:00
|
|
|
|
2018-01-28 22:56:08 +01:00
|
|
|
return ret;
|
2018-01-14 23:03:27 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|