QML UI: sort by date, not by date string

Just a quick bit of cleanup to separate date (the sortable, numeric value)
from the date string that we want to display (but not sort by).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-24 11:17:48 -07:00
parent 0029844b1c
commit 7e7dcb2451
2 changed files with 27 additions and 10 deletions

View file

@ -13,8 +13,8 @@ MobileDive::MobileDive(dive *d)
//trip is valid //trip is valid
setTrip(trip->location); setTrip(trip->location);
} }
setDate(d->when);
setDate(get_dive_date_string(d->when)); setDateString(get_dive_date_string(d->when));
setDepth(get_depth_string(d->maxdepth)); setDepth(get_depth_string(d->maxdepth));
setDuration(get_dive_duration_string(d->duration.seconds, "h:","min")); setDuration(get_dive_duration_string(d->duration.seconds, "h:","min"));
@ -32,14 +32,24 @@ MobileDive::MobileDive(dive *d)
setDivemaster(d->divemaster); setDivemaster(d->divemaster);
} }
QString MobileDive::date() const QString MobileDive::dateString() const
{
return m_dateString;
}
void MobileDive::setDateString(const QString &date)
{
m_dateString = date;
}
timestamp_t MobileDive::date() const
{ {
return m_date; return m_date;
} }
void MobileDive::setDate(const QString &date) void MobileDive::setDate(timestamp_t when)
{ {
m_date = date; m_date = when;
} }
QString MobileDive::location() const QString MobileDive::location() const
@ -265,7 +275,9 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
else if (role == DiveTripRole) else if (role == DiveTripRole)
return dive.trip(); return dive.trip();
else if (role == DiveDateRole) else if (role == DiveDateRole)
return dive.date(); return (qlonglong)dive.date();
else if (role == DiveDateStringRole)
return dive.dateString();
else if (role == DiveRatingRole) else if (role == DiveRatingRole)
return dive.rating(); return dive.rating();
else if (role == DiveDepthRole) else if (role == DiveDepthRole)
@ -306,7 +318,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[DiveNumberRole] = "diveNumber"; roles[DiveNumberRole] = "diveNumber";
roles[DiveTripRole] = "trip"; roles[DiveTripRole] = "trip";
roles[DiveDateRole] = "date"; roles[DiveDateStringRole] = "date";
roles[DiveRatingRole] = "rating"; roles[DiveRatingRole] = "rating";
roles[DiveDepthRole] = "depth"; roles[DiveDepthRole] = "depth";
roles[DiveDurationRole] = "duration"; roles[DiveDurationRole] = "duration";

View file

@ -8,8 +8,11 @@ class MobileDive {
public: public:
MobileDive(dive* d); MobileDive(dive* d);
QString date() const; QString dateString() const;
void setDate(const QString &date); void setDateString(const QString &date);
timestamp_t date() const;
void setDate(const timestamp_t when);
QString location() const; QString location() const;
void setLocation(const QString &location); void setLocation(const QString &location);
@ -70,7 +73,8 @@ private:
QString m_diveNumber; QString m_diveNumber;
QString m_trip; QString m_trip;
QString m_date; timestamp_t m_date;
QString m_dateString;
QString m_rating; QString m_rating;
QString m_depth; QString m_depth;
QString m_duration; QString m_duration;
@ -100,6 +104,7 @@ public:
DiveNumberRole = Qt::UserRole + 1, DiveNumberRole = Qt::UserRole + 1,
DiveTripRole, DiveTripRole,
DiveDateRole, DiveDateRole,
DiveDateStringRole,
DiveRatingRole, DiveRatingRole,
DiveDepthRole, DiveDepthRole,
DiveDurationRole, DiveDurationRole,