diff options
author | Stefan Fuchs <sfuchs@gmx.de> | 2018-02-19 21:55:18 +0100 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2018-03-05 16:28:18 +0100 |
commit | aacc6886705e720809d253d22e0f6f49444993e0 (patch) | |
tree | 4d8026cae13f8706d2bb904f7115089d60a7d603 | |
parent | 18c034ea37f830880e4cbf3636819c6be43d0464 (diff) | |
download | subsurface-aacc6886705e720809d253d22e0f6f49444993e0.tar.gz |
Use correct numeric format based on selected locale (Qt domain part)
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator
In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
-rw-r--r-- | core/helpers.h | 1 | ||||
-rw-r--r-- | core/qthelper.cpp | 27 | ||||
-rw-r--r-- | profile-widget/divecartesianaxis.cpp | 2 | ||||
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 9 | ||||
-rw-r--r-- | qt-models/cylindermodel.cpp | 6 | ||||
-rw-r--r-- | qt-models/divetripmodel.cpp | 22 |
6 files changed, 29 insertions, 38 deletions
diff --git a/core/helpers.h b/core/helpers.h index 57be623c5..36db01093 100644 --- a/core/helpers.h +++ b/core/helpers.h @@ -20,6 +20,7 @@ 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_string(int mliter, bool showunit = false); QString get_volume_unit(); QString get_pressure_string(pressure_t pressure, bool showunit = false); QString get_pressure_unit(); diff --git a/core/qthelper.cpp b/core/qthelper.cpp index d012e2d29..798d98c20 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -46,10 +46,10 @@ QString weight_string(int weight_in_grams) QString str; if (get_units()->weight == units::KG) { double kg = (double) weight_in_grams / 1000.0; - str = QString("%1").arg(kg, 0, 'f', kg >= 20.0 ? 0 : 1); + str = QString("%L1").arg(kg, 0, 'f', kg >= 20.0 ? 0 : 1); } else { double lbs = grams_to_lbs(weight_in_grams); - str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1); + str = QString("%L1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1); } return str; } @@ -582,10 +582,10 @@ QString get_depth_string(int mm, bool showunit, bool showdecimal) { if (prefs.units.length == units::METERS) { double meters = mm / 1000.0; - return QString("%1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0).arg(showunit ? translate("gettextFromC", "m") : ""); + return QString("%L1%2").arg(meters, 0, 'f', (showdecimal && meters < 20.0) ? 1 : 0).arg(showunit ? translate("gettextFromC", "m") : ""); } else { double feet = mm_to_feet(mm); - return QString("%1%2").arg(feet, 0, 'f', 0).arg(showunit ? translate("gettextFromC", "ft") : ""); + return QString("%L1%2").arg(feet, 0, 'f', 0).arg(showunit ? translate("gettextFromC", "ft") : ""); } } @@ -627,10 +627,10 @@ QString get_temperature_string(temperature_t temp, bool showunit) return ""; //temperature not defined } else if (prefs.units.temperature == units::CELSIUS) { double celsius = mkelvin_to_C(temp.mkelvin); - return QString("%1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "C") : ""); + return QString("%L1%2%3").arg(celsius, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "C") : ""); } else { double fahrenheit = mkelvin_to_F(temp.mkelvin); - return QString("%1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "F") : ""); + return QString("%L1%2%3").arg(fahrenheit, 0, 'f', 1).arg(showunit ? (UTF8_DEGREE) : "").arg(showunit ? translate("gettextFromC", "F") : ""); } } @@ -642,12 +642,17 @@ QString get_temp_unit() return QString(UTF8_DEGREE "F"); } -QString get_volume_string(volume_t volume, bool showunit) +QString get_volume_string(int mliter, bool showunit) { const char *unit; int decimals; - double value = get_volume_units(volume.mliter, &decimals, &unit); - return QString("%1%2").arg(value, 0, 'f', decimals).arg(showunit ? unit : ""); + double value = get_volume_units(mliter, &decimals, &unit); + return QString("%L1%2").arg(value, 0, 'f', decimals).arg(showunit ? unit : ""); +} + +QString get_volume_string(volume_t volume, bool showunit) +{ + return get_volume_string(volume.mliter, showunit); } QString get_volume_unit() @@ -661,10 +666,10 @@ QString get_pressure_string(pressure_t pressure, bool showunit) { if (prefs.units.pressure == units::BAR) { double bar = pressure.mbar / 1000.0; - return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? translate("gettextFromC", "bar") : ""); + return QString("%L1%2").arg(bar, 0, 'f', 1).arg(showunit ? translate("gettextFromC", "bar") : ""); } else { double psi = mbar_to_PSI(pressure.mbar); - return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? translate("gettextFromC", "psi") : ""); + return QString("%L1%2").arg(psi, 0, 'f', 0).arg(showunit ? translate("gettextFromC", "psi") : ""); } } diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 3ca87dd10..4d7d9eaa3 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -271,7 +271,7 @@ void DiveCartesianAxis::animateChangeLine(const QLineF &newLine) QString DiveCartesianAxis::textForValue(double value) { - return QString::number(value); + return QString("%L1").arg(value, 0, 'g', 4); } void DiveCartesianAxis::setTickSize(qreal size) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 24edba4db..529024c11 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -260,11 +260,9 @@ void DiveProfileItem::settingsChanged() void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color) { - int decimals; - double d = get_depth_units(entry->depth, &decimals, NULL); DiveTextItem *item = new DiveTextItem(this); item->setPos(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)); - item->setText(QString("%1").arg(d, 0, 'f', 1)); + item->setText(get_depth_string(entry->depth, true)); item->setAlignment(flags); item->setBrush(color); texts.append(item); @@ -670,15 +668,12 @@ void DiveMeanDepthItem::createTextItem() { int sec = entry[dataModel->rowCount()-1].sec; qDeleteAll(texts); texts.clear(); - int decimals; - const char *unitText; - double d = get_depth_units(lrint(lastRunningSum), &decimals, &unitText); DiveTextItem *text = new DiveTextItem(this); text->setAlignment(Qt::AlignRight | Qt::AlignTop); text->setBrush(getColor(TEMP_TEXT)); text->setPos(QPointF(hAxis->posAtValue(sec) + 1, vAxis->posAtValue(lastRunningSum))); text->setScale(0.8); // need to call this BEFORE setText() - text->setText(QString("%1%2").arg(d, 0, 'f', 1).arg(unitText)); + text->setText(get_depth_string(lrint(lastRunningSum), true)); texts.append(text); } diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index a5b1b53c0..e81a127a9 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -57,7 +57,7 @@ static QString get_cylinder_string(cylinder_t *cyl) unit = CylindersModel::tr("ℓ"); } - return QString("%1").arg(value, 0, 'f', decimals) + unit; + return QString("%L1").arg(value, 0, 'f', decimals) + unit; } static QString gas_volume_string(int ml, const char *tail) @@ -69,7 +69,7 @@ static QString gas_volume_string(int ml, const char *tail) vol = get_volume_units(ml, NULL, &unit); decimals = (vol > 20.0) ? 0 : (vol > 2.0) ? 1 : 2; - return QString("%1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail); + return QString("%L1 %2 %3").arg(vol, 0, 'f', decimals).arg(unit).arg(tail); } static QVariant gas_wp_tooltip(cylinder_t *cyl); @@ -126,7 +126,7 @@ static QVariant percent_string(fraction_t fraction) if (!permille) return QVariant(); - return QString("%1%").arg(permille / 10.0, 0, 'f', 1); + return QString("%L1%").arg(permille / 10.0, 0, 'f', 1); } QVariant CylindersModel::data(const QModelIndex &index, int role) const diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 63e5f6afd..2e9058d6e 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -387,28 +387,18 @@ QString DiveItem::displayTemperatureWithUnit() const QString DiveItem::displaySac() const { - QString str; struct dive *dive = get_dive_by_uniq_id(diveId); - if (dive->sac) { - const char *unit; - int decimal; - double value = get_volume_units(dive->sac, &decimal, &unit); - return QString::number(value, 'f', decimal); - } - return QString(""); + if (!dive->sac) + return QString(); + return get_volume_string(dive->sac, false); } QString DiveItem::displaySacWithUnit() const { - QString str; struct dive *dive = get_dive_by_uniq_id(diveId); - if (dive->sac) { - const char *unit; - int decimal; - double value = get_volume_units(dive->sac, &decimal, &unit); - return QString::number(value, 'f', decimal) + QString(unit).append(tr("/min")); - } - return QString(""); + if (!dive->sac) + return QString(); + return get_volume_string(dive->sac, true).append(tr("/min")); } QString DiveItem::displayWeight() const |