1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Extended links support + popup fixes

This commit is contained in:
Martin Tůma 2019-10-14 20:07:05 +02:00
parent e7f5da5af7
commit 694847a424
15 changed files with 70 additions and 24 deletions

View File

@ -2,12 +2,13 @@
#include <QApplication> #include <QApplication>
#include <QCursor> #include <QCursor>
#include <QPainter> #include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "map/map.h" #include "map/map.h"
#include "tooltip.h" #include "popup.h"
#include "areaitem.h" #include "areaitem.h"
QString AreaItem::toolTip() const ToolTip AreaItem::toolTip() const
{ {
ToolTip tt; ToolTip tt;
@ -17,7 +18,7 @@ QString AreaItem::toolTip() const
tt.insert(qApp->translate("PolygonItem", "Description"), tt.insert(qApp->translate("PolygonItem", "Description"),
_area.description()); _area.description());
return tt.toString(); return tt;
} }
AreaItem::AreaItem(const Area &area, Map *map, QGraphicsItem *parent) 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); setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
setToolTip(toolTip());
} }
@ -171,3 +170,9 @@ void AreaItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
setZValue(zValue() - 1.0); setZValue(zValue() - 1.0);
update(); update();
} }
void AreaItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Popup::show(event->screenPos(), toolTip().toString(), event->widget());
QGraphicsItem::mousePressEvent(event);
}

View File

@ -3,6 +3,7 @@
#include <QGraphicsItem> #include <QGraphicsItem>
#include "data/area.h" #include "data/area.h"
#include "tooltip.h"
class Map; class Map;
@ -26,13 +27,15 @@ public:
void setStyle(Qt::PenStyle style); void setStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom); void setDigitalZoom(int zoom);
private: protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
QPainterPath painterPath(const Polygon &polygon); QPainterPath painterPath(const Polygon &polygon);
void updatePainterPath(); void updatePainterPath();
QString toolTip() const; ToolTip toolTip() const;
Area _area; Area _area;
Map *_map; Map *_map;

View File

@ -215,12 +215,12 @@ QList<PathItem *> MapView::loadData(const Data &data)
QList<PathItem *> paths; QList<PathItem *> paths;
int zoom = _map->zoom(); 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++) for (int i = 0; i < data.tracks().count(); i++)
paths.append(addTrack(data.tracks().at(i))); paths.append(addTrack(data.tracks().at(i)));
for (int i = 0; i < data.routes().count(); i++) for (int i = 0; i < data.routes().count(); i++)
paths.append(addRoute(data.routes().at(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()); addWaypoints(data.waypoints());
if (_tracks.empty() && _routes.empty() && _waypoints.empty() if (_tracks.empty() && _routes.empty() && _waypoints.empty()

View File

@ -17,6 +17,13 @@ QString RouteItem::toolTip(Units units) const
tt.insert(tr("Description"), _desc); tt.insert(tr("Description"), _desc);
tt.insert(tr("Distance"), Format::distance(path().last().last().distance(), tt.insert(tr("Distance"), Format::distance(path().last().last().distance(),
units)); units));
for (int i = 0; i < _links.size(); i++) {
const Link &link = _links.at(i);
if (!link.URL().isEmpty()) {
tt.insert(tr("Link"), QString("<a href=\"%0\">%1</a>").arg(
link.URL(), link.text().isEmpty() ? link.URL() : link.text()));
}
}
return tt.toString(); return tt.toString();
} }
@ -32,6 +39,7 @@ RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
_name = route.name(); _name = route.name();
_desc = route.description(); _desc = route.description();
_links = route.links();
_coordinatesFormat = DecimalDegrees; _coordinatesFormat = DecimalDegrees;
} }

View File

@ -28,6 +28,7 @@ public:
private: private:
QString _name; QString _name;
QString _desc; QString _desc;
QVector<Link> _links;
CoordinatesFormat _coordinatesFormat; CoordinatesFormat _coordinatesFormat;
QVector<WaypointItem*> _waypoints; QVector<WaypointItem*> _waypoints;

View File

@ -21,6 +21,13 @@ QString TrackItem::toolTip(Units units) const
tt.insert(tr("Moving time"), Format::timeSpan(_movingTime)); tt.insert(tr("Moving time"), Format::timeSpan(_movingTime));
if (!_date.isNull()) if (!_date.isNull())
tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate)); 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("<a href=\"%0\">%1</a>").arg(
link.URL(), link.text().isEmpty() ? link.URL() : link.text()));
}
}
return tt.toString(); return tt.toString();
} }
@ -30,6 +37,7 @@ TrackItem::TrackItem(const Track &track, Map *map, QGraphicsItem *parent)
{ {
_name = track.name(); _name = track.name();
_desc = track.description(); _desc = track.description();
_links = track.links();
_date = track.date(); _date = track.date();
_time = track.time(); _time = track.time();
_movingTime = track.movingTime(); _movingTime = track.movingTime();

View File

@ -21,6 +21,7 @@ public:
private: private:
QString _name; QString _name;
QString _desc; QString _desc;
QVector<Link> _links;
QDateTime _date; QDateTime _date;
qreal _time; qreal _time;
qreal _movingTime; qreal _movingTime;

View File

@ -30,11 +30,14 @@ ToolTip WaypointItem::toolTip(Units units, CoordinatesFormat format)
if (!_waypoint.description().isEmpty()) if (!_waypoint.description().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Description"), tt.insert(qApp->translate("WaypointItem", "Description"),
_waypoint.description()); _waypoint.description());
if (!_waypoint.link().URL().isEmpty()) 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"), tt.insert(qApp->translate("WaypointItem", "Link"),
QString("<a href=\"%0\">%1</a>").arg(_waypoint.link().URL(), QString("<a href=\"%0\">%1</a>").arg(link.URL(),
_waypoint.link().text().isEmpty() ? _waypoint.link().URL() link.text().isEmpty() ? link.URL() : link.text()));
: _waypoint.link().text())); }
}
tt.setImage(_waypoint.image()); tt.setImage(_waypoint.image());
return tt; return tt;
@ -164,5 +167,6 @@ void WaypointItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
ToolTip tt(toolTip(_units, _format)); ToolTip tt(toolTip(_units, _format));
Popup::show(event->screenPos(), tt.toString(), event->widget()); 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 */
} }

View File

@ -162,7 +162,7 @@ void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute)
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.setLink(link()); waypoint.addLink(link());
else if (autoRoute && _reader.name() == QLatin1String("extensions")) else if (autoRoute && _reader.name() == QLatin1String("extensions"))
rteptExtensions(autoRoute); rteptExtensions(autoRoute);
else else
@ -198,6 +198,8 @@ 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"))
route.addLink(link());
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
@ -219,6 +221,8 @@ 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"))
track.addLink(link());
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }

View File

@ -40,7 +40,7 @@ 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.setLink(Link(_reader.readElementText(), waypoint.addLink(Link(_reader.readElementText(),
attr.value("text").toString())); attr.value("text").toString()));
} else } else
_reader.skipCurrentElement(); _reader.skipCurrentElement();

View File

@ -21,6 +21,7 @@ public:
const QString &name() const {return _data.name();} const QString &name() const {return _data.name();}
const QString &description() const {return _data.description();} const QString &description() const {return _data.description();}
const QVector<Link> &links() const {return _data.links();}
bool isValid() const {return _data.size() >= 2;} bool isValid() const {return _data.size() >= 2;}

View File

@ -4,18 +4,23 @@
#include <QVector> #include <QVector>
#include <QString> #include <QString>
#include "waypoint.h" #include "waypoint.h"
#include "link.h"
class RouteData : public QVector<Waypoint> class RouteData : public QVector<Waypoint>
{ {
public: public:
const QString& name() const {return _name;} const QString &name() const {return _name;}
const QString& description() const {return _desc;} const QString &description() const {return _desc;}
const QVector<Link> &links() const {return _links;}
void setName(const QString &name) {_name = name;} void setName(const QString &name) {_name = name;}
void setDescription(const QString &desc) {_desc = desc;} void setDescription(const QString &desc) {_desc = desc;}
void addLink(const Link &link) {_links.append(link);}
private: private:
QString _name; QString _name;
QString _desc; QString _desc;
QVector<Link> _links;
}; };
#endif // ROUTEDATA_H #endif // ROUTEDATA_H

View File

@ -32,6 +32,7 @@ public:
const QString &name() const {return _data.name();} const QString &name() const {return _data.name();}
const QString &description() const {return _data.description();} const QString &description() const {return _data.description();}
const QVector<Link> &links() const {return _data.links();}
bool isValid() const; bool isValid() const;

View File

@ -5,20 +5,25 @@
#include <QVector> #include <QVector>
#include <QString> #include <QString>
#include "trackpoint.h" #include "trackpoint.h"
#include "link.h"
typedef QVector<Trackpoint> SegmentData; typedef QVector<Trackpoint> SegmentData;
class TrackData : public QList<SegmentData> class TrackData : public QList<SegmentData>
{ {
public: public:
const QString& name() const {return _name;} const QString &name() const {return _name;}
const QString& description() const {return _desc;} const QString &description() const {return _desc;}
const QVector<Link> &links() const {return _links;}
void setName(const QString &name) {_name = name;} void setName(const QString &name) {_name = name;}
void setDescription(const QString &desc) {_desc = desc;} void setDescription(const QString &desc) {_desc = desc;}
void addLink(const Link &link) {_links.append(link);}
private: private:
QString _name; QString _name;
QString _desc; QString _desc;
QVector<Link> _links;
}; };
#endif // TRACKDATA_H #endif // TRACKDATA_H

View File

@ -20,7 +20,7 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
const QString &description() const {return _description;} const QString &description() const {return _description;}
const ImageInfo &image() const {return _image;} const ImageInfo &image() const {return _image;}
const Link &link() const {return _link;} const QVector<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;} const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;} qreal elevation() const {return _elevation;}
@ -32,7 +32,7 @@ public:
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;} void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;} void setElevation(qreal elevation) {_elevation = elevation;}
void setImage(const ImageInfo &image) {_image = image;} 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);} bool hasElevation() const {return !std::isnan(_elevation);}
@ -45,7 +45,7 @@ private:
QString _name; QString _name;
QString _description; QString _description;
ImageInfo _image; ImageInfo _image;
Link _link; QVector<Link> _links;
QDateTime _timestamp; QDateTime _timestamp;
qreal _elevation; qreal _elevation;
}; };