2015-11-26 19:13:59 +01:00
|
|
|
#include <QFileInfo>
|
2017-04-21 21:15:58 +02:00
|
|
|
#include <QDir>
|
2020-03-17 21:06:51 +01:00
|
|
|
#include <QApplication>
|
2017-04-21 21:15:58 +02:00
|
|
|
#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"
|
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"
|
2021-02-09 21:05:23 +01:00
|
|
|
#include "sqlitemap.h"
|
2021-04-10 15:27:40 +02:00
|
|
|
#include "mapsforgemap.h"
|
2021-06-17 21:58:25 +02:00
|
|
|
#include "worldfilemap.h"
|
2021-11-14 15:08:33 +01:00
|
|
|
#include "qctmap.h"
|
2022-07-05 11:32:14 +02:00
|
|
|
#include "osmdroidmap.h"
|
2022-07-15 21:24:49 +02:00
|
|
|
#include "gemfmap.h"
|
2022-08-04 00:06:36 +02:00
|
|
|
#include "oruxmap.h"
|
2022-11-04 09:03:36 +01:00
|
|
|
#include "encmap.h"
|
2020-12-09 23:07:05 +01:00
|
|
|
#include "invalidmap.h"
|
2015-11-23 23:19:57 +01:00
|
|
|
#include "maplist.h"
|
|
|
|
|
|
|
|
|
2022-04-29 23:16:10 +02:00
|
|
|
MapList::ParserMap MapList::parsers()
|
|
|
|
{
|
|
|
|
MapList::ParserMap map;
|
|
|
|
|
2022-06-09 00:38:25 +02:00
|
|
|
map.insert("tar", &Atlas::createTAR);
|
2022-06-10 08:09:07 +02:00
|
|
|
map.insert("tar", &OziMap::createTAR);
|
2022-06-09 00:38:25 +02:00
|
|
|
map.insert("tba", &Atlas::createTBA);
|
2022-04-29 23:16:10 +02:00
|
|
|
map.insert("xml", &MapSource::create);
|
2022-06-09 00:38:25 +02:00
|
|
|
map.insert("xml", &IMGMap::createGMAP);
|
|
|
|
map.insert("img", &IMGMap::createIMG);
|
2022-04-29 23:16:10 +02:00
|
|
|
map.insert("jnx", &JNXMap::create);
|
|
|
|
map.insert("tif", &GeoTIFFMap::create);
|
|
|
|
map.insert("tiff", &GeoTIFFMap::create);
|
|
|
|
map.insert("mbtiles", &MBTilesMap::create);
|
|
|
|
map.insert("rmap", &RMap::create);
|
|
|
|
map.insert("rtmap", &RMap::create);
|
|
|
|
map.insert("map", &MapsforgeMap::create);
|
2022-06-10 08:09:07 +02:00
|
|
|
map.insert("map", &OziMap::createMAP);
|
2022-04-29 23:16:10 +02:00
|
|
|
map.insert("kap", &BSBMap::create);
|
|
|
|
map.insert("kmz", &KMZMap::create);
|
|
|
|
map.insert("aqm", &AQMMap::create);
|
|
|
|
map.insert("sqlitedb", &SqliteMap::create);
|
|
|
|
map.insert("wld", &WorldFileMap::create);
|
|
|
|
map.insert("jgw", &WorldFileMap::create);
|
|
|
|
map.insert("gfw", &WorldFileMap::create);
|
|
|
|
map.insert("pgw", &WorldFileMap::create);
|
|
|
|
map.insert("tfw", &WorldFileMap::create);
|
|
|
|
map.insert("qct", &QCTMap::create);
|
2022-07-05 11:32:14 +02:00
|
|
|
map.insert("sqlite", &OsmdroidMap::create);
|
2022-07-15 21:24:49 +02:00
|
|
|
map.insert("gemf", &GEMFMap::create);
|
2022-08-04 00:06:36 +02:00
|
|
|
map.insert("otrk2.xml", &OruxMap::create);
|
2022-11-04 09:03:36 +01:00
|
|
|
map.insert("000", &ENCMap::create);
|
2022-04-29 23:16:10 +02:00
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
MapList::ParserMap MapList::_parsers = parsers();
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
Map *MapList::loadFile(const QString &path, bool *isDir)
|
2017-07-27 19:47:46 +02:00
|
|
|
{
|
2022-04-29 23:16:10 +02:00
|
|
|
ParserMap::iterator it;
|
2018-01-14 23:46:39 +01:00
|
|
|
QFileInfo fi(path);
|
2022-08-04 00:06:36 +02:00
|
|
|
QString suffix(fi.completeSuffix().toLower());
|
2020-02-09 23:24:48 +01:00
|
|
|
Map *map = 0;
|
2022-07-08 02:08:21 +02:00
|
|
|
QStringList errors;
|
2018-01-14 23:46:39 +01:00
|
|
|
|
2022-04-29 23:16:10 +02:00
|
|
|
if ((it = _parsers.find(suffix)) != _parsers.end()) {
|
|
|
|
while (it != _parsers.end() && it.key() == suffix) {
|
|
|
|
delete map;
|
2023-05-04 09:38:35 +02:00
|
|
|
map = it.value()(path, isDir);
|
2022-04-29 23:16:10 +02:00
|
|
|
if (map->isValid())
|
2022-07-08 02:08:21 +02:00
|
|
|
return map;
|
|
|
|
else
|
|
|
|
errors.append(it.key() + ": " + map->errorString());
|
2022-04-29 23:16:10 +02:00
|
|
|
++it;
|
|
|
|
}
|
2022-07-08 02:08:21 +02:00
|
|
|
} else {
|
2022-04-29 23:16:10 +02:00
|
|
|
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
2023-05-04 09:38:35 +02:00
|
|
|
map = it.value()(path, isDir);
|
2022-04-29 23:16:10 +02:00
|
|
|
if (map->isValid())
|
2022-07-08 02:08:21 +02:00
|
|
|
return map;
|
2022-04-29 23:16:10 +02:00
|
|
|
else {
|
2022-06-10 08:09:07 +02:00
|
|
|
errors.append(it.key() + ": " + map->errorString());
|
2022-04-29 23:16:10 +02:00
|
|
|
delete map;
|
|
|
|
map = 0;
|
|
|
|
}
|
2020-02-09 23:24:48 +01:00
|
|
|
}
|
2022-04-29 23:16:10 +02:00
|
|
|
}
|
2019-02-13 00:45:34 +01:00
|
|
|
|
2022-07-08 02:08:21 +02:00
|
|
|
qWarning("%s:", qPrintable(path));
|
|
|
|
for (int i = 0; i < errors.size(); i++)
|
|
|
|
qWarning(" %s", qPrintable(errors.at(i)));
|
|
|
|
|
2020-12-09 23:07:05 +01:00
|
|
|
return map ? map : new InvalidMap(path, "Unknown file format");
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
TreeNode<Map*> MapList::loadDir(const QString &path, TreeNode<Map*> *parent)
|
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();
|
2022-06-19 23:05:01 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
TreeNode<Map*> tree(Util::displayName(path));
|
|
|
|
#else // Q_OS_ANDROID
|
2022-07-05 11:32:14 +02:00
|
|
|
TreeNode<Map*> tree(md.dirName());
|
2022-06-19 23:05:01 +02:00
|
|
|
#endif // Q_OS_ANDROID
|
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();
|
|
|
|
|
2021-03-20 09:59:03 +01:00
|
|
|
if (fi.isDir()) {
|
2023-05-04 09:38:35 +02:00
|
|
|
TreeNode<Map*> child(loadDir(fi.absoluteFilePath(), &tree));
|
2021-03-20 09:59:03 +01:00
|
|
|
if (!child.isEmpty())
|
|
|
|
tree.addChild(child);
|
|
|
|
} else if (filter().contains("*." + suffix)) {
|
|
|
|
bool isDir = false;
|
2023-05-04 09:38:35 +02:00
|
|
|
Map *map = loadFile(fi.absoluteFilePath(), &isDir);
|
2021-03-20 09:59:03 +01:00
|
|
|
if (isDir) {
|
2021-04-25 10:00:15 +02:00
|
|
|
if (parent)
|
|
|
|
parent->addItem(map);
|
|
|
|
else
|
|
|
|
tree.addItem(map);
|
2018-01-14 23:03:27 +01:00
|
|
|
break;
|
2021-03-20 09:59:03 +01:00
|
|
|
} else
|
|
|
|
tree.addItem(map);
|
2018-01-14 23:03:27 +01:00
|
|
|
}
|
2017-04-21 21:15:58 +02:00
|
|
|
}
|
2018-01-14 23:03:27 +01:00
|
|
|
|
2021-03-20 09:59:03 +01:00
|
|
|
return tree;
|
2020-03-17 21:06:51 +01:00
|
|
|
}
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
TreeNode<Map *> MapList::loadMaps(const QString &path)
|
2020-03-17 21:06:51 +01:00
|
|
|
{
|
|
|
|
if (QFileInfo(path).isDir())
|
2023-05-04 09:38:35 +02:00
|
|
|
return loadDir(path);
|
2020-03-17 21:06:51 +01:00
|
|
|
else {
|
2021-03-20 09:59:03 +01:00
|
|
|
TreeNode<Map*> tree;
|
2023-05-04 09:38:35 +02:00
|
|
|
tree.addItem(loadFile(path));
|
2021-03-20 09:59:03 +01:00
|
|
|
return tree;
|
2020-03-17 21:06:51 +01:00
|
|
|
}
|
2018-01-14 23:03:27 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
QString MapList::formats()
|
|
|
|
{
|
2018-02-04 15:30:54 +01:00
|
|
|
return
|
2020-03-17 21:06:51 +01:00
|
|
|
qApp->translate("MapList", "Supported files")
|
|
|
|
+ " (" + filter().join(" ") + ");;"
|
2022-11-04 09:03:36 +01:00
|
|
|
+ qApp->translate("MapList", "Electronic Navigational Charts") + " (*.000);;"
|
2021-02-04 23:22:16 +01:00
|
|
|
+ qApp->translate("MapList", "AlpineQuest maps") + " (*.aqm);;"
|
2022-07-18 08:52:12 +02:00
|
|
|
+ qApp->translate("MapList", "GEMF maps") + " (*.gemf);;"
|
2020-03-17 21:06:51 +01:00
|
|
|
+ qApp->translate("MapList", "Garmin IMG maps")
|
|
|
|
+ " (*.gmap *.gmapi *.img *.xml);;"
|
|
|
|
+ qApp->translate("MapList", "Garmin JNX maps") + " (*.jnx);;"
|
2020-11-28 20:34:25 +01:00
|
|
|
+ qApp->translate("MapList", "BSB nautical charts") + " (*.kap);;"
|
2020-12-22 22:32:07 +01:00
|
|
|
+ qApp->translate("MapList", "KMZ maps") + " (*.kmz);;"
|
2021-04-10 15:27:40 +02:00
|
|
|
+ qApp->translate("MapList", "Mapsforge maps") + " (*.map);;"
|
2020-03-17 21:06:51 +01:00
|
|
|
+ qApp->translate("MapList", "OziExplorer maps") + " (*.map);;"
|
|
|
|
+ qApp->translate("MapList", "MBTiles maps") + " (*.mbtiles);;"
|
2022-08-04 00:06:36 +02:00
|
|
|
+ qApp->translate("MapList", "Orux maps") + " (*.otrk2.xml);;"
|
2021-11-14 15:08:33 +01:00
|
|
|
+ qApp->translate("MapList", "QuickChart maps") + " (*.qct);;"
|
2021-02-09 22:51:19 +01:00
|
|
|
+ qApp->translate("MapList", "TwoNav maps") + " (*.rmap *.rtmap);;"
|
2022-07-05 11:32:14 +02:00
|
|
|
+ qApp->translate("MapList", "Osmdroid SQLite maps") + " (*.sqlite);;"
|
2021-02-13 10:19:17 +01:00
|
|
|
+ qApp->translate("MapList", "Locus/OsmAnd/RMaps SQLite maps")
|
2021-02-09 21:05:23 +01:00
|
|
|
+ " (*.sqlitedb);;"
|
2020-03-17 21:06:51 +01:00
|
|
|
+ qApp->translate("MapList", "TrekBuddy maps/atlases") + " (*.tar *.tba);;"
|
|
|
|
+ qApp->translate("MapList", "GeoTIFF images") + " (*.tif *.tiff);;"
|
2021-06-17 21:58:25 +02:00
|
|
|
+ qApp->translate("MapList", "World-file georeferenced images")
|
|
|
|
+ " (*.wld *.jgw *.gfw *.pgw *.tfw);;"
|
2022-04-29 23:16:10 +02:00
|
|
|
+ qApp->translate("MapList", "Online map sources") + " (*.xml);;"
|
|
|
|
+ qApp->translate("MapList", "All files") + " (*)";
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MapList::filter()
|
|
|
|
{
|
|
|
|
QStringList filter;
|
2022-04-29 23:16:10 +02:00
|
|
|
QString last;
|
|
|
|
|
|
|
|
for (ParserMap::iterator it = _parsers.begin(); it != _parsers.end(); it++) {
|
|
|
|
if (it.key() != last)
|
|
|
|
filter << "*." + it.key();
|
|
|
|
last = it.key();
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
return filter;
|
|
|
|
}
|