aboutsummaryrefslogtreecommitdiffstats
path: root/core
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
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')
-rw-r--r--core/divelogexportlogic.cpp6
-rw-r--r--core/helpers.h3
-rw-r--r--core/qthelper.cpp45
-rw-r--r--core/statistics.c22
-rw-r--r--core/statistics.h4
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp2
6 files changed, 47 insertions, 35 deletions
diff --git a/core/divelogexportlogic.cpp b/core/divelogexportlogic.cpp
index e904b85e6..926dd461c 100644
--- a/core/divelogexportlogic.cpp
+++ b/core/divelogexportlogic.cpp
@@ -52,7 +52,8 @@ static void exportHTMLstatisticsTotal(QTextStream &out, stats_t *total_stats)
out << "{";
out << "\"YEAR\":\"Total\",";
out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
- out << "\"TOTAL_TIME\":\"" << get_time_string(total_stats->total_time.seconds, 0) << "\",";
+ out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(total_stats->total_time.seconds,
+ QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
out << "\"AVERAGE_TIME\":\"--\",";
out << "\"SHORTEST_TIME\":\"--\",";
out << "\"LONGEST_TIME\":\"--\",";
@@ -87,7 +88,8 @@ static void exportHTMLstatistics(const QString filename, struct htmlExportSettin
out << "{";
out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
- out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\",";
+ out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds,
+ QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";
diff --git a/core/helpers.h b/core/helpers.h
index a6e152cbf..06c1c8527 100644
--- a/core/helpers.h
+++ b/core/helpers.h
@@ -36,7 +36,8 @@ 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 secondsText = "", bool isFreeDive = false);
+QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = QObject::tr("sec"), QString separator = ":", bool isFreeDive = false);
+QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4);
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);
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;
diff --git a/core/statistics.c b/core/statistics.c
index 47e65ff72..18f247cb8 100644
--- a/core/statistics.c
+++ b/core/statistics.c
@@ -2,7 +2,6 @@
/* statistics.c
*
* core logic for the Info & Stats page -
- * char *get_time_string(int seconds, int maxdays);
* char *get_minutes(int seconds);
* void process_all_dives(struct dive *dive, struct dive **prev_dive);
* void get_selected_dives_text(char *buffer, int size);
@@ -236,27 +235,6 @@ void process_selected_dives(void)
stats_selection.selection_size = nr;
}
-char *get_time_string_s(int seconds, int maxdays, bool freediving)
-{
- static char buf[80];
- if (maxdays && seconds > 3600 * 24 * maxdays) {
- snprintf(buf, sizeof(buf), translate("gettextFromC", "more than %d days"), maxdays);
- } else {
- int days = seconds / 3600 / 24;
- int hours = (seconds - days * 3600 * 24) / 3600;
- int minutes = (seconds - days * 3600 * 24 - hours * 3600) / 60;
- int secs = (seconds - days * 3600 * 24 - hours * 3600 - minutes*60);
- if (days > 0)
- snprintf(buf, sizeof(buf), translate("gettextFromC", "%dd %dh %dmin"), days, hours, minutes);
- else
- if (freediving && seconds < 3600)
- snprintf(buf, sizeof(buf), translate("gettextFromC", "%dmin %dsecs"), minutes, secs);
- else
- snprintf(buf, sizeof(buf), translate("gettextFromC", "%dh %dmin"), hours, minutes);
- }
- return buf;
-}
-
/* this gets called when at least two but not all dives are selected */
static void get_ranges(char *buffer, int size)
{
diff --git a/core/statistics.h b/core/statistics.h
index 97aa4334c..9f045c16c 100644
--- a/core/statistics.h
+++ b/core/statistics.h
@@ -44,7 +44,6 @@ extern stats_t *stats_monthly;
extern stats_t *stats_by_trip;
extern stats_t *stats_by_type;
-extern char *get_time_string_s(int seconds, int maxdays, bool freediving);
extern char *get_minutes(int seconds);
extern void process_all_dives(struct dive *dive, struct dive **prev_dive);
extern void get_selected_dives_text(char *buffer, size_t size);
@@ -52,9 +51,6 @@ extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
extern void process_selected_dives(void);
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
-inline char *get_time_string(int seconds, int maxdays) {
- return get_time_string_s( seconds, maxdays, false);
-}
#ifdef __cplusplus
}
#endif
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index 0f3172195..9107223f4 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -124,7 +124,7 @@ QString DiveObjectHelper::gps_decimal() const
QString DiveObjectHelper::duration() const
{
- return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h:"), QObject::tr("min"));
+ return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h"), QObject::tr("min"));
}
bool DiveObjectHelper::noDive() const