2019-01-18 00:17:28 +01:00
|
|
|
#include <QApplication>
|
2016-10-24 00:21:40 +02:00
|
|
|
#include <QFile>
|
2016-10-26 20:17:05 +02:00
|
|
|
#include <QFileInfo>
|
2016-10-23 11:09:20 +02:00
|
|
|
#include "gpxparser.h"
|
|
|
|
#include "tcxparser.h"
|
|
|
|
#include "csvparser.h"
|
2016-10-25 19:46:44 +02:00
|
|
|
#include "kmlparser.h"
|
2016-10-31 22:59:08 +01:00
|
|
|
#include "fitparser.h"
|
2016-11-10 00:08:11 +01:00
|
|
|
#include "igcparser.h"
|
2016-11-16 23:54:15 +01:00
|
|
|
#include "nmeaparser.h"
|
2018-04-15 10:08:50 +02:00
|
|
|
#include "oziparsers.h"
|
2018-08-08 20:18:08 +02:00
|
|
|
#include "locparser.h"
|
2018-08-10 22:46:04 +02:00
|
|
|
#include "slfparser.h"
|
2019-01-25 22:18:21 +01:00
|
|
|
#include "geojsonparser.h"
|
2019-03-13 08:42:18 +01:00
|
|
|
#include "exifparser.h"
|
2019-08-15 21:27:55 +02:00
|
|
|
#include "cupparser.h"
|
2019-10-25 22:30:12 +02:00
|
|
|
#include "gpiparser.h"
|
2020-01-14 23:21:05 +01:00
|
|
|
#include "smlparser.h"
|
2021-05-09 22:39:39 +02:00
|
|
|
#include "ov2parser.h"
|
2021-05-12 07:44:25 +02:00
|
|
|
#include "itnparser.h"
|
2021-08-19 19:35:26 +02:00
|
|
|
#include "onmoveparsers.h"
|
2021-12-24 13:43:23 +01:00
|
|
|
#include "twonavparser.h"
|
2016-10-23 11:09:20 +02:00
|
|
|
#include "data.h"
|
|
|
|
|
|
|
|
|
2017-09-14 20:19:19 +02:00
|
|
|
static GPXParser gpx;
|
|
|
|
static TCXParser tcx;
|
|
|
|
static KMLParser kml;
|
|
|
|
static FITParser fit;
|
|
|
|
static CSVParser csv;
|
|
|
|
static IGCParser igc;
|
|
|
|
static NMEAParser nmea;
|
2018-04-13 20:54:38 +02:00
|
|
|
static PLTParser plt;
|
|
|
|
static WPTParser wpt;
|
|
|
|
static RTEParser rte;
|
2018-08-08 20:18:08 +02:00
|
|
|
static LOCParser loc;
|
2018-08-10 22:46:04 +02:00
|
|
|
static SLFParser slf;
|
2019-01-25 22:18:21 +01:00
|
|
|
static GeoJSONParser geojson;
|
2019-03-13 00:25:46 +01:00
|
|
|
static EXIFParser exif;
|
2019-08-15 21:27:55 +02:00
|
|
|
static CUPParser cup;
|
2019-10-25 22:30:12 +02:00
|
|
|
static GPIParser gpi;
|
2020-01-14 23:21:05 +01:00
|
|
|
static SMLParser sml;
|
2021-05-09 22:39:39 +02:00
|
|
|
static OV2Parser ov2;
|
2021-05-12 07:44:25 +02:00
|
|
|
static ITNParser itn;
|
2021-08-18 21:29:28 +02:00
|
|
|
static OMDParser omd;
|
2021-08-19 19:35:26 +02:00
|
|
|
static GHPParser ghp;
|
2021-12-24 13:43:23 +01:00
|
|
|
static TwoNavParser twonav;
|
2017-09-14 20:19:19 +02:00
|
|
|
|
2021-12-24 13:43:23 +01:00
|
|
|
static QMultiMap<QString, Parser*> parsers()
|
2016-10-23 11:09:20 +02:00
|
|
|
{
|
2021-12-24 13:43:23 +01:00
|
|
|
QMultiMap<QString, Parser*> map;
|
2020-02-12 20:33:23 +01:00
|
|
|
|
|
|
|
map.insert("gpx", &gpx);
|
|
|
|
map.insert("tcx", &tcx);
|
|
|
|
map.insert("kml", &kml);
|
|
|
|
map.insert("fit", &fit);
|
|
|
|
map.insert("csv", &csv);
|
|
|
|
map.insert("igc", &igc);
|
|
|
|
map.insert("nmea", &nmea);
|
|
|
|
map.insert("plt", &plt);
|
|
|
|
map.insert("wpt", &wpt);
|
|
|
|
map.insert("rte", &rte);
|
|
|
|
map.insert("loc", &loc);
|
|
|
|
map.insert("slf", &slf);
|
|
|
|
map.insert("json", &geojson);
|
|
|
|
map.insert("geojson", &geojson);
|
|
|
|
map.insert("jpeg", &exif);
|
|
|
|
map.insert("jpg", &exif);
|
|
|
|
map.insert("cup", &cup);
|
|
|
|
map.insert("gpi", &gpi);
|
|
|
|
map.insert("sml", &sml);
|
2021-05-09 22:39:39 +02:00
|
|
|
map.insert("ov2", &ov2);
|
2021-05-12 07:44:25 +02:00
|
|
|
map.insert("itn", &itn);
|
2021-08-18 21:29:28 +02:00
|
|
|
map.insert("omd", &omd);
|
2021-08-19 19:35:26 +02:00
|
|
|
map.insert("ghp", &ghp);
|
2021-12-24 13:43:23 +01:00
|
|
|
map.insert("trk", &twonav);
|
|
|
|
map.insert("rte", &twonav);
|
|
|
|
map.insert("wpt", &twonav);
|
2017-07-27 19:47:46 +02:00
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
return map;
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
|
2021-12-24 13:43:23 +01:00
|
|
|
QMultiMap<QString, Parser*> Data::_parsers = parsers();
|
2017-07-27 19:47:46 +02:00
|
|
|
|
2019-08-29 20:15:03 +02:00
|
|
|
void Data::processData(QList<TrackData> &trackData, QList<RouteData> &routeData)
|
2016-10-23 11:09:20 +02:00
|
|
|
{
|
2020-03-25 23:08:26 +01:00
|
|
|
for (int i = 0; i < trackData.count(); i++)
|
2019-01-31 01:46:53 +01:00
|
|
|
_tracks.append(Track(trackData.at(i)));
|
2020-03-25 23:08:26 +01:00
|
|
|
for (int i = 0; i < routeData.count(); i++)
|
2019-01-31 01:46:53 +01:00
|
|
|
_routes.append(Route(routeData.at(i)));
|
2016-10-26 20:17:05 +02:00
|
|
|
}
|
|
|
|
|
2020-12-06 19:17:09 +01:00
|
|
|
Data::Data(const QString &fileName, bool tryUnknown)
|
2016-10-23 11:09:20 +02:00
|
|
|
{
|
|
|
|
QFile file(fileName);
|
2016-10-26 20:17:05 +02:00
|
|
|
QFileInfo fi(fileName);
|
2019-01-31 01:46:53 +01:00
|
|
|
QList<TrackData> trackData;
|
|
|
|
QList<RouteData> routeData;
|
2016-10-26 20:17:05 +02:00
|
|
|
|
2019-01-18 00:17:28 +01:00
|
|
|
_valid = false;
|
2016-10-23 11:09:20 +02:00
|
|
|
_errorLine = 0;
|
|
|
|
|
2016-10-31 22:59:08 +01:00
|
|
|
if (!file.open(QFile::ReadOnly)) {
|
2016-10-23 11:09:20 +02:00
|
|
|
_errorString = qPrintable(file.errorString());
|
2019-01-18 00:17:28 +01:00
|
|
|
return;
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
|
2021-12-24 13:43:23 +01:00
|
|
|
QMultiMap<QString, Parser*>::iterator it;
|
|
|
|
QString suffix(fi.suffix().toLower());
|
|
|
|
if ((it = _parsers.find(suffix)) != _parsers.end()) {
|
|
|
|
while (it != _parsers.end() && it.key() == suffix) {
|
|
|
|
if (it.value()->parse(&file, trackData, routeData, _polygons,
|
|
|
|
_waypoints)) {
|
|
|
|
processData(trackData, routeData);
|
|
|
|
_valid = true;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_errorLine = it.value()->errorLine();
|
|
|
|
_errorString = it.value()->errorString();
|
|
|
|
}
|
|
|
|
file.reset();
|
|
|
|
++it;
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
2020-12-06 19:17:09 +01:00
|
|
|
} else if (tryUnknown) {
|
2016-10-26 20:17:05 +02:00
|
|
|
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
2019-01-31 01:46:53 +01:00
|
|
|
if (it.value()->parse(&file, trackData, routeData, _polygons,
|
|
|
|
_waypoints)) {
|
2020-03-25 23:08:26 +01:00
|
|
|
processData(trackData, routeData);
|
2019-01-18 00:17:28 +01:00
|
|
|
_valid = true;
|
|
|
|
return;
|
2016-10-26 20:17:05 +02:00
|
|
|
}
|
|
|
|
file.reset();
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
2016-10-26 20:17:05 +02:00
|
|
|
|
2018-09-24 23:07:11 +02:00
|
|
|
qWarning("Error loading data file: %s:", qPrintable(fileName));
|
2016-10-26 20:17:05 +02:00
|
|
|
for (it = _parsers.begin(); it != _parsers.end(); it++)
|
2018-09-24 23:07:11 +02:00
|
|
|
qWarning("%s: line %d: %s", qPrintable(it.key()),
|
2016-10-26 20:17:05 +02:00
|
|
|
it.value()->errorLine(), qPrintable(it.value()->errorString()));
|
|
|
|
|
|
|
|
_errorLine = 0;
|
|
|
|
_errorString = "Unknown format";
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-27 19:47:46 +02:00
|
|
|
|
|
|
|
QString Data::formats()
|
|
|
|
{
|
2018-02-04 15:30:54 +01:00
|
|
|
return
|
2020-02-12 20:33:23 +01:00
|
|
|
qApp->translate("Data", "Supported files") + " (" + filter().join(" ") + ");;"
|
2021-12-24 13:43:23 +01:00
|
|
|
+ qApp->translate("Data", "TwoNav files") + " (*.rte *.trk *.wpt);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "CSV files") + " (*.csv);;"
|
2019-08-15 21:27:55 +02:00
|
|
|
+ qApp->translate("Data", "CUP files") + " (*.cup);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "FIT files") + " (*.fit);;"
|
2019-01-25 22:18:21 +01:00
|
|
|
+ qApp->translate("Data", "GeoJSON files") + " (*.geojson *.json);;"
|
2019-10-25 22:30:12 +02:00
|
|
|
+ qApp->translate("Data", "GPI files") + " (*.gpi);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "GPX files") + " (*.gpx);;"
|
|
|
|
+ qApp->translate("Data", "IGC files") + " (*.igc);;"
|
2021-05-12 07:44:25 +02:00
|
|
|
+ qApp->translate("Data", "ITN files") + " (*.itn);;"
|
2019-03-13 00:25:46 +01:00
|
|
|
+ qApp->translate("Data", "JPEG images") + " (*.jpg *.jpeg);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "KML files") + " (*.kml);;"
|
|
|
|
+ qApp->translate("Data", "LOC files") + " (*.loc);;"
|
|
|
|
+ qApp->translate("Data", "NMEA files") + " (*.nmea);;"
|
2021-08-19 19:35:26 +02:00
|
|
|
+ qApp->translate("Data", "ONmove files") + " (*.omd *.ghp);;"
|
2021-05-09 22:39:39 +02:00
|
|
|
+ qApp->translate("Data", "OV2 files") + " (*.ov2);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "OziExplorer files") + " (*.plt *.rte *.wpt);;"
|
|
|
|
+ qApp->translate("Data", "SLF files") + " (*.slf);;"
|
2020-01-14 23:21:05 +01:00
|
|
|
+ qApp->translate("Data", "SML files") + " (*.sml);;"
|
2019-01-18 00:17:28 +01:00
|
|
|
+ qApp->translate("Data", "TCX files") + " (*.tcx);;"
|
|
|
|
+ qApp->translate("Data", "All files") + " (*)";
|
2017-07-27 19:47:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Data::filter()
|
|
|
|
{
|
|
|
|
QStringList filter;
|
|
|
|
|
2021-12-24 13:43:23 +01:00
|
|
|
for (QMultiMap<QString, Parser*>::iterator it = _parsers.begin();
|
2020-02-12 20:33:23 +01:00
|
|
|
it != _parsers.end(); it++)
|
|
|
|
filter << "*." + it.key();
|
2017-07-27 19:47:46 +02:00
|
|
|
|
|
|
|
return filter;
|
|
|
|
}
|