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

Code cleanup

This commit is contained in:
Martin Tůma 2016-10-27 08:09:12 +02:00
parent 5bbf117f64
commit b67428065f
2 changed files with 25 additions and 26 deletions

View File

@ -51,23 +51,23 @@ Coordinates GPXParser::coordinates()
return Coordinates(lon, lat); return Coordinates(lon, lat);
} }
void GPXParser::handleTrackpointData(DataType type) void GPXParser::handleTrackpointData(DataType type, Trackpoint &trackpoint)
{ {
switch (type) { switch (type) {
case Elevation: case Elevation:
_track->last().setElevation(number()); trackpoint.setElevation(number());
break; break;
case Time: case Time:
_track->last().setTimestamp(time()); trackpoint.setTimestamp(time());
break; break;
case Speed: case Speed:
_track->last().setSpeed(number()); trackpoint.setSpeed(number());
break; break;
case HeartRate: case HeartRate:
_track->last().setHeartRate(number()); trackpoint.setHeartRate(number());
break; break;
case Temperature: case Temperature:
_track->last().setTemperature(number()); trackpoint.setTemperature(number());
break; break;
default: default:
break; break;
@ -94,54 +94,53 @@ void GPXParser::handleWaypointData(DataType type, Waypoint &waypoint)
} }
} }
void GPXParser::tpExtension() void GPXParser::tpExtension(Trackpoint &trackpoint)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "hr") if (_reader.name() == "hr")
handleTrackpointData(HeartRate); handleTrackpointData(HeartRate, trackpoint);
else if (_reader.name() == "atemp") else if (_reader.name() == "atemp")
handleTrackpointData(Temperature); handleTrackpointData(Temperature, trackpoint);
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void GPXParser::extensions() void GPXParser::extensions(Trackpoint &trackpoint)
{ {
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "speed") if (_reader.name() == "speed")
handleTrackpointData(Speed); handleTrackpointData(Speed, trackpoint);
else if (_reader.name() == "hr" || _reader.name() == "heartrate") else if (_reader.name() == "hr" || _reader.name() == "heartrate")
handleTrackpointData(HeartRate); handleTrackpointData(HeartRate, trackpoint);
else if (_reader.name() == "temp") else if (_reader.name() == "temp")
handleTrackpointData(Temperature); handleTrackpointData(Temperature, trackpoint);
else if (_reader.name() == "TrackPointExtension") else if (_reader.name() == "TrackPointExtension")
tpExtension(); tpExtension(trackpoint);
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
} }
void GPXParser::trackpointData() void GPXParser::trackpointData(Trackpoint &trackpoint)
{ {
qreal gh = NAN; qreal gh = NAN;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "ele") if (_reader.name() == "ele")
handleTrackpointData(Elevation); handleTrackpointData(Elevation, trackpoint);
else if (_reader.name() == "time") else if (_reader.name() == "time")
handleTrackpointData(Time); handleTrackpointData(Time, trackpoint);
else if (_reader.name() == "geoidheight") else if (_reader.name() == "geoidheight")
gh = number(); gh = number();
else if (_reader.name() == "extensions") else if (_reader.name() == "extensions")
extensions(); extensions(trackpoint);
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
Trackpoint &t = _track->last(); if (!std::isnan(gh) && !std::isnan(trackpoint.elevation()))
if (!std::isnan(gh) && !std::isnan(t.elevation())) trackpoint.setElevation(trackpoint.elevation() - gh);
t.setElevation(t.elevation() - gh);
} }
void GPXParser::waypointData(Waypoint &waypoint) void GPXParser::waypointData(Waypoint &waypoint)
@ -172,7 +171,7 @@ void GPXParser::trackpoints()
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == "trkpt") { if (_reader.name() == "trkpt") {
_track->append(Trackpoint(coordinates())); _track->append(Trackpoint(coordinates()));
trackpointData(); trackpointData(_track->last());
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }

View File

@ -28,16 +28,16 @@ private:
void track(); void track();
void trackpoints(); void trackpoints();
void routepoints(); void routepoints();
void tpExtension(); void tpExtension(Trackpoint &trackpoint);
void extensions(); void extensions(Trackpoint &trackpoint);
void trackpointData(); void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint); void waypointData(Waypoint &waypoint);
qreal number(); qreal number();
QDateTime time(); QDateTime time();
Coordinates coordinates(); Coordinates coordinates();
void handleWaypointData(DataType type, Waypoint &waypoint); void handleWaypointData(DataType type, Waypoint &waypoint);
void handleTrackpointData(DataType type); void handleTrackpointData(DataType type, Trackpoint &trackpoint);
QXmlStreamReader _reader; QXmlStreamReader _reader;
QVector<Trackpoint> *_track; QVector<Trackpoint> *_track;