summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar jan Iversen <jan@casacondor.com>2020-01-08 12:06:23 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-25 17:13:20 -0800
commitcd3c2266f9f687746770912bfc913c4f94bb124b (patch)
treea5094ecfa0f7c4fda4e97c7da7d093b5682750fe
parent55483767763ca5d7d7c8f299f8939bda38301f1b (diff)
downloadsubsurface-cd3c2266f9f687746770912bfc913c4f94bb124b.tar.gz
dive planner: correct bottomsac/decosac calc.
Move conversion cuft <-> liter from desktop-widget/diveplanner.cpp to plannerShared, to facilitate the same results in mobile diveplanner Use Backend for bottomsac/decosac and update to check for switch LITER <-> CUFT Add bottomsac/decosac to QMLinterface. Signed-off-by: jan Iversen <jan@casacondor.com>
-rw-r--r--backend-shared/plannershared.cpp26
-rw-r--r--desktop-widgets/diveplanner.cpp4
-rw-r--r--mobile-widgets/qml/DivePlannerSetup.qml24
-rw-r--r--mobile-widgets/qmlinterface.cpp4
-rw-r--r--mobile-widgets/qmlinterface.h1
-rw-r--r--tests/testplannershared.cpp8
6 files changed, 49 insertions, 18 deletions
diff --git a/backend-shared/plannershared.cpp b/backend-shared/plannershared.cpp
index 113b0f7e2..542f1aae1 100644
--- a/backend-shared/plannershared.cpp
+++ b/backend-shared/plannershared.cpp
@@ -63,20 +63,42 @@ void plannerShared::set_min_switch_duration(int value)
double plannerShared::bottomsac()
{
- return qPrefDivePlanner::bottomsac() / 1000.0;
+ return (qPrefUnits::volume() == units::LITER) ?
+ qPrefDivePlanner::bottomsac() / 1000.0 :
+ ml_to_cuft(qPrefDivePlanner::bottomsac()
+#ifdef SUBSURFACE_MOBILE
+ * 100 // cuft without decimals (0 - 300)
+#endif
+ );
}
void plannerShared::set_bottomsac(double value)
{
+#ifdef SUBSURFACE_MOBILE
+ if (qPrefUnits::volume() == units::CUFT)
+ value /= 100; // cuft without decimals (0 - 300)
+#endif
+
// NO conversion, this is done in the planner model.
DivePlannerPointsModel::instance()->setBottomSac(value);
}
double plannerShared::decosac()
{
- return qPrefDivePlanner::decosac() / 1000.0;
+ return (qPrefUnits::volume() == units::LITER) ?
+ qPrefDivePlanner::decosac() / 1000.0 :
+ ml_to_cuft(qPrefDivePlanner::decosac()
+#ifdef SUBSURFACE_MOBILE
+ * 100 // cuft without decimals (0 - 300)
+#endif
+ );
}
void plannerShared::set_decosac(double value)
{
+#ifdef SUBSURFACE_MOBILE
+ if (qPrefUnits::volume() == units::CUFT)
+ value /= 100; // cuft without decimals (0 - 300)
+#endif
+
// NO conversion, this is done in the planner model.
DivePlannerPointsModel::instance()->setDecoSac(value);
}
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 62334afbe..f236ec205 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -554,8 +554,8 @@ void PlannerSettingsWidget::settingsChanged()
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));
+ ui.bottomSAC->setValue(plannerShared::bottomsac());
+ ui.decoStopSAC->setValue(plannerShared::decosac());
} else {
ui.bottomSAC->setSuffix(tr("ℓ/min"));
ui.decoStopSAC->setSuffix(tr("ℓ/min"));
diff --git a/mobile-widgets/qml/DivePlannerSetup.qml b/mobile-widgets/qml/DivePlannerSetup.qml
index 294752de3..2c04d4695 100644
--- a/mobile-widgets/qml/DivePlannerSetup.qml
+++ b/mobile-widgets/qml/DivePlannerSetup.qml
@@ -22,8 +22,8 @@ Kirigami.ScrollablePage {
spinDescrate.value = Backend.descrate
}
onVolumeChanged: {
- spinBottomsac.value = Planner.bottomsac
- spinDecosac.value = Planner.decosac
+ spinBottomsac.value = Backend.bottomsac
+ spinDecosac.value = Backend.decosac
}
}
Column {
@@ -227,14 +227,16 @@ Kirigami.ScrollablePage {
TemplateSpinBox {
id: spinBottomsac
from: 1
- to: 99
+ to: (Backend.volume === Enums.LITER) ? 85 : 300
stepSize: 1
- value: Planner.bottomsac
+ value: Backend.bottomsac
textFromValue: function (value, locale) {
- return value + volumeUnit
+ return (Backend.volume === Enums.LITER) ?
+ value + volumeUnit :
+ (value / 100).toFixed(2) + volumeUnit
}
onValueModified: {
- Planner.bottomsac = value
+ Backend.bottomsac = value
}
}
TemplateLabel {
@@ -243,14 +245,16 @@ Kirigami.ScrollablePage {
TemplateSpinBox {
id: spinDecosac
from: 1
- to: 99
+ to: (Backend.volume === Enums.LITER) ? 85 : 300
stepSize: 1
- value: Planner.decosac
+ value: Backend.decosac
textFromValue: function (value, locale) {
- return value + volumeUnit
+ return (Backend.volume === Enums.LITER) ?
+ value + volumeUnit :
+ (value / 100).toFixed(2) + volumeUnit
}
onValueModified: {
- Planner.decosac = value
+ Backend.decosac = value
}
}
TemplateLabel {
diff --git a/mobile-widgets/qmlinterface.cpp b/mobile-widgets/qmlinterface.cpp
index 04fd0b6d9..99dc54f2f 100644
--- a/mobile-widgets/qmlinterface.cpp
+++ b/mobile-widgets/qmlinterface.cpp
@@ -65,6 +65,10 @@ void QMLInterface::setup(QQmlContext *ct)
connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::problemsolvingtimeChanged,
instance(), &QMLInterface::problemsolvingtimeChanged);
+ connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::bottomsacChanged,
+ instance(), &QMLInterface::bottomsacChanged);
+ connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::decosacChanged,
+ instance(), &QMLInterface::decosacChanged);
connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_runtimeChanged,
instance(), &QMLInterface::display_runtimeChanged);
connect(qPrefDivePlanner::instance(), &qPrefDivePlanner::display_durationChanged,
diff --git a/mobile-widgets/qmlinterface.h b/mobile-widgets/qmlinterface.h
index 17b9af0ef..88110937f 100644
--- a/mobile-widgets/qmlinterface.h
+++ b/mobile-widgets/qmlinterface.h
@@ -6,6 +6,7 @@
#include "core/settings/qPrefDivePlanner.h"
#include "core/settings/qPrefTechnicalDetails.h"
#include "qt-models/diveplannermodel.h"
+#include "backend-shared/plannershared.h"
#include <QObject>
#include <QQmlContext>
diff --git a/tests/testplannershared.cpp b/tests/testplannershared.cpp
index 3131590c5..f2655432c 100644
--- a/tests/testplannershared.cpp
+++ b/tests/testplannershared.cpp
@@ -145,9 +145,9 @@ void TestPlannerShared::test_gas()
// Remark return will from qPref is in m / 1000.
qPrefDivePlanner::set_bottomsac(2830);
- QCOMPARE(plannerShared::bottomsac(), 2.83);
+ QCOMPARE(int(plannerShared::bottomsac() * 1000), 99);
qPrefDivePlanner::set_bottomsac(16000);
- QCOMPARE(plannerShared::bottomsac(), 16);
+ QCOMPARE(int(plannerShared::bottomsac() * 1000), 565);
plannerShared::set_decosac(0.9);
QCOMPARE(qPrefDivePlanner::decosac(), 25485);
@@ -156,9 +156,9 @@ void TestPlannerShared::test_gas()
// Remark return will from qPref is in m / 1000.
qPrefDivePlanner::set_decosac(11500);
- QCOMPARE(plannerShared::decosac(), 11.5);
+ QCOMPARE(int(plannerShared::decosac() * 1000), 406);
qPrefDivePlanner::set_decosac(19800);
- QCOMPARE(plannerShared::decosac(), 19.8);
+ QCOMPARE(int(plannerShared::decosac() * 1000), 699);
// Remark bottompo2 is in BAR, even though unit system is
// Imperial, the desktop version is like that.