1 #include <QPainter>
2 #include "data/waypoint.h"
3 #include "map/map.h"
4 #include "format.h"
5 #include "waypointitem.h"
6 #include "tooltip.h"
7 #include "routeitem.h"
8
9
info() const10 QString RouteItem::info() const
11 {
12 ToolTip tt;
13
14 if (!_name.isEmpty())
15 tt.insert(tr("Name"), _name);
16 if (!_desc.isEmpty())
17 tt.insert(tr("Description"), _desc);
18 if (!_comment.isEmpty() && _comment != _desc)
19 tt.insert(tr("Comment"), _comment);
20 tt.insert(tr("Distance"), Format::distance(path().last().last().distance(),
21 _units));
22 if (!_links.isEmpty()) {
23 QString links;
24 for (int i = 0; i < _links.size(); i++) {
25 const Link &link = _links.at(i);
26 links.append(QString("<a href=\"%0\">%1</a>").arg(link.URL(),
27 link.text().isEmpty() ? link.URL() : link.text()));
28 if (i != _links.size() - 1)
29 links.append("<br/>");
30 }
31 tt.insert(tr("Links"), links);
32 }
33
34 return tt.toString();
35 }
36
RouteItem(const Route & route,Map * map,QGraphicsItem * parent)37 RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
38 : PathItem(route.path(), map, parent)
39 {
40 const RouteData &waypoints = route.data();
41
42 _waypoints.resize(waypoints.size());
43 for (int i = 0; i < waypoints.size(); i++)
44 _waypoints[i] = new WaypointItem(waypoints.at(i), map, this);
45
46 _name = route.name();
47 _desc = route.description();
48 _comment = route.comment();
49 _links = route.links();
50 }
51
setMap(Map * map)52 void RouteItem::setMap(Map *map)
53 {
54 for (int i = 0; i < _waypoints.count(); i++)
55 _waypoints[i]->setMap(map);
56
57 PathItem::setMap(map);
58 }
59
showWaypoints(bool show)60 void RouteItem::showWaypoints(bool show)
61 {
62 for (int i = 0; i < _waypoints.count(); i++)
63 _waypoints[i]->setVisible(show);
64 }
65
showWaypointLabels(bool show)66 void RouteItem::showWaypointLabels(bool show)
67 {
68 for (int i = 0; i < _waypoints.count(); i++)
69 _waypoints[i]->showLabel(show);
70 }
71