mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: return value type from WeightModel::weightSystemAt()
There is only one caller of WeightModel::weightSystemAt() and that certainly does not need a pointer into the weightsystem-table of the current dive. Return a value type instead of a pointer. This allows us to mark WeightModel::weightSystemAt() as const and use it from WeightModel::data(). Slightly cleaner code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b3f530bfb9
commit
2cfb35b6d7
3 changed files with 7 additions and 7 deletions
|
@ -371,9 +371,9 @@ QWidget *WSInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
||||||
/* First, call the combobox-create editor, it will setup our globals. */
|
/* First, call the combobox-create editor, it will setup our globals. */
|
||||||
QWidget *editor = ComboBoxDelegate::createEditor(parent, option, index);
|
QWidget *editor = ComboBoxDelegate::createEditor(parent, option, index);
|
||||||
WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
|
WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model);
|
||||||
weightsystem_t *ws = mymodel->weightSystemAt(index);
|
weightsystem_t ws = mymodel->weightSystemAt(index);
|
||||||
currWeight.type = ws->description;
|
currWeight.type = ws.description;
|
||||||
currWeight.weight = ws->weight.grams;
|
currWeight.weight = ws.weight.grams;
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,14 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
||||||
connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved);
|
connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
|
weightsystem_t WeightModel::weightSystemAt(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
if (row < 0 || row >= d->weightsystems.nr) {
|
if (row < 0 || row >= d->weightsystems.nr) {
|
||||||
qWarning("WeightModel: Accessing invalid weightsystem %d (of %d)", row, d->weightsystems.nr);
|
qWarning("WeightModel: Accessing invalid weightsystem %d (of %d)", row, d->weightsystems.nr);
|
||||||
return nullptr;
|
return { { 0 }, nullptr };
|
||||||
}
|
}
|
||||||
return &d->weightsystems.weightsystems[index.row()];
|
return d->weightsystems.weightsystems[index.row()];
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::clear()
|
void WeightModel::clear()
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void passInData(const QModelIndex &index, const QVariant &value);
|
void passInData(const QModelIndex &index, const QVariant &value);
|
||||||
void clear();
|
void clear();
|
||||||
void updateDive(dive *d);
|
void updateDive(dive *d);
|
||||||
weightsystem_t *weightSystemAt(const QModelIndex &index);
|
weightsystem_t weightSystemAt(const QModelIndex &index);
|
||||||
bool changed;
|
bool changed;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
Loading…
Add table
Reference in a new issue