Changeset 92d24a2 in subsurface


Ignore:
Timestamp:
May 6, 2017, 5:43:32 PM (7 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
25cec35d
Parents:
876b479
Message:

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

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/helpers.h

    rb368ecd r92d24a2  
    3737int parseGasMixO2(const QString &text);
    3838int parseGasMixHE(const QString &text);
    39 QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText);
     39QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText = "", bool isFreeDive = false);
    4040QString get_dive_date_string(timestamp_t when);
    4141QString get_short_dive_date_string(timestamp_t when);
  • core/qthelper.cpp

    r4627973 r92d24a2  
    925925}
    926926
    927 QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText)
    928 {
    929         int hrs, mins;
     927QString get_dive_duration_string(timestamp_t when, QString hourText, QString minutesText, QString secondsText, bool isFreeDive)
     928{
     929        int hrs, mins, fullmins, secs;
    930930        mins = (when + 59) / 60;
     931        fullmins = when / 60;
     932        secs = when - 60 * fullmins;
    931933        hrs = mins / 60;
    932         mins -= hrs * 60;
    933934
    934935        QString displayTime;
    935         if (hrs)
    936                 displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(minutesText);
    937         else
    938                 displayTime = QString("%1%2").arg(mins).arg(minutesText);
    939 
     936        if (prefs.units.duration_units == units::ALWAYS_HOURS || (prefs.units.duration_units == units::MIXED && hrs)) {
     937                mins -= hrs * 60;
     938                displayTime = QString("%1%2%3%4").arg(hrs).arg(hourText).arg(mins, 2, 10, QChar('0')).arg(hourText == ":" ? "" : minutesText);
     939        } 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);
     943        }
    940944        return displayTime;
    941945}
     
    965969        QDateTime ts(QDateTime::currentDateTime());;
    966970        QString current_date;
    967        
     971
    968972        current_date = loc.toString(ts, QString(prefs.date_format_short));
    969973
  • qt-models/divetripmodel.cpp

    r5372f12 r92d24a2  
    343343QString DiveItem::displayDuration() const
    344344{
    345         int hrs, mins, fullmins, secs;
    346         struct dive *dive = get_dive_by_uniq_id(diveId);
    347         mins = (dive->duration.seconds + 59) / 60;
    348         fullmins = dive->duration.seconds / 60;
    349         secs = dive->duration.seconds - 60 * fullmins;
    350         hrs = mins / 60;
    351         mins -= hrs * 60;
    352 
    353         QString displayTime;
    354         if (hrs)
    355                 displayTime = QString("%1:%2").arg(hrs).arg(mins, 2, 10, QChar('0'));
    356         else if (mins < 15 || dive->dc.divemode == FREEDIVE)
    357                 displayTime = QString("%1m%2s").arg(fullmins).arg(secs, 2, 10, QChar('0'));
    358         else
    359                 displayTime = QString("%1").arg(mins);
    360         return displayTime;
     345        struct dive *dive = get_dive_by_uniq_id(diveId);
     346        return get_dive_duration_string(dive->duration.seconds, ":", "m", "s", dive->dc.divemode == FREEDIVE);
    361347}
    362348
Note: See TracChangeset for help on using the changeset viewer.