2016-08-30 21:26:28 +02:00
|
|
|
#include <QApplication>
|
2016-08-09 01:16:19 +02:00
|
|
|
#include <QPainter>
|
2016-11-02 17:35:26 +01:00
|
|
|
#include "format.h"
|
2016-08-09 01:16:19 +02:00
|
|
|
#include "waypoint.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
2016-08-30 21:26:28 +02:00
|
|
|
QString RouteItem::toolTip()
|
|
|
|
{
|
|
|
|
ToolTip tt;
|
|
|
|
|
2016-10-28 14:33:36 +02:00
|
|
|
if (!_name.isEmpty())
|
|
|
|
tt.insert(qApp->translate("RouteItem", "Name"), _name);
|
|
|
|
if (!_desc.isEmpty())
|
|
|
|
tt.insert(qApp->translate("RouteItem", "Description"), _desc);
|
2016-08-30 21:26:28 +02:00
|
|
|
tt.insert(qApp->translate("RouteItem", "Distance"),
|
2016-11-14 22:12:43 +01:00
|
|
|
Format::distance(_distance.last(), _units));
|
2016-08-30 21:26:28 +02:00
|
|
|
|
|
|
|
return tt.toString();
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
|
2016-09-19 00:56:10 +02:00
|
|
|
: PathItem(parent)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2016-11-14 22:12:43 +01:00
|
|
|
const RouteData &r = route.routeData();
|
2016-08-09 01:16:19 +02:00
|
|
|
Q_ASSERT(r.count() >= 2);
|
2016-10-24 00:21:40 +02:00
|
|
|
QPointF p;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2016-10-28 14:33:36 +02:00
|
|
|
_name = r.name();
|
|
|
|
_desc = r.description();
|
2016-11-14 22:12:43 +01:00
|
|
|
_distance = route.distanceData();
|
2016-10-28 14:33:36 +02:00
|
|
|
|
2016-09-25 18:57:17 +02:00
|
|
|
new WaypointItem(r.at(0), this);
|
2016-10-24 00:21:40 +02:00
|
|
|
p = r.at(0).coordinates().toMercator();
|
|
|
|
_path.moveTo(QPointF(p.x(), -p.y()));
|
2016-08-09 01:16:19 +02:00
|
|
|
for (int i = 1; i < r.size(); i++) {
|
2016-10-24 00:21:40 +02:00
|
|
|
p = r.at(i).coordinates().toMercator();
|
|
|
|
_path.lineTo(QPointF(p.x(), -p.y()));
|
2016-09-25 18:57:17 +02:00
|
|
|
new WaypointItem(r.at(i), this);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 21:26:28 +02:00
|
|
|
updateShape();
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
_marker->setPos(_path.pointAtPercent(0));
|
|
|
|
|
2016-09-26 21:01:58 +02:00
|
|
|
_pen.setStyle(Qt::DotLine);
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2016-09-26 21:01:58 +02:00
|
|
|
setToolTip(toolTip());
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RouteItem::setScale(qreal scale)
|
|
|
|
{
|
2016-09-25 18:57:17 +02:00
|
|
|
QList<QGraphicsItem *> childs = childItems();
|
|
|
|
for (int i = 0; i < childs.count(); i++)
|
|
|
|
childs.at(i)->setScale(1.0/scale);
|
|
|
|
|
2016-09-26 21:01:58 +02:00
|
|
|
PathItem::setScale(scale);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 21:26:28 +02:00
|
|
|
void RouteItem::setUnits(enum Units units)
|
|
|
|
{
|
2016-09-26 21:01:58 +02:00
|
|
|
PathItem::setUnits(units);
|
2016-08-30 21:26:28 +02:00
|
|
|
setToolTip(toolTip());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|