aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-15 00:11:39 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-09-14 13:20:59 +0200
commitc6b3309d1360e329252f5ab4c9dc7f345ea22694 (patch)
tree374df8301d26eba1de680bd1287776c649518643 /qt-models
parent54720e6cff65ae860fb78431324b75203e71809a (diff)
downloadsubsurface-c6b3309d1360e329252f5ab4c9dc7f345ea22694.tar.gz
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>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divelistmodel.cpp10
-rw-r--r--qt-models/divelistmodel.h1
2 files changed, 10 insertions, 1 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 15934f9d6..b41a16003 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -241,14 +241,21 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
DiveObjectHelper *curr_dive = m_dives[index.row()];
const dive *d = curr_dive->getDive();
+ if (!d)
+ return QVariant();
switch(role) {
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
case TripIdRole: return d->divetrip ? QString::number((quint64)d->divetrip, 16) : QString();
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();
-
}
QHash<int, QByteArray> DiveListModel::roleNames() const
@@ -258,6 +265,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
roles[DiveDateRole] = "date";
roles[TripIdRole] = "tripId";
roles[TripNrDivesRole] = "tripNrDives";
+ roles[DateTimeRole] = "dateTime";
return roles;
}
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index e799ecf8a..c0d7aa0a0 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -40,6 +40,7 @@ public:
DiveDateRole,
TripIdRole,
TripNrDivesRole,
+ DateTimeRole
};
static DiveListModel *instance();