1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 03:42:09 +01:00

Various route-releated fixes & improvements

This commit is contained in:
Martin Tůma 2016-08-30 21:26:28 +02:00
parent c00ebdeefd
commit 8624b42e0b
7 changed files with 75 additions and 2 deletions

View File

@ -607,6 +607,14 @@
<translation>km</translation>
</message>
</context>
<context>
<name>RouteItem</name>
<message>
<location filename="../src/routeitem.cpp" line="17"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
</context>
<context>
<name>ScaleItem</name>
<message>

View File

@ -55,6 +55,22 @@ GraphView::GraphView(QWidget *parent)
_sliderPos = 0;
}
GraphView::~GraphView()
{
if (_xAxis->scene() != _scene)
delete _xAxis;
if (_yAxis->scene() != _scene)
delete _yAxis;
if (_slider->scene() != _scene)
delete _slider;
if (_info->scene() != _scene)
delete _info;
for (int i = 0; i < _graphs.count(); i++)
if (_graphs.at(i)->scene() != _scene)
delete _graphs[i];
}
void GraphView::createXLabel()
{
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));

View File

@ -33,6 +33,7 @@ class GraphView : public QGraphicsView
public:
GraphView(QWidget *parent = 0);
~GraphView();
void loadData(const QVector<QPointF> &data, int id = 0);
int count() const {return _graphs.count();}

View File

@ -146,10 +146,14 @@ void Parser::routepointData()
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
handleRoutepointData(Name, _reader.readElementText());
else if (_reader.name() == "desc")
handleRoutepointData(Description, _reader.readElementText());
else if (_reader.name() == "ele")
handleRoutepointData(Elevation, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleRoutepointData(Geoidheight, _reader.readElementText());
else if (_reader.name() == "time")
handleRoutepointData(Time, _reader.readElementText());
else
_reader.skipCurrentElement();
}

View File

@ -1,12 +1,32 @@
#include <QApplication>
#include <QPainter>
#include "ll.h"
#include "misc.h"
#include "waypoint.h"
#include "waypointitem.h"
#include "tooltip.h"
#include "routeitem.h"
#define ROUTE_WIDTH 3
QString RouteItem::toolTip()
{
ToolTip tt;
tt.insert(qApp->translate("RouteItem", "Distance"),
::distance(_distance, _units));
return tt.toString();
}
void RouteItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(ROUTE_WIDTH * 1.0/scale());
_shape = s.createStroke(_path);
}
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
@ -26,8 +46,14 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
wi->setParentItem(this);
}
_units = Metric;
_distance = route.distance();
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
updateShape();
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
@ -60,6 +86,8 @@ void RouteItem::setScale(qreal scale)
QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale);
updateShape();
}
void RouteItem::setColor(const QColor &color)
@ -68,6 +96,12 @@ void RouteItem::setColor(const QColor &color)
update();
}
void RouteItem::setUnits(enum Units units)
{
_units = units;
setToolTip(toolTip());
}
void RouteItem::moveMarker(qreal distance)
{
if (distance > _distance)

View File

@ -4,13 +4,16 @@
#include <QGraphicsItem>
#include "markeritem.h"
#include "route.h"
#include "units.h"
class RouteItem : public QGraphicsItem
{
public:
RouteItem(const Route &route, QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _path.boundingRect();}
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
@ -18,6 +21,7 @@ public:
void setScale(qreal scale);
void setColor(const QColor &color);
void setUnits(enum Units units);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal distance);
@ -26,11 +30,16 @@ public:
void showWaypointLabels(bool show);
private:
void updateShape();
QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
qreal _distance;
};

View File

@ -341,7 +341,8 @@ void TrackView::setUnits(enum Units units)
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->setUnits(units);
for (int i = 0; i < _routes.count(); i++)
_routes[i]->setUnits(units);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setUnits(units);