mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Editing air or water temperature should modify dive computer, not dive
The dive fields are summary fields, the actual data needs to be in the divecomputer specific fields. Fixes #307
This commit is contained in:
parent
d936c55a01
commit
ff5fa70a88
4 changed files with 25 additions and 11 deletions
22
dive.c
22
dive.c
|
@ -646,19 +646,29 @@ static void fixup_duration(struct dive *dive)
|
||||||
dive->duration.seconds = duration;
|
dive->duration.seconds = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fixup_watertemp(struct dive *dive)
|
/*
|
||||||
|
* What do the dive computers say the water temperature is?
|
||||||
|
* (not in the samples, but as dc property for dcs that support that)
|
||||||
|
*/
|
||||||
|
unsigned int dc_watertemp(struct divecomputer *dc)
|
||||||
{
|
{
|
||||||
struct divecomputer *dc;
|
|
||||||
int sum = 0, nr = 0;
|
int sum = 0, nr = 0;
|
||||||
|
|
||||||
for_each_dc(dive, dc) {
|
do {
|
||||||
if (dc->watertemp.mkelvin) {
|
if (dc->watertemp.mkelvin) {
|
||||||
sum += dc->watertemp.mkelvin;
|
sum += dc->watertemp.mkelvin;
|
||||||
nr++;
|
nr++;
|
||||||
}
|
}
|
||||||
}
|
} while ((dc = dc->next) != NULL);
|
||||||
if (nr)
|
if (!nr)
|
||||||
dive->watertemp.mkelvin = (sum + nr / 2) / nr;
|
return 0;
|
||||||
|
return (sum + nr / 2) / nr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fixup_watertemp(struct dive *dive)
|
||||||
|
{
|
||||||
|
if (!dive->watertemp.mkelvin)
|
||||||
|
dive->watertemp.mkelvin = dc_watertemp(&dive->dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
1
dive.h
1
dive.h
|
@ -651,6 +651,7 @@ extern void finish_sample(struct divecomputer *dc);
|
||||||
extern void sort_table(struct dive_table *table);
|
extern void sort_table(struct dive_table *table);
|
||||||
extern struct dive *fixup_dive(struct dive *dive);
|
extern struct dive *fixup_dive(struct dive *dive);
|
||||||
extern unsigned int dc_airtemp(struct divecomputer *dc);
|
extern unsigned int dc_airtemp(struct divecomputer *dc);
|
||||||
|
extern unsigned int dc_watertemp(struct divecomputer *dc);
|
||||||
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded);
|
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded);
|
||||||
extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
|
extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
|
||||||
extern void renumber_dives(int nr);
|
extern void renumber_dives(int nr);
|
||||||
|
|
|
@ -759,13 +759,13 @@ void MainTab::on_divemaster_textChanged(const QString& text)
|
||||||
|
|
||||||
void MainTab::on_airtemp_textChanged(const QString& text)
|
void MainTab::on_airtemp_textChanged(const QString& text)
|
||||||
{
|
{
|
||||||
EDIT_SELECTED_DIVES( mydive->airtemp.mkelvin = parseTemperatureToMkelvin(text) );
|
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->airtemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||||
markChangedWidget(ui.airtemp);
|
markChangedWidget(ui.airtemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::on_watertemp_textChanged(const QString& text)
|
void MainTab::on_watertemp_textChanged(const QString& text)
|
||||||
{
|
{
|
||||||
EDIT_SELECTED_DIVES( mydive->watertemp.mkelvin = parseTemperatureToMkelvin(text) );
|
EDIT_SELECTED_DIVES( select_dc(&mydive->dc)->watertemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||||
markChangedWidget(ui.watertemp);
|
markChangedWidget(ui.watertemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,13 +153,16 @@ static void save_depths(FILE *f, struct divecomputer *dc)
|
||||||
|
|
||||||
static void save_dive_temperature(FILE *f, struct dive *dive)
|
static void save_dive_temperature(FILE *f, struct dive *dive)
|
||||||
{
|
{
|
||||||
if (!dive->airtemp.mkelvin)
|
if (!dive->airtemp.mkelvin && !dive->watertemp.mkelvin)
|
||||||
return;
|
return;
|
||||||
if (dive->airtemp.mkelvin == dc_airtemp(&dive->dc))
|
if (dive->airtemp.mkelvin == dc_airtemp(&dive->dc) || dive->watertemp.mkelvin == dc_watertemp(&dive->dc))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fputs(" <divetemperature", f);
|
fputs(" <divetemperature", f);
|
||||||
show_temperature(f, dive->airtemp, " air='", "'");
|
if (dive->airtemp.mkelvin && dive->airtemp.mkelvin != dc_airtemp(&dive->dc))
|
||||||
|
show_temperature(f, dive->airtemp, " air='", "'");
|
||||||
|
if (dive->watertemp.mkelvin && dive->watertemp.mkelvin != dc_watertemp(&dive->dc))
|
||||||
|
show_temperature(f, dive->watertemp, " water='", "'");
|
||||||
fputs("/>\n", f);
|
fputs("/>\n", f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue