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

54 lines
1.4 KiB
C++
Raw Normal View History

#include <QLocale>
#include "tooltip.h"
2018-03-10 20:25:13 +01:00
#include "format.h"
#include "speedgraphitem.h"
SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, qreal movingTime, QGraphicsItem *parent)
: GraphItem(graph, type, width, color, parent)
{
2017-09-25 19:56:04 +02:00
_units = Metric;
_timeType = Total;
2019-02-11 23:28:08 +01:00
_max = GraphItem::max();
_avg = graph.last().last().s() / graph.last().last().t();
_mavg = graph.last().last().s() / movingTime;
2017-09-25 19:56:04 +02:00
setToolTip(toolTip());
}
2017-09-25 19:56:04 +02:00
QString SpeedGraphItem::toolTip() const
{
ToolTip tt;
2018-02-11 23:51:57 +01:00
qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical)
? MS2KN : MS2KMH;
QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical)
? tr("kn") : tr("km/h");
2018-03-10 20:25:13 +01:00
QString pace = Format::timeSpan((3600.0 / ((_timeType == Total)
? avg() * scale : mavg() * scale)), false);
QString pu = (_units == Metric) ? tr("min/km") : (_units == Imperial) ?
tr("min/mi") : tr("min/nmi");
QLocale l(QLocale::system());
tt.insert(tr("Maximum"), l.toString(max() * scale, 'f', 1)
+ UNIT_SPACE + su);
tt.insert(tr("Average"), l.toString((_timeType == Total)
2017-09-25 19:56:04 +02:00
? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su);
2018-03-10 20:25:13 +01:00
tt.insert(tr("Pace"), pace + UNIT_SPACE + pu);
return tt.toString();
}
void SpeedGraphItem::setUnits(Units units)
{
2017-09-25 19:56:04 +02:00
_units = units;
setToolTip(toolTip());
}
void SpeedGraphItem::setTimeType(TimeType type)
{
_timeType = type;
setToolTip(toolTip());
}