diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 12:38:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-01 12:43:40 -0700 |
commit | c539c8f861928c637f6b3e790b05e89914e2be8f (patch) | |
tree | 9728f8d08279bbe98fa8afdec73de9de1d55b66a /qt-ui/models.cpp | |
parent | 1a040134538b7733f3088ea34f101cfedecc2c64 (diff) | |
download | subsurface-c539c8f861928c637f6b3e790b05e89914e2be8f.tar.gz |
Remove the .used member of the cylinder structure
Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.
There is one wrinkle to this - previously we abused the '.used' member to
make sure that a manually added cylinder didn't disappear the moment it
was added (think of the workflow: you add a cylinder, then you add a gas
change to that cylinder -> right after you add it it is unused and would
not be shown).
I am thinking that we might have to add the "manually_added" property to
the properties that we store in XML / git.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
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; |