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

62 lines
1.4 KiB
C++
Raw Normal View History

2016-08-09 01:16:19 +02:00
#include <QPainter>
2016-11-02 17:35:26 +01:00
#include "format.h"
2016-08-02 00:28:56 +02:00
#include "tooltip.h"
#include "trackitem.h"
QString TrackItem::toolTip()
{
2016-08-02 00:28:56 +02:00
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(_distance.last(), _units));
2016-08-02 00:28:56 +02:00
if (_time > 0)
2017-01-08 20:02:51 +01:00
tt.insert(tr("Time"), Format::timeSpan(_time));
if (_movingTime > 0)
tt.insert(tr("Moving Time"), Format::timeSpan(_movingTime));
2016-08-02 00:28:56 +02:00
if (!_date.isNull())
2017-01-08 20:02:51 +01:00
tt.insert(tr("Date"), _date.toString(Qt::SystemLocaleShortDate));
2016-08-02 00:28:56 +02:00
return tt.toString();
}
2016-08-02 00:28:56 +02:00
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
2016-09-19 00:56:10 +02:00
: PathItem(parent)
{
QPointF p;
2016-11-13 09:49:31 +01:00
const Path &path = track.path();
Q_ASSERT(path.count() >= 2);
2016-11-14 22:12:43 +01:00
p = path.first().coordinates().toMercator();
_path.moveTo(QPointF(p.x(), -p.y()));
2016-11-14 22:12:43 +01:00
_distance.append(path.first().distance());
2016-11-13 09:49:31 +01:00
for (int i = 1; i < path.size(); i++) {
if (path.at(i).coordinates() == path.at(i-1).coordinates())
continue;
2016-11-14 22:12:43 +01:00
p = path.at(i).coordinates().toMercator();
_path.lineTo(QPointF(p.x(), -p.y()));
2016-11-14 22:12:43 +01:00
_distance.append(path.at(i).distance());
}
2016-09-26 21:01:58 +02:00
updateShape();
2016-11-05 17:33:29 +01:00
_name = track.name();
_desc = track.description();
_date = track.date();
_time = track.time();
_movingTime = track.movingTime();
_marker->setPos(_path.elementAt(0));
2016-08-09 01:16:19 +02:00
2016-09-26 21:01:58 +02:00
setToolTip(toolTip());
}
void TrackItem::setUnits(enum Units units)
{
2016-09-26 21:01:58 +02:00
PathItem::setUnits(units);
setToolTip(toolTip());
}