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

Added support for imperial units

This commit is contained in:
Martin Tůma 2015-12-19 20:23:07 +01:00
parent 4a2c7b19fb
commit 141226b509
15 changed files with 298 additions and 97 deletions

View File

@ -63,7 +63,7 @@ Section "GPXSee (required)" SEC_APP
; Write the uninstall keys for Windows
WriteRegStr HKCU "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKCU "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "2.4"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "2.5"
WriteRegStr HKCU "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKCU "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKCU "${REGENTRY}" "NoRepair" 1

View File

@ -27,7 +27,8 @@ HEADERS += src/config.h \
src/filebrowser.h \
src/map.h \
src/maplist.h \
src/downloader.h
src/downloader.h \
src/units.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \

View File

@ -15,31 +15,43 @@
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="15"/>
<location filename="../src/elevationgraph.cpp" line="81"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="16"/>
<location filename="../src/elevationgraph.cpp" line="82"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="52"/>
<location filename="../src/elevationgraph.cpp" line="22"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="54"/>
<location filename="../src/elevationgraph.cpp" line="24"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="58"/>
<location filename="../src/elevationgraph.cpp" line="28"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="56"/>
<location filename="../src/elevationgraph.cpp" line="86"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="87"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="26"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
@ -52,12 +64,12 @@
<translation>O Qt</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="319"/>
<location filename="../src/gui.cpp" line="339"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="381"/>
<location filename="../src/gui.cpp" line="400"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
@ -67,7 +79,7 @@
<translation>Uložit jako</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="434"/>
<location filename="../src/gui.cpp" line="455"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
@ -83,8 +95,8 @@
</message>
<message>
<location filename="../src/gui.cpp" line="132"/>
<location filename="../src/gui.cpp" line="335"/>
<location filename="../src/gui.cpp" line="336"/>
<location filename="../src/gui.cpp" line="355"/>
<location filename="../src/gui.cpp" line="356"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
@ -104,20 +116,20 @@
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="262"/>
<location filename="../src/gui.cpp" line="279"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="216"/>
<location filename="../src/gui.cpp" line="253"/>
<location filename="../src/gui.cpp" line="229"/>
<location filename="../src/gui.cpp" line="270"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="130"/>
<location filename="../src/gui.cpp" line="354"/>
<location filename="../src/gui.cpp" line="355"/>
<location filename="../src/gui.cpp" line="373"/>
<location filename="../src/gui.cpp" line="374"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
@ -148,190 +160,205 @@
</message>
<message>
<location filename="../src/gui.cpp" line="198"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="204"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="211"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="201"/>
<location filename="../src/gui.cpp" line="214"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="205"/>
<location filename="../src/gui.cpp" line="218"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="208"/>
<location filename="../src/gui.cpp" line="221"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="230"/>
<location filename="../src/gui.cpp" line="243"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="235"/>
<location filename="../src/gui.cpp" line="248"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="239"/>
<location filename="../src/gui.cpp" line="252"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="243"/>
<location filename="../src/gui.cpp" line="253"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="260"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="287"/>
<location filename="../src/gui.cpp" line="307"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="288"/>
<location filename="../src/gui.cpp" line="308"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="338"/>
<location filename="../src/gui.cpp" line="358"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="339"/>
<location filename="../src/gui.cpp" line="359"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="341"/>
<location filename="../src/gui.cpp" line="361"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="342"/>
<location filename="../src/gui.cpp" line="362"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="344"/>
<location filename="../src/gui.cpp" line="363"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="358"/>
<location filename="../src/gui.cpp" line="377"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="362"/>
<location filename="../src/gui.cpp" line="381"/>
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="370"/>
<location filename="../src/gui.cpp" line="389"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="425"/>
<location filename="../src/gui.cpp" line="441"/>
<location filename="../src/gui.cpp" line="446"/>
<location filename="../src/gui.cpp" line="462"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="493"/>
<location filename="../src/gui.cpp" line="514"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="495"/>
<location filename="../src/gui.cpp" line="516"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="135"/>
<location filename="../src/gui.cpp" line="315"/>
<location filename="../src/gui.cpp" line="335"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="269"/>
<location filename="../src/gui.cpp" line="286"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="317"/>
<location filename="../src/gui.cpp" line="337"/>
<source>GPX viewer and analyzer</source>
<translation>Prohlížeč a analyzátor GPX</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="357"/>
<location filename="../src/gui.cpp" line="376"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="369"/>
<location filename="../src/gui.cpp" line="388"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="486"/>
<location filename="../src/gui.cpp" line="507"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="488"/>
<location filename="../src/gui.cpp" line="509"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="489"/>
<location filename="../src/gui.cpp" line="510"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="490"/>
<location filename="../src/gui.cpp" line="492"/>
<location filename="../src/gui.cpp" line="494"/>
<location filename="../src/gui.cpp" line="496"/>
<location filename="../src/gui.cpp" line="511"/>
<location filename="../src/gui.cpp" line="513"/>
<location filename="../src/gui.cpp" line="515"/>
<location filename="../src/gui.cpp" line="517"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="491"/>
<location filename="../src/gui.cpp" line="512"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="588"/>
<location filename="../src/gui.cpp" line="611"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="487"/>
<location filename="../src/gui.cpp" line="591"/>
<location filename="../src/gui.cpp" line="508"/>
<location filename="../src/gui.cpp" line="614"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="427"/>
<location filename="../src/gui.cpp" line="442"/>
<location filename="../src/gui.cpp" line="448"/>
<location filename="../src/gui.cpp" line="463"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="422"/>
<location filename="../src/gui.cpp" line="443"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="438"/>
<location filename="../src/gui.cpp" line="459"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
@ -352,11 +379,13 @@
</message>
<message>
<location filename="../src/speedgraph.cpp" line="11"/>
<location filename="../src/speedgraph.cpp" line="67"/>
<source>km</source>
<translation></translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="68"/>
<source>km/h</source>
<translation>km/h</translation>
</message>
@ -370,5 +399,15 @@
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="72"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="73"/>
<source>mi/h</source>
<translation>mi/h</translation>
</message>
</context>
</TS>

View File

@ -3,7 +3,7 @@
#define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
#define APP_VERSION "2.4"
#define APP_VERSION "2.5"
#define FONT_FAMILY "Arial"
#define FONT_SIZE 12

View File

@ -14,7 +14,19 @@ ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
Graph::setYLabel(tr("Elevation"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("m"));
Graph::setXScale(0.001);
Graph::setXScale(M2KM);
}
void ElevationGraph::addInfo()
{
Graph::addInfo(tr("Ascent"), QString::number(_ascent * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Descent"), QString::number(_descent * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Minimum"), QString::number(_min * _yScale, 'f', 0)
+ THIN_SPACE + _yUnits);
}
void ElevationGraph::loadGPX(const GPX &gpx)
@ -49,16 +61,8 @@ void ElevationGraph::loadGPX(const GPX &gpx)
_max = qMax(_max, max);
_min = qMin(_min, min);
addInfo(tr("Ascent"), QString::number(_ascent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Descent"), QString::number(_descent, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max, 'f', 0)
+ THIN_SPACE + _yUnits);
addInfo(tr("Minimum"), QString::number(_min, 'f', 0)
+ THIN_SPACE + _yUnits);
Graph::loadData(data);
addInfo();
loadData(data);
}
void ElevationGraph::clear()
@ -70,3 +74,23 @@ void ElevationGraph::clear()
Graph::clear();
}
void ElevationGraph::setUnits(enum Units units)
{
if (units == Metric) {
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("m"));
Graph::setXScale(M2KM);
Graph::setYScale(1);
} else {
Graph::setXUnits(tr("mi"));
Graph::setYUnits(tr("ft"));
Graph::setXScale(M2MI);
Graph::setYScale(M2FT);
}
clearInfo();
addInfo();
redraw();
}

View File

@ -3,6 +3,7 @@
#include "graph.h"
#include "gpx.h"
#include "units.h"
class ElevationGraph : public Graph
{
@ -13,6 +14,7 @@ public:
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal ascent() const {return _ascent;}
qreal descent() const {return _descent;}
@ -20,6 +22,8 @@ public:
qreal min() const {return _min;}
private:
void addInfo();
qreal _ascent, _descent;
qreal _max, _min;
};

View File

@ -116,6 +116,16 @@ void Graph::setYUnits(const QString &units)
createYLabel();
}
void Graph::setXScale(qreal scale)
{
_xScale = scale;
}
void Graph::setYScale(qreal scale)
{
_yScale = scale;
}
void Graph::loadData(const QVector<QPointF> &data)
{
QPainterPath path;
@ -143,7 +153,13 @@ void Graph::loadData(const QVector<QPointF> &data)
if (_graphs.size() > 1)
_sliderInfo->hide();
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
redraw();
}
void Graph::redraw()
{
if (!_graphs.isEmpty())
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
}
void Graph::resize(const QSizeF &size)
@ -187,8 +203,11 @@ void Graph::resize(const QSizeF &size)
_scene->addItem(_xAxis);
_scene->addItem(_yAxis);
qreal sp = (_slider->pos().x() == _slider->area().left())
? 0 : (_slider->pos().x() - _slider->area().left())
/ _slider->area().width();
_slider->setArea(r);
_slider->setPos(r.bottomLeft());
_slider->setPos(QPointF(sp * r.width(), r.bottom()));
_scene->addItem(_slider);
r = _scene->itemsBoundingRect();
@ -202,7 +221,7 @@ void Graph::resize(const QSizeF &size)
void Graph::resizeEvent(QResizeEvent *)
{
if (!_graphs.empty())
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
redraw();
}
void Graph::plot(QPainter *painter, const QRectF &target)
@ -234,6 +253,7 @@ void Graph::clear()
_scene->removeItem(_info);
_sliderInfo->show();
_slider->clear();
_info->clear();
_scene->clear();
_graphs.clear();
@ -285,3 +305,8 @@ void Graph::addInfo(const QString &key, const QString &value)
{
_info->insert(key, value);
}
void Graph::clearInfo()
{
_info->clear();
}

View File

@ -41,10 +41,12 @@ public:
void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units);
void setXScale(qreal scale) {_xScale = scale;}
void setYScale(qreal scale) {_yScale = scale;}
void setXScale(qreal scale);
void setYScale(qreal scale);
void setPrecision(int p) {_precision = p;}
void redraw();
void plot(QPainter *painter, const QRectF &target);
void clear();
@ -52,6 +54,7 @@ public:
void setSliderPosition(qreal pos);
void addInfo(const QString &key, const QString &value);
void clearInfo();
signals:
void sliderPositionChanged(qreal);

View File

@ -31,7 +31,7 @@ static QString timeSpan(qreal time)
s = time - (h * 3600) - (m * 60);
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
.arg(s,2, 10, QChar('0'));
.arg(s, 2, 10, QChar('0'));
}
@ -193,6 +193,19 @@ void GUI::createActions()
_showToolbarsAction->setChecked(true);
connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
SLOT(showToolbars(bool)));
QActionGroup *ag = new QActionGroup(this);
ag->setExclusive(true);
_metricUnitsAction = new QAction(tr("Metric"), this);
_metricUnitsAction->setCheckable(true);
_metricUnitsAction->setActionGroup(ag);
_metricUnitsAction->setChecked(true);
connect(_metricUnitsAction, SIGNAL(triggered()), this,
SLOT(setMetricUnits()));
_imperialUnitsAction = new QAction(tr("Imperial"), this);
_imperialUnitsAction->setCheckable(true);
_imperialUnitsAction->setActionGroup(ag);
connect(_imperialUnitsAction, SIGNAL(triggered()), this,
SLOT(setImperialUnits()));
// Navigation actions
_nextAction = new QAction(QIcon(QPixmap(NEXT_FILE_ICON)), tr("Next"), this);
@ -237,6 +250,10 @@ void GUI::createMenus()
_poiMenu->addAction(_showPOIAction);
_settingsMenu = menuBar()->addMenu(tr("Settings"));
_unitsMenu = _settingsMenu->addMenu(tr("Units"));
_unitsMenu->addAction(_metricUnitsAction);
_unitsMenu->addAction(_imperialUnitsAction);
_settingsMenu->addSeparator();
_settingsMenu->addAction(_showToolbarsAction);
_settingsMenu->addAction(_showGraphsAction);
@ -487,17 +504,31 @@ void GUI::saveFile(const QString &fileName)
QGraphicsScene scene;
InfoItem info;
info.insert(tr("Distance"), QString::number(_distance / 1000, 'f', 1)
+ THIN_SPACE + tr("km"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent(), 'f', 0)
+ THIN_SPACE + tr("m"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent(), 'f',
0) + THIN_SPACE + tr("m"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max(), 'f', 0)
+ THIN_SPACE + tr("m"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min(), 'f', 0)
+ THIN_SPACE + tr("m"));
if (_imperialUnitsAction->isChecked()) {
info.insert(tr("Distance"), QString::number(_distance * M2MI, 'f', 1)
+ THIN_SPACE + tr("mi"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min()
* M2FT, 'f', 0) + THIN_SPACE + tr("ft"));
} else {
info.insert(tr("Distance"), QString::number(_distance * M2KM, 'f', 1)
+ THIN_SPACE + tr("km"));
info.insert(tr("Time"), timeSpan(_time));
info.insert(tr("Ascent"), QString::number(_elevationGraph->ascent(),
'f', 0) + THIN_SPACE + tr("m"));
info.insert(tr("Descent"), QString::number(_elevationGraph->descent(),
'f', 0) + THIN_SPACE + tr("m"));
info.insert(tr("Maximum"), QString::number(_elevationGraph->max(), 'f',
0) + THIN_SPACE + tr("m"));
info.insert(tr("Minimum"), QString::number(_elevationGraph->min(), 'f',
0) + THIN_SPACE + tr("m"));
}
scene.addItem(&info);
scene.render(&p, QRectF(0, 0, printer.width(), 200));
@ -593,8 +624,12 @@ void GUI::updateStatusBarInfo()
else
_fileNameLabel->setText(tr("%1 tracks").arg(_files.size()));
_distanceLabel->setText(QString::number(_distance / 1000, 'f', 1)
+ " " + tr("km"));
if (_imperialUnitsAction->isChecked())
_distanceLabel->setText(QString::number(_distance * M2MI, 'f', 1)
+ " " + tr("mi"));
else
_distanceLabel->setText(QString::number(_distance * M2KM, 'f', 1)
+ " " + tr("km"));
_timeLabel->setText(timeSpan(_time));
}
@ -633,6 +668,20 @@ void GUI::updateNavigationActions()
}
}
void GUI::setMetricUnits()
{
_elevationGraph->setUnits(Metric);
_speedGraph->setUnits(Metric);
updateStatusBarInfo();
}
void GUI::setImperialUnits()
{
_elevationGraph->setUnits(Imperial);
_speedGraph->setUnits(Imperial);
updateStatusBarInfo();
}
void GUI::next()
{
QString file = _browser->next();

View File

@ -50,6 +50,9 @@ private slots:
void last();
void first();
void setMetricUnits();
void setImperialUnits();
private:
void loadFiles();
@ -73,6 +76,7 @@ private:
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
QMenu *_unitsMenu;
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
@ -100,6 +104,8 @@ private:
QAction *_prevAction;
QAction *_lastAction;
QAction *_firstAction;
QAction *_metricUnitsAction;
QAction *_imperialUnitsAction;
QList<QAction*> _mapActions;
QLabel *_fileNameLabel;

View File

@ -46,3 +46,9 @@ QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value
return QGraphicsItem::itemChange(change, value);
}
void SliderItem::clear()
{
_area = QRectF();
setPos(QPointF());
}

View File

@ -17,6 +17,8 @@ public:
QRectF area() {return _area;}
void setArea(const QRectF &area) {_area = area;}
void clear();
signals:
void positionChanged(const QPointF&);

View File

@ -10,11 +10,19 @@ SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
Graph::setYLabel(tr("Speed"));
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("km/h"));
Graph::setXScale(0.001);
Graph::setYScale(3.6);
Graph::setXScale(M2KM);
Graph::setYScale(MS2KMH);
Graph::setPrecision(1);
}
void SpeedGraph::addInfo()
{
Graph::addInfo(tr("Average"), QString::number(avg() * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
Graph::addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
}
void SpeedGraph::loadGPX(const GPX &gpx)
{
QVector<QPointF> data;
@ -31,13 +39,8 @@ void SpeedGraph::loadGPX(const GPX &gpx)
max = qMax(max, data.at(i).y());
_max = qMax(_max, max);
addInfo(tr("Average"), QString::number(avg() * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 1)
+ THIN_SPACE + _yUnits);
Graph::loadData(data);
addInfo();
loadData(data);
}
qreal SpeedGraph::avg() const
@ -60,3 +63,23 @@ void SpeedGraph::clear()
Graph::clear();
}
void SpeedGraph::setUnits(enum Units units)
{
if (units == Metric) {
Graph::setXUnits(tr("km"));
Graph::setYUnits(tr("km/h"));
Graph::setXScale(M2KM);
Graph::setYScale(MS2KMH);
} else {
Graph::setXUnits(tr("mi"));
Graph::setYUnits(tr("mi/h"));
Graph::setXScale(M2MI);
Graph::setYScale(MS2MIH);
}
clearInfo();
addInfo();
redraw();
}

View File

@ -4,6 +4,7 @@
#include <QList>
#include "graph.h"
#include "gpx.h"
#include "units.h"
class SpeedGraph : public Graph
{
@ -14,11 +15,14 @@ public:
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal avg() const;
qreal max() const {return _max;}
private:
void addInfo();
qreal _max;
QList<QPointF> _avg;
};

15
src/units.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef UNITS_H
#define UNITS_H
enum Units {
Metric,
Imperial
};
#define M2KM 0.001000000000 // m -> km
#define M2MI 0.000621371192 // m -> mi
#define M2FT 3.280839900000 // m -> ft
#define MS2KMH 3.600000000000 // m/s -> km/h
#define MS2MIH 2.236936290000 // m/s -> mi/h
#endif // UNITS_H