2015-11-26 19:13:59 +01:00
|
|
|
#include <QFileInfo>
|
2017-04-21 21:15:58 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include "atlas.h"
|
|
|
|
#include "offlinemap.h"
|
2017-03-18 01:30:31 +01:00
|
|
|
#include "onlinemap.h"
|
2018-05-22 22:40:15 +02:00
|
|
|
#include "jnxmap.h"
|
2018-01-29 00:19:57 +01:00
|
|
|
#include "mapsource.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();
|
2018-05-22 22:40:15 +02:00
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
delete map;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 23:19:57 +01:00
|
|
|
|
2018-05-22 22:40:15 +02:00
|
|
|
bool 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;
|
2017-07-27 19:47:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-22 22:40:15 +02:00
|
|
|
map->setParent(this);
|
|
|
|
|
|
|
|
return loadMap(map, path, dir);
|
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();
|
|
|
|
|
2018-01-14 23:03:27 +01:00
|
|
|
if (Atlas::isAtlas(path)) {
|
2018-01-28 22:56:08 +01:00
|
|
|
*atlas = true;
|
2018-05-22 22:40:15 +02:00
|
|
|
return loadMap(new Atlas(path, this), path, dir);
|
|
|
|
} else if (suffix == "xml")
|
2018-01-29 00:19:57 +01:00
|
|
|
return loadSource(path, dir);
|
2018-05-22 22:40:15 +02:00
|
|
|
else if (suffix == "jnx")
|
|
|
|
return loadMap(new JNXMap(path, this), path, dir);
|
|
|
|
else
|
|
|
|
return loadMap(new OfflineMap(path, this), path, dir);
|
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);
|
|
|
|
}
|
|
|
|
|
2018-01-14 23:03:27 +01:00
|
|
|
void MapList::clear()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _maps.count(); i++)
|
|
|
|
delete _maps.at(i);
|
|
|
|
_maps.clear();
|
2015-11-23 23:19:57 +01:00
|
|
|
}
|
2017-07-27 19:47:46 +02:00
|
|
|
|
|
|
|
QString MapList::formats()
|
|
|
|
{
|
2018-02-04 15:30:54 +01:00
|
|
|
return
|
2018-05-22 22:40:15 +02:00
|
|
|
tr("Supported files") + " (*.jnx *.map *.tar *.tba *.tif *.tiff *.xml);;"
|
|
|
|
+ tr("Garmin JNX maps") + " (*.jnx);;"
|
2018-02-04 15:30:54 +01:00
|
|
|
+ tr("OziExplorer maps") + " (*.map);;"
|
|
|
|
+ tr("TrekBuddy maps/atlases") + " (*.tar *.tba);;"
|
|
|
|
+ tr("GeoTIFF images") + " (*.tif *.tiff);;"
|
|
|
|
+ tr("Online map sources") + " (*.xml)";
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MapList::filter()
|
|
|
|
{
|
|
|
|
QStringList filter;
|
2018-05-28 22:30:13 +02:00
|
|
|
filter << "*.jnx" << "*.map" << "*.tba" << "*.tar" << "*.xml" << "*.tif"
|
2018-05-22 22:40:15 +02:00
|
|
|
<< "*.tiff";
|
2017-07-27 19:47:46 +02:00
|
|
|
return filter;
|
|
|
|
}
|