diff --git a/helpers.h b/helpers.h index 81fddbd5e..783efe530 100644 --- a/helpers.h +++ b/helpers.h @@ -11,11 +11,16 @@ #include "dive.h" #include "qthelper.h" -QString get_depth_string(depth_t depth, bool showunit); -QString get_weight_string(weight_t weight, bool showunit); -QString get_temperature_string(temperature_t temp, bool showunit); -QString get_volume_string(volume_t volume, bool showunit); -QString get_pressure_string(pressure_t pressure, bool showunit); +QString get_depth_string(depth_t depth, bool showunit = false); +QString get_depth_unit(); +QString get_weight_string(weight_t weight, bool showunit = false); +QString get_weight_unit(); +QString get_temperature_string(temperature_t temp, bool showunit = false); +QString get_temp_unit(); +QString get_volume_string(volume_t volume, bool showunit = false); +QString get_volume_unit(); +QString get_pressure_string(pressure_t pressure, bool showunit = false); +QString get_pressure_unit(); void set_default_dive_computer(const char *vendor, const char *product); void set_default_dive_computer_device(const char *name); QString getSubsurfaceDataPath(QString folderToFind); diff --git a/qt-gui.cpp b/qt-gui.cpp index 10b7d8086..2474d407d 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -196,6 +196,14 @@ QString get_depth_string(depth_t depth, bool showunit) } } +QString get_depth_unit() +{ + if (prefs.units.length == units::METERS) + return "m"; + else + return "ft"; +} + QString get_weight_string(weight_t weight, bool showunit) { if (prefs.units.weight == units::KG) { @@ -207,6 +215,14 @@ QString get_weight_string(weight_t weight, bool showunit) } } +QString get_weight_unit() +{ + if (prefs.units.weight == units::KG) + return "kg"; + else + return "lbs"; +} + QString get_temperature_string(temperature_t temp, bool showunit) { if (prefs.units.temperature == units::CELSIUS) { @@ -220,6 +236,14 @@ QString get_temperature_string(temperature_t temp, bool showunit) } } +QString get_temp_unit() +{ + if (prefs.units.temperature == units::CELSIUS) + return QString(UTF8_DEGREE "C"); + else + return QString(UTF8_DEGREE "F"); +} + QString get_volume_string(volume_t volume, bool showunit) { if (prefs.units.volume == units::LITER) { @@ -231,6 +255,14 @@ QString get_volume_string(volume_t volume, bool showunit) } } +QString get_volume_unit() +{ + if (prefs.units.volume == units::LITER) + return "l"; + else + return "cuft"; +} + QString get_pressure_string(pressure_t pressure, bool showunit) { if (prefs.units.pressure == units::BAR) { diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 7f3ce9a1a..a5321ce76 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1302,7 +1302,6 @@ YearStatisticsItem::YearStatisticsItem(stats_t interval) : stats_interval(interv QVariant YearStatisticsItem::data(int column, int role) const { - const char *unit; double value; QVariant ret; @@ -1317,29 +1316,26 @@ QVariant YearStatisticsItem::data(int column, int role) const case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); break; case SHORTEST_TIME: ret = get_minutes(stats_interval.shortest_time.seconds); break; case LONGEST_TIME: ret = get_minutes(stats_interval.longest_time.seconds); break; - case AVG_DEPTH: ret = stats_interval.avg_depth.mm; break; - case MIN_DEPTH: ret = stats_interval.min_depth.mm; break; - case MAX_DEPTH: ret = stats_interval.max_depth.mm; break; - case AVG_SAC: ret = stats_interval.avg_sac.mliter; break; - case MIN_SAC: ret = stats_interval.min_sac.mliter; break; - case MAX_SAC: ret = stats_interval.max_sac.mliter; break; + case AVG_DEPTH: ret = get_depth_string(stats_interval.avg_depth); break; + case MIN_DEPTH: ret = get_depth_string(stats_interval.min_depth); break; + case MAX_DEPTH: ret = get_depth_string(stats_interval.max_depth); break; + case AVG_SAC: ret = get_volume_string(stats_interval.avg_sac); break; + case MIN_SAC: ret = get_volume_string(stats_interval.min_sac); break; + case MAX_SAC: ret = get_volume_string(stats_interval.max_sac); break; case AVG_TEMP: - get_temp_units(stats_interval.min_temp, &unit); if (stats_interval.combined_temp && stats_interval.combined_count) { - ret = QString("%1 %2").arg(stats_interval.combined_temp / stats_interval.combined_count).arg(unit); + ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1); } break; case MIN_TEMP: - value = get_temp_units(stats_interval.min_temp, &unit); - if (value > -100.0) { - ret = QString("%1 %2").arg(value).arg(unit); - } + value = get_temp_units(stats_interval.min_temp, NULL); + if (value > -100.0) + ret = QString::number(value, 'f', 1); break; case MAX_TEMP: - value = get_temp_units(stats_interval.max_temp, &unit); - if (value > -100.0) { - ret = QString("%1 %2").arg(value).arg(unit); - } + value = get_temp_units(stats_interval.max_temp, NULL); + if (value > -100.0) + ret = QString::number(value, 'f', 1); break; } return ret; @@ -1362,18 +1358,18 @@ QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientat case YEAR: val = tr("Year \n > Month"); break; case DIVES: val = tr("#"); break; case TOTAL_TIME: val = tr("Duration \n Total"); break; - case AVERAGE_TIME: val = tr("Average"); break; - case SHORTEST_TIME: val = tr("Shortest"); break; - case LONGEST_TIME: val = tr("Longest"); break; - case AVG_DEPTH: val = tr("Depth \n Average"); break; - case MIN_DEPTH: val = tr("Minimum"); break; - case MAX_DEPTH: val = tr("Maximum"); break; - case AVG_SAC: val = tr("SAC \n Average"); break; - case MIN_SAC: val = tr("Minimum"); break; - case MAX_SAC: val = tr("Maximum"); break; - case AVG_TEMP: val = tr("Temperature \n Average"); break; - case MIN_TEMP: val = tr("Minimum"); break; - case MAX_TEMP: val = tr("Maximum"); break; + case AVERAGE_TIME: val = tr("\nAverage"); break; + case SHORTEST_TIME: val = tr("\nShortest"); break; + case LONGEST_TIME: val = tr("\nLongest"); break; + case AVG_DEPTH: val = QString(tr("Depth (%1)\n Average")).arg(get_depth_unit()); break; + case MIN_DEPTH: val = tr("\nMinimum"); break; + case MAX_DEPTH: val = tr("\nMaximum"); break; + case AVG_SAC: val = QString(tr("SAC (%1)\n Average")).arg(get_volume_unit()); break; + case MIN_SAC: val = tr("\nMinimum"); break; + case MAX_SAC: val = tr("\nMaximum"); break; + case AVG_TEMP: val = QString(tr("Temp. (%1)\n Average").arg(get_temp_unit())); break; + case MIN_TEMP: val = tr("\nMinimum"); break; + case MAX_TEMP: val = tr("\nMaximum"); break; } } return val;