1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 17:15:14 +01:00

Added support for nautical units

This commit is contained in:
Martin Tůma 2018-02-11 23:51:57 +01:00
parent 27632bf07e
commit 820f967bd6
10 changed files with 100 additions and 41 deletions

View File

@ -62,12 +62,17 @@ ExportDialog::ExportDialog(Export *exp, QWidget *parent)
_bottomMargin = new QDoubleSpinBox(); _bottomMargin = new QDoubleSpinBox();
_leftMargin = new QDoubleSpinBox(); _leftMargin = new QDoubleSpinBox();
_rightMargin = new QDoubleSpinBox(); _rightMargin = new QDoubleSpinBox();
QString us = (_export->units == Imperial) ? tr("in") : tr("mm"); QString us = (_export->units == Metric) ? tr("mm") : tr("in");
_topMargin->setSuffix(UNIT_SPACE + us); _topMargin->setSuffix(UNIT_SPACE + us);
_bottomMargin->setSuffix(UNIT_SPACE + us); _bottomMargin->setSuffix(UNIT_SPACE + us);
_leftMargin->setSuffix(UNIT_SPACE + us); _leftMargin->setSuffix(UNIT_SPACE + us);
_rightMargin->setSuffix(UNIT_SPACE + us); _rightMargin->setSuffix(UNIT_SPACE + us);
if (_export->units == Imperial) { if (_export->units == Metric) {
_topMargin->setValue(_export->margins.top());
_bottomMargin->setValue(_export->margins.bottom());
_leftMargin->setValue(_export->margins.left());
_rightMargin->setValue(_export->margins.right());
} else {
_topMargin->setValue(_export->margins.top() * MM2IN); _topMargin->setValue(_export->margins.top() * MM2IN);
_bottomMargin->setValue(_export->margins.bottom() * MM2IN); _bottomMargin->setValue(_export->margins.bottom() * MM2IN);
_leftMargin->setValue(_export->margins.left() * MM2IN); _leftMargin->setValue(_export->margins.left() * MM2IN);
@ -76,11 +81,6 @@ ExportDialog::ExportDialog(Export *exp, QWidget *parent)
_bottomMargin->setSingleStep(0.1); _bottomMargin->setSingleStep(0.1);
_leftMargin->setSingleStep(0.1); _leftMargin->setSingleStep(0.1);
_rightMargin->setSingleStep(0.1); _rightMargin->setSingleStep(0.1);
} else {
_topMargin->setValue(_export->margins.top());
_bottomMargin->setValue(_export->margins.bottom());
_leftMargin->setValue(_export->margins.left());
_rightMargin->setValue(_export->margins.right());
} }
QGridLayout *marginsLayout = new QGridLayout(); QGridLayout *marginsLayout = new QGridLayout();

View File

@ -53,6 +53,13 @@ QString Format::distance(qreal value, Units units)
else else
return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE return QString::number(value * M2MI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "mi"); + qApp->translate("Format", "mi");
} else if (units == Nautical) {
if (value < NMIINM)
return QString::number(value * M2FT, 'f', 0) + UNIT_SPACE
+ qApp->translate("Format", "ft");
else
return QString::number(value * M2NMI, 'f', 1) + UNIT_SPACE
+ qApp->translate("Format", "nmi");
} else { } else {
if (value < KMINM) if (value < KMINM)
return QString::number(value, 'f', 0) + UNIT_SPACE return QString::number(value, 'f', 0) + UNIT_SPACE

View File

@ -104,15 +104,7 @@ void GraphView::setYUnits(const QString &units)
void GraphView::setXUnits() void GraphView::setXUnits()
{ {
if (_graphType == Distance) { if (_graphType == Distance) {
if (_units == Metric) { if (_units == Imperial) {
if (bounds().width() < KMINM) {
_xUnits = tr("m");
_xScale = 1;
} else {
_xUnits = tr("km");
_xScale = M2KM;
}
} else {
if (bounds().width() < MIINM) { if (bounds().width() < MIINM) {
_xUnits = tr("ft"); _xUnits = tr("ft");
_xScale = M2FT; _xScale = M2FT;
@ -120,6 +112,22 @@ void GraphView::setXUnits()
_xUnits = tr("mi"); _xUnits = tr("mi");
_xScale = M2MI; _xScale = M2MI;
} }
} else if (_units == Nautical) {
if (bounds().width() < NMIINM) {
_xUnits = tr("ft");
_xScale = M2FT;
} else {
_xUnits = tr("nmi");
_xScale = M2NMI;
}
} else {
if (bounds().width() < KMINM) {
_xUnits = tr("m");
_xScale = 1;
} else {
_xUnits = tr("km");
_xScale = M2KM;
}
} }
} else { } else {
if (bounds().width() < MININS) { if (bounds().width() < MININS) {

View File

@ -372,6 +372,11 @@ void GUI::createActions()
_imperialUnitsAction->setActionGroup(ag); _imperialUnitsAction->setActionGroup(ag);
connect(_imperialUnitsAction, SIGNAL(triggered()), this, connect(_imperialUnitsAction, SIGNAL(triggered()), this,
SLOT(setImperialUnits())); SLOT(setImperialUnits()));
_nauticalUnitsAction = new QAction(tr("Nautical"), this);
_nauticalUnitsAction->setCheckable(true);
_nauticalUnitsAction->setActionGroup(ag);
connect(_nauticalUnitsAction, SIGNAL(triggered()), this,
SLOT(setNauticalUnits()));
ag = new QActionGroup(this); ag = new QActionGroup(this);
ag->setExclusive(true); ag->setExclusive(true);
_decimalDegreesAction = new QAction(tr("Decimal degrees (DD)"), this); _decimalDegreesAction = new QAction(tr("Decimal degrees (DD)"), this);
@ -479,6 +484,7 @@ void GUI::createMenus()
QMenu *unitsMenu = settingsMenu->addMenu(tr("Units")); QMenu *unitsMenu = settingsMenu->addMenu(tr("Units"));
unitsMenu->addAction(_metricUnitsAction); unitsMenu->addAction(_metricUnitsAction);
unitsMenu->addAction(_imperialUnitsAction); unitsMenu->addAction(_imperialUnitsAction);
unitsMenu->addAction(_nauticalUnitsAction);
QMenu *coordinatesMenu = settingsMenu->addMenu(tr("Coordinates format")); QMenu *coordinatesMenu = settingsMenu->addMenu(tr("Coordinates format"));
coordinatesMenu->addAction(_decimalDegreesAction); coordinatesMenu->addAction(_decimalDegreesAction);
coordinatesMenu->addAction(_degreesMinutesAction); coordinatesMenu->addAction(_degreesMinutesAction);
@ -1463,10 +1469,10 @@ void GUI::writeSettings()
TIME_TYPE_DEFAULT) TIME_TYPE_DEFAULT)
settings.setValue(TIME_TYPE_SETTING, _movingTimeAction->isChecked() settings.setValue(TIME_TYPE_SETTING, _movingTimeAction->isChecked()
? Moving : Total); ? Moving : Total);
if ((_imperialUnitsAction->isChecked() ? Imperial : Metric) != Units units = _imperialUnitsAction->isChecked() ? Imperial
UNITS_DEFAULT) : _nauticalUnitsAction->isChecked() ? Nautical : Metric;
settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked() if (units != UNITS_DEFAULT)
? Imperial : Metric); settings.setValue(UNITS_SETTING, units);
CoordinatesFormat format = _DMSAction->isChecked() ? DMS CoordinatesFormat format = _DMSAction->isChecked() ? DMS
: _degreesMinutesAction->isChecked() ? DegreesMinutes : DecimalDegrees; : _degreesMinutesAction->isChecked() ? DegreesMinutes : DecimalDegrees;
if (format != COORDINATES_DEFAULT) if (format != COORDINATES_DEFAULT)
@ -1630,6 +1636,7 @@ void GUI::writeSettings()
void GUI::readSettings() void GUI::readSettings()
{ {
int value;
QSettings settings(APP_NAME, APP_NAME); QSettings settings(APP_NAME, APP_NAME);
settings.beginGroup(WINDOW_SETTINGS_GROUP); settings.beginGroup(WINDOW_SETTINGS_GROUP);
@ -1644,15 +1651,18 @@ void GUI::readSettings()
else else
_totalTimeAction->activate(QAction::Trigger); _totalTimeAction->activate(QAction::Trigger);
if (settings.value(UNITS_SETTING, UNITS_DEFAULT).toInt() == Imperial) value = settings.value(UNITS_SETTING, UNITS_DEFAULT).toInt();
if (value == Imperial)
_imperialUnitsAction->activate(QAction::Trigger); _imperialUnitsAction->activate(QAction::Trigger);
else if (value == Nautical)
_nauticalUnitsAction->activate(QAction::Trigger);
else else
_metricUnitsAction->activate(QAction::Trigger); _metricUnitsAction->activate(QAction::Trigger);
if (settings.value(COORDINATES_SETTING, COORDINATES_DEFAULT).toInt() == DMS) value = settings.value(COORDINATES_SETTING, COORDINATES_DEFAULT).toInt();
if (value == DMS)
_DMSAction->activate(QAction::Trigger); _DMSAction->activate(QAction::Trigger);
else if (settings.value(COORDINATES_SETTING, COORDINATES_DEFAULT).toInt() else if (value == DegreesMinutes)
== DegreesMinutes)
_degreesMinutesAction->activate(QAction::Trigger); _degreesMinutesAction->activate(QAction::Trigger);
else else
_decimalDegreesAction->activate(QAction::Trigger); _decimalDegreesAction->activate(QAction::Trigger);
@ -1900,7 +1910,8 @@ int GUI::mapIndex(const QString &name)
Units GUI::units() const Units GUI::units() const
{ {
return _imperialUnitsAction->isChecked() ? Imperial : Metric; return _imperialUnitsAction->isChecked() ? Imperial
: _nauticalUnitsAction->isChecked() ? Nautical : Metric;
} }
qreal GUI::distance() const qreal GUI::distance() const

View File

@ -74,6 +74,7 @@ private slots:
void setMovingTime() {setTimeType(Moving);} void setMovingTime() {setTimeType(Moving);}
void setMetricUnits() {setUnits(Metric);} void setMetricUnits() {setUnits(Metric);}
void setImperialUnits() {setUnits(Imperial);} void setImperialUnits() {setUnits(Imperial);}
void setNauticalUnits() {setUnits(Nautical);}
void setDistanceGraph() {setGraphType(Distance);} void setDistanceGraph() {setGraphType(Distance);}
void setTimeGraph() {setGraphType(Time);} void setTimeGraph() {setGraphType(Time);}
void setDecimalDegrees() {setCoordinatesFormat(DecimalDegrees);} void setDecimalDegrees() {setCoordinatesFormat(DecimalDegrees);}
@ -170,6 +171,7 @@ private:
QAction *_firstAction; QAction *_firstAction;
QAction *_metricUnitsAction; QAction *_metricUnitsAction;
QAction *_imperialUnitsAction; QAction *_imperialUnitsAction;
QAction *_nauticalUnitsAction;
QAction *_decimalDegreesAction; QAction *_decimalDegreesAction;
QAction *_degreesMinutesAction; QAction *_degreesMinutesAction;
QAction *_DMSAction; QAction *_DMSAction;

View File

@ -291,6 +291,9 @@ QWidget *OptionsDialog::createDataPage()
if (_options->units == Imperial) { if (_options->units == Imperial) {
_pauseSpeed->setValue(_options->pauseSpeed * MS2MIH); _pauseSpeed->setValue(_options->pauseSpeed * MS2MIH);
_pauseSpeed->setSuffix(UNIT_SPACE + tr("mi/h")); _pauseSpeed->setSuffix(UNIT_SPACE + tr("mi/h"));
} else if (_options->units == Nautical) {
_pauseSpeed->setValue(_options->pauseSpeed * MS2KN);
_pauseSpeed->setSuffix(UNIT_SPACE + tr("kn"));
} else { } else {
_pauseSpeed->setValue(_options->pauseSpeed * MS2KMH); _pauseSpeed->setValue(_options->pauseSpeed * MS2KMH);
_pauseSpeed->setSuffix(UNIT_SPACE + tr("km/h")); _pauseSpeed->setSuffix(UNIT_SPACE + tr("km/h"));
@ -323,6 +326,9 @@ QWidget *OptionsDialog::createPOIPage()
if (_options->units == Imperial) { if (_options->units == Imperial) {
_poiRadius->setValue(_options->poiRadius / MIINM); _poiRadius->setValue(_options->poiRadius / MIINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("mi")); _poiRadius->setSuffix(UNIT_SPACE + tr("mi"));
} else if (_options->units == Nautical) {
_poiRadius->setValue(_options->poiRadius / NMIINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("nmi"));
} else { } else {
_poiRadius->setValue(_options->poiRadius / KMINM); _poiRadius->setValue(_options->poiRadius / KMINM);
_poiRadius->setSuffix(UNIT_SPACE + tr("km")); _poiRadius->setSuffix(UNIT_SPACE + tr("km"));
@ -525,13 +531,15 @@ void OptionsDialog::accept()
_options->powerFilter = _powerFilter->value(); _options->powerFilter = _powerFilter->value();
_options->outlierEliminate = _outlierEliminate->isChecked(); _options->outlierEliminate = _outlierEliminate->isChecked();
qreal pauseSpeed = (_options->units == Imperial) qreal pauseSpeed = (_options->units == Imperial)
? _pauseSpeed->value() / MS2MIH : _pauseSpeed->value() / MS2KMH; ? _pauseSpeed->value() / MS2MIH : (_options->units == Nautical)
? _pauseSpeed->value() / MS2KN : _pauseSpeed->value() / MS2KMH;
if (qAbs(pauseSpeed - _options->pauseSpeed) > 0.01) if (qAbs(pauseSpeed - _options->pauseSpeed) > 0.01)
_options->pauseSpeed = pauseSpeed; _options->pauseSpeed = pauseSpeed;
_options->pauseInterval = _pauseInterval->value(); _options->pauseInterval = _pauseInterval->value();
qreal poiRadius = (_options->units == Imperial) qreal poiRadius = (_options->units == Imperial)
? _poiRadius->value() * MIINM : _poiRadius->value() * KMINM; ? _poiRadius->value() * MIINM : (_options->units == Nautical)
? _poiRadius->value() * NMIINM : _poiRadius->value() * KMINM;
if (qAbs(poiRadius - _options->poiRadius) > 0.01) if (qAbs(poiRadius - _options->poiRadius) > 0.01)
_options->poiRadius = poiRadius; _options->poiRadius = poiRadius;

View File

@ -82,6 +82,9 @@ QString ScaleItem::units() const
if (_units == Imperial) if (_units == Imperial)
return _scale ? qApp->translate("ScaleItem", "mi") return _scale ? qApp->translate("ScaleItem", "mi")
: qApp->translate("ScaleItem", "ft"); : qApp->translate("ScaleItem", "ft");
else if (_units == Nautical)
return _scale ? qApp->translate("ScaleItem", "nmi")
: qApp->translate("ScaleItem", "ft");
else else
return _scale ? qApp->translate("ScaleItem", "km") return _scale ? qApp->translate("ScaleItem", "km")
: qApp->translate("ScaleItem", "m"); : qApp->translate("ScaleItem", "m");
@ -94,8 +97,18 @@ void ScaleItem::computeScale()
if (_units == Imperial) { if (_units == Imperial) {
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1); _length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= MIINFT) { if (_length >= MIINFT) {
_length = niceNum((res * M2FT * FT2MI * SCALE_WIDTH) / SEGMENTS, 1); _length = niceNum((res * M2MI * SCALE_WIDTH) / SEGMENTS, 1);
_width = (_length / (res * M2FT * FT2MI)); _width = (_length / (res * M2MI));
_scale = true;
} else {
_width = (_length / (res * M2FT));
_scale = false;
}
} else if (_units == Nautical) {
_length = niceNum((res * M2FT * SCALE_WIDTH) / SEGMENTS, 1);
if (_length >= NMIINFT) {
_length = niceNum((res * M2NMI * SCALE_WIDTH) / SEGMENTS, 1);
_width = (_length / (res * M2NMI));
_scale = true; _scale = true;
} else { } else {
_width = (_length / (res * M2FT)); _width = (_length / (res * M2FT));

View File

@ -79,12 +79,15 @@ void SpeedGraph::clear()
void SpeedGraph::setYUnits(Units units) void SpeedGraph::setYUnits(Units units)
{ {
if (units == Metric) { if (units == Nautical) {
GraphView::setYUnits(tr("km/h")); GraphView::setYUnits(tr("kn"));
setYScale(MS2KMH); setYScale(MS2KN);
} else { } else if (units == Imperial) {
GraphView::setYUnits(tr("mi/h")); GraphView::setYUnits(tr("mi/h"));
setYScale(MS2MIH); setYScale(MS2MIH);
} else {
GraphView::setYUnits(tr("km/h"));
setYScale(MS2KMH);
} }
} }

View File

@ -16,8 +16,10 @@ SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type,
QString SpeedGraphItem::toolTip() const QString SpeedGraphItem::toolTip() const
{ {
ToolTip tt; ToolTip tt;
qreal scale = (_units == Metric) ? MS2KMH : MS2MIH; qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical)
QString su = (_units == Metric) ? tr("km/h") : tr("mi/h"); ? MS2KN : MS2KMH;
QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical)
? tr("kn") : tr("km/h");
tt.insert(tr("Maximum"), QString::number(max() * scale, 'f', 1) tt.insert(tr("Maximum"), QString::number(max() * scale, 'f', 1)
+ UNIT_SPACE + su); + UNIT_SPACE + su);

View File

@ -3,24 +3,29 @@
enum Units { enum Units {
Metric, Metric,
Imperial Imperial,
Nautical
}; };
#define M2KM 0.001000000000 // m -> km #define M2KM 0.001000000000 // m -> km
#define M2MI 0.000621371192 // m -> mi #define M2MI 0.000621371192 // m -> mi
#define M2NMI 0.000539956803 // m -> nmi
#define M2FT 3.280839900000 // m -> ft #define M2FT 3.280839900000 // m -> ft
#define MS2KMH 3.600000000000 // m/s -> km/h #define MS2KMH 3.600000000000 // m/s -> km/h
#define MS2MIH 2.236936290000 // m/s -> mi/h #define MS2MIH 2.236936290000 // m/s -> mi/h
#define MS2KN 1.943844490000 // m/s -> kn
#define FT2MI 0.000189393939 // ft -> mi #define FT2MI 0.000189393939 // ft -> mi
#define MM2IN 0.039370100000 // mm -> in #define MM2IN 0.039370100000 // mm -> in
#define H2S 0.000277777778 // h -> s #define H2S 0.000277777778 // h -> s
#define MIN2S 0.016666666667 // min -> s #define MIN2S 0.016666666667 // min -> s
#define KMINM 1000.0 // 1 km in m #define KMINM 1000.0 // 1 km in m
#define MIINFT 5280.0 // 1 mi in ft #define MIINFT 5280.0 // 1 mi in ft
#define MIINM 1609.344 // 1 mi in m #define NMIINFT 6076.11549 // 1 nm in ft
#define MININS 60.0 // 1 min in s #define MIINM 1609.344 // 1 mi in m
#define HINS 3600.0 // 1 hins #define NMIINM 1852 // 1 nmi in m
#define MININS 60.0 // 1 min in s
#define HINS 3600.0 // 1 hins
#define C2FS 1.8 // Celsius to Farenheit - scale #define C2FS 1.8 // Celsius to Farenheit - scale
#define C2FO 32.0 // Celsius to Farenheit - offset #define C2FO 32.0 // Celsius to Farenheit - offset