aboutsummaryrefslogtreecommitdiffstats
path: root/core/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Stefan Fuchs <sfuchs@gmx.de>2017-05-11 22:43:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-26 15:50:52 -0700
commite6d884cf26161df65c2b4b8c39d6b4133760537b (patch)
tree2b9132e7d057c514c852a7cf7bed39fa67455a6f /core/qthelper.cpp
parent53a8075bd8d7231f2bb483b9adca0fc60d4446f1 (diff)
downloadsubsurface-e6d884cf26161df65c2b4b8c39d6b4133760537b.tar.gz
Creation of dive duration string and surface interval string
Update the function to create the dive duration string in a way that it can be used also in info and stats tab and added some more flexibility. Changed layout for <1h freedives to "0:05:35" (w/o units) or "5:35min" (with units and :) or "5min 35sec" (with units with space). Add a new function to create the surface interval string. Completely remove old function get_time_string() and get_time_string_s(). Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Diffstat (limited to 'core/qthelper.cpp')
-rw-r--r--core/qthelper.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 238a0bc11..811f6538a 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -924,10 +924,10 @@ int parseGasMixHE(const QString &text)
return he;
}
-QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive)
+QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText, QString separator, bool isFreeDive)
{
int hrs, mins, fullmins, secs;
- mins = (when + 59) / 60;
+ mins = (when + 30) / 60;
fullmins = when / 60;
secs = when - 60 * fullmins;
hrs = mins / 60;
@@ -935,15 +935,50 @@ QString get_dive_duration_string(timestamp_t when, QString hourText, QString min
QString displayTime;
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);
+ displayTime = QString("%1%2%3%4%5").arg(hrs).arg(separator == ":" ? "" : hoursText).arg(separator)
+ .arg(mins, 2, 10, QChar('0')).arg(separator == ":" ? hoursText : minutesText);
+ } else if (isFreeDive && ( prefs.units.duration_units == units::MINUTES_ONLY || minutesText != "" )) {
+ // Freedive <1h and we display no hours but only minutes for other dives
+ // --> display a short (5min 35sec) freedives e.g. as "5:35"
+ // Freedive <1h and we display a unit for minutes
+ // --> display a short (5min 35sec) freedives e.g. as "5:35min"
+ if (separator == ":") displayTime = QString("%1%2%3%4").arg(fullmins).arg(separator)
+ .arg(secs, 2, 10, QChar('0')).arg(minutesText);
+ else displayTime = QString("%1%2%3%4%5").arg(fullmins).arg(minutesText).arg(separator)
+ .arg(secs).arg(secondsText);
} else if (isFreeDive) {
- displayTime = QString("%1%2%3%4").arg(fullmins).arg(minutesText).arg(secs, 2, 10, QChar('0')).arg(secondsText);
+ // Mixed display (hh:mm / mm only) and freedive < 1h and we have no unit for minutes
+ // --> Prefix duration with "0:" --> "0:05:35"
+ if (separator == ":") displayTime = QString("%1%2%3%4%5%6").arg(hrs).arg(separator)
+ .arg(fullmins, 2, 10, QChar('0')).arg(separator)
+ .arg(secs, 2, 10, QChar('0')).arg(hoursText);
+ // Separator != ":" and no units for minutes --> unlikely case - remove?
+ else displayTime = QString("%1%2%3%4%5%6%7%8").arg(hrs).arg(hoursText).arg(separator)
+ .arg(fullmins).arg(minutesText).arg(separator)
+ .arg(secs).arg(secondsText);
} else {
- displayTime = QString("%1%2").arg(mins).arg(hourText == ":" ? "" : minutesText);
+ displayTime = QString("%1%2").arg(mins).arg(minutesText);
}
return displayTime;
}
+QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator, int maxdays)
+{
+ int days, hrs, mins;
+ days = when / 3600 / 24;
+ hrs = (when - days * 3600 * 24) / 3600;
+ mins = (when + 30 - days * 3600 * 24 - hrs * 3600) / 60;
+
+ QString displayInt;
+ if (maxdays && days > maxdays) displayInt = QString("more than %1 days").arg(maxdays);
+ else if (days) displayInt = QString("%1%2%3%4%5%6%7%8").arg(days).arg(daysText).arg(separator)
+ .arg(hrs).arg(hoursText).arg(separator)
+ .arg(mins).arg(minutesText);
+ else displayInt = QString("%1%2%3%4%5").arg(hrs).arg(hoursText).arg(separator)
+ .arg(mins).arg(minutesText);
+ return displayInt;
+}
+
QString get_dive_date_string(timestamp_t when)
{
QDateTime ts;