diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-10-02 17:25:17 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-04-10 13:31:07 +0000 |
commit | 235ac95520a0fc2c822dedce7358e3c64a764255 (patch) | |
tree | 5619dd0db97ddc8ae6b1fc6d6b20924d1f51e0a7 /src/corelib/tools/qlocale_unix.cpp | |
parent | a20da2353cc308aab15e3efa05ab7d899e9c6ca7 (diff) |
Improve the default selection of locale for QCollator
QCollator was using the default-constructed QLocale() as its default;
this locale's default was the system locale; however, that didn't pay
any attention to system settings for collation such as Unix's
environment variable LC_COLLATE or the MS-Win LOCALE_SSORTLOCALE
configuration option.
Teach the system locale back-ends to look up their relevant settings,
add QLocale::collation() as a channel via which to access that and
change no-parameter construction of QCollator to a separate
implementation (rather than the constructor taking QLocale having a
default) using it.
[ChangeLog][QtCore][QLocale] The system locale now knows what to use
for collation, QLocale::system().collation().
[ChangeLog][QtCore][QCollator] The default QCollator now uses the
system's collation locale, rather than the system locale itself.
Fixes: QTBUG-58621
Change-Id: I90f86621541385330315d1f9d6a4b982bdcea9d5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlocale_unix.cpp')
-rw-r--r-- | src/corelib/tools/qlocale_unix.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp index f202082213..ff4274d932 100644 --- a/src/corelib/tools/qlocale_unix.cpp +++ b/src/corelib/tools/qlocale_unix.cpp @@ -69,6 +69,7 @@ struct QSystemLocaleData QLocale lc_messages; QByteArray lc_messages_var; QByteArray lc_measurement_var; + QByteArray lc_collate_var; QStringList uiLanguages; }; @@ -82,6 +83,7 @@ void QSystemLocaleData::readEnvironment() QByteArray monetary = all.isEmpty() ? qgetenv("LC_MONETARY") : all; lc_messages_var = all.isEmpty() ? qgetenv("LC_MESSAGES") : all; lc_measurement_var = all.isEmpty() ? qgetenv("LC_MEASUREMENT") : all; + lc_collate_var = all.isEmpty() ? qgetenv("LC_COLLATE") : all; QByteArray lang = qgetenv("LANG"); if (lang.isEmpty()) lang = QByteArray("C"); @@ -95,6 +97,8 @@ void QSystemLocaleData::readEnvironment() lc_messages_var = lang; if (lc_measurement_var.isEmpty()) lc_measurement_var = lang; + if (lc_collate_var.isEmpty()) + lc_collate_var = lang; lc_numeric = QLocale(QString::fromLatin1(numeric)); lc_time = QLocale(QString::fromLatin1(time)); lc_monetary = QLocale(QString::fromLatin1(monetary)); @@ -247,13 +251,15 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const return QString(); } case MeasurementSystem: { - const QString meas_locale = QString::fromLatin1(d->lc_measurement_var.constData(), d->lc_measurement_var.size()); + const QString meas_locale = QString::fromLatin1(d->lc_measurement_var); if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; return QVariant((int)QLocale(meas_locale).measurementSystem()); } + case Collation: + return QString::fromLatin1(d->lc_collate_var); case UILanguages: { if (!d->uiLanguages.isEmpty()) return d->uiLanguages; |