diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/diveplanner.cpp | 6 | ||||
-rw-r--r-- | qt-ui/models.cpp | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 252c0ffc3..1c6c05702 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -120,8 +120,13 @@ void DivePlannerPointsModel::setupCylinders() return; if (stagingDive != current_dive) { + // we are planning a dive if (current_dive) { + // take the cylinders from the selected dive as starting point + CylindersModel::instance()->copyFromDive(current_dive); copy_cylinders(current_dive, stagingDive); + reset_cylinders(stagingDive); + return; } else { if (!same_string(prefs.default_cylinder, "")) { fill_default_cylinder(&stagingDive->cylinder[0]); @@ -130,7 +135,6 @@ void DivePlannerPointsModel::setupCylinders() stagingDive->cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData()); stagingDive->cylinder[0].type.size.mliter = 11100; stagingDive->cylinder[0].type.workingpressure.mbar = 207000; - stagingDive->cylinder[0].used = true; } } } diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 2228c8e5e..340276059 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -286,8 +286,7 @@ void CylindersModel::add() int row = rows; fill_default_cylinder(¤t->cylinder[row]); - // mark the cylinder as 'used' since it was manually added - current->cylinder[row].used = true; + current->cylinder[row].manually_added = true; beginInsertRows(QModelIndex(), row, row); rows++; changed = true; @@ -316,9 +315,8 @@ void CylindersModel::setDive(dive *d) rows = 0; for (int i = 0; i < MAX_CYLINDERS; i++) { if (!cylinder_none(&d->cylinder[i]) && - (prefs.display_unused_tanks || d->cylinder[i].used)) { + (prefs.display_unused_tanks || cylinder_is_used(d, &d->cylinder[i]) || d->cylinder[i].manually_added)) rows = i + 1; - } } current = d; changed = false; @@ -334,8 +332,7 @@ void CylindersModel::copyFromDive(dive *d) return; rows = 0; for (int i = 0; i < MAX_CYLINDERS; i++) { - if (!cylinder_none(&d->cylinder[i]) && - (prefs.display_unused_tanks || d->cylinder[i].used)) { + if (!cylinder_none(&d->cylinder[i]) && cylinder_is_used(d, &d->cylinder[i])) { rows = i + 1; } } @@ -360,9 +357,10 @@ void CylindersModel::remove(const QModelIndex &index) cylinder_t *cyl = ¤t->cylinder[index.row()]; if ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING && DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) || - (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && cyl->used)) { + (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && + (cyl->manually_added || (current_dive && cylinder_is_used(current_dive, cyl))))) { QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT( - tr("Cylinder cannot be removed"), + tr("Cylinder cannot be removed"), tr("This gas in use. Only cylinders that are not used in the dive can be removed.")), QMessageBox::Ok); return; |