summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-19 11:13:55 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-19 11:36:54 -0500
commit6ed189f32c466f99167ab6657264a45da4b56e8e (patch)
tree659c97401ad49daf996fb04b397897bb2669a3f3
parent150676ce3df0f60bd99204886c3a4e458253c093 (diff)
downloadsubsurface-6ed189f32c466f99167ab6657264a45da4b56e8e.tar.gz
Planner: bring sanity to the SAC rate handling
The old implementation was... let's call it creative. This tries to actually get things right instead of using magic. Don't pretend that double values are ints. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c9
-rw-r--r--dive.h2
-rw-r--r--qt-ui/diveplanner.cpp46
-rw-r--r--qt-ui/diveplanner.h8
-rw-r--r--qt-ui/plannerSettings.ui44
5 files changed, 61 insertions, 48 deletions
diff --git a/dive.c b/dive.c
index 38599b104..22cf3ad46 100644
--- a/dive.c
+++ b/dive.c
@@ -188,15 +188,12 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
return vol;
}
-int units_to_sac(int volume)
+int units_to_sac(double volume)
{
if(get_units()->volume == CUFT)
- if (volume < 10)
- return cuft_to_l(volume) * 100;
- else
- return cuft_to_l(volume) * 10;
+ return rint(cuft_to_l(volume) * 1000.0);
else
- return volume * 1000;
+ return rint(volume * 1000);
}
unsigned int units_to_depth(double depth)
diff --git a/dive.h b/dive.h
index 8232e5407..fd7959f00 100644
--- a/dive.h
+++ b/dive.h
@@ -99,7 +99,7 @@ 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);
extern unsigned int units_to_depth(double depth);
-extern int units_to_sac(int volume);
+extern int units_to_sac(double volume);
/* Volume in mliter of a cylinder at pressure 'p' */
extern int gas_volume(cylinder_t *cyl, pressure_t p);
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index e51400ac0..6a6f2d6c3 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -350,12 +350,12 @@ void DivePlannerWidget::heightChanged(const int height)
plannerModel->setSurfacePressure(pressure);
}
-void PlannerSettingsWidget::bottomSacChanged(const int bottomSac)
+void PlannerSettingsWidget::bottomSacChanged(const double bottomSac)
{
plannerModel->setBottomSac(bottomSac);
}
-void PlannerSettingsWidget::decoSacChanged(const int decosac)
+void PlannerSettingsWidget::decoSacChanged(const double decosac)
{
plannerModel->setDecoSac(decosac);
}
@@ -408,16 +408,14 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f)
connect(ui.bottompo2, SIGNAL(valueChanged(double)), this, SLOT(setBottomPo2(double)));
connect(ui.decopo2, SIGNAL(valueChanged(double)), this, SLOT(setDecoPo2(double)));
connect(ui.drop_stone_mode, SIGNAL(toggled(bool)), plannerModel, SLOT(setDropStoneMode(bool)));
- connect(ui.bottomSAC, SIGNAL(valueChanged(int)), this, SLOT(bottomSacChanged(int)));
- connect(ui.decoStopSAC, SIGNAL(valueChanged(int)), this, SLOT(decoSacChanged(int)));
+ connect(ui.bottomSAC, SIGNAL(valueChanged(double)), this, SLOT(bottomSacChanged(double)));
+ connect(ui.decoStopSAC, SIGNAL(valueChanged(double)), this, SLOT(decoSacChanged(double)));
connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
connect(ui.gfhigh, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFHigh()));
connect(ui.gflow, SIGNAL(editingFinished()), plannerModel, SLOT(triggerGFLow()));
connect(ui.backgasBreaks, SIGNAL(toggled(bool)), this, SLOT(setBackgasBreaks(bool)));
-
- ui.bottomSAC->setValue(rint(get_volume_units(prefs.bottomsac, NULL, NULL)));
- ui.decoStopSAC->setValue(rint(get_volume_units(prefs.decosac, NULL, NULL)));
+ settingsChanged();
ui.gflow->setValue(prefs.gflow);
ui.gfhigh->setValue(prefs.gfhigh);
@@ -455,6 +453,9 @@ PlannerSettingsWidget::~PlannerSettingsWidget()
void PlannerSettingsWidget::settingsChanged()
{
QString vs;
+ // don't recurse into setting the value from the ui when setting the ui from the value
+ ui.bottomSAC->blockSignals(true);
+ ui.decoStopSAC->blockSignals(true);
if (get_units()->length == units::FEET) {
vs.append(tr("ft/min"));
ui.lastStop->setText(tr("Last stop at 20ft"));
@@ -469,18 +470,24 @@ void PlannerSettingsWidget::settingsChanged()
if(get_units()->volume == units::CUFT) {
ui.bottomSAC->setSuffix(tr("cuft/min"));
ui.decoStopSAC->setSuffix(tr("cuft/min"));
- ui.bottomSAC->setPrefix(".");
- ui.decoStopSAC->setPrefix(".");
- ui.bottomSAC->setValue(rint(ml_to_cuft(prefs.bottomsac) * 100.0));
- ui.decoStopSAC->setValue(rint(ml_to_cuft(prefs.decosac) * 100.0));
+ ui.bottomSAC->setDecimals(2);
+ ui.bottomSAC->setSingleStep(0.1);
+ ui.decoStopSAC->setDecimals(2);
+ ui.decoStopSAC->setSingleStep(0.1);
+ ui.bottomSAC->setValue(ml_to_cuft(prefs.bottomsac));
+ ui.decoStopSAC->setValue(ml_to_cuft(prefs.decosac));
} else {
ui.bottomSAC->setSuffix(tr("ℓ/min"));
ui.decoStopSAC->setSuffix(tr("ℓ/min"));
- ui.bottomSAC->setPrefix("");
- ui.decoStopSAC->setPrefix("");
- ui.bottomSAC->setValue(rint((double) prefs.bottomsac / 1000.0));
- ui.decoStopSAC->setValue(rint((double) prefs.decosac / 1000.0));
+ ui.bottomSAC->setDecimals(0);
+ ui.bottomSAC->setSingleStep(1);
+ ui.decoStopSAC->setDecimals(0);
+ ui.decoStopSAC->setSingleStep(1);
+ ui.bottomSAC->setValue((double) prefs.bottomsac / 1000.0);
+ ui.decoStopSAC->setValue((double) prefs.decosac / 1000.0);
}
+ ui.bottomSAC->blockSignals(false);
+ ui.decoStopSAC->blockSignals(false);
updateUnitsUI();
ui.ascRate75->setSuffix(vs);
ui.ascRate50->setSuffix(vs);
@@ -703,18 +710,15 @@ void DivePlannerPointsModel::emitDataChanged()
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
-void DivePlannerPointsModel::setBottomSac(int sac)
+void DivePlannerPointsModel::setBottomSac(double sac)
{
- volume_t newSAC;
- newSAC.mliter = units_to_sac(sac);
- diveplan.bottomsac = newSAC.mliter;
+ diveplan.bottomsac = units_to_sac(sac);
prefs.bottomsac = diveplan.bottomsac;
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
}
-void DivePlannerPointsModel::setDecoSac(int sac)
+void DivePlannerPointsModel::setDecoSac(double sac)
{
- volume_t newSAC;
diveplan.decosac = units_to_sac(sac);
prefs.decosac = diveplan.decosac;
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 22c599ab1..468893bba 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -70,8 +70,8 @@ slots:
void triggerGFLow();
void setSurfacePressure(int pressure);
int getSurfacePressure();
- void setBottomSac(int sac);
- void setDecoSac(int sac);
+ void setBottomSac(double sac);
+ void setDecoSac(double sac);
void setStartTime(const QTime &t);
void setStartDate(const QDate &date);
void setLastStop6m(bool value);
@@ -160,8 +160,8 @@ public
slots:
void settingsChanged();
void atmPressureChanged(const QString &pressure);
- void bottomSacChanged(const int bottomSac);
- void decoSacChanged(const int decosac);
+ void bottomSacChanged(const double bottomSac);
+ void decoSacChanged(const double decosac);
void printDecoPlan();
void setAscRate75(int rate);
void setAscRate50(int rate);
diff --git a/qt-ui/plannerSettings.ui b/qt-ui/plannerSettings.ui
index a28453c01..3e323ebc3 100644
--- a/qt-ui/plannerSettings.ui
+++ b/qt-ui/plannerSettings.ui
@@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>1078</width>
- <height>418</height>
+ <width>1084</width>
+ <height>424</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
@@ -367,13 +367,6 @@
</property>
</widget>
</item>
- <item row="0" column="1">
- <widget class="QSpinBox" name="bottomSAC">
- <property name="suffix">
- <string>ℓ/min</string>
- </property>
- </widget>
- </item>
<item row="1" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
@@ -381,13 +374,6 @@
</property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QSpinBox" name="decoStopSAC">
- <property name="suffix">
- <string>ℓ/min</string>
- </property>
- </widget>
- </item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
@@ -447,6 +433,32 @@
</property>
</spacer>
</item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="bottomSAC">
+ <property name="suffix">
+ <string>ℓ/min</string>
+ </property>
+ <property name="decimals">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <double>99.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="decoStopSAC">
+ <property name="suffix">
+ <string>ℓ/min</string>
+ </property>
+ <property name="decimals">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <double>99.000000000000000</double>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>