2017-11-26 18:54:03 +01:00
|
|
|
#include "data/data.h"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "temperaturegraphitem.h"
|
2016-06-16 20:33:56 +02:00
|
|
|
#include "temperaturegraph.h"
|
|
|
|
|
|
|
|
|
2016-06-24 00:55:44 +02:00
|
|
|
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
2016-06-16 20:33:56 +02:00
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = true;
|
2016-06-16 20:33:56 +02:00
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
setYUnits(Metric);
|
2016-06-16 20:33:56 +02:00
|
|
|
setYLabel(tr("Temperature"));
|
|
|
|
|
|
|
|
setSliderPrecision(1);
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
void TemperatureGraph::setInfo()
|
2016-06-16 20:33:56 +02:00
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
if (_showTracks) {
|
|
|
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
|
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale()
|
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
|
|
|
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
|
|
|
} else
|
|
|
|
clearInfo();
|
2016-06-16 20:33:56 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
|
2016-06-16 20:33:56 +02:00
|
|
|
{
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> graphs;
|
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++) {
|
|
|
|
const Graph &graph = data.tracks().at(i)->temperature();
|
2016-06-16 20:33:56 +02:00
|
|
|
|
2016-09-19 23:35:04 +02:00
|
|
|
if (graph.size() < 2) {
|
2016-06-16 20:33:56 +02:00
|
|
|
skipColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
|
|
|
TemperatureGraphItem *gi = new TemperatureGraphItem(graph,
|
|
|
|
_graphType);
|
|
|
|
GraphView::addGraph(gi);
|
|
|
|
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
|
|
|
|
graphs.append(gi);
|
2016-06-16 20:33:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
for (int i = 0; i < data.routes().count(); i++) {
|
2016-08-09 01:16:19 +02:00
|
|
|
skipColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
}
|
2016-08-09 01:16:19 +02:00
|
|
|
|
|
|
|
setInfo();
|
|
|
|
redraw();
|
2018-05-04 19:36:37 +02:00
|
|
|
|
|
|
|
return graphs;
|
2016-06-16 20:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal TemperatureGraph::avg() const
|
|
|
|
{
|
|
|
|
qreal sum = 0, w = 0;
|
|
|
|
QList<QPointF>::const_iterator it;
|
|
|
|
|
|
|
|
for (it = _avg.begin(); it != _avg.end(); it++) {
|
|
|
|
sum += it->y() * it->x();
|
|
|
|
w += it->x();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (sum / w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TemperatureGraph::clear()
|
|
|
|
{
|
|
|
|
_avg.clear();
|
|
|
|
|
|
|
|
GraphView::clear();
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
void TemperatureGraph::setYUnits(Units units)
|
2016-06-16 20:33:56 +02:00
|
|
|
{
|
2017-10-04 23:15:39 +02:00
|
|
|
if (units == Metric) {
|
2016-07-28 00:23:22 +02:00
|
|
|
GraphView::setYUnits(QChar(0x00B0) + tr("C"));
|
2016-06-16 20:33:56 +02:00
|
|
|
setYScale(1);
|
|
|
|
setYOffset(0);
|
|
|
|
} else {
|
2016-07-28 00:23:22 +02:00
|
|
|
GraphView::setYUnits(QChar(0x00B0) + tr("F"));
|
2016-06-16 20:33:56 +02:00
|
|
|
setYScale(C2FS);
|
|
|
|
setYOffset(C2FO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
void TemperatureGraph::setUnits(Units units)
|
2016-06-16 20:33:56 +02:00
|
|
|
{
|
2017-10-04 23:15:39 +02:00
|
|
|
setYUnits(units);
|
2016-08-09 01:16:19 +02:00
|
|
|
setInfo();
|
2016-06-16 20:33:56 +02:00
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
GraphView::setUnits(units);
|
2016-06-16 20:33:56 +02:00
|
|
|
}
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
void TemperatureGraph::showTracks(bool show)
|
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = show;
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
showGraph(show);
|
2016-08-20 11:28:08 +02:00
|
|
|
setInfo();
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|