aboutsummaryrefslogtreecommitdiffstats
path: root/core/subsurface-qt/DiveObjectHelper.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-22 22:10:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-23 13:22:24 -0800
commit68414531adeb68f7ad01c98bbac4d4d950409f02 (patch)
treeb1cf1d28c5d779c5e5e17b90b92b0ca03913b40f /core/subsurface-qt/DiveObjectHelper.cpp
parenta863386cd4c6260d14b1d7f5fbf7e3a21e580aaa (diff)
downloadsubsurface-68414531adeb68f7ad01c98bbac4d4d950409f02.tar.gz
Mobile: don't format trip heading for all dives
QML's ListView uses the "section" property to test if items belong to the same section. Apparently, this must be a string and therefore we can't pass e.g. a dive-trip object. Therefore a specially formatted string was passed in, which was guaranteed to be unique (contained the dive-trip pointer value) and the fully formatted trip-title and short-date. The disadvantage of that approach is that the formatting is performed for every dive and not every trip. Perhaps not a problem now, but it makes it for example necessary to cache the number of filtered dives. To be more flexible, pass in only the pointer value formatted as hexadecimal string and provide a function to convert that string back to a trip-pointer (in the form of a QVariant, so that it can be passed to QML). Moreover provide two functions for formatting the title and the short-date. The three new functions are members of DiveListSortModel. This might not be the perfect place, but it is easy to reach from the DiveListView. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/subsurface-qt/DiveObjectHelper.cpp')
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp37
1 files changed, 3 insertions, 34 deletions
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index e522e3e39..e8e11e7d9 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -324,40 +324,9 @@ QList<CylinderObjectHelper*> DiveObjectHelper::cylinderObjects() const
return m_cyls;
}
-// combine the pointer address with the trip title so that
-// we detect multiple, destinct trips with the same title
-// the trip title is designed to be
-// location (# dives)
-// or, if there is no location name
-// date range (# dives)
-// where the date range is given as "month year" or "month-month year" or "month year - month year"
-QString DiveObjectHelper::tripMeta() const
-{
- QString ret = EMPTY_DIVE_STRING;
- struct dive_trip *dt = m_dive->divetrip;
- if (dt) {
- QString numDives = tr("(%n dive(s))", "", dt->showndives);
- QString title(dt->location);
- QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(dt), Qt::UTC);
- QString firstMonth = firstTime.toString("MMM");
- QString tripDate = QStringLiteral("%1@%2").arg(firstMonth,firstTime.toString("yy"));
-
- if (title.isEmpty()) {
- // so use the date range
- QString firstYear = firstTime.toString("yyyy");
- QDateTime lastTime = QDateTime::fromMSecsSinceEpoch(1000*dt->dives.dives[0]->when, Qt::UTC);
- QString lastMonth = lastTime.toString("MMM");
- QString lastYear = lastTime.toString("yyyy");
- if (lastMonth == firstMonth && lastYear == firstYear)
- title = firstMonth + " " + firstYear;
- else if (lastMonth != firstMonth && lastYear == firstYear)
- title = firstMonth + "-" + lastMonth + " " + firstYear;
- else
- title = firstMonth + " " + firstYear + " - " + lastMonth + " " + lastYear;
- }
- ret = QString::number((quint64)m_dive->divetrip, 16) + QLatin1Literal("++") + tripDate + QLatin1Literal("::") + QStringLiteral("%1 %2").arg(title, numDives);
- }
- return ret;
+QString DiveObjectHelper::tripId() const
+{
+ return m_dive->divetrip ? QString::number((quint64)m_dive->divetrip, 16) : QString();
}
int DiveObjectHelper::tripNrDives() const