Mobile: return depthDuration directly from DiveListModel

We don't want to generate a DiveObjectHelper numerous times for
every item in the dive list. Therefore, return this data directly
from the model. In this case, don't remove from DiveObjectHelper,
as these data might be used by grantlee templates.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-15 00:30:56 +02:00 committed by bstoeger
parent c4831d7ace
commit a79c45e401
3 changed files with 5 additions and 1 deletions

View file

@ -178,7 +178,7 @@ Kirigami.ScrollablePage {
} }
// let's try to show the depth / duration very compact // let's try to show the depth / duration very compact
Controls.Label { Controls.Label {
text: dive.depth + ' / ' + dive.duration text: depthDuration
width: Math.max(Kirigami.Units.gridUnit * 3, paintedWidth) // helps vertical alignment throughout listview width: Math.max(Kirigami.Units.gridUnit * 3, paintedWidth) // helps vertical alignment throughout listview
font.pointSize: subsurfaceTheme.smallPointSize font.pointSize: subsurfaceTheme.smallPointSize
color: innerListItem.checked ? subsurfaceTheme.darkerPrimaryTextColor : secondaryTextColor color: innerListItem.checked ? subsurfaceTheme.darkerPrimaryTextColor : secondaryTextColor

View file

@ -257,6 +257,8 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
case IdRole: return d->id; case IdRole: return d->id;
case NumberRole: return d->number; case NumberRole: return d->number;
case LocationRole: return get_dive_location(d); case LocationRole: return get_dive_location(d);
case DepthDurationRole: return QStringLiteral("%1 / %2").arg(get_depth_string(d->dc.maxdepth.mm, true, true),
get_dive_duration_string(d->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min")));
} }
return QVariant(); return QVariant();
} }
@ -272,6 +274,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
roles[IdRole] = "id"; roles[IdRole] = "id";
roles[NumberRole] = "number"; roles[NumberRole] = "number";
roles[LocationRole] = "location"; roles[LocationRole] = "location";
roles[DepthDurationRole] = "depthDuration";
return roles; return roles;
} }

View file

@ -44,6 +44,7 @@ public:
IdRole, IdRole,
NumberRole, NumberRole,
LocationRole, LocationRole,
DepthDurationRole,
}; };
static DiveListModel *instance(); static DiveListModel *instance();