1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/routeitem.cpp

86 lines
1.9 KiB
C++
Raw Normal View History

#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"
#include "tooltip.h"
2016-08-09 01:16:19 +02:00
#include "routeitem.h"
QString RouteItem::toolTip()
{
ToolTip tt;
if (!_name.isEmpty())
tt.insert(qApp->translate("RouteItem", "Name"), _name);
if (!_desc.isEmpty())
tt.insert(qApp->translate("RouteItem", "Description"), _desc);
tt.insert(qApp->translate("RouteItem", "Distance"),
2016-11-14 22:12:43 +01:00
Format::distance(_distance.last(), _units));
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);
QPointF p;
2016-08-09 01:16:19 +02:00
_name = r.name();
_desc = r.description();
2016-11-14 22:12:43 +01:00
_distance = route.distanceData();
new WaypointItem(r.at(0), this);
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++) {
p = r.at(i).coordinates().toMercator();
_path.lineTo(QPointF(p.x(), -p.y()));
new WaypointItem(r.at(i), this);
2016-08-09 01:16:19 +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)
{
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
}
void RouteItem::setUnits(enum Units units)
{
2016-09-26 21:01:58 +02:00
PathItem::setUnits(units);
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);
}
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);
}
}
}