diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -68,7 +68,9 @@ QCOMPARE(sampleRate.formatAsDisplayString(QVariant(44100)), QString(QLocale().toString(44.1) + QStringLiteral(" kHz"))); PropertyInfo bitRate(Property::BitRate); - QCOMPARE(bitRate.formatAsDisplayString(QVariant(128000)), QStringLiteral("128 kB/s")); + QCOMPARE(bitRate.formatAsDisplayString(QVariant(128000)), QStringLiteral("128 kbit/s")); + QCOMPARE(bitRate.formatAsDisplayString(QVariant(1350000)), QString(QLocale().toString(1.35) + QStringLiteral(" Mbit/s"))); + QCOMPARE(bitRate.formatAsDisplayString(QVariant(14700000)), QString(QLocale().toString(14.7) + QStringLiteral(" Mbit/s"))); PropertyInfo orientation(Property::ImageOrientation); QCOMPARE(orientation.formatAsDisplayString(QVariant(5)), QStringLiteral("Transposed")); diff --git a/src/formatstrings.cpp b/src/formatstrings.cpp --- a/src/formatstrings.cpp +++ b/src/formatstrings.cpp @@ -19,11 +19,21 @@ #include "formatstrings_p.h" +#include #include #include using namespace KFileMetaData; +int significantDigits(int value) +{ + if (value == 0) { + return 0; + } + int before_decimal_point = static_cast(log10(value > 0 ? value : -value)) % 3; + return 2 - before_decimal_point; +} + QString FormatStrings::toStringFunction(const QVariant& value) { return value.toString(); @@ -58,12 +68,14 @@ QString FormatStrings::formatBitRate(const QVariant& value) { KFormat form; - return i18nc("@label bitrate (per second)", "%1/s", form.formatByteSize(value.toInt(), 0, KFormat::MetricBinaryDialect)); + return i18nc("@label bitrate (per second)", "%1/s", form.formatValue(value.toInt(), + KFormat::Unit::Bit, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect)); } QString FormatStrings::formatSampleRate(const QVariant& value) { - return i18nc("@label samplerate in kilohertz", "%1 kHz", QLocale().toString(value.toDouble() / 1000)); + KFormat form; + return form.formatValue(value.toInt(), KFormat::Unit::Hertz, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); } QString FormatStrings::formatOrientationValue(const QVariant& value)