mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Consistently show dive duration based on preferences
We now respect the settings in the preferences and also only show the duration as minutes and seconds if the dive is a free dive. Fixes #361 Fixes #362 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
876b479d69
commit
92d24a2912
3 changed files with 15 additions and 25 deletions
|
@ -36,7 +36,7 @@ int parseWeightToGrams(const QString &text);
|
|||
int parsePressureToMbar(const QString &text);
|
||||
int parseGasMixO2(const QString &text);
|
||||
int parseGasMixHE(const QString &text);
|
||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText);
|
||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText = "", bool isFreeDive = false);
|
||||
QString get_dive_date_string(timestamp_t when);
|
||||
QString get_short_dive_date_string(timestamp_t when);
|
||||
bool is_same_day (timestamp_t trip_when, timestamp_t dive_when);
|
||||
|
|
|
@ -924,19 +924,23 @@ int parseGasMixHE(const QString &text)
|
|||
return he;
|
||||
}
|
||||
|
||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText)
|
||||
QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive)
|
||||
{
|
||||
int hrs, mins;
|
||||
int hrs, mins, fullmins, secs;
|
||||
mins = (when + 59) / 60;
|
||||
fullmins = when / 60;
|
||||
secs = when - 60 * fullmins;
|
||||
hrs = mins / 60;
|
||||
mins -= hrs * 60;
|
||||
|
||||
QString displayTime;
|
||||
if (hrs)
|
||||
displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(minutesText);
|
||||
else
|
||||
displayTime = QString("%1%2").arg(mins).arg(minutesText);
|
||||
|
||||
if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) {
|
||||
mins -= hrs * 60;
|
||||
displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(hourText == ":" ? "" : minutesText);
|
||||
} else if (isFreeDive) {
|
||||
displayTime = QString("%1%2%3%4").arg(fullmins).arg(minutesText).arg(secs, 2, 10, QChar('0')).arg(secondsText);
|
||||
} else {
|
||||
displayTime = QString("%1%2").arg(mins).arg(hourText == ":" ? "" : minutesText);
|
||||
}
|
||||
return displayTime;
|
||||
}
|
||||
|
||||
|
@ -964,7 +968,7 @@ extern "C" const char *get_current_date()
|
|||
{
|
||||
QDateTime ts(QDateTime::currentDateTime());;
|
||||
QString current_date;
|
||||
|
||||
|
||||
current_date = loc.toString(ts, QString(prefs.date_format_short));
|
||||
|
||||
return strdup(current_date.toUtf8().data());
|
||||
|
|
|
@ -342,22 +342,8 @@ int DiveItem::countPhotos(dive *dive) const
|
|||
|
||||
QString DiveItem::displayDuration() const
|
||||
{
|
||||
int hrs, mins, fullmins, secs;
|
||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
mins = (dive->duration.seconds + 59) / 60;
|
||||
fullmins = dive->duration.seconds / 60;
|
||||
secs = dive->duration.seconds - 60 * fullmins;
|
||||
hrs = mins / 60;
|
||||
mins -= hrs * 60;
|
||||
|
||||
QString displayTime;
|
||||
if (hrs)
|
||||
displayTime = QString("%1:%2").arg(hrs).arg(mins, 2, 10, QChar('0'));
|
||||
else if (mins < 15 || dive->dc.divemode == FREEDIVE)
|
||||
displayTime = QString("%1m%2s").arg(fullmins).arg(secs, 2, 10, QChar('0'));
|
||||
else
|
||||
displayTime = QString("%1").arg(mins);
|
||||
return displayTime;
|
||||
return get_dive_duration_string(dive->duration.seconds, ":", "m", "s", dive->dc.divemode == FREEDIVE);
|
||||
}
|
||||
|
||||
QString DiveItem::displayTemperature() const
|
||||
|
|
Loading…
Add table
Reference in a new issue