aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/cylindermodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-08 08:49:12 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-19 13:11:10 -0700
commit38ba434966409987e5dfb894c27c8c03168cfdc6 (patch)
treee9e4d9721ada0f3c2040f49e3c062b49ba6824e0 /qt-models/cylindermodel.cpp
parent54d6c3f004f27a813f4b0adf48927aca5cb79cd1 (diff)
downloadsubsurface-38ba434966409987e5dfb894c27c8c03168cfdc6.tar.gz
Cleanup: return directly from data() methods
There is this anti-pattern in QModel data() functions to assign to a "ret" variable and return at the end of the function. This is inefficient, as the object is not directly constructed at the space reserved by the caller. Change the functions in WeightModel and CylinderModel to return the objects directly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/cylindermodel.cpp')
-rw-r--r--qt-models/cylindermodel.cpp69
1 files changed, 27 insertions, 42 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 52adda753..0e5388818 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -132,10 +132,8 @@ static QVariant percent_string(fraction_t fraction)
QVariant CylindersModel::data(const QModelIndex &index, int role) const
{
- QVariant ret;
-
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
- return ret;
+ return QVariant();
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
@@ -151,7 +149,7 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
endp = cyl->end.mbar ? cyl->end : cyl->sample_end;
if ((startp.mbar && !endp.mbar) ||
(endp.mbar && startp.mbar <= endp.mbar))
- ret = REDORANGE1_HIGH_TRANS;
+ return REDORANGE1_HIGH_TRANS;
break;
}
break;
@@ -167,65 +165,57 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
font.setItalic(!cyl->end.mbar);
break;
}
- ret = font;
- break;
+ return font;
}
case Qt::TextAlignmentRole:
- ret = Qt::AlignCenter;
- break;
+ return Qt::AlignCenter;
case Qt::DisplayRole:
case Qt::EditRole:
switch (index.column()) {
case TYPE:
- ret = QString(cyl->type.description);
- break;
+ return QString(cyl->type.description);
case SIZE:
if (cyl->type.size.mliter)
- ret = get_cylinder_string(cyl);
+ return get_cylinder_string(cyl);
break;
case WORKINGPRESS:
if (cyl->type.workingpressure.mbar)
- ret = get_pressure_string(cyl->type.workingpressure, true);
+ return get_pressure_string(cyl->type.workingpressure, true);
break;
case START:
if (cyl->start.mbar)
- ret = get_pressure_string(cyl->start, true);
+ return get_pressure_string(cyl->start, true);
else if (cyl->sample_start.mbar)
- ret = get_pressure_string(cyl->sample_start, true);
+ return get_pressure_string(cyl->sample_start, true);
break;
case END:
if (cyl->end.mbar)
- ret = get_pressure_string(cyl->end, true);
+ return get_pressure_string(cyl->end, true);
else if (cyl->sample_end.mbar)
- ret = get_pressure_string(cyl->sample_end, true);
+ return get_pressure_string(cyl->sample_end, true);
break;
case O2:
- ret = percent_string(cyl->gasmix.o2);
- break;
+ return percent_string(cyl->gasmix.o2);
case HE:
- ret = percent_string(cyl->gasmix.he);
- break;
+ return percent_string(cyl->gasmix.he);
case DEPTH:
- ret = get_depth_string(cyl->depth, true);
- break;
+ return get_depth_string(cyl->depth, true);
case MOD:
if (cyl->bestmix_o2) {
- ret = QString("*");
+ return QStringLiteral("*");
} else {
pressure_t modpO2;
modpO2.mbar = prefs.bottompo2;
- ret = get_depth_string(gas_mod(cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(1,1)), true);
+ return get_depth_string(gas_mod(cyl->gasmix, modpO2, &displayed_dive, M_OR_FT(1,1)), true);
}
- break;
case MND:
if (cyl->bestmix_he)
- ret = QString("*");
+ return QStringLiteral("*");
else
- ret = get_depth_string(gas_mnd(cyl->gasmix, prefs.bestmixend, &displayed_dive, M_OR_FT(1,1)), true);
+ return get_depth_string(gas_mnd(cyl->gasmix, prefs.bestmixend, &displayed_dive, M_OR_FT(1,1)), true);
break;
case USE:
- ret = gettextFromC::tr(cylinderuse_text[cyl->cylinder_use]);
- break;
+ return gettextFromC::tr(cylinderuse_text[cyl->cylinder_use]);
}
break;
case Qt::DecorationRole:
@@ -233,21 +223,19 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
if (index.column() == REMOVE) {
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
- ret = trashForbiddenIcon();
+ return trashForbiddenIcon();
}
- else ret = trashIcon();
+ return trashIcon();
}
break;
-
case Qt::ToolTipRole:
switch (index.column()) {
case REMOVE:
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
(!in_planner() && is_cylinder_prot(&displayed_dive, index.row()))) {
- ret = tr("This gas is in use. Only cylinders that are not used in the dive can be removed.");
+ return 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;
+ return tr("Clicking here will remove this cylinder.");
case TYPE:
case SIZE:
return gas_usage_tooltip(cyl);
@@ -258,19 +246,16 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case END:
return gas_end_tooltip(cyl);
case DEPTH:
- ret = tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
- break;
+ return tr("Switch depth for deco gas. Calculated using Deco pO₂ preference, unless set manually.");
case MOD:
- ret = tr("Calculated using Bottom pO₂ preference. Setting MOD adjusts O₂%, set to '*' for best O₂% for max. depth.");
- break;
+ return tr("Calculated using Bottom pO₂ preference. Setting MOD adjusts O₂%, set to '*' for best O₂% for max. depth.");
case MND:
- ret = tr("Calculated using Best Mix END preference. Setting MND adjusts He%, set to '*' for best He% for max. depth.");
- break;
+ return tr("Calculated using Best Mix END preference. Setting MND adjusts He%, set to '*' for best He% for max. depth.");
}
break;
}
- return ret;
+ return QVariant();
}
cylinder_t *CylindersModel::cylinderAt(const QModelIndex &index)