Skip to content

Commit bd86591

Browse files
author
hannes krueger
committed
desktop: option to change display of decimals of depth in dive table
The qthelper get_depth_string does now what is expected, depending on the given bool showdecimal (<20m exception removed). A preference (units.show_mdecimal_table) was introduced to change whether decimals are displayed for (metric) max depths in the dive list. the setting can be change via UI at preferences/units. Signed-off-by: Hannes Krueger <hannes.krueger@gmail.com>
1 parent fc62b7d commit bd86591

9 files changed

Lines changed: 31 additions & 9 deletions

File tree

core/qthelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ QString get_depth_string(int mm, bool showunit, bool showdecimal)
494494
{
495495
if (prefs.units.length == units::METERS) {
496496
double meters = mm / 1000.0;
497-
return QString("%L1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0).arg(showunit ? gettextFromC::tr("m") : QString());
497+
return QString("%L1%2").arg(meters, 0, 'f', showdecimal ? 1 : 0).arg(showunit ? gettextFromC::tr("m") : QString());
498498
} else {
499499
double feet = mm_to_feet(mm);
500500
return QString("%L1%2").arg(feet, 0, 'f', 0).arg(showunit ? gettextFromC::tr("ft") : QString());

core/settings/qPrefUnit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void qPrefUnits::loadSync(bool doSync)
1919
disk_length(doSync);
2020
disk_pressure(doSync);
2121
disk_show_units_table(doSync);
22+
disk_show_mdecimal_table(doSync);
2223
disk_temperature(doSync);
2324
disk_unit_system(doSync);
2425
disk_vertical_speed_time(doSync);
@@ -39,6 +40,8 @@ DISK_LOADSYNC_ENUM_EXT(Units, "pressure", units::PRESSURE, pressure, units.);
3940

4041
HANDLE_PREFERENCE_BOOL_EXT(Units, "show_units_table", show_units_table, units.);
4142

43+
HANDLE_PREFERENCE_BOOL_EXT(Units, "show_mdecimal_table", show_mdecimal_table, units.);
44+
4245
SET_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, temperature, units.);
4346
DISK_LOADSYNC_ENUM_EXT(Units, "temperature", units::TEMPERATURE, temperature, units.);
4447

core/settings/qPrefUnit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class qPrefUnits : public QObject {
1010
Q_OBJECT
1111
Q_PROPERTY(bool coordinates_traditional READ coordinates_traditional WRITE set_coordinates_traditional NOTIFY coordinates_traditionalChanged)
1212
Q_PROPERTY(bool show_units_table READ show_units_table WRITE set_show_units_table NOTIFY show_units_tableChanged)
13+
Q_PROPERTY(bool show_mdecimal_table READ show_mdecimal_table WRITE set_show_mdecimal_table NOTIFY show_mdecimal_tableChanged)
1314

1415
public:
1516
static qPrefUnits *instance();
@@ -25,6 +26,7 @@ class qPrefUnits : public QObject {
2526
static units::LENGTH length() { return prefs.units.length; }
2627
static units::PRESSURE pressure() { return prefs.units.pressure; }
2728
static bool show_units_table() { return prefs.units.show_units_table; }
29+
static bool show_mdecimal_table() { return prefs.units.show_mdecimal_table; }
2830
static unit_system_values unit_system() { return prefs.unit_system; }
2931
static units::TEMPERATURE temperature() { return prefs.units.temperature; }
3032
static units::TIME vertical_speed_time() { return prefs.units.vertical_speed_time; }
@@ -37,6 +39,7 @@ public slots:
3739
static void set_length(units::LENGTH value);
3840
static void set_pressure(units::PRESSURE value);
3941
static void set_show_units_table(bool value);
42+
static void set_show_mdecimal_table(bool value);
4043
static void set_temperature(units::TEMPERATURE value);
4144
static void set_unit_system(unit_system_values value);
4245
static void set_vertical_speed_time(units::TIME value);
@@ -49,6 +52,7 @@ public slots:
4952
void lengthChanged(units::LENGTH value);
5053
void pressureChanged(units::PRESSURE value);
5154
void show_units_tableChanged(bool value);
55+
void show_mdecimal_tableChanged(bool value);
5256
void temperatureChanged(units::TEMPERATURE value);
5357
void unit_systemChanged(unit_system_values value);
5458
void vertical_speed_timeChanged(units::TIME value);
@@ -63,6 +67,7 @@ public slots:
6367
static void disk_length(bool doSync);
6468
static void disk_pressure(bool doSync);
6569
static void disk_show_units_table(bool doSync);
70+
static void disk_show_mdecimal_table(bool doSync);
6671
static void disk_temperature(bool doSync);
6772
static void disk_unit_system(bool doSync);
6873
static void disk_vertical_speed_time(bool doSync);

core/units.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const struct units SI_units = SI_UNITS;
77
const struct units IMPERIAL_units = {
88
.length = units::FEET, .volume = units::CUFT, .pressure = units::PSI, .temperature = units::FAHRENHEIT, .weight = units::LBS,
9-
.vertical_speed_time = units::MINUTES, .duration_units = units::MIXED, .show_units_table = false
9+
.vertical_speed_time = units::MINUTES, .duration_units = units::MIXED, .show_units_table = false, .show_mdecimal_table = false
1010
};
1111

1212
int get_pressure_units(int mb, const char **units)

core/units.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ struct units {
478478
ALWAYS_HOURS
479479
} duration_units;
480480
bool show_units_table;
481+
bool show_mdecimal_table;
481482
};
482483

483484
/*
@@ -490,7 +491,7 @@ struct units {
490491
#define SI_UNITS \
491492
{ \
492493
.length = units::METERS, .volume = units::LITER, .pressure = units::BAR, .temperature = units::CELSIUS, .weight = units::KG, \
493-
.vertical_speed_time = units::MINUTES, .duration_units = units::MIXED, .show_units_table = false \
494+
.vertical_speed_time = units::MINUTES, .duration_units = units::MIXED, .show_units_table = false, .show_mdecimal_table = false \
494495
}
495496

496497
extern const struct units SI_units, IMPERIAL_units;

desktop-widgets/preferences/preferences_units.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void PreferencesUnits::refreshSettings()
4343
ui->duration_no_hours->setChecked(prefs.units.duration_units == units::MINUTES_ONLY);
4444
ui->duration_show_hours->setChecked(prefs.units.duration_units == units::ALWAYS_HOURS);
4545
ui->show_units_table->setChecked(prefs.units.show_units_table);
46+
ui->show_mdecimal_table->setChecked(prefs.units.show_mdecimal_table);
4647
}
4748

4849
void PreferencesUnits::syncSettings()
@@ -60,4 +61,5 @@ void PreferencesUnits::syncSettings()
6061
qPrefUnits::set_coordinates_traditional(ui->gpsTraditional->isChecked());
6162
qPrefUnits::set_duration_units(ui->duration_mixed->isChecked() ? units::MIXED : (ui->duration_no_hours->isChecked() ? units::MINUTES_ONLY : units::ALWAYS_HOURS));
6263
qPrefUnits::set_show_units_table(ui->show_units_table->isChecked());
64+
qPrefUnits::set_show_mdecimal_table(ui->show_mdecimal_table->isChecked());
6365
}

desktop-widgets/preferences/preferences_units.ui

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>455</width>
10-
<height>515</height>
9+
<width>511</width>
10+
<height>568</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -281,6 +281,13 @@
281281
</property>
282282
</widget>
283283
</item>
284+
<item>
285+
<widget class="QCheckBox" name="show_mdecimal_table">
286+
<property name="text">
287+
<string>metric depth decimals</string>
288+
</property>
289+
</widget>
290+
</item>
284291
</layout>
285292
</widget>
286293
</item>
@@ -348,7 +355,6 @@
348355
<tabstop>duration_show_hours</tabstop>
349356
<tabstop>duration_no_hours</tabstop>
350357
<tabstop>duration_mixed</tabstop>
351-
<tabstop>show_units_table</tabstop>
352358
<tabstop>gpsTraditional</tabstop>
353359
<tabstop>gpsDecimal</tabstop>
354360
</tabstops>
@@ -532,10 +538,10 @@
532538
</connection>
533539
</connections>
534540
<buttongroups>
535-
<buttongroup name="buttonGroup"/>
541+
<buttongroup name="buttonGroup_5"/>
536542
<buttongroup name="buttonGroup_2"/>
537543
<buttongroup name="buttonGroup_3"/>
544+
<buttongroup name="buttonGroup"/>
538545
<buttongroup name="buttonGroup_4"/>
539-
<buttongroup name="buttonGroup_5"/>
540546
</buttongroups>
541547
</ui>

qt-models/divetripmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role)
325325
case DATE:
326326
return get_dive_date_string(d->when);
327327
case DEPTH:
328-
return get_depth_string(d->maxdepth, prefs.units.show_units_table);
328+
return get_depth_string(d->maxdepth, prefs.units.show_units_table, prefs.units.show_mdecimal_table);
329329
case DURATION:
330330
return displayDuration(d);
331331
case TEMPERATURE:

translations/subsurface_de_DE.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7480,6 +7480,11 @@ Siehe https://doc.qt.io/archives/qt-4.8/qdatetime.html#fromString</translation>
74807480
<source>Show units in dive list table</source>
74817481
<translation>Einheiten in der Tauchgangsliste anzeigen</translation>
74827482
</message>
7483+
<message>
7484+
<location filename="../desktop-widgets/preferences/preferences_units.ui" line="287"/>
7485+
<source>metric depth decimals</source>
7486+
<translation>Meter mit Nachkommastelle</translation>
7487+
</message>
74837488
<message>
74847489
<location filename="../desktop-widgets/preferences/preferences_units.ui" line="290"/>
74857490
<source>GPS coordinates</source>

0 commit comments

Comments
 (0)