2016-08-09 01:16:19 +02:00
|
|
|
#include <QPainter>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/waypoint.h"
|
|
|
|
#include "map/map.h"
|
2016-11-02 17:35:26 +01:00
|
|
|
#include "format.h"
|
2016-08-09 01:16:19 +02:00
|
|
|
#include "waypointitem.h"
|
2016-08-30 21:26:28 +02:00
|
|
|
#include "tooltip.h"
|
2016-08-09 01:16:19 +02:00
|
|
|
#include "routeitem.h"
|
|
|
|
|
|
|
|
|
2017-09-24 19:54:13 +02:00
|
|
|
QString RouteItem::toolTip(Units units) const
|
2016-08-30 21:26:28 +02:00
|
|
|
{
|
|
|
|
ToolTip tt;
|
|
|
|
|
2016-10-28 14:33:36 +02:00
|
|
|
if (!_name.isEmpty())
|
2017-01-08 20:02:51 +01:00
|
|
|
tt.insert(tr("Name"), _name);
|
2016-10-28 14:33:36 +02:00
|
|
|
if (!_desc.isEmpty())
|
2017-01-08 20:02:51 +01:00
|
|
|
tt.insert(tr("Description"), _desc);
|
2019-05-24 18:37:15 +02:00
|
|
|
tt.insert(tr("Distance"), Format::distance(path().last().last().distance(),
|
2019-02-11 23:28:08 +01:00
|
|
|
units));
|
2019-10-14 20:07:05 +02:00
|
|
|
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()));
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 21:26:28 +02:00
|
|
|
|
|
|
|
return tt.toString();
|
|
|
|
}
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
|
|
|
|
: PathItem(route.path(), map, parent)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2019-08-29 20:15:03 +02:00
|
|
|
const RouteData &waypoints = route.data();
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2019-05-24 18:37:15 +02:00
|
|
|
_waypoints.resize(waypoints.size());
|
2017-03-18 01:30:31 +01:00
|
|
|
for (int i = 0; i < waypoints.size(); i++)
|
2019-05-24 18:37:15 +02:00
|
|
|
_waypoints[i] = new WaypointItem(waypoints.at(i), map, this);
|
2016-11-15 18:08:44 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
_name = route.name();
|
|
|
|
_desc = route.description();
|
2019-10-14 20:07:05 +02:00
|
|
|
_links = route.links();
|
2018-02-11 20:39:39 +01:00
|
|
|
_coordinatesFormat = DecimalDegrees;
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
void RouteItem::setMap(Map *map)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2019-05-24 18:37:15 +02:00
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints[i]->setMap(map);
|
2016-09-25 18:57:17 +02:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
PathItem::setMap(map);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2019-05-23 08:44:55 +02:00
|
|
|
void RouteItem::setUnits(Units u)
|
2016-08-30 21:26:28 +02:00
|
|
|
{
|
2019-05-23 08:44:55 +02:00
|
|
|
if (units() == u)
|
2018-02-11 20:39:39 +01:00
|
|
|
return;
|
|
|
|
|
2019-05-24 18:37:15 +02:00
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
2019-10-13 20:20:32 +02:00
|
|
|
_waypoints[i]->setToolTipFormat(u, _coordinatesFormat);
|
2019-10-07 22:03:26 +02:00
|
|
|
|
|
|
|
PathItem::setUnits(u);
|
2018-02-11 20:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RouteItem::setCoordinatesFormat(CoordinatesFormat format)
|
|
|
|
{
|
|
|
|
if (_coordinatesFormat == format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_coordinatesFormat = format;
|
|
|
|
|
2019-05-24 18:37:15 +02:00
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints[i]->setToolTipFormat(units(), _coordinatesFormat);
|
2016-08-30 21:26:28 +02:00
|
|
|
}
|
|
|
|
|
2016-08-09 10:47:49 +02:00
|
|
|
void RouteItem::showWaypoints(bool show)
|
|
|
|
{
|
2019-05-24 18:37:15 +02:00
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints[i]->setVisible(show);
|
2016-08-09 10:47:49 +02:00
|
|
|
}
|
2016-08-09 23:08:49 +02:00
|
|
|
|
|
|
|
void RouteItem::showWaypointLabels(bool show)
|
|
|
|
{
|
2019-05-24 18:37:15 +02:00
|
|
|
for (int i = 0; i < _waypoints.count(); i++)
|
|
|
|
_waypoints[i]->showLabel(show);
|
2016-08-09 23:08:49 +02:00
|
|
|
}
|