diff options
author | willemferguson <willemferguson@zoology.up.ac.za> | 2019-11-19 19:16:45 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-01-06 07:00:34 +0900 |
commit | d2cf58e07e64b4e1e6a81f07c2efce38c55be78b (patch) | |
tree | 1b0ad636f59da7600f4a38a819f8ddd5d03fc437 | |
parent | ebabbfb457184ea4d9e939ad8501986c35699264 (diff) | |
download | subsurface-d2cf58e07e64b4e1e6a81f07c2efce38c55be78b.tar.gz |
core: read and write the user-specified salinity
Both XML and git storage are added.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | commands/command.cpp | 5 | ||||
-rw-r--r-- | commands/command.h | 1 | ||||
-rw-r--r-- | commands/command_edit.cpp | 21 | ||||
-rw-r--r-- | commands/command_edit.h | 9 | ||||
-rw-r--r-- | core/load-git.c | 5 | ||||
-rw-r--r-- | core/parse-xml.c | 2 | ||||
-rw-r--r-- | core/save-git.c | 2 | ||||
-rw-r--r-- | core/save-xml.c | 5 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.cpp | 29 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.h | 1 |
10 files changed, 62 insertions, 18 deletions
diff --git a/commands/command.cpp b/commands/command.cpp index 9ea0e860f..29702c703 100644 --- a/commands/command.cpp +++ b/commands/command.cpp @@ -218,6 +218,11 @@ int editAtmPress(int newValue, bool currentDiveOnly) return execute_edit(new EditAtmPress(newValue, currentDiveOnly)); } +int editWaterTypeUser(int newValue, bool currentDiveOnly) +{ + return execute_edit(new EditWaterTypeUser(newValue, currentDiveOnly)); +} + int editDepth(int newValue, bool currentDiveOnly) { return execute_edit(new EditDepth(newValue, currentDiveOnly)); diff --git a/commands/command.h b/commands/command.h index 0f93a3e85..34df6eba8 100644 --- a/commands/command.h +++ b/commands/command.h @@ -71,6 +71,7 @@ int editChill(int newValue, bool currentDiveOnly); int editAirTemp(int newValue, bool currentDiveOnly); int editWaterTemp(int newValue, bool currentDiveOnly); int editAtmPress(int newValue, bool currentDiveOnly); +int editWaterTypeUser(int newValue, bool currentDiveOnly); int editDepth(int newValue, bool currentDiveOnly); int editDuration(int newValue, bool currentDiveOnly); int editDiveSite(struct dive_site *newValue, bool currentDiveOnly); diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 701da3ee1..31ca4ea23 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -355,6 +355,27 @@ DiveField EditWaterTemp::fieldId() const return DiveField::WATER_TEMP; } +// ***** Water Type ***** +void EditWaterTypeUser::set(struct dive *d, int value) const +{ + d->user_salinity = value > 0 ? value : 0; +} + +int EditWaterTypeUser::data(struct dive *d) const +{ + return d->user_salinity; +} + +QString EditWaterTypeUser::fieldName() const +{ + return tr("salinity"); +} + +DiveField EditWaterTypeUser::fieldId() const +{ + return DiveField::SALINITY; +} + // ***** Atmospheric pressure ***** void EditAtmPress::set(struct dive *d, int value) const { diff --git a/commands/command_edit.h b/commands/command_edit.h index 76b538b4d..aa749ceda 100644 --- a/commands/command_edit.h +++ b/commands/command_edit.h @@ -161,6 +161,15 @@ public: DiveField fieldId() const override; }; +class EditWaterTypeUser : public EditBase<int> { +public: + using EditBase<int>::EditBase; // Use constructor of base class. + void set(struct dive *d, int value) const override; + int data(struct dive *d) const override; + QString fieldName() const override; + DiveField fieldId() const override; +}; + class EditDuration : public EditBase<int> { public: using EditBase<int>::EditBase; // Use constructor of base class. diff --git a/core/load-git.c b/core/load-git.c index c9c195ca6..add7afe8c 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -285,6 +285,9 @@ static void parse_dive_surge(char *line, struct membuffer *str, struct git_parse static void parse_dive_chill(char *line, struct membuffer *str, struct git_parser_state *state) { UNUSED(str); state->active_dive->chill = get_index(line); } +static void parse_dive_watersalinity(char *line, struct membuffer *str, struct git_parser_state *state) +{ UNUSED(str); state->active_dive->user_salinity = get_salinity(line); } + static void parse_dive_notrip(char *line, struct membuffer *str, struct git_parser_state *state) { UNUSED(str); @@ -1001,7 +1004,7 @@ struct keyword_action dive_action[] = { #define D(x) { #x, parse_dive_ ## x } D(airpressure), D(airtemp), D(buddy), D(chill), D(current), D(cylinder), D(divemaster), D(divesiteid), D(duration), D(gps), D(location), D(notes), D(notrip), D(rating), D(suit), D(surge), - D(tags), D(visibility), D(watertemp), D(wavesize), D(weightsystem) + D(tags), D(visibility), D(watersalinity), D(watertemp), D(wavesize), D(weightsystem) }; static void dive_parser(char *line, struct membuffer *str, struct git_parser_state *state) diff --git a/core/parse-xml.c b/core/parse-xml.c index cd87d27a1..a7aec8c6a 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1331,6 +1331,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str return; if (MATCH("buddy", utf8_string, &dive->buddy)) return; + if (MATCH("watersalinity", salinity, &dive->user_salinity)) + return; if (MATCH("rating.dive", get_rating, &dive->rating)) return; if (MATCH("visibility.dive", get_rating, &dive->visibility)) diff --git a/core/save-git.c b/core/save-git.c index 8f27c8b0b..4f6110eb1 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -437,6 +437,8 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b) SAVE("current", current); SAVE("surge", surge); SAVE("chill", chill); + if (dive->user_salinity) + put_format(b, "watersalinity %d g/l\n", (int)(dive->user_salinity/10)); if (surface_pressure.mbar) SAVE("airpressure", surface_pressure.mbar); cond_put_format(dive->notrip, b, "notrip\n"); diff --git a/core/save-xml.c b/core/save-xml.c index 2a8ec5fa7..963907fb2 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -499,9 +499,10 @@ void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize) if (dive->chill) put_format(b, " chill='%d'", dive->chill); save_tags(b, dive->tag_list); - if (dive->dive_site) { + if (dive->dive_site) put_format(b, " divesiteid='%8x'", dive->dive_site->uuid); - } + if (dive->user_salinity) + put_salinity(b, dive->user_salinity, " watersalinity='", " g/l'"); show_date(b, dive->when); if (surface_pressure.mbar) put_pressure(b, surface_pressure, " airpressure='", " bar'"); diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 1c7f30496..d588cce80 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -189,22 +189,23 @@ int TabDiveInformation::updateSalinityComboIndex(int salinity) // 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->salinityOverWrittenIcon->setVisible(false); - } + int dc_value = current_dive->dc.salinity; + int user_value = current_dive->user_salinity; + bool show_indicator = false; + if (current_dive && dc_value && user_value && (user_value != dc_value)) + if ((dc_value < 10250) || (user_value < 10250)) // Provide for libdivecomputer that defines seawater density + show_indicator = true; // as 1.025 in contrast to Subsurface's value of 1.03 + ui->salinityOverWrittenIcon->setVisible(show_indicator); } void TabDiveInformation::showCurrentWidget(bool show, int position) { - ui->groupBox_wavesize->setVisible(show); - ui->groupBox_surge->setVisible(show); - ui->groupBox_chill->setVisible(show); - int layoutPosition = ui->diveInfoScrollAreaLayout->indexOf(ui->groupBox_current); - ui->diveInfoScrollAreaLayout->takeAt(layoutPosition); - ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1); + ui->groupBox_wavesize->setVisible(show); + ui->groupBox_surge->setVisible(show); + ui->groupBox_chill->setVisible(show); + int layoutPosition = ui->diveInfoScrollAreaLayout->indexOf(ui->groupBox_current); + ui->diveInfoScrollAreaLayout->takeAt(layoutPosition); + ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1); } void TabDiveInformation::updateData() @@ -258,6 +259,7 @@ void TabDiveInformation::updateData() showCurrentWidget(false, 0); // Show current star widget at lefthand side } +// From the index of the water type combo box, set the dive->salinity to an appropriate value void TabDiveInformation::on_waterTypeCombo_activated(int index) { int combobox_salinity = 0; int dc_salinity = current_dive->dc.salinity; @@ -284,8 +286,7 @@ void TabDiveInformation::on_waterTypeCombo_activated(int index) { } // 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. + 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); else diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index 0ff142f76..f905bc597 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -32,7 +32,6 @@ private slots: private: Ui::TabDiveInformation *ui; void updateProfile(); - void updateSalinity(); int updateSalinityComboIndex(int salinity); void checkDcSalinityOverWritten(); void updateWhen(); |