Change QCollator's default locale to QLocale().collation()

This replaces QLocale::system().collation(), which left client code
with no way to change this default. Since QLocale's default is the
system locale initially, the old behavior is retained until the first
call to QLocale;:setDefault(). Addition of a separate collation locale
in 5.14 changed from using the default locale to using the system's
collation locale; the present change restores the ability to override
this.

[ChangeLog][QtCore][QCollator] The default locale used by QCollator is
now the collation locale of the default QLocale. This restores the
ability (lost at 5.14) to control the locale used by
QString::localeAwareCompare(), while retaining the use of a collation
locale when the default is the system locale.

Task-number: QTBUG-95050
Change-Id: I232772bb8f23fffd74573174de70ef2deae372a9
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 973ca1fac680d8c593645058fae3fe7c84a7fa16)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2021-07-12 10:46:14 +02:00 committed by Qt Cherry-pick Bot
parent 80e1f25f68
commit 8db031cb0f

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
** Contact: https://www.qt.io/licensing/
**
@ -77,12 +77,16 @@ QT_BEGIN_NAMESPACE
/*!
\since 5.13
Constructs a QCollator using the system's default collation locale.
Constructs a QCollator using the default locale's collation locale.
\sa setLocale(), QLocale::collation()
The system locale, when used as default locale, may have a collation locale
other than itself (e.g. on Unix, if LC_COLLATE is set differently to LANG in
the environment). All other locales are their own collation locales.
\sa setLocale(), QLocale::collation(), QLocale::setDefault()
*/
QCollator::QCollator()
: d(new QCollatorPrivate(QLocale::system().collation()))
: d(new QCollatorPrivate(QLocale().collation()))
{
d->init();
}