mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Updated strategy for removing cylinders
Change the strategy when to allow cylinder removal from a dive: - Not remove when cylinder has gas switch events, in any other cases allow removal - Remove this whole "cylinder with same gas" thing being a criteria for cylinder removal When removing a cylinder which has corresponding pressure info in samples, also remove this pressure info from the samples. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
parent
cd5e17cf79
commit
4cbf8b87a3
5 changed files with 42 additions and 37 deletions
14
core/dive.c
14
core/dive.c
|
@ -2072,7 +2072,7 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int
|
||||||
if (mapping[0] > 0)
|
if (mapping[0] > 0)
|
||||||
add_initial_gaschange(dive, dc);
|
add_initial_gaschange(dive, dc);
|
||||||
|
|
||||||
/* Remap the sensor indexes */
|
/* Remap or delete the sensor indexes */
|
||||||
for (i = 0; i < dc->samples; i++) {
|
for (i = 0; i < dc->samples; i++) {
|
||||||
struct sample *s = dc->sample + i;
|
struct sample *s = dc->sample + i;
|
||||||
int j;
|
int j;
|
||||||
|
@ -2081,8 +2081,18 @@ static void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int
|
||||||
int sensor;
|
int sensor;
|
||||||
|
|
||||||
sensor = mapping[s->sensor[j]];
|
sensor = mapping[s->sensor[j]];
|
||||||
if (sensor >= 0)
|
if (sensor == -1) {
|
||||||
|
// Remove sensor and gas pressure info
|
||||||
|
if (i == 0) {
|
||||||
|
s->sensor[j] = 0;
|
||||||
|
s->pressure[j].mbar = 0;
|
||||||
|
} else {
|
||||||
|
s->sensor[j] = s[-1].sensor[j];
|
||||||
|
s->pressure[j].mbar = s[-1].pressure[j].mbar;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
s->sensor[j] = sensor;
|
s->sensor[j] = sensor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -812,6 +812,7 @@ extern void free_events(struct event *ev);
|
||||||
extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only);
|
extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only);
|
||||||
extern void copy_samples(struct divecomputer *s, struct divecomputer *d);
|
extern void copy_samples(struct divecomputer *s, struct divecomputer *d);
|
||||||
extern bool is_cylinder_used(struct dive *dive, int idx);
|
extern bool is_cylinder_used(struct dive *dive, int idx);
|
||||||
|
extern bool is_cylinder_prot(struct dive *dive, int idx);
|
||||||
extern void fill_default_cylinder(cylinder_t *cyl);
|
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_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
|
||||||
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
|
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
|
||||||
|
|
|
@ -345,6 +345,19 @@ bool is_cylinder_used(struct dive *dive, int idx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_cylinder_prot(struct dive *dive, int idx)
|
||||||
|
{
|
||||||
|
struct divecomputer *dc;
|
||||||
|
if (cylinder_none(&dive->cylinder[idx]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for_each_dc(dive, dc) {
|
||||||
|
if (has_gaschange_event(dive, dc, idx))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
|
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
|
|
|
@ -136,7 +136,6 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
int same_gas = -1;
|
|
||||||
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
|
@ -231,10 +230,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
case Qt::SizeHintRole:
|
case Qt::SizeHintRole:
|
||||||
if (index.column() == REMOVE) {
|
if (index.column() == REMOVE) {
|
||||||
same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
|
|
||||||
|
|
||||||
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
||||||
(!in_planner() && is_cylinder_used(&displayed_dive, index.row()) && same_gas == -1)) {
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
|
||||||
ret = trashForbiddenIcon();
|
ret = trashForbiddenIcon();
|
||||||
}
|
}
|
||||||
else ret = trashIcon();
|
else ret = trashIcon();
|
||||||
|
@ -244,10 +241,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
|
|
||||||
|
|
||||||
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
||||||
(!in_planner() && is_cylinder_used(&displayed_dive, index.row()) && same_gas == -1)) {
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
|
||||||
ret = tr("This gas is in use. Only cylinders that are not used in the dive can be removed.");
|
ret = tr("This gas is in use. Only cylinders that are not used in the dive can be removed.");
|
||||||
}
|
}
|
||||||
else ret = tr("Clicking here will remove this cylinder.");
|
else ret = tr("Clicking here will remove this cylinder.");
|
||||||
|
@ -541,38 +536,22 @@ void CylindersModel::remove(const QModelIndex &index)
|
||||||
if (index.column() != REMOVE) {
|
if (index.column() != REMOVE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
|
||||||
int same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
|
|
||||||
|
|
||||||
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
||||||
(!in_planner() && is_cylinder_used(&displayed_dive, index.row()) && same_gas == -1))
|
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row())))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
||||||
rows--;
|
rows--;
|
||||||
// if we didn't find an identical gas, point same_gas at the index.row()
|
|
||||||
if (same_gas == -1)
|
remove_cylinder(&displayed_dive, index.row());
|
||||||
same_gas = index.row();
|
for (int i = 0; i < index.row(); i++)
|
||||||
if (index.row() == 0) {
|
mapping[i] = i;
|
||||||
// first gas - we need to make sure that the same gas ends up
|
// No mapping for removed gas, set to -1
|
||||||
// as first gas
|
mapping[index.row()] = -1;
|
||||||
memmove(cyl, &displayed_dive.cylinder[same_gas], sizeof(*cyl));
|
for (int i = index.row() + 1; i < MAX_CYLINDERS; i++)
|
||||||
remove_cylinder(&displayed_dive, same_gas);
|
mapping[i] = i - 1;
|
||||||
for (int i = 0; i < same_gas - 1; i++)
|
|
||||||
mapping[i] = i;
|
|
||||||
mapping[same_gas] = 0;
|
|
||||||
for (int i = same_gas + 1; i < MAX_CYLINDERS; i++)
|
|
||||||
mapping[i] = i - 1;
|
|
||||||
} else {
|
|
||||||
remove_cylinder(&displayed_dive, index.row());
|
|
||||||
if (same_gas > index.row())
|
|
||||||
same_gas--;
|
|
||||||
for (int i = 0; i < index.row(); i++)
|
|
||||||
mapping[i] = i;
|
|
||||||
mapping[index.row()] = same_gas;
|
|
||||||
for (int i = index.row() + 1; i < MAX_CYLINDERS; i++)
|
|
||||||
mapping[i] = i - 1;
|
|
||||||
}
|
|
||||||
cylinder_renumber(&displayed_dive, mapping);
|
cylinder_renumber(&displayed_dive, mapping);
|
||||||
if (in_planner())
|
if (in_planner())
|
||||||
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
|
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
|
||||||
|
|
|
@ -346,8 +346,10 @@ void DivePlannerPointsModel::gasChange(const QModelIndex &index, int newcylinder
|
||||||
|
|
||||||
void DivePlannerPointsModel::cylinderRenumber(int mapping[])
|
void DivePlannerPointsModel::cylinderRenumber(int mapping[])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < rowCount(); i++)
|
for (int i = 0; i < rowCount(); i++) {
|
||||||
divepoints[i].cylinderid = mapping[divepoints[i].cylinderid];
|
if (mapping[divepoints[i].cylinderid] >= 0)
|
||||||
|
divepoints[i].cylinderid = mapping[divepoints[i].cylinderid];
|
||||||
|
}
|
||||||
emitDataChanged();
|
emitDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue