diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-01-04 16:06:28 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-01-06 07:00:34 +0900 |
commit | 1e4cc49f83c4af4394a0aa7deca1affa99fd64fa (patch) | |
tree | 78dc9534f5e91e6aa280038cdd6221cb75112efe | |
parent | c0bb04994bd31a1e1c7621cdd34ec45e66cec220 (diff) | |
download | subsurface-1e4cc49f83c4af4394a0aa7deca1affa99fd64fa.tar.gz |
desktop UI: treat an unknown salinity as that
We were royally confused when we didn't know the salinity value (e.g., if the
dive computer didn't provide that information). We somehow treated this as the
same as wanting to use the salinity information in the dive computer. Which
makes no sense.
While cleaning this up, this also adds the textual representations of the water
types as a string list that corresponds to the enum values that we use - this
way it's easier to stay consistent.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.cpp | 29 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.h | 1 |
2 files changed, 18 insertions, 12 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index dd5750ef0..ccc39decd 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -17,7 +17,7 @@ #define TEXT_EDITED 1 #define CSS_SET_HEADING_BLUE "QLabel { color: mediumblue;} " -enum watertypes { FRESHWATER, SALTYWATER, EN13319WATER, SALTWATER, NO_WATERTYPE}; +enum watertypes { FRESHWATER, SALTYWATER, EN13319WATER, SALTWATER, DC_WATERTYPE}; TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) { @@ -26,7 +26,8 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne QStringList atmPressTypes { "mbar", get_depth_unit() ,tr("use dc")}; ui->atmPressType->insertItems(0, atmPressTypes); pressTypeIndex = 0; - QStringList waterTypes {tr("Fresh"), tr("Salty"), "EN13319", tr("Salt"), tr("use dc")}; + // the water types need to match the enum above + waterTypes = QStringList({tr("Fresh"), tr("Salty"), "EN13319", tr("Salt"), tr("use dc")}); ui->waterTypeCombo->insertItems(0, waterTypes); // This needs to be the same order as enum dive_comp_type in dive.h! @@ -179,7 +180,7 @@ void TabDiveInformation::updateWhen() int TabDiveInformation::updateSalinityComboIndex(int salinity) { if (salinity == 0) - return NO_WATERTYPE; + return -1; // we don't know else if (salinity < 10050) return FRESHWATER; else if (salinity < 10190) @@ -237,19 +238,19 @@ void TabDiveInformation::updateData() 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(tr("Fresh")); + ui->waterTypeText->setText(waterTypes[FRESHWATER]); else if (salinity_value < 10190) - ui->waterTypeText->setText(tr("Salty")); + ui->waterTypeText->setText(waterTypes[SALTYWATER]); else if (salinity_value < 10210) - ui->waterTypeText->setText("EN13319"); + ui->waterTypeText->setText(waterTypes[EN13319WATER]); else - ui->waterTypeText->setText(tr("Salt")); + ui->waterTypeText->setText(waterTypes[SALTWATER]); } 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->waterTypeCombo->setCurrentIndex(-1); + ui->waterTypeText->setText(tr("unknown")); ui->salinityText->clear(); } updateMode(current_dive); @@ -282,16 +283,20 @@ void TabDiveInformation::on_waterTypeCombo_activated(int index) { case SALTWATER: combobox_salinity = SEAWATER_SALINITY; break; - case NO_WATERTYPE: + case DC_WATERTYPE: combobox_salinity = dc_salinity; ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(combobox_salinity)); break; default: - // we really should never get here... do nothing + // the index was set to -1 to indicate an unknown water type + combobox_salinity = 0; break; } // Save and display the new salinity value - ui->salinityText->setText(QString("%1g/ℓ").arg(combobox_salinity / 10.0)); + if (combobox_salinity) + ui->salinityText->setText(QString("%1g/ℓ").arg(combobox_salinity / 10.0)); + else + ui->salinityText->clear(); divesEdited(Command::editWaterTypeUser(combobox_salinity, false)); if (dc_salinity == combobox_salinity) // If salinity differs from that of dc, then save it ui->salinityOverWrittenIcon->setVisible(false); diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index 008d40f61..374ad4784 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -43,6 +43,7 @@ private: void divesEdited(int); void closeWarning(); void showCurrentWidget(bool show, int position); + QStringList waterTypes; }; #endif |