Choose water presets from a qcombobox in planner, custom value possible

Add a combo box for water types with defaults for fresh water, sea water
and the EN 13319. All values taken from units.h, where EN 13319 was added
beforehand.
Custom values can be entered through a spinbox.
Also changed "Salinity" in TapDiveInformation.ui to "Water type".

Translation required!

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
This commit is contained in:
Oliver Schwaneberg 2018-02-10 23:28:05 +01:00 committed by Dirk Hohndel
parent afc9dd5f38
commit 0ca52f868e
6 changed files with 151 additions and 68 deletions

View file

@ -1,2 +1,4 @@
- Add imperial support for UDCF import - 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 # add new entries above this line

View file

@ -30,6 +30,7 @@ extern "C" {
/* Salinity is expressed in weight in grams per 10l */ /* Salinity is expressed in weight in grams per 10l */
#define SEAWATER_SALINITY 10300 #define SEAWATER_SALINITY 10300
#define EN13319_SALINITY 10200
#define FRESHWATER_SALINITY 10000 #define FRESHWATER_SALINITY 10000
#include <stdint.h> #include <stdint.h>

View file

@ -117,6 +117,10 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
ui.cylinderTableWidget->setTitle(tr("Available gases")); ui.cylinderTableWidget->setTitle(tr("Available gases"));
ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder")); ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
ui.cylinderTableWidget->setModel(CylindersModel::instance()); 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(); QTableView *view = ui.cylinderTableWidget->view();
view->setColumnHidden(CylindersModel::START, true); view->setColumnHidden(CylindersModel::START, true);
view->setColumnHidden(CylindersModel::END, 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.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int))); connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(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))); connect(plannerModel, SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
// Creating (and canceling) the plan // Creating (and canceling) the plan
@ -195,7 +200,23 @@ void PlannerSettingsWidget::setDiveMode(int mode)
void DivePlannerWidget::setSalinity(int salinity) 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() void DivePlannerWidget::settingsChanged()
@ -232,10 +253,34 @@ void DivePlannerWidget::heightChanged(const int height)
plannerModel->setSurfacePressure(pressure); plannerModel->setSurfacePressure(pressure);
} }
void DivePlannerWidget::salinityChanged(const double salinity) void DivePlannerWidget::waterTypeUpdateTexts()
{ {
/* Salinity is expressed in weight in grams per 10l */ double density;
plannerModel->setSalinity(lrint(10000 * salinity)); /* 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) void PlannerSettingsWidget::bottomSacChanged(const double bottomSac)

View file

@ -51,13 +51,15 @@ slots:
void settingsChanged(); void settingsChanged();
void atmPressureChanged(const int pressure); void atmPressureChanged(const int pressure);
void heightChanged(const int height); void heightChanged(const int height);
void salinityChanged(const double salinity); void waterTypeChanged(const int index);
void customSalinityChanged(double density);
void printDecoPlan(); void printDecoPlan();
void setSurfacePressure(int surface_pressure); void setSurfacePressure(int surface_pressure);
void setSalinity(int salinity); void setSalinity(int salinity);
private: private:
Ui::DivePlanner ui; Ui::DivePlanner ui;
QAbstractButton *replanButton; QAbstractButton *replanButton;
void waterTypeUpdateTexts();
}; };
#include "ui_plannerSettings.h" #include "ui_plannerSettings.h"

View file

@ -62,41 +62,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing">
<number>2</number>
</property>
<item row="5" column="0" colspan="3">
<widget class="TableView" name="tableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="TableView" name="cylinderTableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="sizePolicy"> <property name="sizePolicy">
@ -133,7 +98,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="2" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -163,26 +128,7 @@
<item row="2" column="2"> <item row="2" column="2">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Salinity</string> <string>Water type</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="ATMPressure">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>mbar</string>
</property>
<property name="minimum">
<number>689</number>
</property>
<property name="maximum">
<number>1100</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -208,28 +154,115 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="3" column="1">
<widget class="QDoubleSpinBox" name="salinity"> <widget class="QSpinBox" name="ATMPressure">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="suffix">
<string>mbar</string>
</property>
<property name="minimum">
<number>689</number>
</property>
<property name="maximum">
<number>1100</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="waterType">
<item>
<property name="text">
<string>Fresh water</string>
</property>
</item>
<item>
<property name="text">
<string>Sea water</string>
</property>
</item>
<item>
<property name="text">
<string>EN13319</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item row="3" column="3">
<widget class="QDoubleSpinBox" name="customSalinity">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string extracomment="Custom water density"/>
</property>
<property name="suffix"> <property name="suffix">
<string>kg/</string> <string>kg/</string>
</property> </property>
<property name="minimum"> <property name="minimum">
<double>1.000000000000000</double> <double>0.990000000000000</double>
</property> </property>
<property name="maximum"> <property name="maximum">
<double>1.050000000000000</double> <double>1.300000000000000</double>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<double>0.010000000000000</double> <double>0.010000000000000</double>
</property> </property>
<property name="value"> <property name="value">
<double>1.030000000000000</double> <double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="TableView" name="cylinderTableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="TableView" name="tableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -303,7 +303,7 @@
<item row="4" column="1"> <item row="4" column="1">
<widget class="QGroupBox" name="groupBox_1"> <widget class="QGroupBox" name="groupBox_1">
<property name="title"> <property name="title">
<string>Salinity</string> <string>Water type</string>
</property> </property>
<layout class="QHBoxLayout" name="diveInfoSalinityLayout"> <layout class="QHBoxLayout" name="diveInfoSalinityLayout">
<item> <item>