mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Refactoring
This commit is contained in:
parent
46989bd7a0
commit
68671ed994
@ -1,7 +1,8 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
|
|
||||||
void Parser::handleDataElement(Element element, const QString &value)
|
void Parser::handleTrackpointData(TrackpointElement element,
|
||||||
|
const QString &value)
|
||||||
{
|
{
|
||||||
switch (element) {
|
switch (element) {
|
||||||
case Elevation:
|
case Elevation:
|
||||||
@ -26,19 +27,19 @@ void Parser::handleDataElement(Element element, const QString &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleWayPointData(QStringRef element, const QString &value)
|
void Parser::handleWaypointData(WaypointElement element, const QString &value)
|
||||||
{
|
{
|
||||||
if (element == "name")
|
if (element == Name)
|
||||||
_waypoints.last().setDescription(value);
|
_waypoints.last().setDescription(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleTrekPointAttributes(const QXmlStreamAttributes &attr)
|
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
|
||||||
{
|
{
|
||||||
_track->last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
|
_track->last().coordinates.setY(attr.value("lat").toLatin1().toDouble());
|
||||||
_track->last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
|
_track->last().coordinates.setX(attr.value("lon").toLatin1().toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
|
void Parser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
|
||||||
{
|
{
|
||||||
_waypoints.last().setCoordinates(QPointF(
|
_waypoints.last().setCoordinates(QPointF(
|
||||||
attr.value("lon").toLatin1().toDouble(),
|
attr.value("lon").toLatin1().toDouble(),
|
||||||
@ -49,9 +50,9 @@ void Parser::tpExtension()
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "hr")
|
if (_reader.name() == "hr")
|
||||||
handleDataElement(HeartRate, _reader.readElementText());
|
handleTrackpointData(HeartRate, _reader.readElementText());
|
||||||
else if (_reader.name() == "atemp")
|
else if (_reader.name() == "atemp")
|
||||||
handleDataElement(Temperature, _reader.readElementText());
|
handleTrackpointData(Temperature, _reader.readElementText());
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -61,11 +62,11 @@ void Parser::extensions()
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "speed")
|
if (_reader.name() == "speed")
|
||||||
handleDataElement(Speed, _reader.readElementText());
|
handleTrackpointData(Speed, _reader.readElementText());
|
||||||
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
|
else if (_reader.name() == "hr" || _reader.name() == "heartrate")
|
||||||
handleDataElement(HeartRate, _reader.readElementText());
|
handleTrackpointData(HeartRate, _reader.readElementText());
|
||||||
else if (_reader.name() == "temp")
|
else if (_reader.name() == "temp")
|
||||||
handleDataElement(Temperature, _reader.readElementText());
|
handleTrackpointData(Temperature, _reader.readElementText());
|
||||||
else if (_reader.name() == "TrackPointExtension")
|
else if (_reader.name() == "TrackPointExtension")
|
||||||
tpExtension();
|
tpExtension();
|
||||||
else
|
else
|
||||||
@ -73,15 +74,15 @@ void Parser::extensions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::trackPointData()
|
void Parser::trackpointData()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "ele")
|
if (_reader.name() == "ele")
|
||||||
handleDataElement(Elevation, _reader.readElementText());
|
handleTrackpointData(Elevation, _reader.readElementText());
|
||||||
else if (_reader.name() == "time")
|
else if (_reader.name() == "time")
|
||||||
handleDataElement(Time, _reader.readElementText());
|
handleTrackpointData(Time, _reader.readElementText());
|
||||||
else if (_reader.name() == "geoidheight")
|
else if (_reader.name() == "geoidheight")
|
||||||
handleDataElement(Geoidheight, _reader.readElementText());
|
handleTrackpointData(Geoidheight, _reader.readElementText());
|
||||||
else if (_reader.name() == "extensions")
|
else if (_reader.name() == "extensions")
|
||||||
extensions();
|
extensions();
|
||||||
else
|
else
|
||||||
@ -89,13 +90,13 @@ void Parser::trackPointData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::trackPoints()
|
void Parser::trackpoints()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "trkpt") {
|
if (_reader.name() == "trkpt") {
|
||||||
_track->append(Trackpoint());
|
_track->append(Trackpoint());
|
||||||
handleTrekPointAttributes(_reader.attributes());
|
handleTrackpointAttributes(_reader.attributes());
|
||||||
trackPointData();
|
trackpointData();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -105,17 +106,17 @@ void Parser::track()
|
|||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "trkseg") {
|
if (_reader.name() == "trkseg") {
|
||||||
trackPoints();
|
trackpoints();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::wayPointData()
|
void Parser::waypointData()
|
||||||
{
|
{
|
||||||
while (_reader.readNextStartElement()) {
|
while (_reader.readNextStartElement()) {
|
||||||
if (_reader.name() == "name")
|
if (_reader.name() == "name")
|
||||||
handleWayPointData(_reader.name(), _reader.readElementText());
|
handleWaypointData(Name, _reader.readElementText());
|
||||||
else
|
else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -130,8 +131,8 @@ void Parser::gpx()
|
|||||||
track();
|
track();
|
||||||
} else if (_reader.name() == "wpt") {
|
} else if (_reader.name() == "wpt") {
|
||||||
_waypoints.append(Waypoint());
|
_waypoints.append(Waypoint());
|
||||||
handleWayPointAttributes(_reader.attributes());
|
handleWaypointAttributes(_reader.attributes());
|
||||||
wayPointData();
|
waypointData();
|
||||||
} else
|
} else
|
||||||
_reader.skipCurrentElement();
|
_reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
19
src/parser.h
19
src/parser.h
@ -18,23 +18,26 @@ public:
|
|||||||
int errorLine() const {return _reader.lineNumber();}
|
int errorLine() const {return _reader.lineNumber();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Element {
|
enum TrackpointElement {
|
||||||
Elevation, Time, Geoidheight, Speed, HeartRate, Temperature
|
Elevation, Time, Geoidheight, Speed, HeartRate, Temperature
|
||||||
};
|
};
|
||||||
|
enum WaypointElement {
|
||||||
|
Name
|
||||||
|
};
|
||||||
|
|
||||||
bool parse();
|
bool parse();
|
||||||
void gpx();
|
void gpx();
|
||||||
void track();
|
void track();
|
||||||
void trackPoints();
|
void trackpoints();
|
||||||
void tpExtension();
|
void tpExtension();
|
||||||
void extensions();
|
void extensions();
|
||||||
void trackPointData();
|
void trackpointData();
|
||||||
void wayPointData();
|
void waypointData();
|
||||||
|
|
||||||
void handleWayPointAttributes(const QXmlStreamAttributes &attr);
|
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleWayPointData(QStringRef element, const QString &value);
|
void handleWaypointData(WaypointElement element, const QString &value);
|
||||||
void handleTrekPointAttributes(const QXmlStreamAttributes &attr);
|
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
|
||||||
void handleDataElement(Element element, const QString &value);
|
void handleTrackpointData(TrackpointElement element, const QString &value);
|
||||||
|
|
||||||
QXmlStreamReader _reader;
|
QXmlStreamReader _reader;
|
||||||
QList<QVector<Trackpoint> > &_tracks;
|
QList<QVector<Trackpoint> > &_tracks;
|
||||||
|
Loading…
Reference in New Issue
Block a user