diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-09-14 12:39:41 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-09-15 10:29:55 +0200 |
commit | 61343b5a3f10f5b9166729176d4b95a4c538c278 (patch) | |
tree | 1adbfa95019286dffea81995957fd768d7bc6f41 /src/corelib/text/qlocale.cpp | |
parent | 05d336620cf87fbffc07f2df15e1ba5aeea7ef71 (diff) |
Teach QLocale::system() to use narrow format
QLocale::system() was not making use of QLocaleFormat::Narrow, always
treating it in the same way as QLocaleFormat::Short.
This patch fixes the issue for day and month names.
The implementation falls back to CLDR if system locale fails to
provide some data.
Pick-to: 6.2
Task-number: QTBUG-84877
Change-Id: Ia37e59dbf02d7a5e230f2767d294b9ab7de37f33
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 8ff896b0c5..2eb5e4e252 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2642,8 +2642,13 @@ QString QLocale::toString(double f, char format, int precision) const /*! Returns a QLocale object initialized to the system locale. - On Windows and Mac, this locale will use the decimal/grouping characters and - date/time formats specified in the system configuration panel. + The system locale may use system-specific sources for locale data, where + available, otherwise falling back on QLocale's built-in database entry for + the language, script and territory the system reports. + + For example, on Windows and Mac, this locale will use the decimal/grouping + characters and date/time formats specified in the system configuration + panel. \sa c() */ @@ -2906,10 +2911,19 @@ QString QGregorianCalendar::monthName(const QLocale &locale, int month, int year #ifndef QT_NO_SYSTEMLOCALE if (locale.d->m_data == &systemLocaleData) { Q_ASSERT(month >= 1 && month <= 12); - QVariant res = systemLocale()->query(format == QLocale::LongFormat - ? QSystemLocale::MonthNameLong - : QSystemLocale::MonthNameShort, - month); + QSystemLocale::QueryType queryType = QSystemLocale::MonthNameLong; + switch (format) { + case QLocale::LongFormat: + queryType = QSystemLocale::MonthNameLong; + break; + case QLocale::ShortFormat: + queryType = QSystemLocale::MonthNameShort; + break; + case QLocale::NarrowFormat: + queryType = QSystemLocale::MonthNameNarrow; + break; + } + QVariant res = systemLocale()->query(queryType, month); if (!res.isNull()) return res.toString(); } @@ -2932,10 +2946,19 @@ QString QGregorianCalendar::standaloneMonthName(const QLocale &locale, int month #ifndef QT_NO_SYSTEMLOCALE if (locale.d->m_data == &systemLocaleData) { Q_ASSERT(month >= 1 && month <= 12); - QVariant res = systemLocale()->query(format == QLocale::LongFormat - ? QSystemLocale::StandaloneMonthNameLong - : QSystemLocale::StandaloneMonthNameShort, - month); + QSystemLocale::QueryType queryType = QSystemLocale::StandaloneMonthNameLong; + switch (format) { + case QLocale::LongFormat: + queryType = QSystemLocale::StandaloneMonthNameLong; + break; + case QLocale::ShortFormat: + queryType = QSystemLocale::StandaloneMonthNameShort; + break; + case QLocale::NarrowFormat: + queryType = QSystemLocale::StandaloneMonthNameNarrow; + break; + } + QVariant res = systemLocale()->query(queryType, month); if (!res.isNull()) return res.toString(); } @@ -2954,10 +2977,19 @@ QString QCalendarBackend::weekDayName(const QLocale &locale, int day, #ifndef QT_NO_SYSTEMLOCALE if (locale.d->m_data == &systemLocaleData) { - QVariant res = systemLocale()->query(format == QLocale::LongFormat - ? QSystemLocale::DayNameLong - : QSystemLocale::DayNameShort, - day); + QSystemLocale::QueryType queryType = QSystemLocale::DayNameLong; + switch (format) { + case QLocale::LongFormat: + queryType = QSystemLocale::DayNameLong; + break; + case QLocale::ShortFormat: + queryType = QSystemLocale::DayNameShort; + break; + case QLocale::NarrowFormat: + queryType = QSystemLocale::DayNameNarrow; + break; + } + QVariant res = systemLocale()->query(queryType, day); if (!res.isNull()) return res.toString(); } @@ -2974,10 +3006,19 @@ QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day, #ifndef QT_NO_SYSTEMLOCALE if (locale.d->m_data == &systemLocaleData) { - QVariant res = systemLocale()->query(format == QLocale::LongFormat - ? QSystemLocale::StandaloneDayNameLong - : QSystemLocale::StandaloneDayNameShort, - day); + QSystemLocale::QueryType queryType = QSystemLocale::StandaloneDayNameLong; + switch (format) { + case QLocale::LongFormat: + queryType = QSystemLocale::StandaloneDayNameLong; + break; + case QLocale::ShortFormat: + queryType = QSystemLocale::StandaloneDayNameShort; + break; + case QLocale::NarrowFormat: + queryType = QSystemLocale::StandaloneDayNameNarrow; + break; + } + QVariant res = systemLocale()->query(queryType, day); if (!res.isNull()) return res.toString(); } |