mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Improve handling of cylinders with identical gasmix
In reality we have no concept for handling those, yet. But the UI doesn't prevent the user from entering multiple cylinders with the same gasmix, so we need to help the user to get rid of them as well. If the user attempts to remove a cylinder we check if there's a second cylinder with the same gas. If that's the case then we can proceed and remove the cylinder the user wants to get rid of without losing that gas for the dive. The only tricky issue is that we need to make sure that if we remove the first cylinder that one is actually replaced with one with the same gas. Fixes #622 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
0cf55d7e39
commit
10e66823b0
1 changed files with 23 additions and 6 deletions
|
@ -346,20 +346,37 @@ void CylindersModel::remove(const QModelIndex &index)
|
|||
if (index.column() != REMOVE) {
|
||||
return;
|
||||
}
|
||||
int same_gas = -1;
|
||||
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
||||
if ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
|
||||
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
|
||||
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
|
||||
(cyl->manually_added || cylinder_is_used(&displayed_dive, cyl)))) {
|
||||
struct gasmix *mygas = &cyl->gasmix;
|
||||
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||
if (i == index.row() || cylinder_none(&displayed_dive.cylinder[i]))
|
||||
continue;
|
||||
struct gasmix *gas2 = &displayed_dive.cylinder[i].gasmix;
|
||||
if (gasmix_distance(mygas, gas2) == 0)
|
||||
same_gas = i;
|
||||
}
|
||||
if (same_gas == -1 &&
|
||||
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
|
||||
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
|
||||
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
|
||||
(cyl->manually_added || cylinder_is_used(&displayed_dive, cyl))))) {
|
||||
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
|
||||
tr("Cylinder cannot be removed"),
|
||||
tr("This gas in use. Only cylinders that are not used in the dive can be removed.")),
|
||||
tr("This gas is in use. Only cylinders that are not used in the dive can be removed.")),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
||||
rows--;
|
||||
remove_cylinder(&displayed_dive, index.row());
|
||||
if (index.row() == 0) {
|
||||
// first gas - we need to make sure that the same gas ends up
|
||||
// as first gas
|
||||
memmove(cyl, &displayed_dive.cylinder[same_gas], sizeof(*cyl));
|
||||
remove_cylinder(&displayed_dive, same_gas);
|
||||
} else {
|
||||
remove_cylinder(&displayed_dive, index.row());
|
||||
}
|
||||
changed = true;
|
||||
endRemoveRows();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue