diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-13 21:45:54 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-13 21:56:22 +0900 |
commit | d7fb6853a30d430d73df9d1b076ea194ddeacac2 (patch) | |
tree | a2f33260f6d8bff8c30a8c5cdc7944682aa1fdce /qt-ui/models.cpp | |
parent | aa76d3592361ec7b07a8fc15fd466bcd392629ec (diff) | |
download | subsurface-d7fb6853a30d430d73df9d1b076ea194ddeacac2.tar.gz |
Connect changes in the tanks with the dive that is being added
- you can no longer delete a tank when its gas is in use
- therefore you can no longer delete the last tank
- when you change the gas mix of a tank, the corresponding segments in the
dive change as well
- when changing gas for a segment the correct available gases are offered
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 2a9208389..51faa0670 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -5,6 +5,8 @@ * */ #include "models.h" +#include "diveplanner.h" +#include "mainwindow.h" #include "../helpers.h" #include "../dive.h" #include "../device.h" @@ -17,6 +19,7 @@ #include <QBrush> #include <QFont> #include <QIcon> +#include <QMessageBox> QFont defaultModelFont() { @@ -196,6 +199,10 @@ void CylindersModel::passInData(const QModelIndex& index, const QVariant& value) bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role) { + bool addDiveMode = DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING; + if (addDiveMode) + DivePlannerPointsModel::instance()->rememberTanks(); + cylinder_t *cyl = cylinderAt(index); switch(index.column()) { case TYPE: @@ -296,6 +303,8 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in } } dataChanged(index, index); + if (addDiveMode) + DivePlannerPointsModel::instance()->tanksUpdated(); return true; } @@ -311,7 +320,7 @@ void CylindersModel::add() } int row = rows; - + fill_default_cylinder(¤t->cylinder[row]); beginInsertRows(QModelIndex(), row, row); rows++; changed = true; @@ -366,6 +375,14 @@ void CylindersModel::remove(const QModelIndex& index) if (index.column() != REMOVE) { return; } + cylinder_t *cyl = ¤t->cylinder[index.row()]; + if (DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) { + QMessageBox::warning(mainWindow(), + 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; + } beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly. rows--; remove_cylinder(current, index.row()); |