summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-11 21:31:56 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-09 12:41:11 -0700
commit89f84578570112dc82cc194c3b0daedd5e660bc5 (patch)
treef13202e0a4c9635ee8e020c9ae5be7a2bdb381c6 /qt-models/divetripmodel.cpp
parentc5d17c3d4ddd61a3d0938b3290d002fe6b7622d0 (diff)
downloadsubsurface-89f84578570112dc82cc194c3b0daedd5e660bc5.tar.gz
mobile/divelist: implement trip title and short date for mobile
We pass this through to the underlying data function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/divetripmodel.cpp')
-rw-r--r--qt-models/divetripmodel.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 98868ee40..6c1a7218a 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -58,6 +58,42 @@ static QVariant dive_table_alignment(int column)
return QVariant();
}
+QString DiveTripModelBase::tripShortDate(const dive_trip *trip)
+{
+ if (!trip)
+ return QString();
+ QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(trip), Qt::UTC);
+ QString firstMonth = firstTime.toString("MMM");
+ return QStringLiteral("%1\n'%2").arg(firstMonth,firstTime.toString("yy"));
+}
+
+QString DiveTripModelBase::tripTitle(const dive_trip *trip)
+{
+ if (!trip)
+ return QString();
+ QString numDives = tr("(%n dive(s))", "", trip->dives.nr);
+ int shown = trip_shown_dives(trip);
+ QString shownDives = shown != trip->dives.nr ? QStringLiteral(" ") + tr("(%L1 shown)").arg(shown) : QString();
+ QString title(trip->location);
+
+ if (title.isEmpty()) {
+ // so use the date range
+ QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(trip), Qt::UTC);
+ QString firstMonth = firstTime.toString("MMM");
+ QString firstYear = firstTime.toString("yyyy");
+ QDateTime lastTime = QDateTime::fromMSecsSinceEpoch(1000*trip->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;
+ }
+ return QStringLiteral("%1 %2%3").arg(title, numDives, shownDives);
+}
+
QVariant DiveTripModelBase::tripData(const dive_trip *trip, int column, int role)
{
#ifdef SUBSURFACE_MOBILE
@@ -65,6 +101,8 @@ QVariant DiveTripModelBase::tripData(const dive_trip *trip, int column, int role
switch(role) {
case MobileListModel::TripIdRole: return QString::number(trip->id);
case MobileListModel::TripNrDivesRole: return trip->dives.nr;
+ case MobileListModel::TripShortDateRole: return tripShortDate(trip);
+ case MobileListModel::TripTitleRole: return tripTitle(trip);
}
#endif