From 00ef815738d1a35acd26cd98c296514605aa2318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 25 Sep 2017 19:56:04 +0200 Subject: [PATCH] Unified average speed handling --- lang/gpxsee_cs.ts | 17 ++++++----------- lang/gpxsee_de.ts | 17 ++++++----------- lang/gpxsee_sv.ts | 17 ++++++----------- src/graphview.h | 2 +- src/speedgraph.cpp | 4 ++++ src/speedgraphitem.cpp | 26 +++++++++++++++++--------- src/speedgraphitem.h | 7 ++++++- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index acc55d3e..ffe8838f 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -1292,7 +1292,7 @@ Rychlost - + km/h km/h @@ -1307,7 +1307,7 @@ Maximum - + mi/h mi/h @@ -1315,30 +1315,25 @@ SpeedGraphItem - + km/h km/h - + mi/h mi/h - + Maximum Maximum - + Average Průměr - - - Moving average - Čistý průměr - TemperatureGraph diff --git a/lang/gpxsee_de.ts b/lang/gpxsee_de.ts index db03ac70..0dfdb4bf 100644 --- a/lang/gpxsee_de.ts +++ b/lang/gpxsee_de.ts @@ -1291,7 +1291,7 @@ Geschwindigkeit - + km/h km/h @@ -1306,7 +1306,7 @@ Maximum - + mi/h mi/h @@ -1314,30 +1314,25 @@ SpeedGraphItem - + km/h km/h - + mi/h mi/h - + Maximum Maximum - + Average Durchschnitt - - - Moving average - Bewegungsdurchschnitt - TemperatureGraph diff --git a/lang/gpxsee_sv.ts b/lang/gpxsee_sv.ts index 729ccbd6..9f92434a 100644 --- a/lang/gpxsee_sv.ts +++ b/lang/gpxsee_sv.ts @@ -1291,7 +1291,7 @@ Hastighet - + km/h km/h @@ -1306,7 +1306,7 @@ Max - + mi/h mi/h @@ -1314,30 +1314,25 @@ SpeedGraphItem - + km/h km/h - + mi/h mi/h - + Maximum - + Average - - - Moving average - - TemperatureGraph diff --git a/src/graphview.h b/src/graphview.h index dcd77de2..b68de5c9 100644 --- a/src/graphview.h +++ b/src/graphview.h @@ -68,6 +68,7 @@ protected: void clearInfo(); void skipColor() {_palette.nextColor();} + QList _graphs; Units _units; GraphType _graphType; @@ -103,7 +104,6 @@ private: InfoItem *_info; GridItem *_grid; - QList _graphs; QList _visible; QSet _hide; QRectF _bounds; diff --git a/src/speedgraph.cpp b/src/speedgraph.cpp index 60b741a6..1d75e261 100644 --- a/src/speedgraph.cpp +++ b/src/speedgraph.cpp @@ -39,6 +39,7 @@ void SpeedGraph::loadData(const Data &data, const QList &paths) } SpeedGraphItem *gi = new SpeedGraphItem(graph, track->movingTime()); + gi->setTimeType(_timeType); GraphView::addGraph(gi, paths.at(i)); _avg.append(QPointF(track->distance(), gi->avg())); @@ -100,6 +101,9 @@ void SpeedGraph::setTimeType(enum TimeType type) { _timeType = type; + for (int i = 0; i < _graphs.size(); i++) + static_cast(_graphs.at(i))->setTimeType(type); + setInfo(); redraw(); } diff --git a/src/speedgraphitem.cpp b/src/speedgraphitem.cpp index 3449d939..ccd06250 100644 --- a/src/speedgraphitem.cpp +++ b/src/speedgraphitem.cpp @@ -4,29 +4,37 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, qreal movingTime, QGraphicsItem *parent) : GraphItem(graph, parent) { + _units = Metric; + _timeType = Total; + _avg = graph.last().s() / graph.last().t(); _mavg = graph.last().s() / movingTime; - setToolTip(toolTip(Metric)); + setToolTip(toolTip()); } -QString SpeedGraphItem::toolTip(Units units) const +QString SpeedGraphItem::toolTip() const { ToolTip tt; - qreal scale = (units == Metric) ? MS2KMH : MS2MIH; - QString su = (units == Metric) ? tr("km/h") : tr("mi/h"); + qreal scale = (_units == Metric) ? MS2KMH : MS2MIH; + QString su = (_units == Metric) ? tr("km/h") : tr("mi/h"); tt.insert(tr("Maximum"), QString::number(max() * scale, 'f', 1) + UNIT_SPACE + su); - tt.insert(tr("Average"), QString::number(avg() * scale, 'f', 1) - + UNIT_SPACE + su); - tt.insert(tr("Moving average"), QString::number(mavg() * scale, 'f', 1) - + UNIT_SPACE + su); + tt.insert(tr("Average"), QString::number((_timeType == Total) + ? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su); return tt.toString(); } void SpeedGraphItem::setUnits(Units units) { - setToolTip(toolTip(units)); + _units = units; + setToolTip(toolTip()); +} + +void SpeedGraphItem::setTimeType(TimeType type) +{ + _timeType = type; + setToolTip(toolTip()); } diff --git a/src/speedgraphitem.h b/src/speedgraphitem.h index 8a4962a6..af9ba7e7 100644 --- a/src/speedgraphitem.h +++ b/src/speedgraphitem.h @@ -1,6 +1,7 @@ #ifndef SPEEDGRAPHITEM_H #define SPEEDGRAPHITEM_H +#include "timetype.h" #include "graphitem.h" class SpeedGraphItem : public GraphItem @@ -16,11 +17,15 @@ public: qreal mavg() const {return _mavg;} void setUnits(Units units); + void setTimeType(TimeType type); private: - QString toolTip(Units units) const; + QString toolTip() const; qreal _avg, _mavg; + + Units _units; + TimeType _timeType; }; #endif // SPEEDGRAPHITEM_H