1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-25 12:15:54 +01:00
GPXSee/src/GUI/routeitem.cpp

104 lines
2.3 KiB
C++
Raw Normal View History

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"
#include "tooltip.h"
2016-08-09 01:16:19 +02:00
#include "routeitem.h"
QString RouteItem::toolTip(Units units) const
{
ToolTip tt;
if (!_name.isEmpty())
2017-01-08 20:02:51 +01:00
tt.insert(tr("Name"), _name);
if (!_desc.isEmpty())
2017-01-08 20:02:51 +01:00
tt.insert(tr("Description"), _desc);
tt.insert(tr("Distance"), Format::distance(_path.last().distance(), units));
return tt.toString();
}
RouteItem::RouteItem(const Route &route, Map *map, QGraphicsItem *parent)
: PathItem(route.path(), map, parent)
2016-08-09 01:16:19 +02:00
{
const QVector<Waypoint> &waypoints = route.waypoints();
2016-08-09 01:16:19 +02:00
for (int i = 0; i < waypoints.size(); i++)
new WaypointItem(waypoints.at(i), map, this);
_name = route.name();
_desc = route.description();
_units = Metric;
_coordinatesFormat = DecimalDegrees;
setToolTip(toolTip(Metric));
2016-08-09 01:16:19 +02:00
}
void RouteItem::setMap(Map *map)
2016-08-09 01:16:19 +02:00
{
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->setMap(map);
}
}
PathItem::setMap(map);
2016-08-09 01:16:19 +02:00
}
void RouteItem::setUnits(Units units)
{
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-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);
}
}
}