diff --git a/src/data/gpxparser.cpp b/src/data/gpxparser.cpp index ef02dec3..0286c086 100644 --- a/src/data/gpxparser.cpp +++ b/src/data/gpxparser.cpp @@ -197,8 +197,42 @@ void GPXParser::track(TrackData &track) } } +void GPXParser::area(Area &area) +{ + area.append(Polygon()); + area.last().append(QVector()); + QVector &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 &areas) +{ + while (_reader.readNextStartElement()) { + if (_reader.name() == QLatin1String("area")) { + areas.append(Area()); + area(areas.last()); + } else + _reader.skipCurrentElement(); + } +} + void GPXParser::gpx(QList &tracks, QList &routes, - QVector &waypoints) + QList &areas, QVector &waypoints) { while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("trk")) { @@ -210,24 +244,23 @@ void GPXParser::gpx(QList &tracks, QList &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 &tracks, - QList &routes, QList &polygons, - QVector &waypoints) + QList &routes, QList &areas, QVector &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"); } diff --git a/src/data/gpxparser.h b/src/data/gpxparser.h index 26d42ad7..978f83fc 100644 --- a/src/data/gpxparser.h +++ b/src/data/gpxparser.h @@ -9,13 +9,13 @@ class GPXParser : public Parser { public: bool parse(QFile *file, QList &tracks, QList &routes, - QList &polygons, QVector &waypoints); + QList &areas, QVector &waypoints); QString errorString() const {return _reader.errorString();} int errorLine() const {return _reader.lineNumber();} private: void gpx(QList &tracks, QList &routes, - QVector &waypoints); + QList &areas, QVector &waypoints); void track(TrackData &track); void trackpoints(TrackData &track); void routepoints(RouteData &route, QList &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 &areas); void trackpointData(Trackpoint &trackpoint); void waypointData(Waypoint &waypoint, TrackData *autoRoute = 0); qreal number();