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

128 lines
3.5 KiB
C++
Raw Normal View History

#include <QFileInfo>
#include <QDir>
#include <QApplication>
#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"
2020-02-09 23:24:48 +01:00
#include "IMG/gmap.h"
2020-11-27 01:11:50 +01:00
#include "bsbmap.h"
2020-12-22 22:32:07 +01:00
#include "kmzmap.h"
2021-02-04 23:22:16 +01:00
#include "aqmmap.h"
#include "sqlitemap.h"
#include "invalidmap.h"
#include "maplist.h"
Map *MapList::loadFile(const QString &path, bool *terminate)
2017-07-27 19:47:46 +02:00
{
2018-01-14 23:46:39 +01:00
QFileInfo fi(path);
QString suffix = fi.suffix().toLower();
2020-02-09 23:24:48 +01:00
Map *map = 0;
2018-01-14 23:46:39 +01:00
if (Atlas::isAtlas(path)) {
2020-02-12 20:32:57 +01:00
if (terminate)
*terminate = true;
map = new Atlas(path);
2019-02-13 00:45:34 +01:00
} else if (suffix == "xml") {
if (MapSource::isMap(path)) {
map = MapSource::loadMap(path);
} else if (GMAP::isGMAP(path)) {
map = new IMGMap(path);
2020-02-12 20:32:57 +01:00
if (terminate)
*terminate = true;
2020-02-09 23:24:48 +01:00
}
2019-02-13 00:45:34 +01:00
} else if (suffix == "jnx")
map = new JNXMap(path);
else if (suffix == "tif" || suffix == "tiff")
map = new GeoTIFFMap(path);
2018-09-20 07:59:47 +02:00
else if (suffix == "mbtiles")
map = new MBTilesMap(path);
2019-03-07 22:58:43 +01:00
else if (suffix == "rmap" || suffix == "rtmap")
map = new RMap(path);
2019-05-10 18:56:19 +02:00
else if (suffix == "img")
map = new IMGMap(path);
2020-02-12 20:32:57 +01:00
else if (suffix == "map" || suffix == "tar")
map = new OziMap(path);
else if (suffix == "kap")
2020-11-27 01:11:50 +01:00
map = new BSBMap(path);
2020-12-22 22:32:07 +01:00
else if (suffix == "kmz")
map = new KMZMap(path);
2021-02-04 23:22:16 +01:00
else if (suffix == "aqm")
map = new AQMMap(path);
else if (suffix == "sqlitedb")
map = new SqliteMap(path);
2019-02-13 00:45:34 +01:00
return map ? map : new InvalidMap(path, "Unknown file format");
2017-07-27 19:47:46 +02:00
}
QList<Map*> MapList::loadDir(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();
QList<Map*> list;
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower();
2020-02-09 23:24:48 +01:00
bool terminate = false;
if (fi.isDir() && fi.fileName() != "set")
list.append(loadDir(fi.absoluteFilePath()));
else if (filter().contains("*." + suffix)) {
list.append(loadFile(fi.absoluteFilePath(), &terminate));
2020-02-09 23:24:48 +01:00
if (terminate)
break;
}
}
return list;
}
QList<Map*> MapList::loadMaps(const QString &path)
{
if (QFileInfo(path).isDir())
return loadDir(path);
else {
QList<Map*> list;
list.append(loadFile(path, 0));
return list;
}
}
2017-07-27 19:47:46 +02:00
QString MapList::formats()
{
2018-02-04 15:30:54 +01:00
return
qApp->translate("MapList", "Supported files")
+ " (" + filter().join(" ") + ");;"
2021-02-04 23:22:16 +01:00
+ qApp->translate("MapList", "AlpineQuest maps") + " (*.aqm);;"
+ qApp->translate("MapList", "Garmin IMG maps")
+ " (*.gmap *.gmapi *.img *.xml);;"
+ qApp->translate("MapList", "Garmin JNX maps") + " (*.jnx);;"
+ qApp->translate("MapList", "BSB nautical charts") + " (*.kap);;"
2020-12-22 22:32:07 +01:00
+ qApp->translate("MapList", "KMZ maps") + " (*.kmz);;"
+ qApp->translate("MapList", "OziExplorer maps") + " (*.map);;"
+ qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;"
2021-02-09 22:51:19 +01:00
+ qApp->translate("MapList", "TwoNav maps") + " (*.rmap *.rtmap);;"
+ qApp->translate("MapList", "Locus/OsmAnd/RMaps sqlite maps")
+ " (*.sqlitedb);;"
+ qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;"
+ qApp->translate("MapList", "GeoTIFF images") + " (*.tif *.tiff);;"
+ qApp->translate("MapList", "Online map sources") + " (*.xml)";
2017-07-27 19:47:46 +02:00
}
QStringList MapList::filter()
{
QStringList filter;
2021-02-04 23:22:16 +01:00
filter << "*.aqm" << "*.gmap" << "*.gmapi" << "*.img" << "*.jnx" << "*.kap"
<< "*.kmz" << "*.map" << "*.mbtiles" << "*.rmap" << "*.rtmap"
<< "*.sqlitedb" << "*.tar" << "*.tba" << "*.tif" << "*.tiff" << "*.xml";
2017-07-27 19:47:46 +02:00
return filter;
}