mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Code cleanup
This commit is contained in:
parent
0ce2f02178
commit
46989bd7a0
@ -1,25 +1,29 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
|
|
||||||
void Parser::handleExtensionData(QStringRef element, const QString &value)
|
void Parser::handleDataElement(Element element, const QString &value)
|
||||||
{
|
{
|
||||||
if (element == "speed")
|
switch (element) {
|
||||||
_track->last().speed = value.toDouble();
|
case Elevation:
|
||||||
else if (element == "hr" || element == "heartrate")
|
_track->last().elevation = value.toLatin1().toDouble();
|
||||||
_track->last().heartRate = value.toDouble();
|
break;
|
||||||
else if (element == "atemp" || element == "temp")
|
case Time:
|
||||||
_track->last().temperature = value.toDouble();
|
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
|
||||||
}
|
Qt::ISODate);
|
||||||
|
break;
|
||||||
void Parser::handleTrekPointData(QStringRef element, const QString &value)
|
case Geoidheight:
|
||||||
{
|
_track->last().geoidheight = value.toLatin1().toDouble();
|
||||||
if (element == "ele")
|
break;
|
||||||
_track->last().elevation = value.toLatin1().toDouble();
|
case Speed:
|
||||||
else if (element == "time")
|
_track->last().speed = value.toDouble();
|
||||||
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
|
break;
|
||||||
Qt::ISODate);
|
case HeartRate:
|
||||||
else if (element == "geoidheight")
|
_track->last().heartRate = value.toDouble();
|
||||||
_track->last().geoidheight = value.toLatin1().toDouble();
|
break;
|
||||||
|
case Temperature:
|
||||||
|
_track->last().temperature = value.toDouble();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleWayPointData(QStringRef element, const QString &value)
|
void Parser::handleWayPointData(QStringRef element, const QString &value)
|
||||||
@ -44,8 +48,10 @@ void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
|
|||||||
void Parser::tpExtension()
|
void Parser::tpExtension()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "hr" || _reader.name() == "atemp")
|
if (_reader.name() == "hr")
|
||||||
handleExtensionData(_reader.name(), _reader.readElementText());
|
handleDataElement(HeartRate, _reader.readElementText());
|
||||||
|
else if (_reader.name() == "atemp")
|
||||||
|
handleDataElement(Temperature, _reader.readElementText());
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -54,9 +60,12 @@ void Parser::tpExtension()
|
|||||||
void Parser::extensions()
|
void Parser::extensions()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "speed" || _reader.name() == "hr"
|
if (_reader.name() == "speed")
|
||||||
|| _reader.name() == "heartrate" || _reader.name() == "temp")
|
handleDataElement(Speed, _reader.readElementText());
|
||||||
handleExtensionData(_reader.name(), _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")
|
else if (_reader.name() == "TrackPointExtension")
|
||||||
tpExtension();
|
tpExtension();
|
||||||
else
|
else
|
||||||
@ -67,9 +76,12 @@ void Parser::extensions()
|
|||||||
void Parser::trackPointData()
|
void Parser::trackPointData()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "ele" || _reader.name() == "time"
|
if (_reader.name() == "ele")
|
||||||
|| _reader.name() == "geoidheight")
|
handleDataElement(Elevation, _reader.readElementText());
|
||||||
handleTrekPointData(_reader.name(), _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")
|
else if (_reader.name() == "extensions")
|
||||||
extensions();
|
extensions();
|
||||||
else
|
else
|
||||||
|
@ -18,6 +18,10 @@ public:
|
|||||||
int errorLine() const {return _reader.lineNumber();}
|
int errorLine() const {return _reader.lineNumber();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum Element {
|
||||||
|
Elevation, Time, Geoidheight, Speed, HeartRate, Temperature
|
||||||
|
};
|
||||||
|
|
||||||
bool parse();
|
bool parse();
|
||||||
void gpx();
|
void gpx();
|
||||||
void track();
|
void track();
|
||||||
@ -30,8 +34,7 @@ private:
|
|||||||
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
|
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleWayPointData(QStringRef element, const QString &value);
|
void handleWayPointData(QStringRef element, const QString &value);
|
||||||
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
|
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleTrekPointData(QStringRef element, const QString &value);
|
void handleDataElement(Element element, const QString &value);
|
||||||
void handleExtensionData(QStringRef element, const QString &value);
|
|
||||||
|
|
||||||
QXmlStreamReader _reader;
|
QXmlStreamReader _reader;
|
||||||
QList<QVector<Trackpoint> > &_tracks;
|
QList<QVector<Trackpoint> > &_tracks;
|
||||||
|
Loading…
Reference in New Issue
Block a user