From 8660f6e385b2070db1b33dab85b5686a00fec06b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 22 Mar 2012 10:53:45 +0100 Subject: Fix measurement system for the UK THe UK still uses the Imperial system at least for distances and many other things. Change-Id: I99379de35620114328ad6a7fc9b226a46692bedd Reviewed-by: Denis Dzyubenko --- src/corelib/tools/qlocale.cpp | 2 +- src/corelib/tools/qlocale.h | 7 ++++++- src/corelib/tools/qlocale.qdoc | 8 +++++--- src/corelib/tools/qlocale_data_p.h | 10 ++++++---- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e40917c5d8..2d1444c315 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2080,7 +2080,7 @@ QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) { if (ImperialMeasurementSystems[i].languageId == m_language_id && ImperialMeasurementSystems[i].countryId == m_country_id) { - return QLocale::ImperialSystem; + return ImperialMeasurementSystems[i].system; } } return QLocale::MetricSystem; diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index c029f627b2..6c97a05ba8 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -565,7 +565,12 @@ public: }; // GENERATED PART ENDS HERE - enum MeasurementSystem { MetricSystem, ImperialSystem }; + enum MeasurementSystem { + MetricSystem, + ImperialUSSystem, + ImperialUKSystem, + ImperialSystem = ImperialUSSystem // Qt 4 compatibility + }; enum FormatType { LongFormat, ShortFormat, NarrowFormat }; enum NumberOption { diff --git a/src/corelib/tools/qlocale.qdoc b/src/corelib/tools/qlocale.qdoc index 8e90d7d94e..02a6ef1c6d 100644 --- a/src/corelib/tools/qlocale.qdoc +++ b/src/corelib/tools/qlocale.qdoc @@ -672,9 +672,11 @@ \value MetricSystem This value indicates metric units, such as meters, centimeters and millimeters. - \value ImperialSystem This value indicates imperial units, such as inches and - miles. There are several distinct imperial systems in the world; this - value stands for the official United States imperial units. + \value ImperialUSSystem This value indicates imperial units, such as inches and + miles as they are used in the United States. + \value ImperialUKSystem This value indicates imperial units, such as inches and + miles as they are used in the United Kingdom. + \value ImperialSystem Provided for compatibility. Same as ImperialUSSystem \since 4.4 */ diff --git a/src/corelib/tools/qlocale_data_p.h b/src/corelib/tools/qlocale_data_p.h index 1508b982f1..db19e5bcd6 100644 --- a/src/corelib/tools/qlocale_data_p.h +++ b/src/corelib/tools/qlocale_data_p.h @@ -62,12 +62,14 @@ struct CountryLanguage { quint16 languageId; quint16 countryId; + QLocale::MeasurementSystem system; }; static const CountryLanguage ImperialMeasurementSystems[] = { - { 31, 225 }, - { 31, 226 }, - { 111, 225 }, - { 163, 225 } + { QLocale::English, QLocale::UnitedStates, QLocale::ImperialUSSystem }, + { QLocale::English, QLocale::UnitedStatesMinorOutlyingIslands, QLocale::ImperialUSSystem }, + { QLocale::Spanish, QLocale::UnitedStates, QLocale::ImperialUSSystem }, + { QLocale::Hawaiian, QLocale::UnitedStates, QLocale::ImperialUSSystem }, + { QLocale::English, QLocale::UnitedKingdom, QLocale::ImperialUKSystem } }; static const int ImperialMeasurementSystemsCount = sizeof(ImperialMeasurementSystems)/sizeof(ImperialMeasurementSystems[0]); diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index b3b573c64b..f9de2f0c05 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -133,6 +133,8 @@ private slots: void weekendDays(); void listPatterns(); + void measurementSystems(); + private: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; QString m_sysapp; @@ -2034,5 +2036,20 @@ void tst_QLocale::listPatterns() QCOMPARE(zh_CN.createSeparatedList(sl5), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe3\x80\x81" "ccc" "\xe5\x92\x8c" "ddd")); } +void tst_QLocale::measurementSystems() +{ + QLocale locale(QLocale::English, QLocale::UnitedStates); + QCOMPARE(locale.measurementSystem(), QLocale::ImperialUSSystem); + + locale = QLocale(QLocale::English, QLocale::UnitedKingdom); + QCOMPARE(locale.measurementSystem(), QLocale::ImperialUKSystem); + + locale = QLocale(QLocale::English, QLocale::Australia); + QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem); + + locale = QLocale(QLocale::German); + QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem); +} + QTEST_MAIN(tst_QLocale) #include "tst_qlocale.moc" -- cgit v1.2.3