diff --git a/dive.c b/dive.c index 66d282d10..1d8986ab9 100644 --- a/dive.c +++ b/dive.c @@ -127,6 +127,30 @@ double get_depth_units(unsigned int mm, int *frac, const char **units) return d; } +double get_vertical_speed_units(unsigned int mms, int *frac, const char **units) +{ + double d; + const char *unit; + const struct units *units_p = get_units(); + const double time_factor = units_p->vertical_speed_time == MINUTES ? 60.0 : 1.0; + + switch (units_p->length) { + case METERS: + d = mms / 1000.0 * time_factor; + unit = _((units_p->vertical_speed_time == MINUTES) ? "m/min" : "m/s"); + break; + case FEET: + d = mm_to_feet(mms) * time_factor; + unit = _((units_p->vertical_speed_time == MINUTES) ? "ft/min" : "ft/s"); + break; + } + if (frac) + *frac = d < 10; + if (units) + *units = unit; + return d; +} + double get_weight_units(unsigned int grams, int *frac, const char **units) { int decimals; diff --git a/dive.h b/dive.h index dbfaf7202..9fb47f21a 100644 --- a/dive.h +++ b/dive.h @@ -160,6 +160,7 @@ extern double get_depth_units(unsigned int mm, int *frac, const char **units); extern double get_volume_units(unsigned int ml, int *frac, const char **units); extern double get_temp_units(unsigned int mk, const char **units); extern double get_weight_units(unsigned int grams, int *frac, const char **units); +extern double get_vertical_speed_units(unsigned int mms, int *frac, const char **units); static inline double grams_to_lbs(int grams) { @@ -476,6 +477,7 @@ struct units { enum { BAR, PSI, PASCAL } pressure; enum { CELSIUS, FAHRENHEIT, KELVIN } temperature; enum { KG, LBS } weight; + enum { SECONDS, MINUTES } vertical_speed_time; }; /* @@ -490,7 +492,8 @@ struct units { .volume = LITER, \ .pressure = BAR, \ .temperature = CELSIUS, \ - .weight = KG \ + .weight = KG, \ + .vertical_speed_time = MINUTES \ } #define IMPERIAL_UNITS { \ @@ -498,7 +501,8 @@ struct units { .volume = CUFT, \ .pressure = PSI, \ .temperature = FAHRENHEIT, \ - .weight = LBS \ + .weight = LBS, \ + .vertical_speed_time = MINUTES \ } extern const struct units SI_units, IMPERIAL_units; extern struct units xml_parsing_units; diff --git a/profile.c b/profile.c index f71552eca..2e100c30a 100644 --- a/profile.c +++ b/profile.c @@ -1213,7 +1213,7 @@ static void plot_string(struct plot_data *entry, char *buf, int bufsize, int depth, int pressure, int temp, gboolean has_ndl) { int pressurevalue, mod, ead, end, eadd; - const char *depth_unit, *pressure_unit, *temp_unit; + const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit; char *buf2 = malloc(bufsize); double depthvalue, tempvalue, speedvalue; @@ -1236,12 +1236,12 @@ static void plot_string(struct plot_data *entry, char *buf, int bufsize, snprintf(buf, bufsize, _("%s\nT:%.1f %s"), buf2, tempvalue, temp_unit); } - speedvalue = get_depth_units(abs(entry->speed), NULL, &depth_unit)*60; + speedvalue = get_vertical_speed_units(abs(entry->speed), NULL, &vertical_speed_unit); memcpy(buf2, buf, bufsize); /* Ascending speeds are positive, descending are negative */ if (entry->speed > 0) speedvalue *= -1; - snprintf(buf, bufsize, _("%s\nV:%.1f %s/min"), buf2, speedvalue, depth_unit); + snprintf(buf, bufsize, _("%s\nV:%.2f %s"), buf2, speedvalue, vertical_speed_unit); if (entry->ceiling) { depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 9a26404e2..fc11d790c 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -547,6 +547,7 @@ void MainWindow::readSettings() GET_UNIT("temperature", temperature, units::FAHRENHEIT, units::CELSIUS); GET_UNIT("weight", weight, units::LBS, units::KG); } + GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS); s.endGroup(); s.beginGroup("DisplayListColumns"); GET_BOOL("CYLINDER", visible_cols.cylinder); @@ -614,6 +615,7 @@ void MainWindow::writeSettings() SAVE_VALUE("volume", units.volume); SAVE_VALUE("temperature", units.temperature); SAVE_VALUE("weight", units.weight); + SAVE_VALUE("vertical_speed_time", units.vertical_speed_time); settings.endGroup(); settings.beginGroup("DisplayListColumns"); SAVE_VALUE("TEMPERATURE", visible_cols.temperature); diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index b996bf2df..e188cdba7 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -73,6 +73,8 @@ void PreferencesDialog::setUiFromPrefs() ui.defaultfilename->setText(prefs.default_filename); ui.displayinvalid->setChecked(prefs.show_invalid); ui.show_time->setChecked(prefs.show_time); + ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); + ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); } void PreferencesDialog::restorePrefs() @@ -109,6 +111,7 @@ void PreferencesDialog::setPrefsFromUi() prefs.units.pressure = ui.psi->isChecked() ? units::PSI : units::BAR; prefs.units.volume = ui.cuft->isChecked() ? units::CUFT : units::LITER; prefs.units.weight = ui.lbs->isChecked() ? units::LBS : units::KG; + prefs.units.vertical_speed_time = ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS; prefs.divelist_font = strdup(ui.font->font().family().toUtf8().data()); prefs.font_size = ui.fontsize->value(); prefs.default_filename = strdup(ui.defaultfilename->text().toUtf8().data()); @@ -151,6 +154,7 @@ void PreferencesDialog::syncSettings() s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR); s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); + s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); s.endGroup(); // Defaults s.beginGroup("GeneralSettings"); diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui index 55076235d..18767a790 100644 --- a/qt-ui/preferences.ui +++ b/qt-ui/preferences.ui @@ -401,6 +401,46 @@ + + + + + + Time units + + + + + + Ascent/Descent speed denominator + + + + + + + Minutes + + + verticalSpeed + + + + + + + Seconds + + + verticalSpeed + + + + + + + + @@ -414,19 +454,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -999,5 +1026,6 @@ +