Changeset e6d884c in subsurface


Ignore:
Timestamp:
May 26, 2017, 3:50:52 PM (4 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
bb6ceba
Parents:
53a8075
git-author:
Stefan Fuchs <sfuchs@…> (05/11/17 13:43:36)
git-committer:
Dirk Hohndel <dirk@…> (05/26/17 15:50:52)
Message:

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@…>

Files:
13 edited

Legend:

Unmodified
Added
Removed
  • core/divelogexportlogic.cpp

    rb368ecd re6d884c  
    5353        out << "\"YEAR\":\"Total\",";
    5454        out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
    55         out << "\"TOTAL_TIME\":\"" << get_time_string(total_stats->total_time.seconds, 0) << "\",";
     55        out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(total_stats->total_time.seconds,
     56                                                                        QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
    5657        out << "\"AVERAGE_TIME\":\"--\",";
    5758        out << "\"SHORTEST_TIME\":\"--\",";
     
    8889                        out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
    8990                        out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
    90                         out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\",";
     91                        out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats_yearly[i].total_time.seconds,
     92                                                                                        QObject::tr("h"), QObject::tr("min"), QObject::tr("sec"), " ") << "\",";
    9193                        out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
    9294                        out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
  • core/helpers.h

    r92d24a2 re6d884c  
    3737int parseGasMixO2(const QString &text);
    3838int parseGasMixHE(const QString &text);
    39 QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText = "", bool isFreeDive = false);
     39QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText = QObject::tr("sec"), QString separator = ":", bool isFreeDive = false);
     40QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator = " ", int maxdays = 4);
    4041QString get_dive_date_string(timestamp_t when);
    4142QString get_short_dive_date_string(timestamp_t when);
  • core/qthelper.cpp

    rccf9163 re6d884c  
    925925}
    926926
    927 QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive)
     927QString get_dive_duration_string(timestamp_t when, QString hoursText, QString minutesText, QString secondsText, QString separator, bool isFreeDive)
    928928{
    929929        int hrs, mins, fullmins, secs;
    930         mins = (when + 59) / 60;
     930        mins = (when + 30) / 60;
    931931        fullmins = when / 60;
    932932        secs = when - 60 * fullmins;
     
    936936        if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) {
    937937                mins -= hrs * 60;
    938                 displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(hourText == ":" ? "" : minutesText);
     938                displayTime = QString("%1%2%3%4%5").arg(hrs).arg(separator == ":" ? "" : hoursText).arg(separator)
     939                        .arg(mins, 2, 10, QChar('0')).arg(separator == ":" ? hoursText : minutesText);
     940        } else if (isFreeDive && ( prefs.units.duration_units == units::MINUTES_ONLY || minutesText != "" )) {
     941                // Freedive <1h and we display no hours but only minutes for other dives
     942                // --> display a short (5min 35sec) freedives e.g. as "5:35"
     943                // Freedive <1h and we display a unit for minutes
     944                // --> display a short (5min 35sec) freedives e.g. as "5:35min"
     945                if (separator == ":") displayTime = QString("%1%2%3%4").arg(fullmins).arg(separator)
     946                        .arg(secs, 2, 10, QChar('0')).arg(minutesText);
     947                else displayTime = QString("%1%2%3%4%5").arg(fullmins).arg(minutesText).arg(separator)
     948                        .arg(secs).arg(secondsText);
    939949        } else if (isFreeDive) {
    940                 displayTime = QString("%1%2%3%4").arg(fullmins).arg(minutesText).arg(secs, 2, 10, QChar('0')).arg(secondsText);
    941         } else {
    942                 displayTime = QString("%1%2").arg(mins).arg(hourText == ":" ? "" : minutesText);
     950                // Mixed display (hh:mm / mm only) and freedive < 1h and we have no unit for minutes
     951                // --> Prefix duration with "0:" --> "0:05:35"
     952                if (separator == ":") displayTime = QString("%1%2%3%4%5%6").arg(hrs).arg(separator)
     953                        .arg(fullmins, 2, 10, QChar('0')).arg(separator)
     954                        .arg(secs, 2, 10, QChar('0')).arg(hoursText);
     955                // Separator != ":" and no units for minutes --> unlikely case - remove?
     956                else displayTime = QString("%1%2%3%4%5%6%7%8").arg(hrs).arg(hoursText).arg(separator)
     957                        .arg(fullmins).arg(minutesText).arg(separator)
     958                        .arg(secs).arg(secondsText);
     959        } else {
     960                displayTime = QString("%1%2").arg(mins).arg(minutesText);
    943961        }
    944962        return displayTime;
     963}
     964
     965QString get_dive_surfint_string(timestamp_t when, QString daysText, QString hoursText, QString minutesText, QString separator, int maxdays)
     966{
     967        int days, hrs, mins;
     968        days = when / 3600 / 24;
     969        hrs = (when - days * 3600 * 24) / 3600;
     970        mins = (when + 30 - days * 3600 * 24 - hrs * 3600) / 60;
     971
     972        QString displayInt;
     973        if (maxdays && days > maxdays) displayInt = QString("more than %1 days").arg(maxdays);
     974        else if (days) displayInt = QString("%1%2%3%4%5%6%7%8").arg(days).arg(daysText).arg(separator)
     975                .arg(hrs).arg(hoursText).arg(separator)
     976                .arg(mins).arg(minutesText);
     977        else displayInt = QString("%1%2%3%4%5").arg(hrs).arg(hoursText).arg(separator)
     978                .arg(mins).arg(minutesText);
     979        return displayInt;
    945980}
    946981
  • core/statistics.c

    r6399eaf re6d884c  
    33 *
    44 * core logic for the Info & Stats page -
    5  * char *get_time_string(int seconds, int maxdays);
    65 * char *get_minutes(int seconds);
    76 * void process_all_dives(struct dive *dive, struct dive **prev_dive);
     
    235234        }
    236235        stats_selection.selection_size = nr;
    237 }
    238 
    239 char *get_time_string_s(int seconds, int maxdays, bool freediving)
    240 {
    241         static char buf[80];
    242         if (maxdays && seconds > 3600 * 24 * maxdays) {
    243                 snprintf(buf, sizeof(buf), translate("gettextFromC", "more than %d days"), maxdays);
    244         } else {
    245                 int days = seconds / 3600 / 24;
    246                 int hours = (seconds - days * 3600 * 24) / 3600;
    247                 int minutes = (seconds - days * 3600 * 24 - hours * 3600) / 60;
    248                 int secs = (seconds - days * 3600 * 24 - hours * 3600 - minutes*60);
    249                 if (days > 0)
    250                         snprintf(buf, sizeof(buf), translate("gettextFromC", "%dd %dh %dmin"), days, hours, minutes);
    251                 else
    252                         if (freediving && seconds < 3600)
    253                                 snprintf(buf, sizeof(buf), translate("gettextFromC", "%dmin %dsecs"), minutes, secs);
    254                         else
    255                                 snprintf(buf, sizeof(buf), translate("gettextFromC", "%dh %dmin"), hours, minutes);
    256         }
    257         return buf;
    258236}
    259237
  • core/statistics.h

    r6399eaf re6d884c  
    4545extern stats_t *stats_by_type;
    4646
    47 extern char *get_time_string_s(int seconds, int maxdays, bool freediving);
    4847extern char *get_minutes(int seconds);
    4948extern void process_all_dives(struct dive *dive, struct dive **prev_dive);
     
    5352void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
    5453
    55 inline char *get_time_string(int seconds, int maxdays) {
    56         return get_time_string_s( seconds,  maxdays, false);
    57 }
    5854#ifdef __cplusplus
    5955}
  • core/subsurface-qt/DiveObjectHelper.cpp

    rb368ecd re6d884c  
    125125QString DiveObjectHelper::duration() const
    126126{
    127         return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h:"), QObject::tr("min"));
     127        return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h"), QObject::tr("min"));
    128128}
    129129
  • desktop-widgets/downloadfromdivecomputer.cpp

    r9021a44 re6d884c  
    704704                        return QVariant(get_short_dive_date_string(d->when));
    705705                case 1:
    706                         return QVariant(get_dive_duration_string(d->duration.seconds, tr("h:"), tr("min")));
     706                        return QVariant(get_dive_duration_string(d->duration.seconds, tr("h"), tr("min")));
    707707                case 2:
    708708                        return QVariant(get_depth_string(d->maxdepth.mm, true, false));
  • desktop-widgets/plugins/facebook/facebookconnectwidget.cpp

    r9021a44 re6d884c  
    307307        if (ui->duration->isChecked()) {
    308308                fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds,
    309                                                                                tr("h:", "abbreviation for hours plus separator"),
     309                                                                               tr("h", "abbreviation for hours"),
    310310                                                                               tr("min", "abbreviation for minutes")));
    311311        }
  • desktop-widgets/tab-widgets/TabDiveInformation.cpp

    r9021a44 re6d884c  
    7575        ui->oxygenHeliumText->setText(gaslist);
    7676
    77         int sum = displayed_dive.dc.divemode != FREEDIVE ? 30 : 0;
    78         ui->diveTimeText->setText(get_time_string_s(displayed_dive.duration.seconds + sum, 0, false));
     77        ui->diveTimeText->setText(get_dive_duration_string(displayed_dive.duration.seconds, tr("h"), tr("min"), tr("sec"),
     78                        " ", displayed_dive.dc.divemode == FREEDIVE));
    7979
    8080        struct dive *prevd;
     
    8282
    8383        if (prevd)
    84                 ui->surfaceIntervalText->setText(get_time_string_s(displayed_dive.when - (prevd->when + prevd->duration.seconds), 4,
    85                                                                         (displayed_dive.dc.divemode == FREEDIVE)));
     84                ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (prevd->when + prevd->duration.seconds), tr("d"), tr("h"), tr("min")));
     85
    8686        else
    8787                ui->surfaceIntervalText->clear();
  • desktop-widgets/tab-widgets/TabDiveStatistics.cpp

    ra784b15 re6d884c  
    8585
    8686        ui->divesAllText->setText(QString::number(stats_selection.selection_size));
    87         ui->totalTimeAllText->setText(get_time_string_s(stats_selection.total_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
     87        ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"),
     88                " ", displayed_dive.dc.divemode == FREEDIVE));
     89       
    8890        int seconds = stats_selection.total_time.seconds;
    8991        if (stats_selection.selection_size)
    9092                seconds /= stats_selection.selection_size;
    91         ui->timeLimits->setAverage(get_time_string_s(seconds, 0,(displayed_dive.dc.divemode == FREEDIVE)));
     93        ui->timeLimits->setAverage(get_dive_duration_string(seconds, tr("h"), tr("min"), tr("sec"),
     94                        " ", displayed_dive.dc.divemode == FREEDIVE));
    9295        if (amount_selected > 1) {
    93                 ui->timeLimits->setMaximum(get_time_string_s(stats_selection.longest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
    94                 ui->timeLimits->setMinimum(get_time_string_s(stats_selection.shortest_time.seconds, 0, (displayed_dive.dc.divemode == FREEDIVE)));
     96                ui->timeLimits->setMaximum(get_dive_duration_string(stats_selection.longest_time.seconds, tr("h"), tr("min"), tr("sec"),
     97                        " ", displayed_dive.dc.divemode == FREEDIVE));
     98                ui->timeLimits->setMinimum(get_dive_duration_string(stats_selection.shortest_time.seconds, tr("h"), tr("min"), tr("sec"),
     99                        " ", displayed_dive.dc.divemode == FREEDIVE));
    95100        } else {
    96101                ui->timeLimits->setMaximum("");
  • desktop-widgets/templatelayout.h

    r9021a44 re6d884c  
    110110        return object.year->max_temp == 0 ? "0" : QString::number(temp, 'g', 2) + unit;
    111111} else if (property == "total_time") {
    112         return get_time_string(object.year->total_time.seconds, 0);
     112        return get_dive_duration_string(object.year->total_time.seconds, QObject::tr("h"),
     113                                                                        QObject::tr("min"), QObject::tr("sec"), " ");
    113114} else if (property == "avg_time") {
    114115        return get_minutes(object.year->total_time.seconds / object.year->selection_size);
  • qt-models/divetripmodel.cpp

    r92d24a2 re6d884c  
    344344{
    345345        struct dive *dive = get_dive_by_uniq_id(diveId);
    346         return get_dive_duration_string(dive->duration.seconds, ":", "m", "s", dive->dc.divemode == FREEDIVE);
     346        return get_dive_duration_string(dive->duration.seconds, "", "", "", ":", dive->dc.divemode == FREEDIVE);
     347        // Next line is test for alternative display with units
     348        // return get_dive_duration_string(dive->duration.seconds, tr("h"), tr("min"), "", ":", dive->dc.divemode == FREEDIVE);
    347349}
    348350
  • qt-models/yearlystatisticsmodel.cpp

    r5372f12 re6d884c  
    6262                break;
    6363        case TOTAL_TIME:
    64                 ret = get_time_string(stats_interval.total_time.seconds, 0);
     64                ret = get_dive_duration_string(stats_interval.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ");
    6565                break;
    6666        case AVERAGE_TIME:
Note: See TracChangeset for help on using the changeset viewer.