5 #include "speedgraphitem.h"
6 #include "speedgraph.h"
9 SpeedGraph::SpeedGraph(QWidget
*parent
) : GraphTab(parent
)
16 setYLabel(tr("Speed"));
18 setSliderPrecision(1);
21 SpeedGraph::~SpeedGraph()
26 void SpeedGraph::setInfo()
29 QLocale
l(QLocale::system());
30 QString pace
= Format::timeSpan((3600.0 / (avg() * yScale())), false);
31 QString pu
= (_units
== Metric
) ? tr("min/km") : (_units
== Imperial
) ?
32 tr("min/mi") : tr("min/nmi");
35 GraphView::addInfo(tr("Avg"), l
.toString(avg() * yScale(), 'f', 1)
36 + UNIT_SPACE
+ yUnits());
37 GraphView::addInfo(tr("Max"), l
.toString(max() * yScale(), 'f', 1)
38 + UNIT_SPACE
+ yUnits());
40 GraphView::addInfo(tr("Average"), l
.toString(avg() * yScale(), 'f',
41 1) + UNIT_SPACE
+ yUnits());
42 GraphView::addInfo(tr("Maximum"), l
.toString(max() * yScale(), 'f',
43 1) + UNIT_SPACE
+ yUnits());
44 #endif // Q_OS_ANDROID
45 GraphView::addInfo(tr("Pace"), pace
+ UNIT_SPACE
+ pu
);
50 GraphItem
*SpeedGraph::loadGraph(const Graph
&graph
, const Track
&track
,
51 const QColor
&color
, bool primary
)
56 SpeedGraphItem
*gi
= new SpeedGraphItem(graph
, _graphType
, _width
,
57 color
, primary
? Qt::SolidLine
: Qt::DashLine
, track
.movingTime());
58 gi
->setTimeType(_timeType
);
66 _avg
.append(QPointF(track
.distance(), gi
->avg()));
67 _mavg
.append(QPointF(track
.distance(), gi
->mavg()));
73 QList
<GraphItem
*> SpeedGraph::loadData(const Data
&data
)
75 QList
<GraphItem
*> graphs
;
77 for (int i
= 0; i
< data
.tracks().count(); i
++) {
78 GraphItem
*primary
, *secondary
;
79 QColor
color(_palette
.nextColor());
80 const Track
&track
= data
.tracks().at(i
);
81 const GraphPair
&gp
= track
.speed();
83 primary
= loadGraph(gp
.primary(), track
, color
, true);
85 ? loadGraph(gp
.secondary(), track
, color
, false) : 0;
86 if (primary
&& secondary
)
87 primary
->setSecondaryGraph(secondary
);
89 graphs
.append(primary
);
92 for (int i
= 0; i
< data
.routes().count(); i
++) {
97 for (int i
= 0; i
< data
.areas().count(); i
++)
106 qreal
SpeedGraph::avg() const
108 qreal sum
= 0, w
= 0;
109 const QVector
<QPointF
> &vector
= (_timeType
== Moving
) ? _mavg
: _avg
;
111 for (int i
= 0; i
< vector
.size(); i
++) {
112 const QPointF
&p
= vector
.at(i
);
113 sum
+= p
.y() * p
.x();
120 void SpeedGraph::clear()
131 void SpeedGraph::setYUnits()
133 if (_units
== Nautical
) {
134 GraphView::setYUnits(tr("kn"));
136 } else if (_units
== Imperial
) {
137 GraphView::setYUnits(tr("mi/h"));
140 GraphView::setYUnits(tr("km/h"));
145 void SpeedGraph::setUnits(Units units
)
152 GraphView::setUnits(units
);
155 void SpeedGraph::setTimeType(enum TimeType type
)
159 for (int i
= 0; i
< _tracks
.size(); i
++)
160 _tracks
.at(i
)->setTimeType(type
);
166 void SpeedGraph::showTracks(bool show
)
170 for (int i
= 0; i
< _tracks
.size(); i
++) {
172 addGraph(_tracks
.at(i
));
174 removeGraph(_tracks
.at(i
));