diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index c2681ed2..d30c2623 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -19,10 +19,8 @@ QString RouteItem::info() const _units)); for (int i = 0; i < _links.size(); i++) { const Link &link = _links.at(i); - if (!link.URL().isEmpty()) { - tt.insert(tr("Link"), QString("%1").arg( - link.URL(), link.text().isEmpty() ? link.URL() : link.text())); - } + tt.insert(tr("Link"), QString("%1").arg( + link.URL(), link.text().isEmpty() ? link.URL() : link.text())); } return tt.toString(); diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index 63097ba0..ded2fb8c 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -23,10 +23,8 @@ QString TrackItem::info() const tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate)); for (int i = 0; i < _links.size(); i++) { const Link &link = _links.at(i); - if (!link.URL().isEmpty()) { - tt.insert(tr("Link"), QString("%1").arg( - link.URL(), link.text().isEmpty() ? link.URL() : link.text())); - } + tt.insert(tr("Link"), QString("%1").arg( + link.URL(), link.text().isEmpty() ? link.URL() : link.text())); } return tt.toString(); diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index 0692a00c..39553016 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -32,11 +32,9 @@ QString WaypointItem::info() const _waypoint.description()); for (int i = 0; i < _waypoint.links().size(); i++) { const Link &link = _waypoint.links().at(i); - if (!link.URL().isEmpty()) { - tt.insert(qApp->translate("WaypointItem", "Link"), - QString("%1").arg(link.URL(), - link.text().isEmpty() ? link.URL() : link.text())); - } + tt.insert(qApp->translate("WaypointItem", "Link"), + QString("%1").arg(link.URL(), + link.text().isEmpty() ? link.URL() : link.text())); } tt.setImage(_waypoint.image()); diff --git a/src/data/gpxparser.cpp b/src/data/gpxparser.cpp index 5844352f..6e35c3e2 100644 --- a/src/data/gpxparser.cpp +++ b/src/data/gpxparser.cpp @@ -149,6 +149,7 @@ void GPXParser::trackpointData(Trackpoint &trackpoint) void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute) { qreal gh = NAN; + Link link10; while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("name")) @@ -161,14 +162,22 @@ void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute) gh = number(); else if (_reader.name() == QLatin1String("time")) waypoint.setTimestamp(time()); - else if (_reader.name() == QLatin1String("link")) - waypoint.addLink(link()); + else if (_reader.name() == QLatin1String("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")) rteptExtensions(autoRoute); else _reader.skipCurrentElement(); } + if (!link10.URL().isEmpty()) + waypoint.addLink(link10); if (!std::isnan(gh) && !std::isnan(waypoint.elevation())) waypoint.setElevation(waypoint.elevation() - gh); } @@ -189,6 +198,7 @@ void GPXParser::routepoints(RouteData &route, QList &tracks) TrackData autoRoute; autoRoute.append(SegmentData()); SegmentData &autoRouteSegment = autoRoute.last(); + Link link10; while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("rtept")) { @@ -198,12 +208,21 @@ void GPXParser::routepoints(RouteData &route, QList &tracks) route.setName(_reader.readElementText()); else if (_reader.name() == QLatin1String("desc")) route.setDescription(_reader.readElementText()); - else if (_reader.name() == QLatin1String("link")) - route.addLink(link()); + else if (_reader.name() == QLatin1String("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 _reader.skipCurrentElement(); } + if (!link10.URL().isEmpty()) + route.addLink(link10); + if (!autoRouteSegment.isEmpty()) { autoRoute.setName(route.name()); autoRoute.setDescription(route.description()); @@ -213,6 +232,8 @@ void GPXParser::routepoints(RouteData &route, QList &tracks) void GPXParser::track(TrackData &track) { + Link link10; + while (_reader.readNextStartElement()) { if (_reader.name() == QLatin1String("trkseg")) { track.append(SegmentData()); @@ -221,11 +242,20 @@ void GPXParser::track(TrackData &track) track.setName(_reader.readElementText()); else if (_reader.name() == QLatin1String("desc")) track.setDescription(_reader.readElementText()); - else if (_reader.name() == QLatin1String("link")) - track.addLink(link()); + else if (_reader.name() == QLatin1String("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 _reader.skipCurrentElement(); } + + if (!link10.URL().isEmpty()) + track.addLink(link10); } void GPXParser::area(Area &area) diff --git a/src/data/link.h b/src/data/link.h index 20d5edf1..8ad5d8a7 100644 --- a/src/data/link.h +++ b/src/data/link.h @@ -9,6 +9,8 @@ public: Link(const QString &URL, const QString &text = QString()) : _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 &text() const {return _text;} diff --git a/src/data/locparser.cpp b/src/data/locparser.cpp index 3e7672dd..4ab4b2ce 100644 --- a/src/data/locparser.cpp +++ b/src/data/locparser.cpp @@ -40,8 +40,9 @@ void LOCParser::waypoint(Waypoint &waypoint) _reader.skipCurrentElement(); } else if (_reader.name() == QLatin1String("link")) { const QXmlStreamAttributes &attr = _reader.attributes(); - waypoint.addLink(Link(_reader.readElementText(), - attr.value("text").toString())); + QString URL(_reader.readElementText()); + if (!URL.isEmpty()) + waypoint.addLink(Link(URL, attr.value("text").toString())); } else _reader.skipCurrentElement(); }