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

Code cleanup

This commit is contained in:
Martin Tůma 2016-06-20 23:56:42 +02:00
parent 0ce2f02178
commit 46989bd7a0
2 changed files with 43 additions and 28 deletions

View File

@ -1,25 +1,29 @@
#include "parser.h"
void Parser::handleExtensionData(QStringRef element, const QString &value)
void Parser::handleDataElement(Element element, const QString &value)
{
if (element == "speed")
_track->last().speed = value.toDouble();
else if (element == "hr" || element == "heartrate")
_track->last().heartRate = value.toDouble();
else if (element == "atemp" || element == "temp")
_track->last().temperature = value.toDouble();
}
void Parser::handleTrekPointData(QStringRef element, const QString &value)
{
if (element == "ele")
_track->last().elevation = value.toLatin1().toDouble();
else if (element == "time")
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
Qt::ISODate);
else if (element == "geoidheight")
_track->last().geoidheight = value.toLatin1().toDouble();
switch (element) {
case Elevation:
_track->last().elevation = value.toLatin1().toDouble();
break;
case Time:
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
Qt::ISODate);
break;
case Geoidheight:
_track->last().geoidheight = value.toLatin1().toDouble();
break;
case Speed:
_track->last().speed = value.toDouble();
break;
case HeartRate:
_track->last().heartRate = value.toDouble();
break;
case Temperature:
_track->last().temperature = value.toDouble();
break;
}
}
void Parser::handleWayPointData(QStringRef element, const QString &value)
@ -44,8 +48,10 @@ void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
void Parser::tpExtension()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "hr" || _reader.name() == "atemp")
handleExtensionData(_reader.name(), _reader.readElementText());
if (_reader.name() == "hr")
handleDataElement(HeartRate, _reader.readElementText());
else if (_reader.name() == "atemp")
handleDataElement(Temperature, _reader.readElementText());
else
_reader.skipCurrentElement();
}
@ -54,9 +60,12 @@ void Parser::tpExtension()
void Parser::extensions()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed" || _reader.name() == "hr"
|| _reader.name() == "heartrate" || _reader.name() == "temp")
handleExtensionData(_reader.name(), _reader.readElementText());
if (_reader.name() == "speed")
handleDataElement(Speed, _reader.readElementText());
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
handleDataElement(HeartRate, _reader.readElementText());
else if (_reader.name() == "temp")
handleDataElement(Temperature, _reader.readElementText());
else if (_reader.name() == "TrackPointExtension")
tpExtension();
else
@ -67,9 +76,12 @@ void Parser::extensions()
void Parser::trackPointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "ele" || _reader.name() == "time"
|| _reader.name() == "geoidheight")
handleTrekPointData(_reader.name(), _reader.readElementText());
if (_reader.name() == "ele")
handleDataElement(Elevation, _reader.readElementText());
else if (_reader.name() == "time")
handleDataElement(Time, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleDataElement(Geoidheight, _reader.readElementText());
else if (_reader.name() == "extensions")
extensions();
else

View File

@ -18,6 +18,10 @@ public:
int errorLine() const {return _reader.lineNumber();}
private:
enum Element {
Elevation, Time, Geoidheight, Speed, HeartRate, Temperature
};
bool parse();
void gpx();
void track();
@ -30,8 +34,7 @@ private:
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
void handleWayPointData(QStringRef element, const QString &value);
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
void handleTrekPointData(QStringRef element, const QString &value);
void handleExtensionData(QStringRef element, const QString &value);
void handleDataElement(Element element, const QString &value);
QXmlStreamReader _reader;
QList<QVector<Trackpoint> > &_tracks;