aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/dive.c6
-rw-r--r--core/save-git.c24
-rw-r--r--core/save-xml.c24
-rw-r--r--profile-widget/diveeventitem.cpp25
4 files changed, 47 insertions, 32 deletions
diff --git a/core/dive.c b/core/dive.c
index 915a04fe5..ecddda6b9 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -159,8 +159,12 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
struct gasmix *get_gasmix_from_event(struct dive *dive, struct event *ev)
{
static struct gasmix dummy;
- if (ev && event_is_gaschange(ev))
+ if (ev && event_is_gaschange(ev)) {
+ int index = ev->gas.index;
+ if (index >= 0 && index <= MAX_CYLINDERS)
+ return &dive->cylinder[index].gasmix;
return &ev->gas.mix;
+ }
return &dummy;
}
diff --git a/core/save-git.c b/core/save-git.c
index ed91debf4..f2803c315 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -220,10 +220,15 @@ static void show_date(struct membuffer *b, timestamp_t when)
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
+static void show_integer(struct membuffer *b, int value, const char *pre, const char *post)
+{
+ put_format(b, " %s%d%s", pre, value, post);
+}
+
static void show_index(struct membuffer *b, int value, const char *pre, const char *post)
{
if (value)
- put_format(b, " %s%d%s", pre, value, post);
+ show_integer(b, value, pre, post);
}
/*
@@ -314,7 +319,7 @@ static void save_samples(struct membuffer *b, int nr, struct sample *s)
}
}
-static void save_one_event(struct membuffer *b, struct event *ev)
+static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev)
{
put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type=", "");
@@ -322,19 +327,18 @@ static void save_one_event(struct membuffer *b, struct event *ev)
show_index(b, ev->value, "value=", "");
show_utf8(b, " name=", ev->name, "");
if (event_is_gaschange(ev)) {
- if (ev->gas.index >= 0) {
- show_index(b, ev->gas.index, "cylinder=", "");
- put_gasmix(b, &ev->gas.mix);
- } else
- put_gasmix(b, &ev->gas.mix);
+ struct gasmix *mix = get_gasmix_from_event(dive, ev);
+ if (ev->gas.index >= 0)
+ show_integer(b, ev->gas.index, "cylinder=", "");
+ put_gasmix(b, mix);
}
put_string(b, "\n");
}
-static void save_events(struct membuffer *b, struct event *ev)
+static void save_events(struct membuffer *b, struct dive *dive, struct event *ev)
{
while (ev) {
- save_one_event(b, ev);
+ save_one_event(b, dive, ev);
ev = ev->next;
}
}
@@ -362,7 +366,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
put_duration(b, dc->surfacetime, "surfacetime ", "min\n");
save_extra_data(b, dc->extra_data);
- save_events(b, dc->events);
+ save_events(b, dive, dc->events);
save_samples(b, dc->samples, dc->sample);
}
diff --git a/core/save-xml.c b/core/save-xml.c
index 045e47c55..80dda63b8 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -178,10 +178,15 @@ static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
}
}
+static void show_integer(struct membuffer *b, int value, const char *pre, const char *post)
+{
+ put_format(b, " %s%d%s", pre, value, post);
+}
+
static void show_index(struct membuffer *b, int value, const char *pre, const char *post)
{
if (value)
- put_format(b, " %s%d%s", pre, value, post);
+ show_integer(b, value, pre, post);
}
static void save_sample(struct membuffer *b, struct sample *sample, struct sample *old)
@@ -258,7 +263,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
put_format(b, " />\n");
}
-static void save_one_event(struct membuffer *b, struct event *ev)
+static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev)
{
put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type='", "'");
@@ -266,20 +271,19 @@ static void save_one_event(struct membuffer *b, struct event *ev)
show_index(b, ev->value, "value='", "'");
show_utf8(b, ev->name, " name='", "'", 1);
if (event_is_gaschange(ev)) {
- if (ev->gas.index >= 0) {
- show_index(b, ev->gas.index, "cylinder='", "'");
- put_gasmix(b, &ev->gas.mix);
- } else
- put_gasmix(b, &ev->gas.mix);
+ struct gasmix *mix = get_gasmix_from_event(dive, ev);
+ if (ev->gas.index >= 0)
+ show_integer(b, ev->gas.index, "cylinder='", "'");
+ put_gasmix(b, mix);
}
put_format(b, " />\n");
}
-static void save_events(struct membuffer *b, struct event *ev)
+static void save_events(struct membuffer *b, struct dive *dive, struct event *ev)
{
while (ev) {
- save_one_event(b, ev);
+ save_one_event(b, dive, ev);
ev = ev->next;
}
}
@@ -360,7 +364,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
save_salinity(b, dc);
put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n");
save_extra_data(b, dc->extra_data);
- save_events(b, dc->events);
+ save_events(b, dive, dc->events);
save_samples(b, dc->samples, dc->sample);
put_format(b, " </divecomputer>\n");
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp
index daef227d8..876c56e16 100644
--- a/profile-widget/diveeventitem.cpp
+++ b/profile-widget/diveeventitem.cpp
@@ -94,9 +94,10 @@ void DiveEventItem::setupPixmap()
transparentPixmap.fill(QColor::fromRgbF(1.0, 1.0, 1.0, 0.01));
setPixmap(transparentPixmap);
} else if (event_is_gaschange(internalEvent)) {
- if (internalEvent->gas.mix.he.permille)
+ struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent);
+ if (mix->he.permille)
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeTrimix"));
- else if (gasmix_is_air(&internalEvent->gas.mix))
+ else if (gasmix_is_air(mix))
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeAir"));
else
setPixmap(EVENT_PIXMAP_BIGGER(":gaschangeNitrox"));
@@ -112,15 +113,17 @@ void DiveEventItem::setupToolTipString()
QString name = gettextFromC::instance()->tr(internalEvent->name);
int value = internalEvent->value;
int type = internalEvent->type;
- if (value) {
- if (event_is_gaschange(internalEvent)) {
- name += ": ";
- name += gasname(&internalEvent->gas.mix);
-
- /* Do we have an explicit cylinder index? Show it. */
- if (internalEvent->gas.index >= 0)
- name += QString(" (cyl %1)").arg(internalEvent->gas.index+1);
- } else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
+
+ if (event_is_gaschange(internalEvent)) {
+ struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent);
+ name += ": ";
+ name += gasname(mix);
+
+ /* Do we have an explicit cylinder index? Show it. */
+ if (internalEvent->gas.index >= 0)
+ name += QString(" (cyl %1)").arg(internalEvent->gas.index+1);
+ } else if (value) {
+ if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
name += QString(":%1").arg((double)value / 1000);
} else {
name += QString(":%1").arg(value);