mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
54d6c3f004
commit
38ba434966
3 changed files with 41 additions and 68 deletions
|
@ -24,9 +24,8 @@ weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
|
|||
|
||||
void WeightModel::remove(const QModelIndex &index)
|
||||
{
|
||||
if (index.column() != REMOVE) {
|
||||
if (index.column() != REMOVE)
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
||||
rows--;
|
||||
remove_weightsystem(&displayed_dive, index.row());
|
||||
|
@ -44,44 +43,36 @@ void WeightModel::clear()
|
|||
|
||||
QVariant WeightModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QVariant ret;
|
||||
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
|
||||
return ret;
|
||||
return QVariant();
|
||||
|
||||
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
||||
|
||||
switch (role) {
|
||||
case Qt::FontRole:
|
||||
ret = defaultModelFont();
|
||||
break;
|
||||
return defaultModelFont();
|
||||
case Qt::TextAlignmentRole:
|
||||
ret = Qt::AlignCenter;
|
||||
break;
|
||||
return Qt::AlignCenter;
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
switch (index.column()) {
|
||||
case TYPE:
|
||||
ret = gettextFromC::tr(ws->description);
|
||||
break;
|
||||
return gettextFromC::tr(ws->description);
|
||||
case WEIGHT:
|
||||
ret = get_weight_string(ws->weight, true);
|
||||
break;
|
||||
return get_weight_string(ws->weight, true);
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == REMOVE)
|
||||
ret = trashIcon();
|
||||
break;
|
||||
return trashIcon();
|
||||
case Qt::SizeHintRole:
|
||||
if (index.column() == REMOVE)
|
||||
ret = trashIcon().size();
|
||||
break;
|
||||
return trashIcon().size();
|
||||
case Qt::ToolTipRole:
|
||||
if (index.column() == REMOVE)
|
||||
ret = tr("Clicking here will remove this weight system.");
|
||||
break;
|
||||
return tr("Clicking here will remove this weight system.");
|
||||
}
|
||||
return ret;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// this is our magic 'pass data in' function that allows the delegate to get
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue