mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
b11af5a1ce
commit
ac52034778
1 changed files with 42 additions and 19 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue