summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/cylindermodel.cpp36
-rw-r--r--qt-models/diveplannermodel.cpp19
2 files changed, 24 insertions, 31 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index d0675ed8a..545341c78 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -139,7 +139,6 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
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: {
@@ -233,15 +232,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
case Qt::SizeHintRole:
if (index.column() == REMOVE) {
- 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;
- }
+ same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
+
if ((in_planner() || same_gas == -1) &&
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
@@ -256,15 +248,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case Qt::ToolTipRole:
switch (index.column()) {
case REMOVE:
- 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;
- }
+ same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
+
if ((in_planner() || same_gas == -1) &&
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
@@ -558,17 +543,9 @@ void CylindersModel::remove(const QModelIndex &index)
if (index.column() != REMOVE) {
return;
}
- int same_gas = -1;
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
- struct gasmix *mygas = &cyl->gasmix;
- 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;
- }
+ int same_gas = same_gasmix_cylinder(cyl, index.row(), &displayed_dive, false);
+
if ((in_planner() || same_gas == -1) &&
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
@@ -604,6 +581,7 @@ void CylindersModel::remove(const QModelIndex &index)
dc_cylinder_renumber(&displayed_dive, dc, mapping);
dc = dc->next;
}
+ dataChanged(index, index);
}
void CylindersModel::updateDecoDepths(pressure_t olddecopo2)
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 482647575..57866b9e8 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -181,7 +181,14 @@ QStringList &DivePlannerPointsModel::getGasList()
cylinder_t *cyl = &displayed_dive.cylinder[i];
if (cylinder_nodata(cyl))
break;
- list.push_back(get_gas_string(cyl->gasmix));
+ /* Check if we have the same gasmix two or more times
+ * If yes return more verbose string */
+ int same_gas = same_gasmix_cylinder(cyl, i, &displayed_dive, true);
+ if (same_gas == -1)
+ list.push_back(get_gas_string(cyl->gasmix));
+ else
+ list.push_back(get_gas_string(cyl->gasmix) + QString(" (%1 %2 ").arg(tr("cyl.")).arg(i + 1) +
+ cyl->type.description + ")");
}
return list;
}
@@ -258,7 +265,15 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
else
return p.time / 60;
case GAS:
- return get_gas_string(displayed_dive.cylinder[p.cylinderid].gasmix);
+ /* Check if we have the same gasmix two or more times
+ * If yes return more verbose string */
+ int same_gas = same_gasmix_cylinder(&displayed_dive.cylinder[p.cylinderid], p.cylinderid, &displayed_dive, true);
+ if (same_gas == -1)
+ return get_gas_string(displayed_dive.cylinder[p.cylinderid].gasmix);
+ else
+ return get_gas_string(displayed_dive.cylinder[p.cylinderid].gasmix) +
+ QString(" (%1 %2 ").arg(tr("cyl.")).arg(p.cylinderid + 1) +
+ displayed_dive.cylinder[p.cylinderid].type.description + ")";
}
} else if (role == Qt::DecorationRole) {
switch (index.column()) {