mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Mobile: return dateTime 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:
parent
54720e6cff
commit
c6b3309d13
3 changed files with 11 additions and 2 deletions
|
@ -171,7 +171,7 @@ Kirigami.ScrollablePage {
|
||||||
|
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
id: dateLabel
|
id: dateLabel
|
||||||
text: dive.date + " " + dive.time
|
text: dateTime
|
||||||
width: Math.max(locationText.width * 0.45, paintedWidth) // helps vertical alignment throughout listview
|
width: Math.max(locationText.width * 0.45, 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
|
||||||
|
|
|
@ -241,14 +241,21 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
DiveObjectHelper *curr_dive = m_dives[index.row()];
|
DiveObjectHelper *curr_dive = m_dives[index.row()];
|
||||||
const dive *d = curr_dive->getDive();
|
const dive *d = curr_dive->getDive();
|
||||||
|
if (!d)
|
||||||
|
return QVariant();
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
||||||
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
||||||
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;
|
||||||
|
case DateTimeRole: {
|
||||||
|
QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000 * d->when, Qt::UTC);
|
||||||
|
localTime.setTimeSpec(Qt::UTC);
|
||||||
|
return QStringLiteral("%1 %2").arg(localTime.date().toString(prefs.date_format_short),
|
||||||
|
localTime.time().toString(prefs.time_format));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> DiveListModel::roleNames() const
|
QHash<int, QByteArray> DiveListModel::roleNames() const
|
||||||
|
@ -258,6 +265,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
|
||||||
roles[DiveDateRole] = "date";
|
roles[DiveDateRole] = "date";
|
||||||
roles[TripIdRole] = "tripId";
|
roles[TripIdRole] = "tripId";
|
||||||
roles[TripNrDivesRole] = "tripNrDives";
|
roles[TripNrDivesRole] = "tripNrDives";
|
||||||
|
roles[DateTimeRole] = "dateTime";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
DiveDateRole,
|
DiveDateRole,
|
||||||
TripIdRole,
|
TripIdRole,
|
||||||
TripNrDivesRole,
|
TripNrDivesRole,
|
||||||
|
DateTimeRole
|
||||||
};
|
};
|
||||||
|
|
||||||
static DiveListModel *instance();
|
static DiveListModel *instance();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue