1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Added support for GPX area extensions

This commit is contained in:
Martin Tůma 2019-02-01 00:26:27 +01:00
parent 4854bff31b
commit 67168b8063
2 changed files with 44 additions and 9 deletions

View File

@ -197,8 +197,42 @@ void GPXParser::track(TrackData &track)
}
}
void GPXParser::area(Area &area)
{
area.append(Polygon());
area.last().append(QVector<Coordinates>());
QVector<Coordinates> &points = area.last().last();
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();
}
}
void GPXParser::gpxExtensions(QList<Area> &areas)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("area")) {
areas.append(Area());
area(areas.last());
} else
_reader.skipCurrentElement();
}
}
void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
QVector<Waypoint> &waypoints)
QList<Area> &areas, QVector<Waypoint> &waypoints)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("trk")) {
@ -210,24 +244,23 @@ void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
} else if (_reader.name() == QLatin1String("wpt")) {
waypoints.append(Waypoint(coordinates()));
waypointData(waypoints.last());
} else
} else if (_reader.name() == QLatin1String("extensions"))
gpxExtensions(areas);
else
_reader.skipCurrentElement();
}
}
bool GPXParser::parse(QFile *file, QList<TrackData> &tracks,
QList<RouteData> &routes, QList<Area> &polygons,
QVector<Waypoint> &waypoints)
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
{
Q_UNUSED(polygons);
_reader.clear();
_reader.setDevice(file);
_reader.setNamespaceProcessing(false);
if (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("gpx"))
gpx(tracks, routes, waypoints);
gpx(tracks, routes, areas, waypoints);
else
_reader.raiseError("Not a GPX file");
}

View File

@ -9,13 +9,13 @@ class GPXParser : public Parser
{
public:
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
QList<Area> &polygons, QVector<Waypoint> &waypoints);
QList<Area> &areas, QVector<Waypoint> &waypoints);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
void gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
QVector<Waypoint> &waypoints);
QList<Area> &areas, QVector<Waypoint> &waypoints);
void track(TrackData &track);
void trackpoints(TrackData &track);
void routepoints(RouteData &route, QList<TrackData> &tracks);
@ -23,6 +23,8 @@ private:
void tpExtension(Trackpoint &trackpoint);
void trkptExtensions(Trackpoint &trackpoint);
void rteptExtensions(TrackData *autoRoute);
void area(Area &area);
void gpxExtensions(QList<Area> &areas);
void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint, TrackData *autoRoute = 0);
qreal number();