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>
This commit is contained in:
willemferguson 2019-11-19 19:16:45 +02:00 committed by Dirk Hohndel
parent ebabbfb457
commit d2cf58e07e
10 changed files with 62 additions and 18 deletions

View file

@ -218,6 +218,11 @@ int editAtmPress(int newValue, bool currentDiveOnly)
return execute_edit(new EditAtmPress(newValue, 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) int editDepth(int newValue, bool currentDiveOnly)
{ {
return execute_edit(new EditDepth(newValue, currentDiveOnly)); return execute_edit(new EditDepth(newValue, currentDiveOnly));

View file

@ -71,6 +71,7 @@ int editChill(int newValue, bool currentDiveOnly);
int editAirTemp(int newValue, bool currentDiveOnly); int editAirTemp(int newValue, bool currentDiveOnly);
int editWaterTemp(int newValue, bool currentDiveOnly); int editWaterTemp(int newValue, bool currentDiveOnly);
int editAtmPress(int newValue, bool currentDiveOnly); int editAtmPress(int newValue, bool currentDiveOnly);
int editWaterTypeUser(int newValue, bool currentDiveOnly);
int editDepth(int newValue, bool currentDiveOnly); int editDepth(int newValue, bool currentDiveOnly);
int editDuration(int newValue, bool currentDiveOnly); int editDuration(int newValue, bool currentDiveOnly);
int editDiveSite(struct dive_site *newValue, bool currentDiveOnly); int editDiveSite(struct dive_site *newValue, bool currentDiveOnly);

View file

@ -355,6 +355,27 @@ DiveField EditWaterTemp::fieldId() const
return DiveField::WATER_TEMP; 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 ***** // ***** Atmospheric pressure *****
void EditAtmPress::set(struct dive *d, int value) const void EditAtmPress::set(struct dive *d, int value) const
{ {

View file

@ -161,6 +161,15 @@ public:
DiveField fieldId() const override; 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> { class EditDuration : public EditBase<int> {
public: public:
using EditBase<int>::EditBase; // Use constructor of base class. using EditBase<int>::EditBase; // Use constructor of base class.

View file

@ -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) static void parse_dive_chill(char *line, struct membuffer *str, struct git_parser_state *state)
{ UNUSED(str); state->active_dive->chill = get_index(line); } { 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) static void parse_dive_notrip(char *line, struct membuffer *str, struct git_parser_state *state)
{ {
UNUSED(str); UNUSED(str);
@ -1001,7 +1004,7 @@ struct keyword_action dive_action[] = {
#define D(x) { #x, parse_dive_ ## x } #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(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(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) static void dive_parser(char *line, struct membuffer *str, struct git_parser_state *state)

View file

@ -1331,6 +1331,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
return; return;
if (MATCH("buddy", utf8_string, &dive->buddy)) if (MATCH("buddy", utf8_string, &dive->buddy))
return; return;
if (MATCH("watersalinity", salinity, &dive->user_salinity))
return;
if (MATCH("rating.dive", get_rating, &dive->rating)) if (MATCH("rating.dive", get_rating, &dive->rating))
return; return;
if (MATCH("visibility.dive", get_rating, &dive->visibility)) if (MATCH("visibility.dive", get_rating, &dive->visibility))

View file

@ -437,6 +437,8 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b)
SAVE("current", current); SAVE("current", current);
SAVE("surge", surge); SAVE("surge", surge);
SAVE("chill", chill); SAVE("chill", chill);
if (dive->user_salinity)
put_format(b, "watersalinity %d g/l\n", (int)(dive->user_salinity/10));
if (surface_pressure.mbar) if (surface_pressure.mbar)
SAVE("airpressure", surface_pressure.mbar); SAVE("airpressure", surface_pressure.mbar);
cond_put_format(dive->notrip, b, "notrip\n"); cond_put_format(dive->notrip, b, "notrip\n");

View file

@ -499,9 +499,10 @@ void save_one_dive_to_mb(struct membuffer *b, struct dive *dive, bool anonymize)
if (dive->chill) if (dive->chill)
put_format(b, " chill='%d'", dive->chill); put_format(b, " chill='%d'", dive->chill);
save_tags(b, dive->tag_list); save_tags(b, dive->tag_list);
if (dive->dive_site) { if (dive->dive_site)
put_format(b, " divesiteid='%8x'", dive->dive_site->uuid); 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); show_date(b, dive->when);
if (surface_pressure.mbar) if (surface_pressure.mbar)
put_pressure(b, surface_pressure, " airpressure='", " bar'"); put_pressure(b, surface_pressure, " airpressure='", " bar'");

View file

@ -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 // If dive->user_salinity != dive->salinity (i.e. dc value) then show the salinity-overwrite indicator
void TabDiveInformation::checkDcSalinityOverWritten() void TabDiveInformation::checkDcSalinityOverWritten()
{ {
if (current_dive && current_dive->dc.salinity && current_dive->user_salinity) { int dc_value = current_dive->dc.salinity;
if (current_dive->dc.salinity != current_dive->user_salinity) int user_value = current_dive->user_salinity;
ui->salinityOverWrittenIcon->setVisible(true); bool show_indicator = false;
} else { if (current_dive && dc_value && user_value && (user_value != dc_value))
ui->salinityOverWrittenIcon->setVisible(false); 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) void TabDiveInformation::showCurrentWidget(bool show, int position)
{ {
ui->groupBox_wavesize->setVisible(show); ui->groupBox_wavesize->setVisible(show);
ui->groupBox_surge->setVisible(show); ui->groupBox_surge->setVisible(show);
ui->groupBox_chill->setVisible(show); ui->groupBox_chill->setVisible(show);
int layoutPosition = ui->diveInfoScrollAreaLayout->indexOf(ui->groupBox_current); int layoutPosition = ui->diveInfoScrollAreaLayout->indexOf(ui->groupBox_current);
ui->diveInfoScrollAreaLayout->takeAt(layoutPosition); ui->diveInfoScrollAreaLayout->takeAt(layoutPosition);
ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1); ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1);
} }
void TabDiveInformation::updateData() void TabDiveInformation::updateData()
@ -258,6 +259,7 @@ void TabDiveInformation::updateData()
showCurrentWidget(false, 0); // Show current star widget at lefthand side 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) { void TabDiveInformation::on_waterTypeCombo_activated(int index) {
int combobox_salinity = 0; int combobox_salinity = 0;
int dc_salinity = current_dive->dc.salinity; 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 // Save and display the new salinity value
ui->salinityText->setText(QString("%1g/").arg(combobox_salinity / 10.0)); 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. divesEdited(Command::editWaterTypeUser(combobox_salinity, false));
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 if (dc_salinity == combobox_salinity) // If salinity differs from that of dc, then save it
ui->salinityOverWrittenIcon->setVisible(false); ui->salinityOverWrittenIcon->setVisible(false);
else else

View file

@ -32,7 +32,6 @@ private slots:
private: private:
Ui::TabDiveInformation *ui; Ui::TabDiveInformation *ui;
void updateProfile(); void updateProfile();
void updateSalinity();
int updateSalinityComboIndex(int salinity); int updateSalinityComboIndex(int salinity);
void checkDcSalinityOverWritten(); void checkDcSalinityOverWritten();
void updateWhen(); void updateWhen();