summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-29 12:05:21 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-29 12:05:21 -0800
commitff5fa70a88d2ac0c424a1f1a994837ebe7e27d9d (patch)
treea226397bac03cb6928d761a96c23a32d11593dee
parentd936c55a015789f61f7e93426b11218ebb4312af (diff)
downloadsubsurface-ff5fa70a88d2ac0c424a1f1a994837ebe7e27d9d.tar.gz
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
-rw-r--r--dive.c22
-rw-r--r--dive.h1
-rw-r--r--qt-ui/maintab.cpp4
-rw-r--r--save-xml.c9
4 files changed, 25 insertions, 11 deletions
diff --git a/dive.c b/dive.c
index bc628589d..d0c22734c 100644
--- a/dive.c
+++ b/dive.c
@@ -646,19 +646,29 @@ static void fixup_duration(struct dive *dive)
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;
- for_each_dc(dive, dc) {
+ do {
if (dc->watertemp.mkelvin) {
sum += dc->watertemp.mkelvin;
nr++;
}
- }
- if (nr)
- dive->watertemp.mkelvin = (sum + nr / 2) / nr;
+ } while ((dc = dc->next) != NULL);
+ if (!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);
}
/*
diff --git a/dive.h b/dive.h
index 41e37a720..7f3a55a99 100644
--- a/dive.h
+++ b/dive.h
@@ -651,6 +651,7 @@ extern void finish_sample(struct divecomputer *dc);
extern void sort_table(struct dive_table *table);
extern struct dive *fixup_dive(struct dive *dive);
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 *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
extern void renumber_dives(int nr);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 0400aa7ed..0e1e52289 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -759,13 +759,13 @@ void MainTab::on_divemaster_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);
}
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);
}
diff --git a/save-xml.c b/save-xml.c
index 0b83a0235..631abda9a 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -153,13 +153,16 @@ static void save_depths(FILE *f, struct divecomputer *dc)
static void save_dive_temperature(FILE *f, struct dive *dive)
{
- if (!dive->airtemp.mkelvin)
+ if (!dive->airtemp.mkelvin && !dive->watertemp.mkelvin)
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;
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);
}