diff --git a/autotests/propertyinfotest.cpp b/autotests/propertyinfotest.cpp --- a/autotests/propertyinfotest.cpp +++ b/autotests/propertyinfotest.cpp @@ -130,8 +130,10 @@ // make VisualStudio compiler happy: QChar(0x00B0) = "°" { Property::PhotoGpsLatitude, true, 25, QStringLiteral("25") + QChar(0x00B0)}, { Property::PhotoGpsLongitude, true, 13.5, QStringLiteral("13.5") + QChar(0x00B0)}, - { Property::PhotoExposureTime, true, 0.0015625, QStringLiteral("0.00156")}, - { Property::PhotoExposureBiasValue, true, 0.3333333, QStringLiteral("0.333")}, + { Property::PhotoExposureTime, true, 0.0015625, QStringLiteral("1/640")}, + { Property::PhotoExposureBiasValue, true, 0.3333333, QStringLiteral("1/3")}, + { Property::PhotoExposureBiasValue, true, -0.3333333, QStringLiteral("-1/3")}, + { Property::PhotoExposureBiasValue, true, 1.2, QStringLiteral("1.2")}, { Property::ReplayGainAlbumGain, true, -9.90, QStringLiteral("-9.9")}, { Property::ReplayGainAlbumPeak, true, 1.512, QStringLiteral("1.51")}, { Property::ReplayGainAlbumGain, true, 10.44, QStringLiteral("10.4")}, diff --git a/src/formatstrings.cpp b/src/formatstrings.cpp --- a/src/formatstrings.cpp +++ b/src/formatstrings.cpp @@ -158,6 +158,20 @@ return i18nc("Symbol of frames per second, with space", "%1 fps", QLocale().toString(round(value.toDouble() * 100) / 100)); } +QString FormatStrings::formatAsDoubleOrRational(const QVariant& value) +{ + auto val = value.toDouble(); + if (abs(val) > 0.35 || qFuzzyIsNull(val)) { + return QLocale().toString(value.toDouble(), 'g', 3); + } else { + if (val < 0) { + return i18nc("Negative rational number, absolute value smaller than 1", "-1/%1", round(-1.0 / val)); + } else { + return i18nc("Positive rational number, absolute value smaller than 1", "1/%1", round(1.0 / val)); + } + } +} + QString FormatStrings::formatAspectRatio(const QVariant& value) { return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); diff --git a/src/formatstrings_p.h b/src/formatstrings_p.h --- a/src/formatstrings_p.h +++ b/src/formatstrings_p.h @@ -51,6 +51,8 @@ static QString formatAsFrameRate(const QVariant& value); + static QString formatAsDoubleOrRational(const QVariant& value); + static QString formatAspectRatio(const QVariant& value); }; diff --git a/src/propertyinfo.cpp b/src/propertyinfo.cpp --- a/src/propertyinfo.cpp +++ b/src/propertyinfo.cpp @@ -251,14 +251,14 @@ d->name = QStringLiteral("photoExposureBiasValue"); d->displayName = i18nc("@label EXIF", "Photo Exposure Bias"); d->valueType = QVariant::Double; - d->formatAsString = &FormatStrings::formatDouble; + d->formatAsString = &FormatStrings::formatAsDoubleOrRational; break; case Property::PhotoExposureTime: d->name = QStringLiteral("photoExposureTime"); d->displayName = i18nc("@label EXIF", "Photo Exposure Time"); d->valueType = QVariant::Double; - d->formatAsString = &FormatStrings::formatDouble; + d->formatAsString = &FormatStrings::formatAsDoubleOrRational; break; case Property::PhotoFlash: