1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55:53 +01:00
GPXSee/src/GUI/temperaturegraph.cpp

109 lines
2.0 KiB
C++
Raw Normal View History

2017-11-26 18:54:03 +01:00
#include "data/data.h"
#include "temperaturegraphitem.h"
#include "temperaturegraph.h"
2016-06-24 00:55:44 +02:00
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
{
2016-08-19 19:48:44 +02:00
_showTracks = true;
2017-10-04 23:15:39 +02:00
setYUnits(Metric);
setYLabel(tr("Temperature"));
setSliderPrecision(1);
}
2016-08-09 01:16:19 +02:00
void TemperatureGraph::setInfo()
{
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();
}
QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
{
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-09-19 23:35:04 +02:00
if (graph.size() < 2) {
skipColor();
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);
}
}
for (int i = 0; i < data.routes().count(); i++) {
2016-08-09 01:16:19 +02:00
skipColor();
graphs.append(0);
}
2016-08-09 01:16:19 +02:00
setInfo();
redraw();
return graphs;
}
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)
{
2017-10-04 23:15:39 +02:00
if (units == Metric) {
GraphView::setYUnits(QChar(0x00B0) + tr("C"));
setYScale(1);
setYOffset(0);
} else {
GraphView::setYUnits(QChar(0x00B0) + tr("F"));
setYScale(C2FS);
setYOffset(C2FO);
}
}
2017-10-04 23:15:39 +02:00
void TemperatureGraph::setUnits(Units units)
{
2017-10-04 23:15:39 +02:00
setYUnits(units);
2016-08-09 01:16:19 +02:00
setInfo();
2017-10-04 23:15:39 +02:00
GraphView::setUnits(units);
}
void TemperatureGraph::showTracks(bool show)
{
2016-08-19 19:48:44 +02:00
_showTracks = show;
showGraph(show);
2016-08-20 11:28:08 +02:00
setInfo();
redraw();
}