1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +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 <QCursor>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#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);
}

View File

@ -3,6 +3,7 @@
#include <QGraphicsItem>
#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;

View File

@ -215,12 +215,12 @@ QList<PathItem *> MapView::loadData(const Data &data)
QList<PathItem *> 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()

View File

@ -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("<a href=\"%0\">%1</a>").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;
}

View File

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

View File

@ -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("<a href=\"%0\">%1</a>").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();

View File

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

View File

@ -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())
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("<a href=\"%0\">%1</a>").arg(_waypoint.link().URL(),
_waypoint.link().text().isEmpty() ? _waypoint.link().URL()
: _waypoint.link().text()));
QString("<a href=\"%0\">%1</a>").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 */
}

View File

@ -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<TrackData> &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();
}

View File

@ -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();

View File

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

View File

@ -4,18 +4,23 @@
#include <QVector>
#include <QString>
#include "waypoint.h"
#include "link.h"
class RouteData : public QVector<Waypoint>
{
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<Link> &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<Link> _links;
};
#endif // ROUTEDATA_H

View File

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

View File

@ -5,20 +5,25 @@
#include <QVector>
#include <QString>
#include "trackpoint.h"
#include "link.h"
typedef QVector<Trackpoint> SegmentData;
class TrackData : public QList<SegmentData>
{
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<Link> &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<Link> _links;
};
#endif // TRACKDATA_H

View File

@ -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<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;}
qreal elevation() const {return _elevation;}
@ -32,7 +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;}
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<Link> _links;
QDateTime _timestamp;
qreal _elevation;
};