From: Lars Knoll Date: Thu, 22 Mar 2012 09:53:45 +0000 (+0100) Subject: Fix measurement system for the UK X-Git-Tag: qt-v5.0.0-alpha1~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8660f6e385b2070db1b33dab85b5686a00fec06b;p=profile%2Fivi%2Fqtbase.git 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 --- diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index e40917c..2d1444c 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 c029f62..6c97a05 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 8e90d7d..02a6ef1 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 1508b98..db19e5b 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 b3b573c..f9de2f0 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"