From ebabbfb457184ea4d9e939ad8501986c35699264 Mon Sep 17 00:00:00 2001 From: willemferguson Date: Tue, 19 Nov 2019 12:27:18 +0200 Subject: [PATCH] desktop UI: create the UI components for editing the salinity. The user may modify the salinity by selecting a water type from the combobox. The new datum does not replace the existing salinity value but is stored in a separate variable within the dive structure. If the dc-based salinity is overwritten, there is an exclamation mark next to the modified salinity value to indicate that the salinity has been overwritten. The dc-derived salinity can always be recovered by selecting the "use dc" option in the combobox. Signed-off-by: willemferguson Signed-off-by: Dirk Hohndel --- core/dive.h | 1 + .../tab-widgets/TabDiveInformation.cpp | 129 +++++++++++++++--- .../tab-widgets/TabDiveInformation.h | 4 + .../tab-widgets/TabDiveInformation.ui | 17 +-- icons/bluewarning.png | Bin 0 -> 446 bytes subsurface.qrc | 1 + 6 files changed, 128 insertions(+), 24 deletions(-) create mode 100644 icons/bluewarning.png diff --git a/core/dive.h b/core/dive.h index 7e45f1c09..b642c3031 100644 --- a/core/dive.h +++ b/core/dive.h @@ -158,6 +158,7 @@ struct dive { pressure_t surface_pressure; duration_t duration; int salinity; // kg per 10000 l + int user_salinity; // water density reflecting a user-specified type struct tag_entry *tag_list; struct divecomputer dc; diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 5edb4811c..1c7f30496 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -16,6 +16,8 @@ #define TEXT_EDITED 1 #define CSS_SET_HEADING_BLUE "QLabel { color: mediumblue;} " +enum watertypes { FRESHWATER, SALTYWATER, EN13319WATER, SALTWATER, NO_WATERTYPE}; + TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) { ui->setupUi(this); @@ -23,13 +25,16 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne QStringList atmPressTypes { "mbar", get_depth_unit() ,"use dc"}; ui->atmPressType->insertItems(0, atmPressTypes); pressTypeIndex = 0; + QStringList waterTypes {"Fresh", "Salty", "EN13319", "Salt", "use dc"}; + ui->waterTypeCombo->insertItems(0, waterTypes); + // This needs to be the same order as enum dive_comp_type in dive.h! QStringList types; for (int i = 0; i < NUM_DIVEMODE; i++) types.append(gettextFromC::tr(divemode_text_ui[i])); ui->diveType->insertItems(0, types); connect(ui->diveType, SIGNAL(currentIndexChanged(int)), this, SLOT(diveModeChanged(int))); - QString CSSSetSmallLabel = "QLabel { color: mediumblue; font-size: " + /* // Using label height ... */ + QString CSSSetSmallLabel = "QLabel { color: mediumblue; font-size: " + // Using label height QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}"; // .. set CSS font size of star widget subscripts ui->scrollAreaWidgetContents_3->setStyleSheet("QGroupBox::title { color: mediumblue;} "); ui->diveHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); @@ -50,6 +55,11 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne connect(action, &QAction::triggered, this, &TabDiveInformation::closeWarning); ui->multiDiveWarningMessage->addAction(action); ui->multiDiveWarningMessage->hide(); + updateWaterTypeWidget(); + QPixmap warning (":salinity-warning-icon"); + ui->salinityOverWrittenIcon->setPixmap(warning); + ui->salinityOverWrittenIcon->setToolTip("Water type differs from that of dc"); + ui->salinityOverWrittenIcon->setToolTipDuration(2500); } TabDiveInformation::~TabDiveInformation() @@ -73,6 +83,7 @@ void TabDiveInformation::clear() ui->atmPressVal->clear(); ui->salinityText->clear(); ui->waterTypeText->clear(); + ui->waterTypeCombo->setCurrentIndex(0); } void TabDiveInformation::divesEdited(int i) @@ -90,6 +101,17 @@ void TabDiveInformation::closeWarning() ui->multiDiveWarningMessage->hide(); } +void TabDiveInformation::updateWaterTypeWidget() +{ + if (prefs.salinityEditDefault) { + ui->waterTypeText->setVisible(false); + ui->waterTypeCombo->setVisible(true); + } else { + ui->waterTypeCombo->setVisible(false); + ui->waterTypeText->setVisible(true); + } +} + // Update fields that depend on the dive profile void TabDiveInformation::updateProfile() { @@ -149,20 +171,29 @@ void TabDiveInformation::updateWhen() ui->surfaceIntervalText->clear(); } -void TabDiveInformation::updateSalinity() +// Provide an index for the combobox that corresponds to the salinity value +int TabDiveInformation::updateSalinityComboIndex(int salinity) { - if (current_dive->salinity) { // Set up the salinity string: - ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0)); - if (current_dive->salinity < 10050) // Set water type indicator: - ui->waterTypeText->setText(tr("Fresh")); - else if (current_dive->salinity < 10190) - ui->waterTypeText->setText(tr("Salty")); - else if (current_dive->salinity < 10210) // (EN13319 = 1.019 - 1.021 g/l) - ui->waterTypeText->setText(tr("EN13319")); - else ui->waterTypeText->setText(tr("Salt")); + if (salinity == 0) + return NO_WATERTYPE; + else if (salinity < 10050) + return FRESHWATER; + else if (salinity < 10190) + return SALTYWATER; + else if (salinity < 10210) + return EN13319WATER; + else + return SALTWATER; +} + +// If dive->user_salinity != dive->salinity (i.e. dc value) then show the salinity-overwrite indicator +void TabDiveInformation::checkDcSalinityOverWritten() +{ + if (current_dive && current_dive->dc.salinity && current_dive->user_salinity) { + if (current_dive->dc.salinity != current_dive->user_salinity) + ui->salinityOverWrittenIcon->setVisible(true); } else { - ui->salinityText->clear(); - ui->waterTypeText->clear(); + ui->salinityOverWrittenIcon->setVisible(false); } } @@ -183,14 +214,39 @@ void TabDiveInformation::updateData() return; } + int salinity_value; + updateWaterTypeWidget(); updateProfile(); updateWhen(); ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true)); ui->airtemp->setText(get_temperature_string(current_dive->airtemp, true)); ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric) ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar + if (current_dive->user_salinity) + salinity_value = current_dive->user_salinity; + else + salinity_value = current_dive->salinity; + if (salinity_value) { // Set water type indicator (EN13319 = 1.020 g/l) + if (prefs.salinityEditDefault) { //If edit-salinity is enabled then set correct water type in combobox: + ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value)); + } else { // If water salinity is not editable: show water type as a text label + if (salinity_value < 10050) + ui->waterTypeText->setText("Fresh"); + else if (salinity_value < 10190) + ui->waterTypeText->setText("Salty"); + else if (salinity_value < 10210) + ui->waterTypeText->setText("EN13319"); + else + ui->waterTypeText->setText("Salt"); + } + checkDcSalinityOverWritten(); // If exclamation is needed (i.e. salinity overwrite by user), then show it + ui->salinityText->setText(QString("%1g/ℓ").arg(salinity_value / 10.0)); + } else { + ui->waterTypeCombo->setCurrentIndex(NO_WATERTYPE); + ui->waterTypeText->clear(); + ui->salinityText->clear(); + } updateMode(current_dive); - updateSalinity(); ui->visibility->setCurrentStars(current_dive->visibility); ui->wavesize->setCurrentStars(current_dive->wavesize); ui->current->setCurrentStars(current_dive->current); @@ -202,10 +258,46 @@ void TabDiveInformation::updateData() showCurrentWidget(false, 0); // Show current star widget at lefthand side } +void TabDiveInformation::on_waterTypeCombo_activated(int index) { + int combobox_salinity = 0; + int dc_salinity = current_dive->dc.salinity; + switch(ui->waterTypeCombo->currentIndex()) { + case FRESHWATER: + combobox_salinity = FRESHWATER_SALINITY; + break; + case SALTYWATER: + combobox_salinity = 10100; + break; + case EN13319WATER: + combobox_salinity = EN13319_SALINITY; + break; + case SALTWATER: + combobox_salinity = SEAWATER_SALINITY; + break; + case NO_WATERTYPE: + combobox_salinity = dc_salinity; + ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(combobox_salinity)); + break; + default: + // we really should never get here... do nothing + break; + } + // Save and display the new salinity value + ui->salinityText->setText(QString("%1g/ℓ").arg(combobox_salinity / 10.0)); +// divesEdited(Command::editWaterTypeUser(combobox_salinity, false)); // This will be enabled in step 4 when the undo is implemented. + current_dive->user_salinity = combobox_salinity; // This will be removed in step 4. This statement allows executable code. + if (dc_salinity == combobox_salinity) // If salinity differs from that of dc, then save it + ui->salinityOverWrittenIcon->setVisible(false); + else + ui->salinityOverWrittenIcon->setVisible(true); +} + // This function gets called if a field gets updated by an undo command. // Refresh the corresponding UI field. void TabDiveInformation::divesChanged(const QVector &dives, DiveField field) { + int salinity_value; + // If the current dive is not in list of changed dives, do nothing if (!current_dive || !dives.contains(current_dive)) return; @@ -231,10 +323,15 @@ void TabDiveInformation::divesChanged(const QVector &dives, DiveField fi if (field.atm_press) ui->atmPressVal->setText(ui->atmPressVal->text().sprintf("%d",current_dive->surface_pressure.mbar)); if (field.salinity) - updateSalinity(); + checkDcSalinityOverWritten(); + if (current_dive->user_salinity) + salinity_value = current_dive->user_salinity; + else + salinity_value = current_dive->salinity; + ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value)); + ui->salinityText->setText(QString("%1g/ℓ").arg(salinity_value / 10.0)); } - void TabDiveInformation::on_visibility_valueChanged(int value) { if (current_dive) diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index e851fe2d3..0ff142f76 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -28,12 +28,16 @@ private slots: void on_chill_valueChanged(int value); void on_airtemp_editingFinished(); void on_watertemp_editingFinished(); + void on_waterTypeCombo_activated(int index); private: Ui::TabDiveInformation *ui; void updateProfile(); void updateSalinity(); + int updateSalinityComboIndex(int salinity); + void checkDcSalinityOverWritten(); void updateWhen(); int pressTypeIndex; + void updateWaterTypeWidget(); void updateTextBox(int event); void updateMode(struct dive *d); void divesEdited(int); diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.ui b/desktop-widgets/tab-widgets/TabDiveInformation.ui index 5a81d7395..2990e6dfc 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.ui +++ b/desktop-widgets/tab-widgets/TabDiveInformation.ui @@ -445,15 +445,17 @@ - - - - EN13319 - - + + + + + + + + + - @@ -461,7 +463,6 @@ - diff --git a/icons/bluewarning.png b/icons/bluewarning.png new file mode 100644 index 0000000000000000000000000000000000000000..f9e66063b8a638bffe8427b879e8e78d5c1835b9 GIT binary patch literal 446 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|wj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pI^TbM&i;)s^zO`wo$W=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<3fz`&^F>Eak-aeC{Njd_P01YGXR?K^bk#6o6skuB4dmT3GG zwNnWFHRa{cHj_V0La8kRyt=MZZ?2Rqah$eUGpA+p4LgBTCFQrI&%S-LCZJP=Nw$%% z!LM*9b0vGEWB%XYt$%FtejkvKxYWb@fh#e_af-_V{{_=FD`=j0vf|vFDIt?}#LUZ2 zr+)vZKk?R|v)kg8l46!0`QCdyuRDCLSMEhFpMR?9{<92PRE&07Uw3j}wqeIU7f}aU z7v}XQ>QgObPHgh&bq+dS+CKg7Gw!_SpAS4-v&P5p(d=E56f%A~UidV-_~i1UQXwDe5lvp9J9vD kR23u3yoUb~%GY(bicons/Oxy_changeICD.png icons/CCR.png icons/OC.png + icons/bluewarning.png icons/flag.png icons/scale.png icons/ruler.png