mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
c5d17c3d4d
commit
89f8457857
3 changed files with 42 additions and 0 deletions
|
@ -58,6 +58,42 @@ static QVariant dive_table_alignment(int column)
|
||||||
return QVariant();
|
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)
|
QVariant DiveTripModelBase::tripData(const dive_trip *trip, int column, int role)
|
||||||
{
|
{
|
||||||
#ifdef SUBSURFACE_MOBILE
|
#ifdef SUBSURFACE_MOBILE
|
||||||
|
@ -65,6 +101,8 @@ QVariant DiveTripModelBase::tripData(const dive_trip *trip, int column, int role
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case MobileListModel::TripIdRole: return QString::number(trip->id);
|
case MobileListModel::TripIdRole: return QString::number(trip->id);
|
||||||
case MobileListModel::TripNrDivesRole: return trip->dives.nr;
|
case MobileListModel::TripNrDivesRole: return trip->dives.nr;
|
||||||
|
case MobileListModel::TripShortDateRole: return tripShortDate(trip);
|
||||||
|
case MobileListModel::TripTitleRole: return tripTitle(trip);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,8 @@ protected:
|
||||||
// Access trip and dive data
|
// Access trip and dive data
|
||||||
static QVariant diveData(const struct dive *d, int column, int role);
|
static QVariant diveData(const struct dive *d, int column, int role);
|
||||||
static QVariant tripData(const dive_trip *trip, int column, int role);
|
static QVariant tripData(const dive_trip *trip, int column, int role);
|
||||||
|
static QString tripTitle(const dive_trip *trip);
|
||||||
|
static QString tripShortDate(const dive_trip *trip);
|
||||||
void currentChanged();
|
void currentChanged();
|
||||||
|
|
||||||
virtual dive *diveOrNull(const QModelIndex &index) const = 0; // Returns a dive if this index represents a dive, null otherwise
|
virtual dive *diveOrNull(const QModelIndex &index) const = 0; // Returns a dive if this index represents a dive, null otherwise
|
||||||
|
|
|
@ -12,6 +12,8 @@ public:
|
||||||
DiveDateRole,
|
DiveDateRole,
|
||||||
TripIdRole,
|
TripIdRole,
|
||||||
TripNrDivesRole,
|
TripNrDivesRole,
|
||||||
|
TripShortDateRole,
|
||||||
|
TripTitleRole,
|
||||||
DateTimeRole,
|
DateTimeRole,
|
||||||
IdRole,
|
IdRole,
|
||||||
NumberRole,
|
NumberRole,
|
||||||
|
|
Loading…
Add table
Reference in a new issue