diff --git a/CHANGELOG.md b/CHANGELOG.md index f7021b77a..090d314ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,4 @@ - Add imperial support for UDCF import +- Desktop: combo box with fresh, sea water and EN 13319 in dive planner +- Desktop: Changed "salinity" to "water type" at dive planner and dive info # add new entries above this line diff --git a/core/units.h b/core/units.h index 8c616728a..2d6b6f73c 100644 --- a/core/units.h +++ b/core/units.h @@ -30,6 +30,7 @@ extern "C" { /* Salinity is expressed in weight in grams per 10l */ #define SEAWATER_SALINITY 10300 +#define EN13319_SALINITY 10200 #define FRESHWATER_SALINITY 10000 #include diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index bac0f9495..fd7dc948e 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -117,6 +117,10 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg ui.cylinderTableWidget->setTitle(tr("Available gases")); ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder")); ui.cylinderTableWidget->setModel(CylindersModel::instance()); + ui.waterType->setItemData(0, FRESHWATER_SALINITY); + ui.waterType->setItemData(1, SEAWATER_SALINITY); + ui.waterType->setItemData(2, EN13319_SALINITY); + waterTypeUpdateTexts(); QTableView *view = ui.cylinderTableWidget->view(); view->setColumnHidden(CylindersModel::START, true); view->setColumnHidden(CylindersModel::END, true); @@ -147,7 +151,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate))); connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int))); connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); - connect(ui.salinity, SIGNAL(valueChanged(double)), this, SLOT(salinityChanged(double))); + connect(ui.waterType, SIGNAL(currentIndexChanged(int)), this, SLOT(waterTypeChanged(int))); + connect(ui.customSalinity, SIGNAL(valueChanged(double)), this, SLOT(customSalinityChanged(double))); connect(plannerModel, SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime))); // Creating (and canceling) the plan @@ -195,7 +200,23 @@ void PlannerSettingsWidget::setDiveMode(int mode) void DivePlannerWidget::setSalinity(int salinity) { - ui.salinity->setValue(salinity / 10000.0); + bool mapped = false; + for (int i = 0; i < ui.waterType->count(); i++) { + if (salinity == ui.waterType->itemData(i).toInt()) { + mapped = true; + ui.waterType->setCurrentIndex(i); + break; + } + } + + if (!mapped) { + /* Assign to last element "custom" in combo box */ + ui.waterType->setItemData(ui.waterType->count()-1, salinity); + ui.waterType->setCurrentIndex(ui.waterType->count()-1); + ui.customSalinity->setEnabled(true); + ui.customSalinity->setValue(salinity / 10000.0); + } + plannerModel->setSalinity(salinity); } void DivePlannerWidget::settingsChanged() @@ -232,10 +253,34 @@ void DivePlannerWidget::heightChanged(const int height) plannerModel->setSurfacePressure(pressure); } -void DivePlannerWidget::salinityChanged(const double salinity) +void DivePlannerWidget::waterTypeUpdateTexts() { - /* Salinity is expressed in weight in grams per 10l */ - plannerModel->setSalinity(lrint(10000 * salinity)); + double density; + /* Do not set text in last/custom element */ + for (int i = 0; i < ui.waterType->count()-1; i++) { + if (ui.waterType->itemData(i) != QVariant::Invalid) { + QString densityText = ui.waterType->itemText(i).split("(")[0].trimmed(); + density = ui.waterType->itemData(i).toInt() / 10000.0; + densityText.append(QString(" (%L1%2)").arg(density, 0, 'f', 2).arg(tr("kg/ℓ"))); + ui.waterType->setItemText(i, densityText); + } + } +} + +void DivePlannerWidget::waterTypeChanged(const int index) +{ + ui.customSalinity->setEnabled(index == ui.waterType->count() - 1); + ui.customSalinity->setValue(ui.waterType->itemData(index).toInt() / 10000.0); + plannerModel->setSalinity(ui.waterType->itemData(index).toInt()); +} + +void DivePlannerWidget::customSalinityChanged(double density) +{ + if (ui.customSalinity->isEnabled()) { + int newSalinity = (int)(density * 10000.0); + ui.waterType->setItemData(ui.waterType->count() - 1, newSalinity); + plannerModel->setSalinity(newSalinity); + } } void PlannerSettingsWidget::bottomSacChanged(const double bottomSac) diff --git a/desktop-widgets/diveplanner.h b/desktop-widgets/diveplanner.h index 8f42dd21d..b7527f3c1 100644 --- a/desktop-widgets/diveplanner.h +++ b/desktop-widgets/diveplanner.h @@ -51,13 +51,15 @@ slots: void settingsChanged(); void atmPressureChanged(const int pressure); void heightChanged(const int height); - void salinityChanged(const double salinity); + void waterTypeChanged(const int index); + void customSalinityChanged(double density); void printDecoPlan(); void setSurfacePressure(int surface_pressure); void setSalinity(int salinity); private: Ui::DivePlanner ui; QAbstractButton *replanButton; + void waterTypeUpdateTexts(); }; #include "ui_plannerSettings.h" diff --git a/desktop-widgets/diveplanner.ui b/desktop-widgets/diveplanner.ui index 5b58f564a..1b67a5fc9 100644 --- a/desktop-widgets/diveplanner.ui +++ b/desktop-widgets/diveplanner.ui @@ -62,41 +62,6 @@ 0 - - 2 - - - - - - 0 - 0 - - - - - 0 - 50 - - - - - - - - - 0 - 0 - - - - - 0 - 50 - - - - @@ -133,7 +98,7 @@ - + @@ -163,26 +128,7 @@ - Salinity - - - - - - - - 0 - 0 - - - - mbar - - - 689 - - - 1100 + Water type @@ -208,28 +154,115 @@ - - + + 0 0 + + mbar + + + 689 + + + 1100 + + + + + + + + Fresh water + + + + + Sea water + + + + + EN13319 + + + + + Custom + + + + + + + + false + + + + 0 + 0 + + + + + 90 + 16777215 + + + + + kg/ℓ - 1.000000000000000 + 0.990000000000000 - 1.050000000000000 + 1.300000000000000 0.010000000000000 - 1.030000000000000 + 1.000000000000000 + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + + + + + 0 + 0 + + + + + 0 + 50 + diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.ui b/desktop-widgets/tab-widgets/TabDiveInformation.ui index 3e855d1c7..f81ab6fe5 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.ui +++ b/desktop-widgets/tab-widgets/TabDiveInformation.ui @@ -303,7 +303,7 @@ - Salinity + Water type