mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:13:24 +00:00
Don't show tanks that aren't used during a dive
Some dive computers will always download all tanks that they store, not just the ones used in a dive. Most people only want to see the tanks that they actually used during the dive (and for the others there's an option to go back to the old behavior, just in case). All this is only in memory / during runtime. If the dive computer provided the extra data we will not throw it away. Fixes #373 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f43a3052cb
commit
23973e8abd
9 changed files with 48 additions and 2 deletions
28
dive.c
28
dive.c
|
@ -594,6 +594,32 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event *
|
|||
return previous;
|
||||
}
|
||||
|
||||
/* mark all tanks that we switch to in this dive computer's data as used */
|
||||
static void mark_used_tanks(struct dive *dive, struct divecomputer *dc)
|
||||
{
|
||||
struct event *ev = get_next_event(dc->events, "gaschange");
|
||||
// unless there is a gas change in the first 30 seconds we can
|
||||
// always mark the first cylinder as used
|
||||
if (!ev || ev->time.seconds > 30)
|
||||
dive->cylinder[0].used = true;
|
||||
while (ev) {
|
||||
int idx = get_cylinder_index(dive, ev);
|
||||
dive->cylinder[idx].used = true;
|
||||
ev = get_next_event(ev->next, "gaschange");
|
||||
}
|
||||
}
|
||||
|
||||
/* walk all divecomputers to find the unused tanks in this dive */
|
||||
static void check_for_unused_tanks(struct dive *dive)
|
||||
{
|
||||
int i;
|
||||
struct divecomputer *dc;
|
||||
|
||||
for_each_dc(dive, dc) {
|
||||
mark_used_tanks(dive, dc);
|
||||
}
|
||||
}
|
||||
|
||||
static void fixup_surface_pressure(struct dive *dive)
|
||||
{
|
||||
struct divecomputer *dc;
|
||||
|
@ -879,7 +905,7 @@ struct dive *fixup_dive(struct dive *dive)
|
|||
fixup_duration(dive);
|
||||
fixup_watertemp(dive);
|
||||
fixup_airtemp(dive);
|
||||
|
||||
check_for_unused_tanks(dive);
|
||||
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||
cylinder_t *cyl = dive->cylinder + i;
|
||||
add_cylinder_description(&cyl->type);
|
||||
|
|
1
dive.h
1
dive.h
|
@ -145,6 +145,7 @@ typedef struct {
|
|||
struct gasmix gasmix;
|
||||
pressure_t start, end, sample_start, sample_end;
|
||||
depth_t depth;
|
||||
bool used;
|
||||
} cylinder_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
1
pref.h
1
pref.h
|
@ -37,6 +37,7 @@ struct preferences {
|
|||
short unit_system;
|
||||
struct units units;
|
||||
short show_sac;
|
||||
bool display_unused_tanks;
|
||||
};
|
||||
enum unit_system_values { METRIC, IMPERIAL, PERSONALIZE };
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ MainWindow::MainWindow() : helpView(0)
|
|||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.InfoWidget, SLOT(updateDiveInfo()));
|
||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlanner, SLOT(settingsChanged()));
|
||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged()));
|
||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
|
||||
|
||||
ui.mainErrorMessage->hide();
|
||||
initialUiSetup();
|
||||
|
@ -647,6 +648,7 @@ void MainWindow::readSettings()
|
|||
GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
|
||||
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
||||
GET_BOOL("show_sac", show_sac);
|
||||
GET_BOOL("display_unused_tanks", display_unused_tanks);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("GeneralSettings");
|
||||
|
|
|
@ -301,7 +301,8 @@ void CylindersModel::setDive(dive* d)
|
|||
return;
|
||||
rows = 0;
|
||||
for(int i = 0; i < MAX_CYLINDERS; i++) {
|
||||
if (!cylinder_none(&d->cylinder[i])) {
|
||||
if (!cylinder_none(&d->cylinder[i]) &&
|
||||
(prefs.display_unused_tanks || d->cylinder[i].used)) {
|
||||
rows = i+1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
/*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
const QString& biggerString() const;
|
||||
void clear();
|
||||
public slots:
|
||||
void update();
|
||||
private:
|
||||
int rows;
|
||||
|
|
|
@ -103,6 +103,7 @@ void PreferencesDialog::setUiFromPrefs()
|
|||
ui.default_cylinder->setCurrentIndex(i);
|
||||
}
|
||||
ui.displayinvalid->setChecked(prefs.display_invalid_dives);
|
||||
ui.display_unused_tanks->setChecked(prefs.display_unused_tanks);
|
||||
ui.show_sac->setChecked(prefs.show_sac);
|
||||
ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES);
|
||||
ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS);
|
||||
|
@ -162,6 +163,7 @@ void PreferencesDialog::syncSettings()
|
|||
s.setValue("gfhigh", ui.gfhigh->value());
|
||||
SB("gf_low_at_maxdepth", ui.gf_low_at_maxdepth);
|
||||
SB("show_sac", ui.show_sac);
|
||||
SB("display_unused_tanks", ui.display_unused_tanks);
|
||||
s.endGroup();
|
||||
|
||||
// Units
|
||||
|
|
|
@ -772,6 +772,17 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11c">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="display_unused_tanks">
|
||||
<property name="text">
|
||||
<string>unused tanks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -29,6 +29,7 @@ struct preferences default_prefs = {
|
|||
.font_size = 14.0,
|
||||
.display_invalid_dives = FALSE,
|
||||
.show_sac = FALSE,
|
||||
.display_unused_tanks = FALSE
|
||||
};
|
||||
|
||||
struct units *get_units()
|
||||
|
|
Loading…
Add table
Reference in a new issue