Skip to content

Commit e1ba553

Browse files
author
mitxel-m
committed
Add configuration option to handle distance rounding
1 parent 5e4b179 commit e1ba553

File tree

6 files changed

+894
-6
lines changed

6 files changed

+894
-6
lines changed

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ V1.17.1
44
[QMS-623] remove use of QTimer in BRouter startup error detection
55
[QMS-630] BRouter on-the-fly routing cannot be canceled
66
[QMS-649] Replace proj strings by EPSG code in CRS definitions
7+
[QMS-651] Add configuration option to handle distance rounding
78
[QMS-654] MacOS build (changes to build scripts)
89

910
V1.17.0

src/qmapshack/units/CUnitImperial.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
**********************************************************************************************/
1919

2020
#include "units/CUnitImperial.h"
21+
#include "helpers/CSettings.h"
2122

2223
CUnitImperial::CUnitImperial(QObject* parent)
2324
: IUnit(eTypeImperial, "ft", footPerMeter, "mi/h", meterPerSecToMilePerHour, "ft", footPerMeter, parent) {}
2425

2526
void CUnitImperial::meter2distance(qreal meter, QString& val, QString& unit) const /* override */
2627
{
28+
qint32 roundLimit;
29+
{
30+
SETTINGS;
31+
roundLimit = cfg.value("Units/roundLimit", 20).toInt();
32+
}
2733
if (meter == NOFLOAT) {
2834
val = "-";
2935
unit.clear();
@@ -33,10 +39,10 @@ void CUnitImperial::meter2distance(qreal meter, QString& val, QString& unit) con
3339
} else if (meter < 1600) {
3440
val = QString::asprintf("%1.0f", meter * footPerMeter);
3541
unit = "ft";
36-
} else if (meter < 16000) {
42+
} else if (meter < (roundLimit * 1600 / 2)) {
3743
val = QString::asprintf("%1.2f", meter * milePerMeter);
3844
unit = "mi";
39-
} else if (meter < 32000) {
45+
} else if (meter < (roundLimit * 1600)) {
4046
val = QString::asprintf("%1.1f", meter * milePerMeter);
4147
unit = "mi";
4248
} else {

src/qmapshack/units/CUnitMetric.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
1818
**********************************************************************************************/
1919
#include "units/CUnitMetric.h"
20+
#include "helpers/CSettings.h"
2021

2122
CUnitMetric::CUnitMetric(QObject* parent) : IUnit(eTypeMetric, "m", 1.0, "km/h", 3.6, "m", 1.0, parent) {}
2223

2324
void CUnitMetric::meter2distance(qreal meter, QString& val, QString& unit) const /* override */
2425
{
26+
qint32 roundLimit;
27+
{
28+
SETTINGS;
29+
roundLimit = cfg.value("Units/roundLimit", 20).toInt();
30+
}
2531
if (meter == NOFLOAT) {
2632
val = "-";
2733
unit.clear();
@@ -31,10 +37,10 @@ void CUnitMetric::meter2distance(qreal meter, QString& val, QString& unit) const
3137
} else if (meter < 1000) {
3238
val = QString::asprintf("%1.0f", meter);
3339
unit = "m";
34-
} else if (meter < 10000) {
40+
} else if (meter < (roundLimit * 1000 / 2)) {
3541
val = QString::asprintf("%1.2f", meter / 1000);
3642
unit = "km";
37-
} else if (meter < 20000) {
43+
} else if (meter < (roundLimit * 1000)) {
3844
val = QString::asprintf("%1.1f", meter / 1000);
3945
unit = "km";
4046
} else {

src/qmapshack/units/CUnitsSetup.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "CMainWindow.h"
2222
#include "units/IUnit.h"
2323

24+
#include "helpers/CSettings.h"
25+
2426
CUnitsSetup::CUnitsSetup(QWidget* parent) : QDialog(parent) {
2527
setupUi(this);
2628

@@ -51,6 +53,11 @@ CUnitsSetup::CUnitsSetup(QWidget* parent) : QDialog(parent) {
5153
radioPercent->setChecked(true);
5254
break;
5355
}
56+
57+
SETTINGS;
58+
cfg.beginGroup("Units");
59+
spinRoundLimit->setValue(cfg.value("roundLimit", 20).toInt());
60+
cfg.endGroup();
5461

5562
adjustSize();
5663
}
@@ -71,5 +78,11 @@ void CUnitsSetup::accept() {
7178
} else if (radioPercent->isChecked()) {
7279
IUnit::setSlopeMode(IUnit::eSlopePercent);
7380
}
81+
82+
SETTINGS;
83+
cfg.beginGroup("Units");
84+
cfg.setValue("roundLimit", spinRoundLimit->value());
85+
cfg.endGroup();
86+
7487
QDialog::accept();
7588
}

src/qmapshack/units/IUnitsSetup.ui

+52-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>269</width>
10-
<height>229</height>
9+
<width>430</width>
10+
<height>340</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -52,6 +52,56 @@
5252
</property>
5353
</widget>
5454
</item>
55+
<item>
56+
<widget class="Line" name="line">
57+
<property name="orientation">
58+
<enum>Qt::Horizontal</enum>
59+
</property>
60+
</widget>
61+
</item>
62+
<item>
63+
<layout class="QHBoxLayout" name="horizontalLayout">
64+
<item>
65+
<widget class="QLabel" name="RoundText">
66+
<property name="text">
67+
<string>Round distances above</string>
68+
</property>
69+
</widget>
70+
</item>
71+
<item>
72+
<widget class="QSpinBox" name="spinRoundLimit">
73+
<property name="maximumSize">
74+
<size>
75+
<width>60</width>
76+
<height>16777215</height>
77+
</size>
78+
</property>
79+
<property name="layoutDirection">
80+
<enum>Qt::LeftToRight</enum>
81+
</property>
82+
<property name="alignment">
83+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
84+
</property>
85+
<property name="minimum">
86+
<number>20</number>
87+
</property>
88+
<property name="maximum">
89+
<number>1000</number>
90+
</property>
91+
<property name="singleStep">
92+
<number>10</number>
93+
</property>
94+
</widget>
95+
</item>
96+
<item>
97+
<widget class="QLabel" name="RoundUnit">
98+
<property name="text">
99+
<string>Km | mi</string>
100+
</property>
101+
</widget>
102+
</item>
103+
</layout>
104+
</item>
55105
</layout>
56106
</widget>
57107
<widget class="QWidget" name="tabSlope">

0 commit comments

Comments
 (0)