summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-15 20:36:49 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-15 20:36:49 -0700
commit10e66823b007ab89f4179931019bc7ffc514c819 (patch)
treef4c5a0f855f24c0cc0c21fa49ad823be535e687c /qt-ui/models.cpp
parent0cf55d7e39316b4b3fc271f556e8ff8abfae8db0 (diff)
downloadsubsurface-10e66823b007ab89f4179931019bc7ffc514c819.tar.gz
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>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 777329cb9..b098659e4 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -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();
}