2021-05-12 21:58:46 +02:00
|
|
|
#include "address.h"
|
2016-10-23 11:09:20 +02:00
|
|
|
#include "gpxparser.h"
|
2015-10-05 01:43:48 +02:00
|
|
|
|
2015-10-15 01:30:21 +02:00
|
|
|
|
2016-10-27 00:20:00 +02:00
|
|
|
qreal GPXParser::number()
|
2015-10-15 01:30:21 +02:00
|
|
|
{
|
2016-10-27 00:20:00 +02:00
|
|
|
bool res;
|
|
|
|
qreal ret = _reader.readElementText().toDouble(&res);
|
|
|
|
if (!res)
|
2016-10-29 12:22:28 +02:00
|
|
|
_reader.raiseError(QString("Invalid %1").arg(
|
2016-10-27 00:20:00 +02:00
|
|
|
_reader.name().toString()));
|
2015-10-05 01:43:48 +02:00
|
|
|
|
2016-10-27 00:20:00 +02:00
|
|
|
return ret;
|
2016-02-11 20:58:52 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 00:20:00 +02:00
|
|
|
QDateTime GPXParser::time()
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2016-10-27 00:20:00 +02:00
|
|
|
QDateTime d = QDateTime::fromString(_reader.readElementText(),
|
|
|
|
Qt::ISODate);
|
|
|
|
if (!d.isValid())
|
2016-10-29 12:22:28 +02:00
|
|
|
_reader.raiseError(QString("Invalid %1").arg(
|
2016-10-27 00:20:00 +02:00
|
|
|
_reader.name().toString()));
|
|
|
|
|
|
|
|
return d;
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2019-10-14 01:16:38 +02:00
|
|
|
Link GPXParser::link()
|
|
|
|
{
|
|
|
|
QString URL = _reader.attributes().value("href").toString();
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("text"))
|
|
|
|
text = _reader.readElementText();
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Link(URL, text);
|
|
|
|
}
|
|
|
|
|
2016-10-27 00:20:00 +02:00
|
|
|
Coordinates GPXParser::coordinates()
|
2016-10-24 00:21:40 +02:00
|
|
|
{
|
|
|
|
bool res;
|
2016-10-27 00:20:00 +02:00
|
|
|
const QXmlStreamAttributes &attr = _reader.attributes();
|
2016-10-24 00:21:40 +02:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
qreal lon = attr.value("lon").toDouble(&res);
|
2016-10-24 00:21:40 +02:00
|
|
|
if (!res || (lon < -180.0 || lon > 180.0)) {
|
2016-10-29 12:22:28 +02:00
|
|
|
_reader.raiseError("Invalid longitude");
|
2016-10-24 00:21:40 +02:00
|
|
|
return Coordinates();
|
|
|
|
}
|
2020-12-22 22:09:09 +01:00
|
|
|
qreal lat = attr.value("lat").toDouble(&res);
|
2016-10-24 00:21:40 +02:00
|
|
|
if (!res || (lat < -90.0 || lat > 90.0)) {
|
2016-10-29 12:22:28 +02:00
|
|
|
_reader.raiseError("Invalid latitude");
|
2016-10-24 00:21:40 +02:00
|
|
|
return Coordinates();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Coordinates(lon, lat);
|
|
|
|
}
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
void GPXParser::rpExtension(SegmentData *autoRoute)
|
2018-05-16 21:53:06 +02:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2019-11-08 21:00:59 +01:00
|
|
|
if (_reader.name() == QLatin1String("rpt")) {
|
|
|
|
if (autoRoute)
|
|
|
|
autoRoute->append(Trackpoint(coordinates()));
|
|
|
|
}
|
2018-05-16 22:01:21 +02:00
|
|
|
_reader.skipCurrentElement();
|
2018-05-16 21:53:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 08:09:12 +02:00
|
|
|
void GPXParser::tpExtension(Trackpoint &trackpoint)
|
2016-03-21 23:13:46 +01:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("hr"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setHeartRate(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("atemp"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setTemperature(number());
|
2024-04-01 13:30:50 +02:00
|
|
|
else if (_reader.name() == QLatin1String("wtemp")
|
|
|
|
&& !trackpoint.hasTemperature())
|
|
|
|
trackpoint.setTemperature(number());
|
2019-02-17 15:32:39 +01:00
|
|
|
else if (_reader.name() == QLatin1String("cad"))
|
|
|
|
trackpoint.setCadence(number());
|
|
|
|
else if (_reader.name() == QLatin1String("speed"))
|
|
|
|
trackpoint.setSpeed(number());
|
2016-03-21 23:13:46 +01:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 21:00:59 +01:00
|
|
|
void GPXParser::address(Waypoint &waypoint)
|
|
|
|
{
|
|
|
|
Address addr;
|
|
|
|
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("StreetAddress"))
|
|
|
|
addr.setStreet(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("City"))
|
|
|
|
addr.setCity(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("PostalCode"))
|
|
|
|
addr.setPostalCode(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("State"))
|
|
|
|
addr.setState(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("Country"))
|
|
|
|
addr.setCountry(_reader.readElementText());
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
2021-05-12 21:58:46 +02:00
|
|
|
if (addr.isValid())
|
|
|
|
waypoint.setAddress(addr.address());
|
2019-11-08 21:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::wpExtension(Waypoint &waypoint)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("Address"))
|
|
|
|
address(waypoint);
|
2021-05-12 21:58:46 +02:00
|
|
|
else if (_reader.name() == QLatin1String("PhoneNumber"))
|
|
|
|
waypoint.setPhone(_reader.readElementText());
|
2019-11-08 21:00:59 +01:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::waypointExtensions(Waypoint &waypoint, SegmentData *autoRoute)
|
2018-05-16 21:53:06 +02:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("RoutePointExtension"))
|
2018-05-16 21:53:06 +02:00
|
|
|
rpExtension(autoRoute);
|
2019-11-08 21:00:59 +01:00
|
|
|
else if (_reader.name() == QLatin1String("WaypointExtension"))
|
|
|
|
wpExtension(waypoint);
|
2018-05-16 21:53:06 +02:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::trkptExtensions(Trackpoint &trackpoint)
|
2015-10-15 01:30:21 +02:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("speed"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setSpeed(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("hr")
|
|
|
|
|| _reader.name() == QLatin1String("heartrate"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setHeartRate(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("temp"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setTemperature(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("cadence"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setCadence(number());
|
2023-04-17 23:32:48 +02:00
|
|
|
else if (_reader.name() == QLatin1String("power")
|
|
|
|
|| _reader.name() == QLatin1String("PowerInWatts"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setPower(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("TrackPointExtension"))
|
2016-10-27 08:09:12 +02:00
|
|
|
tpExtension(trackpoint);
|
2015-10-15 01:30:21 +02:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 08:09:12 +02:00
|
|
|
void GPXParser::trackpointData(Trackpoint &trackpoint)
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
2016-10-27 00:20:00 +02:00
|
|
|
qreal gh = NAN;
|
|
|
|
|
2015-10-05 01:43:48 +02:00
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("ele"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setElevation(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("time"))
|
2016-11-06 03:28:08 +01:00
|
|
|
trackpoint.setTimestamp(time());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("geoidheight"))
|
2016-10-27 00:20:00 +02:00
|
|
|
gh = number();
|
2019-05-28 23:26:03 +02:00
|
|
|
// GPX 1.0
|
|
|
|
else if (_reader.name() == QLatin1String("speed"))
|
|
|
|
trackpoint.setSpeed(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("extensions"))
|
2018-05-16 21:53:06 +02:00
|
|
|
trkptExtensions(trackpoint);
|
2015-10-05 01:43:48 +02:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
2016-10-27 08:09:12 +02:00
|
|
|
if (!std::isnan(gh) && !std::isnan(trackpoint.elevation()))
|
|
|
|
trackpoint.setElevation(trackpoint.elevation() - gh);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute)
|
2016-10-23 11:09:20 +02:00
|
|
|
{
|
2016-10-27 00:20:00 +02:00
|
|
|
qreal gh = NAN;
|
2019-10-20 20:30:10 +02:00
|
|
|
Link link10;
|
2016-10-27 00:20:00 +02:00
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("name"))
|
2016-11-06 03:28:08 +01:00
|
|
|
waypoint.setName(_reader.readElementText());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("desc"))
|
2016-11-06 03:28:08 +01:00
|
|
|
waypoint.setDescription(_reader.readElementText());
|
2020-03-09 20:04:13 +01:00
|
|
|
else if (_reader.name() == QLatin1String("cmt"))
|
|
|
|
waypoint.setComment(_reader.readElementText());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("ele"))
|
2016-11-06 03:28:08 +01:00
|
|
|
waypoint.setElevation(number());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("geoidheight"))
|
2016-10-27 00:20:00 +02:00
|
|
|
gh = number();
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("time"))
|
2016-11-06 03:28:08 +01:00
|
|
|
waypoint.setTimestamp(time());
|
2019-10-20 20:30:10 +02:00
|
|
|
else if (_reader.name() == QLatin1String("link")) {
|
|
|
|
Link l(link());
|
|
|
|
if (!l.URL().isEmpty())
|
|
|
|
waypoint.addLink(l);
|
|
|
|
} else if (_reader.name() == QLatin1String("url"))
|
|
|
|
link10.setURL(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("urlname"))
|
|
|
|
link10.setText(_reader.readElementText());
|
2019-11-08 21:00:59 +01:00
|
|
|
else if (_reader.name() == QLatin1String("extensions"))
|
|
|
|
waypointExtensions(waypoint, autoRoute);
|
2021-10-10 08:38:38 +02:00
|
|
|
else if (_reader.name() == QLatin1String("sym"))
|
|
|
|
waypoint.setSymbol(_reader.readElementText());
|
2016-10-23 11:09:20 +02:00
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
2016-10-27 00:20:00 +02:00
|
|
|
|
2019-10-20 20:30:10 +02:00
|
|
|
if (!link10.URL().isEmpty())
|
|
|
|
waypoint.addLink(link10);
|
2016-10-27 00:20:00 +02:00
|
|
|
if (!std::isnan(gh) && !std::isnan(waypoint.elevation()))
|
|
|
|
waypoint.setElevation(waypoint.elevation() - gh);
|
2016-10-23 11:09:20 +02:00
|
|
|
}
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
void GPXParser::trackpoints(SegmentData &segment)
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("trkpt")) {
|
2019-02-11 23:28:08 +01:00
|
|
|
segment.append(Trackpoint(coordinates()));
|
|
|
|
trackpointData(segment.last());
|
2015-10-05 01:43:48 +02:00
|
|
|
} else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 02:34:18 +02:00
|
|
|
void GPXParser::routeExtension(RouteData &route)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("DisplayColor"))
|
|
|
|
route.setStyle(LineStyle(QColor(_reader.readElementText())));
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::routeExtensions(RouteData &track)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("RouteExtension"))
|
|
|
|
routeExtension(track);
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-16 21:53:06 +02:00
|
|
|
void GPXParser::routepoints(RouteData &route, QList<TrackData> &tracks)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2018-05-16 21:53:06 +02:00
|
|
|
TrackData autoRoute;
|
2019-02-11 23:28:08 +01:00
|
|
|
autoRoute.append(SegmentData());
|
|
|
|
SegmentData &autoRouteSegment = autoRoute.last();
|
2019-10-20 20:30:10 +02:00
|
|
|
Link link10;
|
2018-05-16 21:53:06 +02:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("rtept")) {
|
2016-10-27 08:27:25 +02:00
|
|
|
route.append(Waypoint(coordinates()));
|
2019-02-11 23:28:08 +01:00
|
|
|
waypointData(route.last(), &autoRouteSegment);
|
2018-08-27 22:25:55 +02:00
|
|
|
} else if (_reader.name() == QLatin1String("name"))
|
2016-10-28 14:33:36 +02:00
|
|
|
route.setName(_reader.readElementText());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("desc"))
|
2016-10-28 14:33:36 +02:00
|
|
|
route.setDescription(_reader.readElementText());
|
2020-03-09 20:04:13 +01:00
|
|
|
else if (_reader.name() == QLatin1String("cmt"))
|
|
|
|
route.setComment(_reader.readElementText());
|
2019-10-20 20:30:10 +02:00
|
|
|
else if (_reader.name() == QLatin1String("link")) {
|
|
|
|
Link l(link());
|
|
|
|
if (!l.URL().isEmpty())
|
|
|
|
route.addLink(l);
|
|
|
|
} else if (_reader.name() == QLatin1String("url"))
|
|
|
|
link10.setURL(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("urlname"))
|
|
|
|
link10.setText(_reader.readElementText());
|
2022-09-23 02:34:18 +02:00
|
|
|
else if (_reader.name() == QLatin1String("extensions"))
|
|
|
|
routeExtensions(route);
|
2016-10-28 14:33:36 +02:00
|
|
|
else
|
2016-08-09 01:16:19 +02:00
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
2018-05-16 21:53:06 +02:00
|
|
|
|
2019-10-20 20:30:10 +02:00
|
|
|
if (!link10.URL().isEmpty())
|
|
|
|
route.addLink(link10);
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
if (!autoRouteSegment.isEmpty()) {
|
2018-05-16 21:53:06 +02:00
|
|
|
autoRoute.setName(route.name());
|
|
|
|
autoRoute.setDescription(route.description());
|
|
|
|
tracks.append(autoRoute);
|
|
|
|
}
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 02:34:18 +02:00
|
|
|
void GPXParser::trackExtension(TrackData &track)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("DisplayColor"))
|
|
|
|
track.setStyle(LineStyle(QColor(_reader.readElementText())));
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::trackExtensions(TrackData &track)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("TrackExtension"))
|
|
|
|
trackExtension(track);
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 14:33:36 +02:00
|
|
|
void GPXParser::track(TrackData &track)
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
2019-10-20 20:30:10 +02:00
|
|
|
Link link10;
|
|
|
|
|
2015-10-05 01:43:48 +02:00
|
|
|
while (_reader.readNextStartElement()) {
|
2019-02-11 23:28:08 +01:00
|
|
|
if (_reader.name() == QLatin1String("trkseg")) {
|
|
|
|
track.append(SegmentData());
|
|
|
|
trackpoints(track.last());
|
|
|
|
} else if (_reader.name() == QLatin1String("name"))
|
2016-10-28 14:33:36 +02:00
|
|
|
track.setName(_reader.readElementText());
|
2018-08-27 22:25:55 +02:00
|
|
|
else if (_reader.name() == QLatin1String("desc"))
|
2016-10-28 14:33:36 +02:00
|
|
|
track.setDescription(_reader.readElementText());
|
2020-03-09 20:04:13 +01:00
|
|
|
else if (_reader.name() == QLatin1String("cmt"))
|
|
|
|
track.setComment(_reader.readElementText());
|
2019-10-20 20:30:10 +02:00
|
|
|
else if (_reader.name() == QLatin1String("link")) {
|
|
|
|
Link l(link());
|
|
|
|
if (!l.URL().isEmpty())
|
|
|
|
track.addLink(l);
|
|
|
|
} else if (_reader.name() == QLatin1String("url"))
|
|
|
|
link10.setURL(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("urlname"))
|
|
|
|
link10.setText(_reader.readElementText());
|
2022-09-23 02:34:18 +02:00
|
|
|
else if (_reader.name() == QLatin1String("extensions"))
|
|
|
|
trackExtensions(track);
|
2016-10-28 14:33:36 +02:00
|
|
|
else
|
2015-10-05 01:43:48 +02:00
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
2019-10-20 20:30:10 +02:00
|
|
|
|
|
|
|
if (!link10.URL().isEmpty())
|
|
|
|
track.addLink(link10);
|
2015-10-05 01:43:48 +02:00
|
|
|
}
|
|
|
|
|
2019-02-01 00:26:27 +01:00
|
|
|
void GPXParser::area(Area &area)
|
|
|
|
{
|
2021-03-07 11:58:21 +01:00
|
|
|
QVector<Coordinates> points;
|
2019-02-01 00:26:27 +01:00
|
|
|
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("point")) {
|
|
|
|
Coordinates c(coordinates());
|
|
|
|
_reader.readElementText();
|
|
|
|
if (c.isValid())
|
|
|
|
points.append(c);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
} else if (_reader.name() == QLatin1String("name"))
|
|
|
|
area.setName(_reader.readElementText());
|
|
|
|
else if (_reader.name() == QLatin1String("desc"))
|
|
|
|
area.setDescription(_reader.readElementText());
|
|
|
|
else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
2021-03-07 11:58:21 +01:00
|
|
|
|
|
|
|
area.append(points);
|
2019-02-01 00:26:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPXParser::gpxExtensions(QList<Area> &areas)
|
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
|
|
|
if (_reader.name() == QLatin1String("area")) {
|
|
|
|
areas.append(Area());
|
|
|
|
area(areas.last());
|
|
|
|
} else
|
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
|
2019-02-01 00:26:27 +01:00
|
|
|
QList<Area> &areas, QVector<Waypoint> &waypoints)
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
|
|
|
while (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("trk")) {
|
2017-07-27 19:47:46 +02:00
|
|
|
tracks.append(TrackData());
|
|
|
|
track(tracks.back());
|
2018-08-27 22:25:55 +02:00
|
|
|
} else if (_reader.name() == QLatin1String("rte")) {
|
2017-07-27 19:47:46 +02:00
|
|
|
routes.append(RouteData());
|
2018-05-16 21:53:06 +02:00
|
|
|
routepoints(routes.back(), tracks);
|
2018-08-27 22:25:55 +02:00
|
|
|
} else if (_reader.name() == QLatin1String("wpt")) {
|
2017-07-27 19:47:46 +02:00
|
|
|
waypoints.append(Waypoint(coordinates()));
|
|
|
|
waypointData(waypoints.last());
|
2019-02-01 00:26:27 +01:00
|
|
|
} else if (_reader.name() == QLatin1String("extensions"))
|
|
|
|
gpxExtensions(areas);
|
|
|
|
else
|
2015-10-05 01:43:48 +02:00
|
|
|
_reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:47:46 +02:00
|
|
|
bool GPXParser::parse(QFile *file, QList<TrackData> &tracks,
|
2019-02-01 00:26:27 +01:00
|
|
|
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
|
2015-10-05 01:43:48 +02:00
|
|
|
{
|
2017-07-27 19:47:46 +02:00
|
|
|
_reader.clear();
|
|
|
|
_reader.setDevice(file);
|
2018-05-08 22:09:39 +02:00
|
|
|
_reader.setNamespaceProcessing(false);
|
2017-07-27 19:47:46 +02:00
|
|
|
|
2015-10-05 01:43:48 +02:00
|
|
|
if (_reader.readNextStartElement()) {
|
2018-08-27 22:25:55 +02:00
|
|
|
if (_reader.name() == QLatin1String("gpx"))
|
2019-02-01 00:26:27 +01:00
|
|
|
gpx(tracks, routes, areas, waypoints);
|
2015-10-05 01:43:48 +02:00
|
|
|
else
|
2016-10-29 12:22:28 +02:00
|
|
|
_reader.raiseError("Not a GPX file");
|
2015-10-05 01:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return !_reader.error();
|
|
|
|
}
|