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

143 lines
2.8 KiB
C++
Raw Normal View History

#include <QFileInfo>
#include <QDir>
#include "atlas.h"
#include "offlinemap.h"
#include "onlinemap.h"
2018-01-29 00:19:57 +01:00
#include "mapsource.h"
#include "maplist.h"
2018-01-29 00:19:57 +01:00
bool MapList::loadSource(const QString &path, bool dir)
{
2018-01-29 00:19:57 +01:00
MapSource ms;
Map *map;
2018-02-20 23:37:19 +01:00
if (!(map = ms.loadFile(path))) {
if (dir)
2018-01-29 00:19:57 +01:00
_errorString += path + ": " + ms.errorString() + "\n";
else
2018-01-29 00:19:57 +01:00
_errorString = ms.errorString();
return false;
}
2018-01-29 00:19:57 +01:00
map->setParent(this);
_maps.append(map);
2017-07-27 19:47:46 +02:00
return true;
}
bool MapList::loadMap(const QString &path, bool dir)
{
2017-07-27 19:47:46 +02:00
OfflineMap *map = new OfflineMap(path, this);
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
delete map;
return false;
}
}
bool MapList::loadAtlas(const QString &path, bool dir)
2017-07-27 19:47:46 +02:00
{
Atlas *atlas = new Atlas(path, this);
2017-07-27 19:47:46 +02:00
if (atlas->isValid()) {
_maps.append(atlas);
return true;
} else {
if (dir)
_errorString += path + ": " + atlas->errorString() + "\n";
else
_errorString = atlas->errorString();
2017-07-27 19:47:46 +02:00
delete atlas;
return false;
}
}
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;
return loadAtlas(path, dir);
} else if (suffix == "xml") {
*atlas = false;
2018-01-29 00:19:57 +01:00
return loadSource(path, dir);
2017-07-27 19:47:46 +02:00
} else {
*atlas = false;
return loadMap(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();
bool atlas, ret = true;
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower();
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
tr("Supported files") + " (*.map *.tar *.tba *.tif *.tiff *.xml);;"
+ 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;
filter << "*.map" << "*.tba" << "*.tar" << "*.xml" << "*.tif" << "*.tiff";
2017-07-27 19:47:46 +02:00
return filter;
}