Added configuration options for vertical speed units.

Some people (free divers) are loving ft/s or m/s units for vertical speeds.
Now they can choose between /min or /s in the configuration (only Qt UI).

Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Patrick Valsecchi 2013-10-04 07:57:48 +02:00 committed by Dirk Hohndel
parent 6ae6c768f3
commit c28fe00bfe
6 changed files with 80 additions and 18 deletions

24
dive.c
View file

@ -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;

8
dive.h
View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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");

View file

@ -401,6 +401,46 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QGroupBox">
<property name="title">
<string>Time units</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel">
<property name="text">
<string>Ascent/Descent speed denominator</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="vertical_speed_minutes">
<property name="text">
<string>Minutes</string>
</property>
<attribute name="buttonGroup">
<string notr="true">verticalSpeed</string>
</attribute>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="vertical_speed_seconds">
<property name="text">
<string>Seconds</string>
</property>
<attribute name="buttonGroup">
<string notr="true">verticalSpeed</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@ -414,19 +454,6 @@
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
@ -999,5 +1026,6 @@
<buttongroup name="buttonGroup_5"/>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_6"/>
<buttongroup name="verticalSpeed"/>
</buttongroups>
</ui>