From 694847a424057e4a66c460c0fc09276e8a61e4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 14 Oct 2019 20:07:05 +0200 Subject: [PATCH] Extended links support + popup fixes --- src/GUI/areaitem.cpp | 15 ++++++++++----- src/GUI/areaitem.h | 7 +++++-- src/GUI/mapview.cpp | 4 ++-- src/GUI/routeitem.cpp | 8 ++++++++ src/GUI/routeitem.h | 1 + src/GUI/trackitem.cpp | 8 ++++++++ src/GUI/trackitem.h | 1 + src/GUI/waypointitem.cpp | 16 ++++++++++------ src/data/gpxparser.cpp | 6 +++++- src/data/locparser.cpp | 2 +- src/data/route.h | 1 + src/data/routedata.h | 9 +++++++-- src/data/track.h | 1 + src/data/trackdata.h | 9 +++++++-- src/data/waypoint.h | 6 +++--- 15 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/GUI/areaitem.cpp b/src/GUI/areaitem.cpp index 9d5cd9e9..17a29b14 100644 --- a/src/GUI/areaitem.cpp +++ b/src/GUI/areaitem.cpp @@ -2,12 +2,13 @@ #include #include #include +#include #include "map/map.h" -#include "tooltip.h" +#include "popup.h" #include "areaitem.h" -QString AreaItem::toolTip() const +ToolTip AreaItem::toolTip() const { ToolTip tt; @@ -17,7 +18,7 @@ QString AreaItem::toolTip() const tt.insert(qApp->translate("PolygonItem", "Description"), _area.description()); - return tt.toString(); + return tt; } AreaItem::AreaItem(const Area &area, Map *map, QGraphicsItem *parent) @@ -35,8 +36,6 @@ AreaItem::AreaItem(const Area &area, Map *map, QGraphicsItem *parent) setCursor(Qt::ArrowCursor); setAcceptHoverEvents(true); - - setToolTip(toolTip()); } @@ -171,3 +170,9 @@ void AreaItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) setZValue(zValue() - 1.0); update(); } + +void AreaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Popup::show(event->screenPos(), toolTip().toString(), event->widget()); + QGraphicsItem::mousePressEvent(event); +} diff --git a/src/GUI/areaitem.h b/src/GUI/areaitem.h index 0263aa5a..e0bedf5f 100644 --- a/src/GUI/areaitem.h +++ b/src/GUI/areaitem.h @@ -3,6 +3,7 @@ #include #include "data/area.h" +#include "tooltip.h" class Map; @@ -26,13 +27,15 @@ public: void setStyle(Qt::PenStyle style); void setDigitalZoom(int zoom); -private: +protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); +private: QPainterPath painterPath(const Polygon &polygon); void updatePainterPath(); - QString toolTip() const; + ToolTip toolTip() const; Area _area; Map *_map; diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index ff17b727..0b1ec887 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -215,12 +215,12 @@ QList MapView::loadData(const Data &data) QList paths; int zoom = _map->zoom(); + for (int i = 0; i < data.areas().count(); i++) + addArea(data.areas().at(i)); for (int i = 0; i < data.tracks().count(); i++) paths.append(addTrack(data.tracks().at(i))); for (int i = 0; i < data.routes().count(); i++) paths.append(addRoute(data.routes().at(i))); - for (int i = 0; i < data.areas().count(); i++) - addArea(data.areas().at(i)); addWaypoints(data.waypoints()); if (_tracks.empty() && _routes.empty() && _waypoints.empty() diff --git a/src/GUI/routeitem.cpp b/src/GUI/routeitem.cpp index 8005c230..e643ae2c 100644 --- a/src/GUI/routeitem.cpp +++ b/src/GUI/routeitem.cpp @@ -17,6 +17,13 @@ QString RouteItem::toolTip(Units units) const tt.insert(tr("Description"), _desc); tt.insert(tr("Distance"), Format::distance(path().last().last().distance(), 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())); + } + } return tt.toString(); } @@ -32,6 +39,7 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent) _name = route.name(); _desc = route.description(); + _links = route.links(); _coordinatesFormat = DecimalDegrees; } diff --git a/src/GUI/routeitem.h b/src/GUI/routeitem.h index 32e2dfec..8b531946 100644 --- a/src/GUI/routeitem.h +++ b/src/GUI/routeitem.h @@ -28,6 +28,7 @@ public: private: QString _name; QString _desc; + QVector _links; CoordinatesFormat _coordinatesFormat; QVector _waypoints; diff --git a/src/GUI/trackitem.cpp b/src/GUI/trackitem.cpp index 217e6281..e6437b90 100644 --- a/src/GUI/trackitem.cpp +++ b/src/GUI/trackitem.cpp @@ -21,6 +21,13 @@ QString TrackItem::toolTip(Units units) const tt.insert(tr("Moving time"), Format::timeSpan(_movingTime)); if (!_date.isNull()) 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())); + } + } return tt.toString(); } @@ -30,6 +37,7 @@ TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent) { _name = track.name(); _desc = track.description(); + _links = track.links(); _date = track.date(); _time = track.time(); _movingTime = track.movingTime(); diff --git a/src/GUI/trackitem.h b/src/GUI/trackitem.h index 4e4bdbab..6ef42976 100644 --- a/src/GUI/trackitem.h +++ b/src/GUI/trackitem.h @@ -21,6 +21,7 @@ public: private: QString _name; QString _desc; + QVector _links; QDateTime _date; qreal _time; qreal _movingTime; diff --git a/src/GUI/waypointitem.cpp b/src/GUI/waypointitem.cpp index 50f7a0fa..7dd4d0c3 100644 --- a/src/GUI/waypointitem.cpp +++ b/src/GUI/waypointitem.cpp @@ -30,11 +30,14 @@ 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("%1").arg(_waypoint.link().URL(), - _waypoint.link().text().isEmpty() ? _waypoint.link().URL() - : _waypoint.link().text())); + 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.setImage(_waypoint.image()); return tt; @@ -164,5 +167,6 @@ void WaypointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { ToolTip tt(toolTip(_units, _format)); Popup::show(event->screenPos(), tt.toString(), event->widget()); - QGraphicsItem::mousePressEvent(event); + /* Do not propagate the event any further as lower stacked items (path + items) would replace the popup with their own popup */ } diff --git a/src/data/gpxparser.cpp b/src/data/gpxparser.cpp index d57ffc86..5844352f 100644 --- a/src/data/gpxparser.cpp +++ b/src/data/gpxparser.cpp @@ -162,7 +162,7 @@ void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute) else if (_reader.name() == QLatin1String("time")) waypoint.setTimestamp(time()); else if (_reader.name() == QLatin1String("link")) - waypoint.setLink(link()); + waypoint.addLink(link()); else if (autoRoute && _reader.name() == QLatin1String("extensions")) rteptExtensions(autoRoute); else @@ -198,6 +198,8 @@ 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 _reader.skipCurrentElement(); } @@ -219,6 +221,8 @@ 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 _reader.skipCurrentElement(); } diff --git a/src/data/locparser.cpp b/src/data/locparser.cpp index aeaf3c65..3e7672dd 100644 --- a/src/data/locparser.cpp +++ b/src/data/locparser.cpp @@ -40,7 +40,7 @@ void LOCParser::waypoint(Waypoint &waypoint) _reader.skipCurrentElement(); } else if (_reader.name() == QLatin1String("link")) { const QXmlStreamAttributes &attr = _reader.attributes(); - waypoint.setLink(Link(_reader.readElementText(), + waypoint.addLink(Link(_reader.readElementText(), attr.value("text").toString())); } else _reader.skipCurrentElement(); diff --git a/src/data/route.h b/src/data/route.h index b41c1c44..414a984f 100644 --- a/src/data/route.h +++ b/src/data/route.h @@ -21,6 +21,7 @@ public: const QString &name() const {return _data.name();} const QString &description() const {return _data.description();} + const QVector &links() const {return _data.links();} bool isValid() const {return _data.size() >= 2;} diff --git a/src/data/routedata.h b/src/data/routedata.h index e1470e9b..0c614dfd 100644 --- a/src/data/routedata.h +++ b/src/data/routedata.h @@ -4,18 +4,23 @@ #include #include #include "waypoint.h" +#include "link.h" class RouteData : public QVector { public: - const QString& name() const {return _name;} - const QString& description() const {return _desc;} + const QString &name() const {return _name;} + const QString &description() const {return _desc;} + const QVector &links() const {return _links;} + void setName(const QString &name) {_name = name;} void setDescription(const QString &desc) {_desc = desc;} + void addLink(const Link &link) {_links.append(link);} private: QString _name; QString _desc; + QVector _links; }; #endif // ROUTEDATA_H diff --git a/src/data/track.h b/src/data/track.h index 9dbbfdd9..915bb961 100644 --- a/src/data/track.h +++ b/src/data/track.h @@ -32,6 +32,7 @@ public: const QString &name() const {return _data.name();} const QString &description() const {return _data.description();} + const QVector &links() const {return _data.links();} bool isValid() const; diff --git a/src/data/trackdata.h b/src/data/trackdata.h index 2f2b4953..18c872a7 100644 --- a/src/data/trackdata.h +++ b/src/data/trackdata.h @@ -5,20 +5,25 @@ #include #include #include "trackpoint.h" +#include "link.h" typedef QVector SegmentData; class TrackData : public QList { public: - const QString& name() const {return _name;} - const QString& description() const {return _desc;} + const QString &name() const {return _name;} + const QString &description() const {return _desc;} + const QVector &links() const {return _links;} + void setName(const QString &name) {_name = name;} void setDescription(const QString &desc) {_desc = desc;} + void addLink(const Link &link) {_links.append(link);} private: QString _name; QString _desc; + QVector _links; }; #endif // TRACKDATA_H diff --git a/src/data/waypoint.h b/src/data/waypoint.h index 02602b90..0886d1bd 100644 --- a/src/data/waypoint.h +++ b/src/data/waypoint.h @@ -20,7 +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 QVector &links() const {return _links;} const QDateTime ×tamp() const {return _timestamp;} qreal elevation() const {return _elevation;} @@ -32,7 +32,7 @@ public: void setTimestamp(const QDateTime ×tamp) {_timestamp = timestamp;} void setElevation(qreal elevation) {_elevation = elevation;} void setImage(const ImageInfo &image) {_image = image;} - void setLink(const Link &link) {_link = link;} + void addLink(const Link &link) {_links.append(link);} bool hasElevation() const {return !std::isnan(_elevation);} @@ -45,7 +45,7 @@ private: QString _name; QString _description; ImageInfo _image; - Link _link; + QVector _links; QDateTime _timestamp; qreal _elevation; };