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

Added support for GPX 1.0 links

This commit is contained in:
Martin Tůma 2019-10-20 20:30:10 +02:00
parent 25b42fd2f8
commit 9905de67bd
6 changed files with 48 additions and 21 deletions

View File

@ -19,11 +19,9 @@ QString RouteItem::info() const
_units)); _units));
for (int i = 0; i < _links.size(); i++) { for (int i = 0; i < _links.size(); i++) {
const Link &link = _links.at(i); const Link &link = _links.at(i);
if (!link.URL().isEmpty()) {
tt.insert(tr("Link"), QString("<a href=\"%0\">%1</a>").arg( tt.insert(tr("Link"), QString("<a href=\"%0\">%1</a>").arg(
link.URL(), link.text().isEmpty() ? link.URL() : link.text())); link.URL(), link.text().isEmpty() ? link.URL() : link.text()));
} }
}
return tt.toString(); return tt.toString();
} }

View File

@ -23,11 +23,9 @@ QString TrackItem::info() const
tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate)); tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate));
for (int i = 0; i < _links.size(); i++) { for (int i = 0; i < _links.size(); i++) {
const Link &link = _links.at(i); const Link &link = _links.at(i);
if (!link.URL().isEmpty()) {
tt.insert(tr("Link"), QString("<a href=\"%0\">%1</a>").arg( tt.insert(tr("Link"), QString("<a href=\"%0\">%1</a>").arg(
link.URL(), link.text().isEmpty() ? link.URL() : link.text())); link.URL(), link.text().isEmpty() ? link.URL() : link.text()));
} }
}
return tt.toString(); return tt.toString();
} }

View File

@ -32,12 +32,10 @@ QString WaypointItem::info() const
_waypoint.description()); _waypoint.description());
for (int i = 0; i < _waypoint.links().size(); i++) { for (int i = 0; i < _waypoint.links().size(); i++) {
const Link &link = _waypoint.links().at(i); const Link &link = _waypoint.links().at(i);
if (!link.URL().isEmpty()) {
tt.insert(qApp->translate("WaypointItem", "Link"), tt.insert(qApp->translate("WaypointItem", "Link"),
QString("<a href=\"%0\">%1</a>").arg(link.URL(), QString("<a href=\"%0\">%1</a>").arg(link.URL(),
link.text().isEmpty() ? link.URL() : link.text())); link.text().isEmpty() ? link.URL() : link.text()));
} }
}
tt.setImage(_waypoint.image()); tt.setImage(_waypoint.image());
return tt.toString(); return tt.toString();

View File

@ -149,6 +149,7 @@ void GPXParser::trackpointData(Trackpoint &trackpoint)
void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute) void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute)
{ {
qreal gh = NAN; qreal gh = NAN;
Link link10;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("name")) if (_reader.name() == QLatin1String("name"))
@ -161,14 +162,22 @@ void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute)
gh = number(); gh = number();
else if (_reader.name() == QLatin1String("time")) else if (_reader.name() == QLatin1String("time"))
waypoint.setTimestamp(time()); waypoint.setTimestamp(time());
else if (_reader.name() == QLatin1String("link")) else if (_reader.name() == QLatin1String("link")) {
waypoint.addLink(link()); Link l(link());
if (!l.URL().isEmpty())
waypoint.addLink(l);
} else if (_reader.name() == QLatin1String("url"))
link10.setURL(_reader.readElementText());
else if (_reader.name() == QLatin1String("urlname"))
link10.setText(_reader.readElementText());
else if (autoRoute && _reader.name() == QLatin1String("extensions")) else if (autoRoute && _reader.name() == QLatin1String("extensions"))
rteptExtensions(autoRoute); rteptExtensions(autoRoute);
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
if (!link10.URL().isEmpty())
waypoint.addLink(link10);
if (!std::isnan(gh) && !std::isnan(waypoint.elevation())) if (!std::isnan(gh) && !std::isnan(waypoint.elevation()))
waypoint.setElevation(waypoint.elevation() - gh); waypoint.setElevation(waypoint.elevation() - gh);
} }
@ -189,6 +198,7 @@ void GPXParser::routepoints(RouteData &route, QList<TrackData> &tracks)
TrackData autoRoute; TrackData autoRoute;
autoRoute.append(SegmentData()); autoRoute.append(SegmentData());
SegmentData &autoRouteSegment = autoRoute.last(); SegmentData &autoRouteSegment = autoRoute.last();
Link link10;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("rtept")) { if (_reader.name() == QLatin1String("rtept")) {
@ -198,12 +208,21 @@ void GPXParser::routepoints(RouteData &route, QList<TrackData> &tracks)
route.setName(_reader.readElementText()); route.setName(_reader.readElementText());
else if (_reader.name() == QLatin1String("desc")) else if (_reader.name() == QLatin1String("desc"))
route.setDescription(_reader.readElementText()); route.setDescription(_reader.readElementText());
else if (_reader.name() == QLatin1String("link")) else if (_reader.name() == QLatin1String("link")) {
route.addLink(link()); Link l(link());
if (!l.URL().isEmpty())
route.addLink(l);
} else if (_reader.name() == QLatin1String("url"))
link10.setURL(_reader.readElementText());
else if (_reader.name() == QLatin1String("urlname"))
link10.setText(_reader.readElementText());
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
if (!link10.URL().isEmpty())
route.addLink(link10);
if (!autoRouteSegment.isEmpty()) { if (!autoRouteSegment.isEmpty()) {
autoRoute.setName(route.name()); autoRoute.setName(route.name());
autoRoute.setDescription(route.description()); autoRoute.setDescription(route.description());
@ -213,6 +232,8 @@ void GPXParser::routepoints(RouteData &route, QList<TrackData> &tracks)
void GPXParser::track(TrackData &track) void GPXParser::track(TrackData &track)
{ {
Link link10;
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("trkseg")) { if (_reader.name() == QLatin1String("trkseg")) {
track.append(SegmentData()); track.append(SegmentData());
@ -221,11 +242,20 @@ void GPXParser::track(TrackData &track)
track.setName(_reader.readElementText()); track.setName(_reader.readElementText());
else if (_reader.name() == QLatin1String("desc")) else if (_reader.name() == QLatin1String("desc"))
track.setDescription(_reader.readElementText()); track.setDescription(_reader.readElementText());
else if (_reader.name() == QLatin1String("link")) else if (_reader.name() == QLatin1String("link")) {
track.addLink(link()); Link l(link());
if (!l.URL().isEmpty())
track.addLink(l);
} else if (_reader.name() == QLatin1String("url"))
link10.setURL(_reader.readElementText());
else if (_reader.name() == QLatin1String("urlname"))
link10.setText(_reader.readElementText());
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
if (!link10.URL().isEmpty())
track.addLink(link10);
} }
void GPXParser::area(Area &area) void GPXParser::area(Area &area)

View File

@ -9,6 +9,8 @@ public:
Link(const QString &URL, const QString &text = QString()) Link(const QString &URL, const QString &text = QString())
: _URL(URL), _text(text) {} : _URL(URL), _text(text) {}
void setURL(const QString &URL) {_URL = URL;}
void setText(const QString &text) {_text = text;}
const QString &URL() const {return _URL;} const QString &URL() const {return _URL;}
const QString &text() const {return _text;} const QString &text() const {return _text;}

View File

@ -40,8 +40,9 @@ void LOCParser::waypoint(Waypoint &waypoint)
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} else if (_reader.name() == QLatin1String("link")) { } else if (_reader.name() == QLatin1String("link")) {
const QXmlStreamAttributes &attr = _reader.attributes(); const QXmlStreamAttributes &attr = _reader.attributes();
waypoint.addLink(Link(_reader.readElementText(), QString URL(_reader.readElementText());
attr.value("text").toString())); if (!URL.isEmpty())
waypoint.addLink(Link(URL, attr.value("text").toString()));
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }