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);
|
2017-03-18 01:30:31 +01:00
|
|
|
tt.insert(tr("Distance"), Format::distance(_path.last().distance(), units));
|
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
|
|
|
{
|
2017-03-18 01:30:31 +01:00
|
|
|
const QVector<Waypoint> &waypoints = route.waypoints();
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
for (int i = 0; i < waypoints.size(); 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();
|
2018-02-11 20:39:39 +01:00
|
|
|
_units = Metric;
|
|
|
|
_coordinatesFormat = DecimalDegrees;
|
2016-11-15 18:08:44 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
setToolTip(toolTip(Metric));
|
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
|
|
|
{
|
2016-09-25 18:57:17 +02:00
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
2017-03-18 01:30:31 +01:00
|
|
|
for (int i = 0; i < childs.count(); i++) {
|
|
|
|
if (childs.at(i) != _marker) {
|
|
|
|
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
|
|
|
wi->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
|
|
|
}
|
|
|
|
|
2018-02-11 20:39:39 +01:00
|
|
|
void RouteItem::setUnits(Units units)
|
2016-08-30 21:26:28 +02:00
|
|
|
{
|
2018-02-11 20:39:39 +01:00
|
|
|
if (_units == units)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_units = units;
|
|
|
|
|
|
|
|
setToolTip(toolTip(_units));
|
|
|
|
|
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
|
|
|
for (int i = 0; i < childs.count(); i++) {
|
|
|
|
if (childs.at(i) != _marker) {
|
|
|
|
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
|
|
|
wi->setToolTipFormat(_units, _coordinatesFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RouteItem::setCoordinatesFormat(CoordinatesFormat format)
|
|
|
|
{
|
|
|
|
if (_coordinatesFormat == format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_coordinatesFormat = format;
|
|
|
|
|
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
|
|
|
for (int i = 0; i < childs.count(); i++) {
|
|
|
|
if (childs.at(i) != _marker) {
|
|
|
|
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
|
|
|
wi->setToolTipFormat(_units, _coordinatesFormat);
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 21:26:28 +02:00
|
|
|
}
|
|
|
|
|
2016-08-09 10:47:49 +02:00
|
|
|
void RouteItem::showWaypoints(bool show)
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
|
|
|
for (int i = 0; i < childs.count(); i++)
|
|
|
|
if (childs.at(i) != _marker)
|
|
|
|
childs.at(i)->setVisible(show);
|
|
|
|
}
|
2016-08-09 23:08:49 +02:00
|
|
|
|
|
|
|
void RouteItem::showWaypointLabels(bool show)
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
|
|
|
for (int i = 0; i < childs.count(); i++) {
|
|
|
|
if (childs.at(i) != _marker) {
|
|
|
|
WaypointItem *wi = static_cast<WaypointItem*>(childs.at(i));
|
|
|
|
wi->showLabel(show);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|