diff options
author | Stefan Fuchs <sfuchs@gmx.de> | 2017-03-11 10:39:48 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-03-11 16:01:53 -0800 |
commit | ac52034778bc5c82bb6c689d765b337b6d75b24a (patch) | |
tree | 6eb2f124bbcce00f6db8da412cbc355118b00568 /qt-models | |
parent | b11af5a1ce3982b2942c37829ad4ab5de1c32a0a (diff) | |
download | subsurface-ac52034778bc5c82bb6c689d765b337b6d75b24a.tar.gz |
Correct trash or trashforbidden icon and tooltip in cylinder table
Display the correct trash or trashforbidden icon and tooltip in the cylinder table.
This should fit together with if it is really possible to remove a cylinder.
Search for "same gas" based on used cylinders only. Otherwise one could remove
a used cylinder because there is an unused cylinder with same gas.
ToDo:
In planner update trash icon on change of planner points.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/cylindermodel.cpp | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index 12cf0dd2c..ad6c502a5 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -134,8 +134,12 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() >= MAX_CYLINDERS) return ret; - + + int mapping[MAX_CYLINDERS]; + int same_gas = -1; cylinder_t *cyl = &displayed_dive.cylinder[index.row()]; + struct gasmix *mygas = &cyl->gasmix; + switch (role) { case Qt::BackgroundRole: { switch (index.column()) { @@ -222,26 +226,48 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const } break; case Qt::DecorationRole: - if (index.column() == REMOVE) { - if (rowCount() > 1) - ret = trashIcon(); - else - ret = trashForbiddenIcon(); - } - break; case Qt::SizeHintRole: if (index.column() == REMOVE) { - if (rowCount() > 1) - ret = trashIcon(); - else - ret = trashForbiddenIcon(); + same_gas = -1; + for (int i = 0; i < MAX_CYLINDERS; i++) { + mapping[i] = 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 && is_cylinder_used(&displayed_dive, i)) + same_gas = i; + } + if (same_gas == -1 && + ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING && + DivePlannerPointsModel::instance()->tankInUse(index.row())) || + (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && + is_cylinder_used(&displayed_dive, index.row())))) { + ret = trashForbiddenIcon(); + } + else ret = trashIcon(); } break; case Qt::ToolTipRole: switch (index.column()) { case REMOVE: - ret = tr("Clicking here will remove this cylinder."); + same_gas = -1; + for (int i = 0; i < MAX_CYLINDERS; i++) { + mapping[i] = 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 && is_cylinder_used(&displayed_dive, i)) + same_gas = i; + } + if (same_gas == -1 && + ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING && + DivePlannerPointsModel::instance()->tankInUse(index.row())) || + (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && + is_cylinder_used(&displayed_dive, index.row())))) { + ret = tr("This gas is in use. Only cylinders that are not used in the dive can be removed."); + } + else ret = tr("Clicking here will remove this cylinder."); break; case TYPE: case SIZE: @@ -519,19 +545,16 @@ void CylindersModel::remove(const QModelIndex &index) 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) + if (gasmix_distance(mygas, gas2) == 0 && is_cylinder_used(&displayed_dive, i)) same_gas = i; } if (same_gas == -1 && ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING && DivePlannerPointsModel::instance()->tankInUse(index.row())) || (DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING && - is_cylinder_used(&displayed_dive, index.row())))) { - emit warningMessage(TITLE_OR_TEXT( - tr("Cylinder cannot be removed"), - tr("This gas is in use. Only cylinders that are not used in the dive can be removed."))); + is_cylinder_used(&displayed_dive, index.row())))) return; - } + beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly. rows--; // if we didn't find an identical gas, point same_gas at the index.row() |