Graph loading performance improvement
[GPXSee.git] / src / GUI / speedgraphitem.cpp
blob85d1343e1b0e4a30967534ba97b99e50241425b8
1 #include <QLocale>
2 #include "tooltip.h"
3 #include "format.h"
4 #include "speedgraphitem.h"
7 SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width,
8 const QColor &color, qreal movingTime, QGraphicsItem *parent)
9 : GraphItem(graph, type, width, color, parent)
11 _units = Metric;
12 _timeType = Total;
14 _max = GraphItem::max();
15 _avg = graph.last().last().s() / graph.last().last().t();
16 _mavg = graph.last().last().s() / movingTime;
18 setToolTip(toolTip());
21 QString SpeedGraphItem::toolTip() const
23 ToolTip tt;
24 qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical)
25 ? MS2KN : MS2KMH;
26 QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical)
27 ? tr("kn") : tr("km/h");
28 QString pace = Format::timeSpan((3600.0 / ((_timeType == Total)
29 ? avg() * scale : mavg() * scale)), false);
30 QString pu = (_units == Metric) ? tr("min/km") : (_units == Imperial) ?
31 tr("min/mi") : tr("min/nmi");
32 QLocale l(QLocale::system());
34 tt.insert(tr("Maximum"), l.toString(max() * scale, 'f', 1)
35 + UNIT_SPACE + su);
36 tt.insert(tr("Average"), l.toString((_timeType == Total)
37 ? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su);
38 tt.insert(tr("Pace"), pace + UNIT_SPACE + pu);
40 return tt.toString();
43 void SpeedGraphItem::setUnits(Units units)
45 _units = units;
46 setToolTip(toolTip());
49 void SpeedGraphItem::setTimeType(TimeType type)
51 _timeType = type;
52 setToolTip(toolTip());