-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrackparser.cpp
68 lines (65 loc) · 1.72 KB
/
trackparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "trackparser.h"
#include <QDomDocument>
#include <QDebug>
#include <QFile>
#include "kmlreader.h"
#include "gpxreader.h"
TrackParser::TrackParser(){}
TrackParser::trackType TrackParser::idTrack(const QString &fileName)
{
QDomDocument doc("mydocument");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return OTHER;
if (!doc.setContent(&file))
{
file.close();
return OTHER;
}
file.close();
QDomElement docElem = doc.documentElement();
if (docElem.tagName()=="kml")
{
QString title = docElem.firstChild().firstChild().toElement().text();
track.title=title;
return KML;
}
else if (docElem.tagName()=="gpx")
{
QDomNode domNode = docElem.firstChild().nextSibling().firstChild();
while (!domNode.isNull())
{
if (domNode.toElement().tagName()=="name")
track.title=domNode.toElement().text();
domNode=domNode.nextSibling();
}
return GPX;
}
else return OTHER;
}
Track TrackParser::parse(const QString &fileName)
{
TrackParser::trackType type = idTrack(fileName);
if (type==OTHER) return track;
else if (type==KML)
{
qDebug()<<"kml";
KMLReader reader;
reader.readFile(fileName);
track.setPoints(reader.getPoints());
track.hasEle = reader.has_ele;
track.isValid = true;
return track;
}
else if (type==GPX)
{
qDebug()<<"gpx";
GPXReader reader;
reader.readFile(fileName);
track.setPoints(reader.getPoints());
track.hasEle = reader.has_ele;
track.hasTime = reader.has_time;
track.isValid = true;
return track;
}
}