Fix measurement system for the UK
authorLars Knoll <lars.knoll@nokia.com>
Thu, 22 Mar 2012 09:53:45 +0000 (10:53 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Mar 2012 09:41:07 +0000 (11:41 +0200)
THe UK still uses the Imperial system at least for distances
and many other things.

Change-Id: I99379de35620114328ad6a7fc9b226a46692bedd
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
src/corelib/tools/qlocale.cpp
src/corelib/tools/qlocale.h
src/corelib/tools/qlocale.qdoc
src/corelib/tools/qlocale_data_p.h
tests/auto/corelib/tools/qlocale/tst_qlocale.cpp

index e40917c..2d1444c 100644 (file)
@@ -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;
index c029f62..6c97a05 100644 (file)
@@ -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 {
index 8e90d7d..02a6ef1 100644 (file)
 
     \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
 */
index 1508b98..db19e5b 100644 (file)
@@ -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]);
index b3b573c..f9de2f0 100644 (file)
@@ -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"