1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-12-01 07:01:16 +01:00
GPXSee/src/map/maplist.cpp

126 lines
2.6 KiB
C++
Raw Normal View History

#include <QFileInfo>
#include <QDir>
#include "atlas.h"
#include "offlinemap.h"
#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"
#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();
2018-05-22 22:40:15 +02:00
2017-07-27 19:47:46 +02:00
delete map;
return false;
}
}
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-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;
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
}
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();
if (Atlas::isAtlas(path)) {
*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
{
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);
}
void MapList::clear()
{
for (int i = 0; i < _maps.count(); i++)
delete _maps.at(i);
_maps.clear();
}
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-22 22:40:15 +02:00
filter << "*.jnx *.map" << "*.tba" << "*.tar" << "*.xml" << "*.tif"
<< "*.tiff";
2017-07-27 19:47:46 +02:00
return filter;
}