1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 09:05:14 +01:00

Fixed TCX parser

This commit is contained in:
Martin Tůma 2016-10-24 00:51:19 +02:00
parent 27194d3d36
commit 1c5a19a33a
2 changed files with 35 additions and 30 deletions

View File

@ -13,13 +13,13 @@ Coordinates TCXParser::position()
if (!res || (val < -90.0 || val > 90.0)) if (!res || (val < -90.0 || val > 90.0))
_reader.raiseError("Invalid latitude."); _reader.raiseError("Invalid latitude.");
else else
pos.setLat(_reader.readElementText().toDouble(&res)); pos.setLat(val);
} else if (_reader.name() == "LongitudeDegrees") { } else if (_reader.name() == "LongitudeDegrees") {
val = _reader.readElementText().toDouble(&res); val = _reader.readElementText().toDouble(&res);
if (!res || (val < -180.0 || val > 180.0)) if (!res || (val < -180.0 || val > 180.0))
_reader.raiseError("Invalid longitude."); _reader.raiseError("Invalid longitude.");
else else
pos.setLon(_reader.readElementText().toDouble(&res)); pos.setLon(val);
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -27,53 +27,52 @@ Coordinates TCXParser::position()
return pos; return pos;
} }
void TCXParser::trackpointData() void TCXParser::trackpointData(Trackpoint &t)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "Position") if (_reader.name() == "Position")
_track->last().setCoordinates(position()); t.setCoordinates(position());
else if (_reader.name() == "AltitudeMeters") else if (_reader.name() == "AltitudeMeters")
_track->last().setElevation(_reader.readElementText().toDouble()); t.setElevation(_reader.readElementText().toDouble());
else if (_reader.name() == "Time") else if (_reader.name() == "Time")
_track->last().setTimestamp(QDateTime::fromString( t.setTimestamp(QDateTime::fromString(_reader.readElementText(),
_reader.readElementText(), Qt::ISODate)); Qt::ISODate));
else if (_reader.name() == "HeartRateBpm") else if (_reader.name() == "HeartRateBpm")
_track->last().setHeartRate(_reader.readElementText().toDouble()); t.setHeartRate(_reader.readElementText().toDouble());
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void TCXParser::routepointData() void TCXParser::routepointData(Waypoint &w)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "Position") if (_reader.name() == "Position")
_route->last().setCoordinates(position()); w.setCoordinates(position());
else if (_reader.name() == "AltitudeMeters") else if (_reader.name() == "AltitudeMeters")
_route->last().setElevation(_reader.readElementText().toDouble()); w.setElevation(_reader.readElementText().toDouble());
else if (_reader.name() == "Time") else if (_reader.name() == "Time")
_route->last().setTimestamp(QDateTime::fromString( w.setTimestamp(QDateTime::fromString(_reader.readElementText(),
_reader.readElementText(), Qt::ISODate)); Qt::ISODate));
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void TCXParser::waypointData() void TCXParser::waypointData(Waypoint &w)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "Position") if (_reader.name() == "Position")
_waypoints.last().setCoordinates(position()); w.setCoordinates(position());
else if (_reader.name() == "Name") else if (_reader.name() == "Name")
_waypoints.last().setName(_reader.readElementText()); w.setName(_reader.readElementText());
else if (_reader.name() == "Notes") else if (_reader.name() == "Notes")
_waypoints.last().setDescription(_reader.readElementText()); w.setDescription(_reader.readElementText());
else if (_reader.name() == "AltitudeMeters") else if (_reader.name() == "AltitudeMeters")
_waypoints.last().setElevation( w.setElevation(_reader.readElementText().toDouble());
_reader.readElementText().toDouble());
else if (_reader.name() == "Time") else if (_reader.name() == "Time")
_waypoints.last().setTimestamp(QDateTime::fromString( w.setTimestamp(QDateTime::fromString(_reader.readElementText(),
_reader.readElementText(), Qt::ISODate)); Qt::ISODate));
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -83,8 +82,10 @@ void TCXParser::trackpoints()
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "Trackpoint") { if (_reader.name() == "Trackpoint") {
_track->append(Trackpoint()); Trackpoint t;
trackpointData(); trackpointData(t);
if (t.coordinates().isValid())
_track->append(t);
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -94,8 +95,10 @@ void TCXParser::routepoints()
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "Trackpoint") { if (_reader.name() == "Trackpoint") {
_route->append(Waypoint()); Waypoint w;
routepointData(); routepointData(w);
if (w.coordinates().isValid())
_route->append(w);
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -121,8 +124,10 @@ void TCXParser::course()
_route = &_routes.back(); _route = &_routes.back();
routepoints(); routepoints();
} else if (_reader.name() == "CoursePoint") { } else if (_reader.name() == "CoursePoint") {
_waypoints.append(Waypoint()); Waypoint w;
waypointData(); waypointData(w);
if (w.coordinates().isValid())
_waypoints.append(w);
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }

View File

@ -29,9 +29,9 @@ private:
void lap(); void lap();
void trackpoints(); void trackpoints();
void routepoints(); void routepoints();
void trackpointData(); void trackpointData(Trackpoint &t);
void routepointData(); void routepointData(Waypoint &w);
void waypointData(); void waypointData(Waypoint &w);
Coordinates position(); Coordinates position();
QXmlStreamReader _reader; QXmlStreamReader _reader;