1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Added temperature graphs

Fixed handling of GPX files with inconsistent trackpoint entries
This commit is contained in:
Martin Tůma 2016-06-16 20:33:56 +02:00
parent 31f6eeac26
commit f0c3f9b8c8
3 changed files with 159 additions and 0 deletions

115
src/temperaturegraph.cpp Normal file
View File

@ -0,0 +1,115 @@
#include "gpx.h"
#include "temperaturegraph.h"
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphView(parent)
{
_units = Metric;
setYUnits();
setXLabel(tr("Distance"));
setYLabel(tr("Temperature"));
setSliderPrecision(1);
}
void TemperatureGraph::addInfo()
{
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());
redraw();
}
void TemperatureGraph::loadGPX(const GPX &gpx)
{
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> data;
qreal sum = 0, w = 0;
gpx.track(i).temperatureGraph(data);
if (data.count() < 2) {
skipColor();
continue;
}
for (int j = 1; j < data.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
w += data.at(j).x() - data.at(j-1).x();
}
_avg.append(QPointF(gpx.track(i).distance(), sum/w));
loadData(data);
}
setXUnits();
addInfo();
}
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();
}
void TemperatureGraph::setXUnits()
{
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
GraphView::setXUnits(tr("km"));
setXScale(M2KM);
}
} else {
if (bounds().width() < MIINM) {
GraphView::setXUnits(tr("ft"));
setXScale(M2FT);
} else {
GraphView::setXUnits(tr("mi"));
setXScale(M2MI);
}
}
}
void TemperatureGraph::setYUnits()
{
if (_units == Metric) {
GraphView::setYUnits(QString::fromUtf8("\xC2\xB0") + tr("C"));
setYScale(1);
setYOffset(0);
} else {
GraphView::setYUnits(QString::fromUtf8("\xC2\xB0") + tr("F"));
setYScale(C2FS);
setYOffset(C2FO);
}
}
void TemperatureGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
clearInfo();
addInfo();
}

33
src/temperaturegraph.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef TEMPERATUREGRAPH_H
#define TEMPERATUREGRAPH_H
#include "units.h"
#include "graphview.h"
class GPX;
class TemperatureGraph : public GraphView
{
Q_OBJECT
public:
TemperatureGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal avg() const;
qreal min() const {return bounds().top();}
qreal max() const {return bounds().bottom();}
private:
void setXUnits();
void setYUnits();
void addInfo();
QList<QPointF> _avg;
enum Units _units;
};
#endif // TEMPERATUREGRAPH_H

11
src/trackpoint.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "trackpoint.h"
QDebug operator<<(QDebug dbg, const Trackpoint &trackpoint)
{
dbg.nospace() << "Trackpoint(" << trackpoint.coordinates << ", "
<< trackpoint.timestamp << ", " << trackpoint.elevation << ", "
<< trackpoint.geoidheight << ", " << trackpoint.speed << ", "
<< trackpoint.heartRate << ", " << trackpoint.temperature << ")";
return dbg.maybeSpace();
}