From 06248457a0e7366aecf744c82d24cdfc83e77297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C3=B9ma?= Date: Sun, 27 Mar 2016 15:04:58 +0200 Subject: [PATCH] Improved handlig of small-distance tracks --- src/elevationgraph.cpp | 48 +++++++++++++++++++++++++++++++---------- src/elevationgraph.h | 3 +++ src/gui.cpp | 21 ++++++++++++------ src/heartrategraph.cpp | 37 ++++++++++++++++++++++--------- src/heartrategraph.h | 2 ++ src/speedgraph.cpp | 49 +++++++++++++++++++++++++++++++----------- src/speedgraph.h | 3 +++ src/units.h | 5 +++-- 8 files changed, 127 insertions(+), 41 deletions(-) diff --git a/src/elevationgraph.cpp b/src/elevationgraph.cpp index 02f1f0d2..050a4fce 100644 --- a/src/elevationgraph.cpp +++ b/src/elevationgraph.cpp @@ -8,11 +8,12 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent) _ascent = 0; _descent = 0; + _units = Metric; + + setYUnits(); setXLabel(tr("Distance")); setYLabel(tr("Elevation")); - setXUnits(tr("km")); - setYUnits(tr("m")); - setXScale(M2KM); + setMinYRange(50.0); } @@ -58,6 +59,7 @@ void ElevationGraph::loadGPX(const GPX &gpx) loadData(data); } + setXUnits(); addInfo(); } @@ -69,19 +71,43 @@ void ElevationGraph::clear() GraphView::clear(); } -void ElevationGraph::setUnits(enum Units units) +void ElevationGraph::setXUnits() { - if (units == Metric) { - setXUnits(tr("km")); - setYUnits(tr("m")); - setXScale(M2KM); + 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 ElevationGraph::setYUnits() +{ + if (_units == Metric) { + GraphView::setYUnits(tr("m")); setYScale(1); } else { - setXUnits(tr("mi")); - setYUnits(tr("ft")); - setXScale(M2MI); + GraphView::setYUnits(tr("ft")); setYScale(M2FT); } +} + +void ElevationGraph::setUnits(enum Units units) +{ + _units = units; + setXUnits(); + setYUnits(); clearInfo(); addInfo(); diff --git a/src/elevationgraph.h b/src/elevationgraph.h index bc6443ac..543c4c8f 100644 --- a/src/elevationgraph.h +++ b/src/elevationgraph.h @@ -23,9 +23,12 @@ public: qreal min() const {return bounds().top();} private: + void setXUnits(); + void setYUnits(); void addInfo(); qreal _ascent, _descent; + enum Units _units; }; #endif // ELEVATIONGRAPH_H diff --git a/src/gui.cpp b/src/gui.cpp index dc27640a..f9d4f60d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -746,12 +746,21 @@ void GUI::updateStatusBarInfo() else _fileNameLabel->setText(tr("%1 tracks").arg(_trackCount)); - if (_imperialUnitsAction->isChecked()) - _distanceLabel->setText(QString::number(_distance * M2MI, 'f', 1) - + UNIT_SPACE + tr("mi")); - else - _distanceLabel->setText(QString::number(_distance * M2KM, 'f', 1) - + UNIT_SPACE + tr("km")); + if (_imperialUnitsAction->isChecked()) { + if (_distance < MIINM) + _distanceLabel->setText(QString::number(_distance * M2FT, 'f', 0) + + UNIT_SPACE + tr("ft")); + else + _distanceLabel->setText(QString::number(_distance * M2MI, 'f', 1) + + UNIT_SPACE + tr("mi")); + } else { + if (_distance < KMINM) + _distanceLabel->setText(QString::number(_distance, 'f', 0) + + UNIT_SPACE + tr("m")); + else + _distanceLabel->setText(QString::number(_distance * M2KM, 'f', 1) + + UNIT_SPACE + tr("km")); + } _timeLabel->setText(timeSpan(_time)); } diff --git a/src/heartrategraph.cpp b/src/heartrategraph.cpp index f8ab34ee..ef8133cb 100644 --- a/src/heartrategraph.cpp +++ b/src/heartrategraph.cpp @@ -4,11 +4,11 @@ HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent) { + _units = Metric; + setXLabel(tr("Distance")); setYLabel(tr("Heart rate")); - setXUnits(tr("km")); - setYUnits(tr("1/min")); - setXScale(M2KM); + setSliderPrecision(0); } @@ -43,6 +43,7 @@ void HeartRateGraph::loadGPX(const GPX &gpx) loadData(data); } + setXUnits(); addInfo(); } @@ -66,15 +67,31 @@ void HeartRateGraph::clear() GraphView::clear(); } +void HeartRateGraph::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 HeartRateGraph::setUnits(enum Units units) { - if (units == Metric) { - setXUnits(tr("km")); - setXScale(M2KM); - } else { - setXUnits(tr("mi")); - setXScale(M2MI); - } + _units = units; + setXUnits(); clearInfo(); addInfo(); diff --git a/src/heartrategraph.h b/src/heartrategraph.h index c6010868..713d80f7 100644 --- a/src/heartrategraph.h +++ b/src/heartrategraph.h @@ -21,9 +21,11 @@ public: qreal max() const {return bounds().bottom();} private: + void setXUnits(); void addInfo(); QList _avg; + enum Units _units; }; #endif // HEARTRATEGRAPH_H diff --git a/src/speedgraph.cpp b/src/speedgraph.cpp index b815fc42..57cbebb9 100644 --- a/src/speedgraph.cpp +++ b/src/speedgraph.cpp @@ -5,12 +5,12 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphView(parent) { + _units = Metric; + + setYUnits(); setXLabel(tr("Distance")); setYLabel(tr("Speed")); - setXUnits(tr("km")); - setYUnits(tr("km/h")); - setXScale(M2KM); - setYScale(MS2KMH); + setSliderPrecision(1); } @@ -41,6 +41,7 @@ void SpeedGraph::loadGPX(const GPX &gpx) loadData(data); } + setXUnits(); addInfo(); } @@ -64,19 +65,43 @@ void SpeedGraph::clear() GraphView::clear(); } -void SpeedGraph::setUnits(enum Units units) +void SpeedGraph::setXUnits() { - if (units == Metric) { - setXUnits(tr("km")); - setYUnits(tr("km/h")); - setXScale(M2KM); + 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 SpeedGraph::setYUnits() +{ + if (_units == Metric) { + GraphView::setYUnits(tr("km/h")); setYScale(MS2KMH); } else { - setXUnits(tr("mi")); - setYUnits(tr("mi/h")); - setXScale(M2MI); + GraphView::setYUnits(tr("mi/h")); setYScale(MS2MIH); } +} + +void SpeedGraph::setUnits(enum Units units) +{ + _units = units; + setXUnits(); + setYUnits(); clearInfo(); addInfo(); diff --git a/src/speedgraph.h b/src/speedgraph.h index fc945256..e9118de4 100644 --- a/src/speedgraph.h +++ b/src/speedgraph.h @@ -22,9 +22,12 @@ public: qreal max() const {return bounds().bottom();} private: + void setXUnits(); + void setYUnits(); void addInfo(); QList _avg; + enum Units _units; }; #endif // SPEEDGRAPH_H diff --git a/src/units.h b/src/units.h index da5b8c87..c1891bdf 100644 --- a/src/units.h +++ b/src/units.h @@ -13,8 +13,9 @@ enum Units { #define MS2MIH 2.236936290000 // m/s -> mi/h #define FT2MI 0.000189393939 // ft -> mi -#define MIINFT 5280 // 1 mi in ft -#define KMINM 1000 // 1 km in m +#define KMINM 1000 // 1 km in m +#define MIINFT 5280 // 1 mi in ft +#define MIINM 1609.344 // 1mi in m #ifdef Q_OS_WIN32 #define UNIT_SPACE " "