1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Improved handlig of small-distance tracks

This commit is contained in:
Martin Tůma 2016-03-27 15:04:58 +02:00
parent c9b5e0f2cb
commit 06248457a0
8 changed files with 127 additions and 41 deletions

View File

@ -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"));
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();

View File

@ -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

View File

@ -746,12 +746,21 @@ void GUI::updateStatusBarInfo()
else
_fileNameLabel->setText(tr("%1 tracks").arg(_trackCount));
if (_imperialUnitsAction->isChecked())
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));
}

View File

@ -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::setUnits(enum Units units)
void HeartRateGraph::setXUnits()
{
if (units == Metric) {
setXUnits(tr("km"));
setXScale(M2KM);
if (_units == Metric) {
if (bounds().width() < KMINM) {
GraphView::setXUnits(tr("m"));
setXScale(1);
} else {
setXUnits(tr("mi"));
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)
{
_units = units;
setXUnits();
clearInfo();
addInfo();

View File

@ -21,9 +21,11 @@ public:
qreal max() const {return bounds().bottom();}
private:
void setXUnits();
void addInfo();
QList<QPointF> _avg;
enum Units _units;
};
#endif // HEARTRATEGRAPH_H

View File

@ -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"));
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();

View File

@ -22,9 +22,12 @@ public:
qreal max() const {return bounds().bottom();}
private:
void setXUnits();
void setYUnits();
void addInfo();
QList<QPointF> _avg;
enum Units _units;
};
#endif // SPEEDGRAPH_H

View File

@ -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 MIINFT 5280 // 1 mi in ft
#define MIINM 1609.344 // 1mi in m
#ifdef Q_OS_WIN32
#define UNIT_SPACE " "