1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Some more GPX parser code cleanup

This commit is contained in:
Martin Tůma 2016-10-27 08:27:25 +02:00
parent b67428065f
commit a773921da0
2 changed files with 14 additions and 18 deletions

View File

@ -166,33 +166,33 @@ void GPXParser::waypointData(Waypoint &waypoint)
waypoint.setElevation(waypoint.elevation() - gh); waypoint.setElevation(waypoint.elevation() - gh);
} }
void GPXParser::trackpoints() void GPXParser::trackpoints(QVector<Trackpoint> &track)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") { if (_reader.name() == "trkpt") {
_track->append(Trackpoint(coordinates())); track.append(Trackpoint(coordinates()));
trackpointData(_track->last()); trackpointData(track.last());
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void GPXParser::routepoints() void GPXParser::routepoints(QVector<Waypoint> &route)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") { if (_reader.name() == "rtept") {
_route->append(Waypoint(coordinates())); route.append(Waypoint(coordinates()));
waypointData(_route->last()); waypointData(route.last());
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void GPXParser::track() void GPXParser::track(QVector<Trackpoint> &track)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trkseg") { if (_reader.name() == "trkseg") {
trackpoints(); trackpoints(track);
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -203,12 +203,10 @@ void GPXParser::gpx()
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trk") { if (_reader.name() == "trk") {
_tracks.append(QVector<Trackpoint>()); _tracks.append(QVector<Trackpoint>());
_track = &_tracks.back(); track(_tracks.back());
track();
} else if (_reader.name() == "rte") { } else if (_reader.name() == "rte") {
_routes.append(QVector<Waypoint>()); _routes.append(QVector<Waypoint>());
_route = &_routes.back(); routepoints(_routes.back());
routepoints();
} else if (_reader.name() == "wpt") { } else if (_reader.name() == "wpt") {
_waypoints.append(Waypoint(coordinates())); _waypoints.append(Waypoint(coordinates()));
waypointData(_waypoints.last()); waypointData(_waypoints.last());

View File

@ -11,7 +11,7 @@ class GPXParser : public Parser
public: public:
GPXParser(QList<QVector<Trackpoint> > &tracks, GPXParser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints) QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: Parser(tracks, routes, waypoints) {_track = 0; _route = 0;} : Parser(tracks, routes, waypoints) {}
~GPXParser() {} ~GPXParser() {}
bool loadFile(QIODevice *device); bool loadFile(QIODevice *device);
@ -25,9 +25,9 @@ private:
bool parse(); bool parse();
void gpx(); void gpx();
void track(); void track(QVector<Trackpoint> &track);
void trackpoints(); void trackpoints(QVector<Trackpoint> &track);
void routepoints(); void routepoints(QVector<Waypoint> &route);
void tpExtension(Trackpoint &trackpoint); void tpExtension(Trackpoint &trackpoint);
void extensions(Trackpoint &trackpoint); void extensions(Trackpoint &trackpoint);
void trackpointData(Trackpoint &trackpoint); void trackpointData(Trackpoint &trackpoint);
@ -40,8 +40,6 @@ private:
void handleTrackpointData(DataType type, Trackpoint &trackpoint); void handleTrackpointData(DataType type, Trackpoint &trackpoint);
QXmlStreamReader _reader; QXmlStreamReader _reader;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
}; };
#endif // GPXPARSER_H #endif // GPXPARSER_H