Ok, this is my second try :) I should have fixed coding style issues and I used QString to have the right localization of the trip header.
G 2015-10-05 7:50 GMT+02:00 Giorgio Marzano <[email protected]>: > Agree (I am from Italy). > > Do localization tools provide info on the date format? > > Otherwise "yyyy mm dd" which matches lexicographic and chronological > sorting could be an idea > On Sun, Oct 04, 2015 at 05:00:02AM -0700, Giorgio Marzano wrote: > > Hi, all > > could someone please explain me the workflow to propose, discuss and > implement a change? > > I'd strongly suggest doing that on the developer mailing list, not in the > user forum. > > > Let's say I have a change to propose: to improve readability I would like > the trips with duration < 1 day to be displayed in the form "Month Day Year > (dives)" instead of "Month Year (dives)" > > > > Please, please do not make this a USA-specific format. Any normal European > will scream at you. > Kind regards, > willem >
From 29fde2898e04f839319e65d84092a6cb5e76a7f4 Mon Sep 17 00:00:00 2001 From: Giorgio Marzano <[email protected]> Date: Sun, 4 Oct 2015 13:48:10 +0200 Subject: [PATCH] make trips shorter than 1 day displayed as "Month Day Year" This improves readability in the case that many trip refer to the same month. Signed-off-by: Giorgio Marzano <[email protected]> --- helpers.h | 3 ++- qt-models/divetripmodel.cpp | 8 +++++--- qthelper.cpp | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/helpers.h b/helpers.h index 6c5c31c..760d962 100644 --- a/helpers.h +++ b/helpers.h @@ -33,7 +33,8 @@ int parseTemperatureToMkelvin(const QString &text); QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText); QString get_dive_date_string(timestamp_t when); QString get_short_dive_date_string(timestamp_t when); -QString get_trip_date_string(timestamp_t when, int nr); +bool is_same_day (timestamp_t trip_when, timestamp_t dive_when); +QString get_trip_date_string(timestamp_t when, int nr, bool getday); QString uiLanguage(QLocale *callerLoc); QLocale getLocale(); QString getDateFormat(); diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index fcba4a5..31d62ce 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -43,6 +43,7 @@ static QVariant dive_table_alignment(int column) QVariant TripItem::data(int column, int role) const { QVariant ret; + bool oneDayTrip=true; if (role == DiveTripModel::TRIP_ROLE) return QVariant::fromValue<void *>(trip); @@ -59,14 +60,15 @@ QVariant TripItem::data(int column, int role) const while (d) { if (!d->hidden_by_filter) countShown++; - d = d->next; + oneDayTrip &= is_same_day (trip->when, d->when); + d = d->next; } if (countShown < trip->nrdives) shownText = tr(" (%1 shown)").arg(countShown); if (trip->location && *trip->location) - ret = QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->nrdives) + shownText; + ret = QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + shownText; else - ret = get_trip_date_string(trip->when, trip->nrdives) + shownText; + ret = get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + shownText; break; } } diff --git a/qthelper.cpp b/qthelper.cpp index ed23948..4767be9 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1028,20 +1028,42 @@ const char *get_dive_date_c_string(timestamp_t when) return strdup(text.toUtf8().data()); } -QString get_trip_date_string(timestamp_t when, int nr) +bool is_same_day(timestamp_t trip_when, timestamp_t dive_when) +{ + static timestamp_t twhen = (timestamp_t) 0; + static struct tm tmt; + struct tm tmd; + + utc_mkdate(dive_when, &tmd); + + if (twhen != trip_when) { + twhen = trip_when; + utc_mkdate(twhen, &tmt); + } + + return ((tmd.tm_mday == tmt.tm_mday) && (tmd.tm_mon == tmt.tm_mon) + && (tmd.tm_year == tmt.tm_year)); +} + +QString get_trip_date_string(timestamp_t when, int nr, bool getday) { struct tm tm; utc_mkdate(when, &tm); + QDateTime localTime = QDateTime::fromTime_t(when); + localTime.setTimeSpec(Qt::UTC); + QString ret ; + if (nr != 1) { - QString ret = translate("gettextFromC", "%1 %2 (%3 dives)"); - return ret.arg(monthname(tm.tm_mon)) - .arg(tm.tm_year + 1900) - .arg(nr); + if (getday) { + ret = localTime.date().toString(dateFormat).append(" (%1 dives)").arg(nr); + } else { + ret = localTime.date().toString("MMM yy").append(" (%1 dives)").arg(nr); + } } else { - QString ret = translate("gettextFromC", "%1 %2 (1 dive)"); - return ret.arg(monthname(tm.tm_mon)) - .arg(tm.tm_year + 1900); + ret = localTime.date().toString(dateFormat).append(" (1 dive)"); } + return ret; + } extern "C" void reverseGeoLookup(degrees_t latitude, degrees_t longitude, uint32_t uuid) -- 1.9.1
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
