Mobile: create DiveObjectHelper only when needed

In DiveListModel::data() a DiveObjectHelper was created for any
data-access. Create it only when a DiveObjectHelper is actually
returned.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-13 21:05:55 +02:00 committed by bstoeger
parent a4f3580e10
commit ca939300e2

View file

@ -197,12 +197,11 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
if(index.row() < 0 || index.row() >= dive_table.nr) if(index.row() < 0 || index.row() >= dive_table.nr)
return QVariant(); return QVariant();
DiveObjectHelper curr_dive(dive_table.dives[index.row()]); dive *d = dive_table.dives[index.row()];
const dive *d = curr_dive.getDive();
if (!d) if (!d)
return QVariant(); return QVariant();
switch(role) { switch(role) {
case DiveRole: return QVariant::fromValue<DiveObjectHelper>(curr_dive); case DiveRole: return QVariant::fromValue(DiveObjectHelper(d));
case DiveDateRole: return (qlonglong)d->when; case DiveDateRole: return (qlonglong)d->when;
case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString(); case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString();
case TripNrDivesRole: return d->divetrip ? d->divetrip->dives.nr : 0; case TripNrDivesRole: return d->divetrip ? d->divetrip->dives.nr : 0;