2016-08-09 01:16:19 +02:00
|
|
|
#include <QPainter>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/waypoint.h"
|
2021-01-17 18:39:57 +01:00
|
|
|
#include "data/route.h"
|
2017-11-26 18:54:03 +01:00
|
|
|
#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"
|
|
|
|
|
|
|
|
|
2019-10-15 23:59:15 +02:00
|
|
|
QString RouteItem::info() 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);
|
2020-03-09 20:04:13 +01:00
|
|
|
if (!_comment.isEmpty() && _comment != _desc)
|
|
|
|
tt.insert(tr("Comment"), _comment);
|
2019-05-24 18:37:15 +02:00
|
|
|
tt.insert(tr("Distance"), Format::distance(path().last().last().distance(),
|
2019-10-15 23:59:15 +02:00
|
|
|
_units));
|
2019-10-22 22:27:12 +02:00
|
|
|
if (!_links.isEmpty()) {
|
|
|
|
QString links;
|
|
|
|
for (int i = 0; i < _links.size(); i++) {
|
|
|
|
const Link &link = _links.at(i);
|
|
|
|
links.append(QString("<a href=\"%0\">%1</a>").arg(link.URL(),
|
|
|
|
link.text().isEmpty() ? link.URL() : link.text()));
|
|
|
|
if (i != _links.size() - 1)
|
|
|
|
links.append("<br/>");
|
|
|
|
}
|
|
|
|
tt.insert(tr("Links"), links);
|
2019-10-14 20:07:05 +02:00
|
|
|
}
|
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();
|
2020-03-09 20:04:13 +01:00
|
|
|
_comment = route.comment();
|
2019-10-14 20:07:05 +02:00
|
|
|
_links = route.links();
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|