summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c2
-rw-r--r--dive.h2
-rw-r--r--divelist.c2
-rw-r--r--equipment.c25
-rw-r--r--qt-ui/models.cpp6
-rw-r--r--statistics.c2
6 files changed, 7 insertions, 32 deletions
diff --git a/dive.c b/dive.c
index b39634d5e..acab8ff52 100644
--- a/dive.c
+++ b/dive.c
@@ -448,7 +448,7 @@ void copy_cylinders(struct dive *s, struct dive *d, bool used_only)
if (!s || !d)
return;
for (i = 0; i < MAX_CYLINDERS; i++)
- if (!used_only || cylinder_is_used(s, &s->cylinder[i]))
+ if (!used_only || is_cylinder_used(s, i))
d->cylinder[i] = s->cylinder[i];
else
memset(&d->cylinder[i], 0, sizeof(cylinder_t));
diff --git a/dive.h b/dive.h
index da97e012a..204cb2fee 100644
--- a/dive.h
+++ b/dive.h
@@ -623,7 +623,7 @@ extern void renumber_dives(int start_nr, bool selected_only);
extern void copy_events(struct divecomputer *s, struct divecomputer *d);
extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only);
extern void copy_samples(struct divecomputer *s, struct divecomputer *d);
-extern bool cylinder_is_used(struct dive *d, cylinder_t *cyl);
+extern bool is_cylinder_used(struct dive *dive, int idx);
extern void fill_default_cylinder(cylinder_t *cyl);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
extern void add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name);
diff --git a/divelist.c b/divelist.c
index 1a2111f76..c9e5aebf7 100644
--- a/divelist.c
+++ b/divelist.c
@@ -116,7 +116,7 @@ void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
int o2 = get_o2(&cyl->gasmix);
int he = get_he(&cyl->gasmix);
- if (!cylinder_is_used(dive, cyl))
+ if (!is_cylinder_used(dive, i))
continue;
if (cylinder_none(cyl))
continue;
diff --git a/equipment.c b/equipment.c
index 14d02df77..8ca9f096e 100644
--- a/equipment.c
+++ b/equipment.c
@@ -73,31 +73,6 @@ bool cylinder_none(void *_data)
return cylinder_nodata(cyl) && cylinder_nosamples(cyl);
}
-/* look at all dive computers and figure out if this cylinder is used anywhere
- * d has to be a valid dive (test before calling)
- * cyl does not have to be a cylinder that is part of this dive structure */
-bool cylinder_is_used(struct dive *d, cylinder_t *cyl)
-{
- struct divecomputer *dc = &d->dc;
- bool same_as_first = gasmix_distance(&cyl->gasmix, &d->cylinder[0].gasmix) < 200;
- while (dc) {
- struct event *ev = get_next_event(dc->events, "gaschange");
- if (same_as_first && (!ev || ev->time.seconds > 30)) {
- // unless there is a gas change in the first 30 seconds we can
- // always mark the first cylinder as used
- return true;
- }
- while (ev) {
- if (gasmix_distance(&cyl->gasmix, get_gasmix_from_event(ev)) < 200)
- return true;
-
- ev = get_next_event(ev->next, "gaschange");
- }
- dc = dc->next;
- }
- return false;
-}
-
void get_gas_string(const struct gasmix *gasmix, char *text, int len)
{
if (gasmix_is_air(gasmix))
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index b098659e4..9d43da624 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -308,7 +308,7 @@ void CylindersModel::updateDive()
for (int i = 0; i < MAX_CYLINDERS; i++) {
if (!cylinder_none(&displayed_dive.cylinder[i]) &&
(prefs.display_unused_tanks ||
- cylinder_is_used(&displayed_dive, &displayed_dive.cylinder[i]) ||
+ is_cylinder_used(&displayed_dive, i) ||
displayed_dive.cylinder[i].manually_added))
rows = i + 1;
}
@@ -324,7 +324,7 @@ void CylindersModel::copyFromDive(dive *d)
return;
rows = 0;
for (int i = 0; i < MAX_CYLINDERS; i++) {
- if (!cylinder_none(&d->cylinder[i]) && cylinder_is_used(d, &d->cylinder[i])) {
+ if (!cylinder_none(&d->cylinder[i]) && is_cylinder_used(d, i)) {
rows = i + 1;
}
}
@@ -360,7 +360,7 @@ void CylindersModel::remove(const QModelIndex &index)
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
- (cyl->manually_added || cylinder_is_used(&displayed_dive, cyl))))) {
+ (cyl->manually_added || is_cylinder_used(&displayed_dive, index.row()))))) {
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
tr("Cylinder cannot be removed"),
tr("This gas is in use. Only cylinders that are not used in the dive can be removed.")),
diff --git a/statistics.c b/statistics.c
index 68b9cdd58..21b386b21 100644
--- a/statistics.c
+++ b/statistics.c
@@ -292,7 +292,7 @@ void get_selected_dives_text(char *buffer, int size)
}
}
-static bool is_cylinder_used(struct dive *dive, int idx)
+bool is_cylinder_used(struct dive *dive, int idx)
{
struct divecomputer *dc;
bool firstGasExplicit = false;