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

Added support for waypoint links

This commit is contained in:
Martin Tůma 2019-10-14 01:16:38 +02:00
parent f2bfd584d0
commit d59a37466b
7 changed files with 52 additions and 1 deletions

View File

@ -85,6 +85,7 @@ HEADERS += src/common/config.h \
src/GUI/mapview.h \
src/GUI/font.h \
src/GUI/areaitem.h \
src/data/link.h \
src/map/IMG/bitmapline.h \
src/map/IMG/textpathitem.h \
src/map/IMG/textpointitem.h \

View File

@ -30,6 +30,11 @@ ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format)
if (!_waypoint.description().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Description"),
_waypoint.description());
if (!_waypoint.link().URL().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Link"),
QString("<a href=\"%0\">%1</a>").arg(_waypoint.link().URL(),
_waypoint.link().text().isEmpty() ? _waypoint.link().URL()
: _waypoint.link().text()));
tt.setImage(_waypoint.image());
return tt;

View File

@ -23,6 +23,21 @@ QDateTime GPXParser::time()
return d;
}
Link GPXParser::link()
{
QString URL = _reader.attributes().value("href").toString();
QString text;
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("text"))
text = _reader.readElementText();
else
_reader.skipCurrentElement();
}
return Link(URL, text);
}
Coordinates GPXParser::coordinates()
{
bool res;
@ -146,6 +161,8 @@ 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.setLink(link());
else if (autoRoute && _reader.name() == QLatin1String("extensions"))
rteptExtensions(autoRoute);
else

View File

@ -4,7 +4,6 @@
#include <QXmlStreamReader>
#include "parser.h"
class GPXParser : public Parser
{
public:
@ -30,6 +29,7 @@ private:
qreal number();
QDateTime time();
Coordinates coordinates();
Link link();
QXmlStreamReader _reader;
};

20
src/data/link.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef LINK_H
#define LINK_H
#include <QString>
class Link {
public:
Link() {}
Link(const QString &URL, const QString &text = QString())
: _URL(URL), _text(text) {}
const QString &URL() const {return _URL;}
const QString &text() const {return _text;}
private:
QString _URL;
QString _text;
};
#endif // LINK_H

View File

@ -38,6 +38,10 @@ void LOCParser::waypoint(Waypoint &waypoint)
} else if (_reader.name() == QLatin1String("coord")) {
waypoint.setCoordinates(coordinates());
_reader.skipCurrentElement();
} else if (_reader.name() == QLatin1String("link")) {
const QXmlStreamAttributes &attr = _reader.attributes();
waypoint.setLink(Link(_reader.readElementText(),
attr.value("text").toString()));
} else
_reader.skipCurrentElement();
}

View File

@ -7,6 +7,7 @@
#include <QDebug>
#include "common/coordinates.h"
#include "imageinfo.h"
#include "link.h"
class Waypoint
{
@ -19,6 +20,7 @@ public:
const QString &name() const {return _name;}
const QString &description() const {return _description;}
const ImageInfo &image() const {return _image;}
const Link &link() const {return _link;}
const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;}
@ -30,6 +32,7 @@ public:
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;}
void setImage(const ImageInfo &image) {_image = image;}
void setLink(const Link &link) {_link = link;}
bool hasElevation() const {return !std::isnan(_elevation);}
@ -42,6 +45,7 @@ private:
QString _name;
QString _description;
ImageInfo _image;
Link _link;
QDateTime _timestamp;
qreal _elevation;
};