diff options
-rw-r--r-- | core/divelogexportlogic.cpp | 6 | ||||
-rw-r--r-- | core/helpers.h | 3 | ||||
-rw-r--r-- | core/qthelper.cpp | 45 | ||||
-rw-r--r-- | core/statistics.c | 22 | ||||
-rw-r--r-- | core/statistics.h | 4 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/plugins/facebook/facebookconnectwidget.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveInformation.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveStatistics.cpp | 13 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.h | 3 | ||||
-rw-r--r-- | qt-models/divetripmodel.cpp | 4 | ||||
-rw-r--r-- | qt-models/yearlystatisticsmodel.cpp | 2 |
13 files changed, 68 insertions, 48 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 diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 76796b781..14583ff1d 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -703,7 +703,7 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const case 0: return QVariant(get_short_dive_date_string(d->when)); case 1: - return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min"))); + return QVariant(get_dive_duration_string(d->duration.seconds, tr("h"), tr("min"))); case 2: return QVariant(get_depth_string(d->maxdepth.mm, true, false)); } diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp index f5861775a..e01f2b3fb 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp @@ -306,7 +306,7 @@ void SocialNetworkDialog::selectionChanged() } if (ui->duration->isChecked()) { fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds, - tr("h:", "abbreviation for hours plus separator"), + tr("h", "abbreviation for hours"), tr("min", "abbreviation for minutes"))); } if (ui->Location->isChecked()) { diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 8410c022c..d687cdcd7 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -74,15 +74,15 @@ void TabDiveInformation::updateData() ui->gasUsedText->setText(volumes); ui->oxygenHeliumText->setText(gaslist); - int sum = displayed_dive.dc.divemode != FREEDIVE ? 30 : 0; - ui->diveTimeText->setText(get_time_string_s(displayed_dive.duration.seconds + sum, 0, false)); + ui->diveTimeText->setText(get_dive_duration_string(displayed_dive.duration.seconds, tr("h"), tr("min"), tr("sec"), + " ", displayed_dive.dc.divemode == FREEDIVE)); struct dive *prevd; process_all_dives(&displayed_dive, &prevd); if (prevd) - ui->surfaceIntervalText->setText(get_time_string_s(displayed_dive.when - (prevd->when + prevd->duration.seconds), 4, - (displayed_dive.dc.divemode == FREEDIVE))); + ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (prevd->when + prevd->duration.seconds), tr("d"), tr("h"), tr("min"))); + else ui->surfaceIntervalText->clear(); diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp index e05f076a9..53bab0ef5 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp @@ -84,14 +84,19 @@ void TabDiveStatistics::updateData() ui->divesAllText->setText(QString::number(stats_selection.selection_size)); - ui->totalTimeAllText->setText(get_time_string_s(stats_selection.total_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE))); + ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), + " ", displayed_dive.dc.divemode == FREEDIVE)); + int seconds = stats_selection.total_time.seconds; if (stats_selection.selection_size) seconds /= stats_selection.selection_size; - ui->timeLimits->setAverage(get_time_string_s(seconds, 0,(displayed_dive.dc.divemode == FREEDIVE))); + ui->timeLimits->setAverage(get_dive_duration_string(seconds, tr("h"), tr("min"), tr("sec"), + " ", displayed_dive.dc.divemode == FREEDIVE)); if (amount_selected > 1) { - ui->timeLimits->setMaximum(get_time_string_s(stats_selection.longest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE))); - ui->timeLimits->setMinimum(get_time_string_s(stats_selection.shortest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE))); + ui->timeLimits->setMaximum(get_dive_duration_string(stats_selection.longest_time.seconds, tr("h"), tr("min"), tr("sec"), + " ", displayed_dive.dc.divemode == FREEDIVE)); + ui->timeLimits->setMinimum(get_dive_duration_string(stats_selection.shortest_time.seconds, tr("h"), tr("min"), tr("sec"), + " ", displayed_dive.dc.divemode == FREEDIVE)); } else { ui->timeLimits->setMaximum(""); ui->timeLimits->setMinimum(""); diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index b4f197c64..9c24d096d 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -109,7 +109,8 @@ if (property == "year") { double temp = get_temp_units(object.year->max_temp, &unit); return object.year->max_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit; } else if (property == "total_time") { - return get_time_string(object.year->total_time.seconds, 0); + return get_dive_duration_string(object.year->total_time.seconds, QObject::tr("h"), + QObject::tr("min"), QObject::tr("sec"), " "); } else if (property == "avg_time") { return get_minutes(object.year->total_time.seconds / object.year->selection_size); } else if (property == "shortest_time") { diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index c57541ccd..0293f6a45 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -343,7 +343,9 @@ int DiveItem::countPhotos(dive *dive) const QString DiveItem::displayDuration() const { struct dive *dive = get_dive_by_uniq_id(diveId); - return get_dive_duration_string(dive->duration.seconds, ":", "m", "s", dive->dc.divemode == FREEDIVE); + return get_dive_duration_string(dive->duration.seconds, "", "", "", ":", dive->dc.divemode == FREEDIVE); + // Next line is test for alternative display with units + // return get_dive_duration_string(dive->duration.seconds, tr("h"), tr("min"), "", ":", dive->dc.divemode == FREEDIVE); } QString DiveItem::displayTemperature() const diff --git a/qt-models/yearlystatisticsmodel.cpp b/qt-models/yearlystatisticsmodel.cpp index b27dc8140..54941ac80 100644 --- a/qt-models/yearlystatisticsmodel.cpp +++ b/qt-models/yearlystatisticsmodel.cpp @@ -61,7 +61,7 @@ QVariant YearStatisticsItem::data(int column, int role) const ret = stats_interval.selection_size; break; case TOTAL_TIME: - ret = get_time_string(stats_interval.total_time.seconds, 0); + ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " "); break; case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); |