Merge integration refs/builds/qtci/dev/1618489823

This commit is contained in:
Qt CI Bot 2021-04-15 21:27:52 +00:00
commit 8f6c93b645
45 changed files with 694 additions and 527 deletions

View File

@ -126,7 +126,7 @@ if(QT_BUILD_TESTS)
endif() endif()
if(NOT QT_BUILD_STANDALONE_TESTS) if(NOT QT_BUILD_STANDALONE_TESTS)
if(QT_WILL_BUILD_TOOLS) if(QT_WILL_BUILD_TOOLS AND QT_FEATURE_settings)
add_subdirectory(qmake) add_subdirectory(qmake)
endif() endif()
# As long as we use the mkspecs (for qplatformdefs.h), we need to always # As long as we use the mkspecs (for qplatformdefs.h), we need to always

View File

@ -1,6 +1,6 @@
{ {
"module_name": "${target}", "module_name": "${target}",
"version": "${CMAKE_PROJECT_VERSION}", "version": "${PROJECT_VERSION}",
"built_with": { "built_with": {
"compiler_id": "${CMAKE_CXX_COMPILER_ID}", "compiler_id": "${CMAKE_CXX_COMPILER_ID}",
"compiler_target": "${CMAKE_CXX_COMPILER_TARGET}", "compiler_target": "${CMAKE_CXX_COMPILER_TARGET}",

View File

@ -193,6 +193,7 @@ function(qt_build_internals_set_up_system_prefixes)
list(REMOVE_ITEM CMAKE_SYSTEM_PREFIX_PATH list(REMOVE_ITEM CMAKE_SYSTEM_PREFIX_PATH
"/usr/local" # Homebrew "/usr/local" # Homebrew
"/opt/homebrew" # Apple Silicon Homebrew
"/usr/X11R6" "/usr/X11R6"
"/usr/pkg" "/usr/pkg"
"/opt" "/opt"

View File

@ -247,14 +247,13 @@ void Window::createGeneralOptionsGroupBox()
int index = 0; int index = 0;
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang); QLocale::Language lang = static_cast<QLocale::Language>(_lang);
QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang); const auto territories = QLocale::territoriesForLanguage(lang);
for (int i = 0; i < countries.count(); ++i) { for (auto territory : territories) {
QLocale::Country country = countries.at(i);
QString label = QLocale::languageToString(lang); QString label = QLocale::languageToString(lang);
label += QLatin1Char('/'); label += QLatin1Char('/');
label += QLocale::countryToString(country); label += QLocale::territoryToString(territory);
QLocale locale(lang, country); QLocale locale(lang, territory);
if (this->locale().language() == lang && this->locale().country() == country) if (this->locale().language() == lang && this->locale().territory() == territory)
curLocaleIndex = index; curLocaleIndex = index;
localeCombo->addItem(label, locale); localeCombo->addItem(label, locale);
++index; ++index;

View File

@ -60,18 +60,18 @@ LocaleSelector::LocaleSelector(QWidget *parent)
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang); QLocale::Language lang = static_cast<QLocale::Language>(_lang);
const QList<QLocale> locales = const QList<QLocale> locales =
QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyCountry); QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
for (const QLocale &l : locales) { for (const QLocale &l : locales) {
QString label = QLocale::languageToString(l.language()); QString label = QLocale::languageToString(l.language());
label += QLatin1Char('/'); label += QLatin1Char('/');
label += QLocale::countryToString(l.country()); label += QLocale::territoryToString(l.territory());
// distinguish locales by script, if there are more than one script for a language/country pair // distinguish locales by script, if there are more than one script for a language/territory pair
if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.country()).size() > 1) if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.territory()).size() > 1)
label += QLatin1String(" (") + QLocale::scriptToString(l.script()) + QLatin1Char(')'); label += QLatin1String(" (") + QLocale::scriptToString(l.script()) + QLatin1Char(')');
addItem(label, QVariant::fromValue(l)); addItem(label, QVariant::fromValue(l));
if (l.language() == locale().language() && l.country() == locale().country() if (l.language() == locale().language() && l.territory() == locale().territory()
&& (locale().script() == QLocale::AnyScript || l.script() == locale().script())) { && (locale().script() == QLocale::AnyScript || l.script() == locale().script())) {
curIndex = index; curIndex = index;
} }

View File

@ -59,10 +59,6 @@ int i = egyptian.toInt(s2);
//! [1] //! [1]
QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel));
QLocale hebrew; // Constructs a default QLocale
QString s1 = hebrew.toString(15714.3, 'e');
bool ok; bool ok;
double d; double d;

View File

@ -817,7 +817,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
} }
} }
#ifdef DEBUG_RESOURCE_MATCH #ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "START" << path << locale.country() << locale.language(); qDebug() << "!!!!" << "START" << path << locale.territory() << locale.language();
#endif #endif
if (path == QLatin1String("/")) if (path == QLatin1String("/"))
@ -877,7 +877,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
if (!splitter.hasNext()) { if (!splitter.hasNext()) {
if (!(flags & Directory)) { if (!(flags & Directory)) {
const qint16 country = qFromBigEndian<qint16>(tree + offset); const qint16 territory = qFromBigEndian<qint16>(tree + offset);
offset += 2; offset += 2;
const qint16 language = qFromBigEndian<qint16>(tree + offset); const qint16 language = qFromBigEndian<qint16>(tree + offset);
@ -885,14 +885,15 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
#ifdef DEBUG_RESOURCE_MATCH #ifdef DEBUG_RESOURCE_MATCH
qDebug() << " " << "LOCALE" << country << language; qDebug() << " " << "LOCALE" << country << language;
#endif #endif
if (country == locale.country() && language == locale.language()) { if (territory == locale.territory() && language == locale.language()) {
#ifdef DEBUG_RESOURCE_MATCH #ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node; qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node;
#endif #endif
return sub_node; return sub_node;
} else if ((country == QLocale::AnyCountry } else if ((territory == QLocale::AnyTerritory
&& language == locale.language()) && language == locale.language())
|| (country == QLocale::AnyCountry && language == QLocale::C || (territory == QLocale::AnyTerritory
&& language == QLocale::C
&& node == -1)) { && node == -1)) {
node = sub_node; node = sub_node;
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2019 Intel Corporation. ** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
@ -154,23 +154,23 @@ QLocale::Script QLocalePrivate::codeToScript(QStringView code) noexcept
return QLocale::AnyScript; return QLocale::AnyScript;
} }
QLocale::Country QLocalePrivate::codeToCountry(QStringView code) noexcept QLocale::Territory QLocalePrivate::codeToTerritory(QStringView code) noexcept
{ {
const auto len = code.size(); const auto len = code.size();
if (len != 2 && len != 3) if (len != 2 && len != 3)
return QLocale::AnyCountry; return QLocale::AnyTerritory;
char16_t uc1 = code[0].toUpper().unicode(); char16_t uc1 = code[0].toUpper().unicode();
char16_t uc2 = code[1].toUpper().unicode(); char16_t uc2 = code[1].toUpper().unicode();
char16_t uc3 = len > 2 ? code[2].toUpper().unicode() : 0; char16_t uc3 = len > 2 ? code[2].toUpper().unicode() : 0;
const unsigned char *c = country_code_list; const unsigned char *c = territory_code_list;
for (; *c != 0; c += 3) { for (; *c != 0; c += 3) {
if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2]) if (uc1 == c[0] && uc2 == c[1] && uc3 == c[2])
return QLocale::Country((c - country_code_list)/3); return QLocale::Territory((c - territory_code_list)/3);
} }
return QLocale::AnyCountry; return QLocale::AnyTerritory;
} }
QLatin1String QLocalePrivate::languageToCode(QLocale::Language language) QLatin1String QLocalePrivate::languageToCode(QLocale::Language language)
@ -192,12 +192,12 @@ QLatin1String QLocalePrivate::scriptToCode(QLocale::Script script)
return QLatin1String(reinterpret_cast<const char *>(c), 4); return QLatin1String(reinterpret_cast<const char *>(c), 4);
} }
QLatin1String QLocalePrivate::countryToCode(QLocale::Country country) QLatin1String QLocalePrivate::territoryToCode(QLocale::Territory territory)
{ {
if (country == QLocale::AnyCountry || country > QLocale::LastCountry) if (territory == QLocale::AnyTerritory || territory > QLocale::LastTerritory)
return QLatin1String(); return QLatin1String();
const unsigned char *c = country_code_list + 3 * country; const unsigned char *c = territory_code_list + 3 * territory;
return QLatin1String(reinterpret_cast<const char*>(c), c[2] == 0 ? 2 : 3); return QLatin1String(reinterpret_cast<const char*>(c), c[2] == 0 ? 2 : 3);
} }
@ -222,7 +222,7 @@ bool operator<(const LikelyPair &lhs, const LikelyPair &rhs)
// Comparison order: language, region, script: // Comparison order: language, region, script:
if (int cmp = compare(left.language_id, right.language_id)) if (int cmp = compare(left.language_id, right.language_id))
return cmp < 0; return cmp < 0;
if (int cmp = compare(left.country_id, right.country_id)) if (int cmp = compare(left.territory_id, right.territory_id))
return cmp < 0; return cmp < 0;
return compare(left.script_id, right.script_id) < 0; return compare(left.script_id, right.script_id) < 0;
} }
@ -277,25 +277,25 @@ QLocaleId QLocaleId::withLikelySubtagsAdded() const
// chopping within it - just traverse it all: // chopping within it - just traverse it all:
for (; pairs < afterPairs && pairs->key.language_id == language_id; ++pairs) { for (; pairs < afterPairs && pairs->key.language_id == language_id; ++pairs) {
const QLocaleId &key = pairs->key; const QLocaleId &key = pairs->key;
if (key.country_id && key.country_id != country_id) if (key.territory_id && key.territory_id != territory_id)
continue; continue;
if (key.script_id && key.script_id != script_id) if (key.script_id && key.script_id != script_id)
continue; continue;
QLocaleId value = pairs->value; QLocaleId value = pairs->value;
if (country_id && !key.country_id) if (territory_id && !key.territory_id)
value.country_id = country_id; value.territory_id = territory_id;
if (script_id && !key.script_id) if (script_id && !key.script_id)
value.script_id = script_id; value.script_id = script_id;
return value; return value;
} }
} }
// und_script_region or und_region (in that order): // und_script_region or und_region (in that order):
if (country_id) { if (territory_id) {
sought.key = QLocaleId { 0, script_id, country_id }; sought.key = QLocaleId { 0, script_id, territory_id };
pairs = std::lower_bound(pairs, afterPairs, sought); pairs = std::lower_bound(pairs, afterPairs, sought);
// Again, individual und_?_region block isn't long enough to make binary // Again, individual und_?_region block isn't long enough to make binary
// chop a win: // chop a win:
for (; pairs < afterPairs && pairs->key.country_id == country_id; ++pairs) { for (; pairs < afterPairs && pairs->key.territory_id == territory_id; ++pairs) {
const QLocaleId &key = pairs->key; const QLocaleId &key = pairs->key;
Q_ASSERT(!key.language_id); Q_ASSERT(!key.language_id);
if (key.script_id && key.script_id != script_id) if (key.script_id && key.script_id != script_id)
@ -313,12 +313,12 @@ QLocaleId QLocaleId::withLikelySubtagsAdded() const
sought.key = QLocaleId { 0, script_id, 0 }; sought.key = QLocaleId { 0, script_id, 0 };
pairs = std::lower_bound(pairs, afterPairs, sought); pairs = std::lower_bound(pairs, afterPairs, sought);
if (pairs < afterPairs && pairs->key.script_id == script_id) { if (pairs < afterPairs && pairs->key.script_id == script_id) {
Q_ASSERT(!pairs->key.language_id && !pairs->key.country_id); Q_ASSERT(!pairs->key.language_id && !pairs->key.territory_id);
QLocaleId value = pairs->value; QLocaleId value = pairs->value;
if (language_id) if (language_id)
value.language_id = language_id; value.language_id = language_id;
if (country_id) if (territory_id)
value.country_id = country_id; value.territory_id = territory_id;
return value; return value;
} }
} }
@ -345,8 +345,8 @@ QLocaleId QLocaleId::withLikelySubtagsRemoved() const
return id; return id;
} }
// language_region // language_region
if (country_id) { if (territory_id) {
QLocaleId id { language_id, 0, country_id }; QLocaleId id { language_id, 0, territory_id };
if (id.withLikelySubtagsAdded() == max) if (id.withLikelySubtagsAdded() == max)
return id; return id;
} }
@ -370,7 +370,8 @@ QByteArray QLocaleId::name(char separator) const
const unsigned char *script = const unsigned char *script =
(script_id != QLocale::AnyScript ? script_code_list + 4 * script_id : nullptr); (script_id != QLocale::AnyScript ? script_code_list + 4 * script_id : nullptr);
const unsigned char *country = const unsigned char *country =
(country_id != QLocale::AnyCountry ? country_code_list + 3 * country_id : nullptr); (territory_id != QLocale::AnyTerritory
? territory_code_list + 3 * territory_id : nullptr);
char len = (lang[2] != 0 ? 3 : 2) + (script ? 4 + 1 : 0) char len = (lang[2] != 0 ? 3 : 2) + (script ? 4 + 1 : 0)
+ (country ? (country[2] != 0 ? 3 : 2) + 1 : 0); + (country ? (country[2] != 0 ? 3 : 2) + 1 : 0);
QByteArray name(len, Qt::Uninitialized); QByteArray name(len, Qt::Uninitialized);
@ -416,8 +417,8 @@ QByteArray QLocalePrivate::rawName(char separator) const
parts.append(languageCode().latin1()); parts.append(languageCode().latin1());
if (m_data->m_script_id != QLocale::AnyScript) if (m_data->m_script_id != QLocale::AnyScript)
parts.append(scriptCode().latin1()); parts.append(scriptCode().latin1());
if (m_data->m_country_id != QLocale::AnyCountry) if (m_data->m_territory_id != QLocale::AnyTerritory)
parts.append(countryCode().latin1()); parts.append(territoryCode().latin1());
return parts.join(separator); return parts.join(separator);
} }
@ -433,7 +434,7 @@ static int findLocaleIndexById(const QLocaleId &localeId)
Q_ASSERT(localeId.acceptLanguage(locale_data[idx].m_language_id)); Q_ASSERT(localeId.acceptLanguage(locale_data[idx].m_language_id));
do { do {
if (localeId.acceptScriptCountry(locale_data[idx].id())) if (localeId.acceptScriptTerritory(locale_data[idx].id()))
return idx; return idx;
++idx; ++idx;
} while (localeId.acceptLanguage(locale_data[idx].m_language_id)); } while (localeId.acceptLanguage(locale_data[idx].m_language_id));
@ -467,8 +468,8 @@ int QLocaleData::findLocaleIndex(QLocaleId lid)
CheckCandidate(localeId); CheckCandidate(localeId);
// No match; try again with likely country for language_script // No match; try again with likely country for language_script
if (lid.country_id && (lid.language_id || lid.script_id)) { if (lid.territory_id && (lid.language_id || lid.script_id)) {
localeId.country_id = 0; localeId.territory_id = 0;
likelyId = localeId.withLikelySubtagsAdded(); likelyId = localeId.withLikelySubtagsAdded();
CheckCandidate(likelyId); CheckCandidate(likelyId);
@ -477,8 +478,8 @@ int QLocaleData::findLocaleIndex(QLocaleId lid)
} }
// No match; try again with likely script for language_region // No match; try again with likely script for language_region
if (lid.script_id && (lid.language_id || lid.country_id)) { if (lid.script_id && (lid.language_id || lid.territory_id)) {
localeId = QLocaleId { lid.language_id, 0, lid.country_id }; localeId = QLocaleId { lid.language_id, 0, lid.territory_id };
likelyId = localeId.withLikelySubtagsAdded(); likelyId = localeId.withLikelySubtagsAdded();
CheckCandidate(likelyId); CheckCandidate(likelyId);
@ -502,7 +503,7 @@ static QStringView findTag(QStringView name)
static bool validTag(QStringView tag) static bool validTag(QStringView tag)
{ {
// Returns false if any character in tag is not an ASCII letter or digit // Is tag is a non-empty sequence of ASCII letters and/or digits ?
for (QChar uc : tag) { for (QChar uc : tag) {
const char16_t ch = uc.unicode(); const char16_t ch = uc.unicode();
if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))) if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')))
@ -576,7 +577,7 @@ QLocaleId QLocaleId::fromName(const QString &name)
QLocale::Language langId = QLocalePrivate::codeToLanguage(lang); QLocale::Language langId = QLocalePrivate::codeToLanguage(lang);
if (langId == QLocale::AnyLanguage) if (langId == QLocale::AnyLanguage)
return { QLocale::C, 0, 0 }; return { QLocale::C, 0, 0 };
return { langId, QLocalePrivate::codeToScript(script), QLocalePrivate::codeToCountry(land) }; return { langId, QLocalePrivate::codeToScript(script), QLocalePrivate::codeToTerritory(land) };
} }
QString qt_readEscapedFormatString(QStringView format, int *idx) QString qt_readEscapedFormatString(QStringView format, int *idx)
@ -714,9 +715,9 @@ static void updateSystemPrivate()
systemLocaleData.m_language_id = res.toInt(); systemLocaleData.m_language_id = res.toInt();
systemLocaleData.m_script_id = QLocale::AnyScript; // default for compatibility systemLocaleData.m_script_id = QLocale::AnyScript; // default for compatibility
} }
res = sys_locale->query(QSystemLocale::CountryId); res = sys_locale->query(QSystemLocale::TerritoryId);
if (!res.isNull()) { if (!res.isNull()) {
systemLocaleData.m_country_id = res.toInt(); systemLocaleData.m_territory_id = res.toInt();
systemLocaleData.m_script_id = QLocale::AnyScript; // default for compatibility systemLocaleData.m_script_id = QLocale::AnyScript; // default for compatibility
} }
res = sys_locale->query(QSystemLocale::ScriptId); res = sys_locale->query(QSystemLocale::ScriptId);
@ -813,18 +814,18 @@ static QLocalePrivate *localePrivateByName(const QString &name)
} }
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
QLocale::Country country) QLocale::Territory territory)
{ {
if (language == QLocale::C) if (language == QLocale::C)
return c_private(); return c_private();
int index = QLocaleData::findLocaleIndex(QLocaleId { language, script, country }); int index = QLocaleData::findLocaleIndex(QLocaleId { language, script, territory });
Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1); Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1);
const QLocaleData *data = locale_data + index; const QLocaleData *data = locale_data + index;
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions; QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions;
// If not found, should default to system // If not found, should use default locale:
if (data->m_language_id == QLocale::C) { if (data->m_language_id == QLocale::C) {
if (defaultLocalePrivate.exists()) if (defaultLocalePrivate.exists())
numberOptions = defaultLocalePrivate->data()->m_numberOptions; numberOptions = defaultLocalePrivate->data()->m_numberOptions;
@ -937,33 +938,28 @@ QLocale::QLocale(QLocalePrivate &dd)
/*! /*!
Constructs a QLocale object with the specified \a name, Constructs a QLocale object with the specified \a name,
which has the format which has the format
"language[_script][_country][.codeset][@modifier]" or "C", where: "language[_script][_territory][.codeset][@modifier]" or "C", where:
\list \list
\li language is a lowercase, two-letter, ISO 639 language code (also some \li language is a lowercase, two-letter, ISO 639 language code (some
three-letter codes), three-letter codes are also recognized),
\li script is a titlecase, four-letter, ISO 15924 script code, \li script is a capitalized, four-letter, ISO 15924 script code,
\li country is an uppercase, two-letter, ISO 3166 country code \li territory is an uppercase, two-letter, ISO 3166 territory code
(also "419" as defined by United Nations), (some numeric codes are also recognized), and
\li and codeset and modifier are ignored. \li codeset and modifier are ignored.
\endlist \endlist
The separator can be either underscore \c{'_'} (U+005F, "low line") or a The separator can be either underscore \c{'_'} (U+005F, "low line") or a
dash \c{'-'} (U+002D, "hyphen-minus"). dash \c{'-'} (U+002D, "hyphen-minus"). If the string violates the locale
format, or no suitable data can be found for the specified keys, the "C"
locale is used instead. If QLocale has no data for the specified combination
of language, script and territory, the it uses most suitable match it can
find instead.
If the string violates the locale format, or language is not This constructor is much slower than QLocale(Language, Script, Territory) or
a valid ISO 639 code, the "C" locale is used instead. If country QLocale(Language, Territory).
is not present, or is not a valid ISO 3166 code, the most
appropriate country is chosen for the specified language.
The language, script and country codes are converted to their respective \sa bcp47Name(), {Matching combinations of language, script and territory}
\c Language, \c Script and \c Country enums. After this conversion is
performed, the constructor behaves exactly like QLocale(Country, Script,
Language).
This constructor is much slower than QLocale(Country, Script, Language).
\sa bcp47Name()
*/ */
QLocale::QLocale(const QString &name) QLocale::QLocale(const QString &name)
@ -972,9 +968,10 @@ QLocale::QLocale(const QString &name)
} }
/*! /*!
Constructs a QLocale object initialized with the default locale. If Constructs a QLocale object initialized with the default locale.
no default locale was set using setDefault(), this locale will
be the same as the one returned by system(). If no default locale was set using setDefault(), this locale will be the
same as the one returned by system().
\sa setDefault() \sa setDefault()
*/ */
@ -982,60 +979,48 @@ QLocale::QLocale(const QString &name)
QLocale::QLocale() QLocale::QLocale()
: d(*defaultLocalePrivate) : d(*defaultLocalePrivate)
{ {
// Make sure system data is up to date // Make sure system data is up to date:
systemData(); systemData();
} }
/*! /*!
Constructs a QLocale object with the specified \a language and \a Constructs a QLocale object for the specified \a language and \a territory.
country.
\list If there is more than one script in use for this combination, a likely
\li If the language/country pair is found in the database, it is used. script will be selected. If QLocale has no data for the specified \a
\li If the language is found but the country is not, or if the country language, the default locale is used. If QLocale has no data for the
is \c AnyCountry, the language is used with the most specified combination of \a language and \a territory, an alternative
appropriate available country (for example, Germany for German), territory may be used instead.
\li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist
The language and country that are actually used can be queried \sa setDefault(), {Matching combinations of language, script and territory}
using language() and country().
\sa setDefault(), language(), country()
*/ */
QLocale::QLocale(Language language, Country country) QLocale::QLocale(Language language, Territory territory)
: d(findLocalePrivate(language, QLocale::AnyScript, country)) : d(findLocalePrivate(language, QLocale::AnyScript, territory))
{ {
} }
/*! /*!
\since 4.8 \since 4.8
Constructs a QLocale object with the specified \a language, \a script and Constructs a QLocale object for the specified \a language, \a script and \a
\a country. territory.
If QLocale does not have data for the given combination, it will find data
for as good a match as it can. It falls back on the default locale if
\list \list
\li If the language/script/country is found in the database, it is used. \li \a language is \c AnyLanguage and no language can be inferred from \a
\li If both \a script is AnyScript and \a country is AnyCountry, the script and \a territory
language is used with the most appropriate available script and country \li QLocale has no data for the language, either given as \a language or
(for example, Germany for German), inferred as above.
\li If either \a script is AnyScript or \a country is AnyCountry, the
language is used with the first locale that matches the given \a script
and \a country.
\li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist \endlist
The language, script and country that are actually used can be queried \sa setDefault(), {Matching combinations of language, script and territory}
using language(), script() and country().
\sa setDefault(), language(), script(), country()
*/ */
QLocale::QLocale(Language language, Script script, Country country) QLocale::QLocale(Language language, Script script, Territory territory)
: d(findLocalePrivate(language, script, country)) : d(findLocalePrivate(language, script, territory))
{ {
} }
@ -1262,14 +1247,30 @@ QLocale::Script QLocale::script() const
} }
/*! /*!
Returns the country or region of this locale. \since 6.2
\sa language(), script(), countryToString(), bcp47Name() Returns the territory of this locale.
\sa language(), script(), territoryToString(), bcp47Name()
*/
QLocale::Territory QLocale::territory() const
{
return Territory(d->territoryId());
}
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use territory() instead.
Returns the territory of this locale.
\sa language(), script(), territoryToString(), bcp47Name()
*/ */
QLocale::Country QLocale::country() const QLocale::Country QLocale::country() const
{ {
return Country(d->countryId()); return territory();
} }
#endif
/*! /*!
Returns the language and country of this locale as a Returns the language and country of this locale as a
@ -1290,11 +1291,11 @@ QString QLocale::name() const
if (l == C) if (l == C)
return d->languageCode(); return d->languageCode();
Country c = country(); Territory c = territory();
if (c == AnyCountry) if (c == AnyTerritory)
return d->languageCode(); return d->languageCode();
return d->languageCode() + QLatin1Char('_') + d->countryCode(); return d->languageCode() + QLatin1Char('_') + d->territoryCode();
} }
static qlonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool *ok, static qlonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool *ok,
@ -1375,32 +1376,66 @@ QLocale::Language QLocale::codeToLanguage(QStringView languageCode) noexcept
} }
/*! /*!
Returns the two-letter country code for \a country, as defined \since 6.2
Returns the two-letter territory code for \a territory, as defined
in the ISO 3166 standard. in the ISO 3166 standard.
\note For \c{QLocale::AnyCountry} an empty string is returned. \note For \c{QLocale::AnyTerritory} an empty string is returned.
\since 6.1 \sa codeToTerritory(), territory(), name(), bcp47Name(), languageToCode(), scriptToCode()
\sa codeToCountry(), country(), name(), bcp47Name(), languageToCode(), scriptToCode()
*/ */
QString QLocale::countryToCode(Country country) QString QLocale::territoryToCode(QLocale::Territory territory)
{ {
return QLocalePrivate::countryToCode(country); return QLocalePrivate::territoryToCode(territory);
} }
/*! /*!
Returns the QLocale::Country enum corresponding to the two-letter or \since 6.2
Returns the QLocale::Territory enum corresponding to the two-letter or
three-digit \a territoryCode, as defined in the ISO 3166 standard.
If the code is invalid or not known QLocale::AnyTerritory is returned.
\sa territoryToCode(), codeToLanguage(), codeToScript()
*/
QLocale::Territory QLocale::codeToTerritory(QStringView territoryCode) noexcept
{
return QLocalePrivate::codeToTerritory(territoryCode);
}
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use territoryToCode(Territory) instead.
Returns the two-letter territory code for \a country, as defined
in the ISO 3166 standard.
\note For \c{QLocale::AnyTerritory} or \c{QLocale::AnyCountry} an empty string is returned.
\sa codeToTerritory(), territory(), name(), bcp47Name(), languageToCode(), scriptToCode()
*/
QString QLocale::countryToCode(Country country)
{
return territoryToCode(country);
}
/*!
Returns the QLocale::Territory enum corresponding to the two-letter or
three-digit \a countryCode, as defined in the ISO 3166 standard. three-digit \a countryCode, as defined in the ISO 3166 standard.
If the code is invalid or not known QLocale::AnyCountry is returned. If the code is invalid or not known QLocale::AnyTerritory is returned.
\obsolete Use codeToTerritory(QStringView) instead.
\since 6.1 \since 6.1
\sa countryToCode(), codeToLanguage(), codeToScript() \sa territoryToCode(), codeToLanguage(), codeToScript()
*/ */
QLocale::Country QLocale::codeToCountry(QStringView countryCode) noexcept QLocale::Country QLocale::codeToCountry(QStringView countryCode) noexcept
{ {
return QLocalePrivate::codeToCountry(countryCode); return QLocalePrivate::codeToTerritory(countryCode);
} }
#endif
/*! /*!
Returns the four-letter script code for \a script, as defined in the Returns the four-letter script code for \a script, as defined in the
@ -1444,17 +1479,32 @@ QString QLocale::languageToString(Language language)
} }
/*! /*!
\since 6.2
Returns a QString containing the name of \a territory.
\sa languageToString(), scriptToString(), territory(), bcp47Name()
*/
QString QLocale::territoryToString(QLocale::Territory territory)
{
if (territory > QLocale::LastTerritory)
return QLatin1String("Unknown");
return QLatin1String(territory_name_list + territory_name_index[territory]);
}
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use territoryToString(Territory) instead.
Returns a QString containing the name of \a country. Returns a QString containing the name of \a country.
\sa languageToString(), scriptToString(), country(), bcp47Name() \sa languageToString(), scriptToString(), territory(), bcp47Name()
*/ */
QString QLocale::countryToString(Country country) QString QLocale::countryToString(Country country)
{ {
if (country > QLocale::LastCountry) return territoryToString(country);
return QLatin1String("Unknown");
return QLatin1String(country_name_list + country_name_index[country]);
} }
#endif
/*! /*!
\since 4.8 \since 4.8
@ -2563,26 +2613,22 @@ QLocale QLocale::system()
return QLocale(locale); return QLocale(locale);
} }
/*! /*!
\since 4.8
Returns a list of valid locale objects that match the given \a language, \a Returns a list of valid locale objects that match the given \a language, \a
script and \a country. script and \a territory.
Getting a list of all locales: Getting a list of all locales:
QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry); QLocale::AnyTerritory);
Getting a list of locales suitable for Russia: Getting a list of locales suitable for Russia:
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::Russia); QLocale::Russia);
*/ */
QList<QLocale> QLocale::matchingLocales(QLocale::Language language, QList<QLocale> QLocale::matchingLocales(QLocale::Language language, QLocale::Script script,
QLocale::Script script, QLocale::Territory territory)
QLocale::Country country)
{ {
const QLocaleId filter { language, script, country }; const QLocaleId filter { language, script, territory };
if (!filter.isValid()) if (!filter.isValid())
return QList<QLocale>(); return QList<QLocale>();
@ -2597,7 +2643,7 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
Q_ASSERT(filter.acceptLanguage(locale_data[index].m_language_id)); Q_ASSERT(filter.acceptLanguage(locale_data[index].m_language_id));
do { do {
const QLocaleId id = locale_data[index].id(); const QLocaleId id = locale_data[index].id();
if (filter.acceptScriptCountry(id)) { if (filter.acceptScriptTerritory(id)) {
result.append(QLocale(*(id.language_id == C ? c_private() result.append(QLocale(*(id.language_id == C ? c_private()
: new QLocalePrivate(locale_data + index, index)))); : new QLocalePrivate(locale_data + index, index))));
} }
@ -2608,7 +2654,37 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
} }
/*! /*!
\obsolete \since 6.2
Returns the list of countries that have entries for \a language in Qt's locale
database. If the result is an empty list, then \a language is not represented in
Qt's locale database.
\sa matchingLocales()
*/
QList<QLocale::Territory> QLocale::territoriesForLanguage(QLocale::Language language)
{
QList<Territory> result;
if (language == C) {
result << AnyTerritory;
return result;
}
unsigned language_id = language;
const QLocaleData *data = locale_data + locale_index[language_id];
while (data->m_language_id == language_id) {
const QLocale::Territory territory = static_cast<Territory>(data->m_territory_id);
if (!result.contains(territory))
result.append(territory);
++data;
}
return result;
}
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use territoriesForLanguage(Language) instead.
\since 4.3 \since 4.3
Returns the list of countries that have entries for \a language in Qt's locale Returns the list of countries that have entries for \a language in Qt's locale
@ -2619,23 +2695,9 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
*/ */
QList<QLocale::Country> QLocale::countriesForLanguage(Language language) QList<QLocale::Country> QLocale::countriesForLanguage(Language language)
{ {
QList<Country> result; return territoriesForLanguage(language);
if (language == C) {
result << AnyCountry;
return result;
}
unsigned language_id = language;
const QLocaleData *data = locale_data + locale_index[language_id];
while (data->m_language_id == language_id) {
const QLocale::Country country = static_cast<Country>(data->m_country_id);
if (!result.contains(country))
result.append(country);
++data;
}
return result;
} }
#endif
/*! /*!
\since 4.2 \since 4.2
@ -2928,7 +2990,7 @@ QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const
{ {
for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) { for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) {
if (ImperialMeasurementSystems[i].languageId == m_data->m_language_id if (ImperialMeasurementSystems[i].languageId == m_data->m_language_id
&& ImperialMeasurementSystems[i].countryId == m_data->m_country_id) { && ImperialMeasurementSystems[i].territoryId == m_data->m_territory_id) {
return ImperialMeasurementSystems[i].system; return ImperialMeasurementSystems[i].system;
} }
} }
@ -4318,7 +4380,7 @@ QLocale QLocale::collation() const
Returns a native name of the language for the locale. For example Returns a native name of the language for the locale. For example
"Schwiizertüütsch" for Swiss-German locale. "Schwiizertüütsch" for Swiss-German locale.
\sa nativeCountryName(), languageToString() \sa nativeTerritoryName(), languageToString()
*/ */
QString QLocale::nativeLanguageName() const QString QLocale::nativeLanguageName() const
{ {
@ -4333,25 +4395,41 @@ QString QLocale::nativeLanguageName() const
} }
/*! /*!
\since 4.8 \since 6.2
Returns a native name of the country for the locale. For example Returns a native name of the territory for the locale. For example
"España" for Spanish/Spain locale. "España" for Spanish/Spain locale.
\sa nativeLanguageName(), countryToString() \sa nativeLanguageName(), territoryToString()
*/ */
QString QLocale::nativeCountryName() const QString QLocale::nativeTerritoryName() const
{ {
#ifndef QT_NO_SYSTEMLOCALE #ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == &systemLocaleData) { if (d->m_data == &systemLocaleData) {
auto res = systemLocale()->query(QSystemLocale::NativeCountryName).toString(); auto res = systemLocale()->query(QSystemLocale::NativeTerritoryName).toString();
if (!res.isEmpty()) if (!res.isEmpty())
return res; return res;
} }
#endif #endif
return d->m_data->endonymCountry().getData(endonyms_data); return d->m_data->endonymTerritory().getData(endonyms_data);
} }
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use nativeTerritoryName() instead.
\since 4.8
Returns a native name of the territory for the locale. For example
"España" for Spanish/Spain locale.
\sa nativeLanguageName(), territoryToString()
*/
QString QLocale::nativeCountryName() const
{
return nativeTerritoryName();
}
#endif
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QLocale &l) QDebug operator<<(QDebug dbg, const QLocale &l)
{ {
@ -4359,7 +4437,7 @@ QDebug operator<<(QDebug dbg, const QLocale &l)
dbg.nospace().noquote() dbg.nospace().noquote()
<< "QLocale(" << QLocale::languageToString(l.language()) << "QLocale(" << QLocale::languageToString(l.language())
<< ", " << QLocale::scriptToString(l.script()) << ", " << QLocale::scriptToString(l.script())
<< ", " << QLocale::countryToString(l.country()) << ')'; << ", " << QLocale::territoryToString(l.territory()) << ')';
return dbg; return dbg;
} }
#endif #endif

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -580,8 +580,9 @@ public:
LastScript = YiScript LastScript = YiScript
}; };
// ### Qt 7: Rename to Territory
enum Country : ushort { enum Country : ushort {
AnyCountry = 0, AnyTerritory = 0,
Afghanistan = 1, Afghanistan = 1,
AlandIslands = 2, AlandIslands = 2,
Albania = 3, Albania = 3,
@ -744,7 +745,7 @@ public:
Mozambique = 160, Mozambique = 160,
Myanmar = 161, Myanmar = 161,
Namibia = 162, Namibia = 162,
NauruCountry = 163, NauruTerritory = 163,
Nepal = 164, Nepal = 164,
Netherlands = 165, Netherlands = 165,
NewCaledonia = 166, NewCaledonia = 166,
@ -815,7 +816,7 @@ public:
Thailand = 231, Thailand = 231,
TimorLeste = 232, TimorLeste = 232,
Togo = 233, Togo = 233,
TokelauCountry = 234, TokelauTerritory = 234,
Tonga = 235, Tonga = 235,
TrinidadAndTobago = 236, TrinidadAndTobago = 236,
TristanDaCunha = 237, TristanDaCunha = 237,
@ -823,7 +824,7 @@ public:
Turkey = 239, Turkey = 239,
Turkmenistan = 240, Turkmenistan = 240,
TurksAndCaicosIslands = 241, TurksAndCaicosIslands = 241,
TuvaluCountry = 242, TuvaluTerritory = 242,
Uganda = 243, Uganda = 243,
Ukraine = 244, Ukraine = 244,
UnitedArabEmirates = 245, UnitedArabEmirates = 245,
@ -844,6 +845,7 @@ public:
Zambia = 260, Zambia = 260,
Zimbabwe = 261, Zimbabwe = 261,
AnyCountry = AnyTerritory,
Bonaire = CaribbeanNetherlands, Bonaire = CaribbeanNetherlands,
BosniaAndHerzegowina = BosniaAndHerzegovina, BosniaAndHerzegowina = BosniaAndHerzegovina,
CuraSao = Curacao, CuraSao = Curacao,
@ -853,6 +855,7 @@ public:
EastTimor = TimorLeste, EastTimor = TimorLeste,
LatinAmericaAndTheCaribbean = LatinAmerica, LatinAmericaAndTheCaribbean = LatinAmerica,
Macau = Macao, Macau = Macao,
NauruCountry = NauruTerritory,
PeoplesRepublicOfCongo = CongoBrazzaville, PeoplesRepublicOfCongo = CongoBrazzaville,
RepublicOfKorea = SouthKorea, RepublicOfKorea = SouthKorea,
RussianFederation = Russia, RussianFederation = Russia,
@ -861,14 +864,19 @@ public:
SvalbardAndJanMayenIslands = SvalbardAndJanMayen, SvalbardAndJanMayenIslands = SvalbardAndJanMayen,
Swaziland = Eswatini, Swaziland = Eswatini,
SyrianArabRepublic = Syria, SyrianArabRepublic = Syria,
TokelauCountry = TokelauTerritory,
TuvaluCountry = TuvaluTerritory,
UnitedStatesMinorOutlyingIslands = UnitedStatesOutlyingIslands, UnitedStatesMinorOutlyingIslands = UnitedStatesOutlyingIslands,
VaticanCityState = VaticanCity, VaticanCityState = VaticanCity,
WallisAndFutunaIslands = WallisAndFutuna, WallisAndFutunaIslands = WallisAndFutuna,
LastCountry = Zimbabwe LastTerritory = Zimbabwe,
LastCountry = LastTerritory
}; };
// GENERATED PART ENDS HERE // GENERATED PART ENDS HERE
using Territory = Country; // ### Qt 7: reverse
Q_ENUM(Language) Q_ENUM(Language)
Q_ENUM(Country) Q_ENUM(Country)
Q_ENUM(Script) Q_ENUM(Script)
@ -918,8 +926,8 @@ public:
QLocale(); QLocale();
explicit QLocale(const QString &name); explicit QLocale(const QString &name);
QLocale(Language language, Country country = AnyCountry); QLocale(Language language, Territory territory);
QLocale(Language language, Script script, Country country); QLocale(Language language, Script script = AnyScript, Territory territory = AnyTerritory);
QLocale(const QLocale &other); QLocale(const QLocale &other);
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QLocale) QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QLocale)
QLocale &operator=(const QLocale &other); QLocale &operator=(const QLocale &other);
@ -929,12 +937,20 @@ public:
Language language() const; Language language() const;
Script script() const; Script script() const;
Territory territory() const;
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use territory() instead")
Country country() const; Country country() const;
#endif
QString name() const; QString name() const;
QString bcp47Name() const; QString bcp47Name() const;
QString nativeLanguageName() const; QString nativeLanguageName() const;
QString nativeTerritoryName() const;
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use nativeTerritoryName() instead")
QString nativeCountryName() const; QString nativeCountryName() const;
#endif
#if QT_STRINGVIEW_LEVEL < 2 #if QT_STRINGVIEW_LEVEL < 2
short toShort(const QString &s, bool *ok = nullptr) const short toShort(const QString &s, bool *ok = nullptr) const
@ -1069,21 +1085,35 @@ public:
static QString languageToCode(Language language); static QString languageToCode(Language language);
static Language codeToLanguage(QStringView languageCode) noexcept; static Language codeToLanguage(QStringView languageCode) noexcept;
static QString territoryToCode(Territory territory);
static Territory codeToTerritory(QStringView territoryCode) noexcept;
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use territoryToCode(Territory) instead")
static QString countryToCode(Country country); static QString countryToCode(Country country);
QT_DEPRECATED_VERSION_X_6_6("Use codeToTerritory(QStringView) instead")
static Country codeToCountry(QStringView countryCode) noexcept; static Country codeToCountry(QStringView countryCode) noexcept;
#endif
static QString scriptToCode(Script script); static QString scriptToCode(Script script);
static Script codeToScript(QStringView scriptCode) noexcept; static Script codeToScript(QStringView scriptCode) noexcept;
static QString languageToString(Language language); static QString languageToString(Language language);
static QString territoryToString(Territory territory);
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use territoryToString(Territory) instead")
static QString countryToString(Country country); static QString countryToString(Country country);
#endif
static QString scriptToString(Script script); static QString scriptToString(Script script);
static void setDefault(const QLocale &locale); static void setDefault(const QLocale &locale);
static QLocale c() { return QLocale(C); } static QLocale c() { return QLocale(C); }
static QLocale system(); static QLocale system();
static QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country); static QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Territory territory);
static QList<Territory> territoriesForLanguage(Language lang);
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use territoriesForLanguage(Language) instead")
static QList<Country> countriesForLanguage(Language lang); static QList<Country> countriesForLanguage(Language lang);
#endif
void setNumberOptions(NumberOptions options); void setNumberOptions(NumberOptions options);
NumberOptions numberOptions() const; NumberOptions numberOptions() const;

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the documentation of the Qt Toolkit. ** This file is part of the documentation of the Qt Toolkit.
@ -36,10 +36,9 @@
\ingroup string-processing \ingroup string-processing
\ingroup shared \ingroup shared
QLocale is constructed for a specified language, optional script and
QLocale is initialized with a language/country pair in its territory. It offers various facilities for formatting data as text,
constructor and offers number-to-string and string-to-number localized appropriately, and for reading data out of localized text.
conversion functions similar to those in QString.
Example: Example:
@ -54,9 +53,6 @@
\list \list
\li If a QLocale object is constructed with the default constructor, \li If a QLocale object is constructed with the default constructor,
it will use the default locale's settings. it will use the default locale's settings.
\li QString::toInt(), QString::toDouble(), etc., interpret the
string according to the default locale. If this fails, it
falls back on the "C" locale.
\li QString::arg() uses the default locale to format a number when \li QString::arg() uses the default locale to format a number when
its position specifier in the format string contains an 'L', its position specifier in the format string contains an 'L',
e.g. "%L1". e.g. "%L1".
@ -66,36 +62,47 @@
\snippet code/src_corelib_text_qlocale.cpp 1 \snippet code/src_corelib_text_qlocale.cpp 1
When a language/country pair is specified in the constructor, one
of three things can happen:
\list
\li If the language/country pair is found in the database, it is used.
\li If the language is found but the country is not, or if the country
is \c AnyCountry, the language is used with the most
appropriate available country (for example, Germany for German),
\li If neither the language nor the country are found, QLocale
defaults to the default locale (see setDefault()).
\endlist
Use language() and country() to determine the actual language and
country values used.
An alternative method for constructing a QLocale object is by An alternative method for constructing a QLocale object is by
specifying the locale name. specifying the locale name.
\snippet code/src_corelib_text_qlocale.cpp 2 \snippet code/src_corelib_text_qlocale.cpp 2
This constructor converts the locale name to a language/country This constructor reads the language, script and/or territory from the given
pair; it does not use the system locale database. name, accepting either uderscore or dash as separator (and ignoring any
trailing \c{.codeset} or \c{@variant} suffix).
\note For the current keyboard input locale take a look at \note For the current keyboard input locale take a look at
QInputMethod::locale(). QInputMethod::locale().
QLocale's data is based on Common Locale Data Repository v38. QLocale's data is based on Common Locale Data Repository v38.
\sa QString::arg(), QString::toInt(), QString::toDouble(), \section1 Matching combinations of language, script and territory
QInputMethod::locale()
QLocale has data, derived from CLDR, for many combinations of language,
script and territory, but not all. If it is constructed with all three of
these key values specified (treating \c AnyLanguage, \c AnyScript or \c
AnyTerritory as unspecified) and QLocale has data for the given combination,
this data is used. Otherwise, QLocale does its best to find a sensible
combination of language, script and territory, for which it does have data,
that matches those that were specified.
The CLDR provides tables of likely combinations, which are used to fill in
any unspecified key or keys; if QLocale has data for the result of such a
likely combination, that is used. If no language is specified, and none can
be determined from script and territory, or if QLocale has no data for the
language, the "C" locale (when reading the keys from a string) or default
locale (otherwise) is used.
When QLocale has no data for the keys specified, with likely keys filled in
where unspecified, but does have data for the resulting language, a
fall-back is sought, based on ignoring either territory, script or both (in
that order). This results in a QLocale which may not match what was asked
for, but provides localization that's as suitable as the available data
permits, for the keys specified.
Use language(), script() and territory() to determine the actual keys used.
\sa QString::arg(), QInputMethod::locale()
*/ */
/*! /*!
@ -457,12 +464,26 @@
\sa language(), languageToString() \sa language(), languageToString()
*/ */
/*!
\enum QLocale::Territory
This enumeration type is an alias for Country,
which shall be renamed to Territory at a future release.
\sa territory(), territoryToString()
*/
/*! /*!
\enum QLocale::Country \enum QLocale::Country
This enumerated type is used to specify a country or a region. This enumerated type is used to identify a territory.
\value AnyCountry An individual territory may be a province of a country, a country (by far the
most common case) or a larger geographic entity, to which some localization
details are specific.
\value AnyCountry Osbolete alias for \c AnyTerritory
\value AnyTerritory Since 6.2
\value Afghanistan \value Afghanistan
\value AlandIslands \value AlandIslands
@ -635,7 +656,8 @@
\value Mozambique \value Mozambique
\value Myanmar \value Myanmar
\value Namibia \value Namibia
\value NauruCountry \value NauruCountry Osbolete alias for \c NauruTerritory
\value NauruTerritory Since 6.2
\value Nepal \value Nepal
\value Netherlands \value Netherlands
\value NewCaledonia \value NewCaledonia
@ -714,7 +736,8 @@
\value Thailand \value Thailand
\value TimorLeste \value TimorLeste
\value Togo \value Togo
\value TokelauCountry \value TokelauCountry Osbolete alias for \c TokelauTerritory
\value TokelauTerritory Since 6.2
\value Tonga \value Tonga
\value TrinidadAndTobago \value TrinidadAndTobago
\value TristanDaCunha \value TristanDaCunha
@ -722,7 +745,8 @@
\value Turkey \value Turkey
\value Turkmenistan \value Turkmenistan
\value TurksAndCaicosIslands \value TurksAndCaicosIslands
\value TuvaluCountry \value TuvaluCountry Osbolete alias for \c TuvaluTerritory
\value TuvaluTerritory Since 6.2
\value Uganda \value Uganda
\value Ukraine \value Ukraine
\value UnitedArabEmirates \value UnitedArabEmirates
@ -746,9 +770,13 @@
\value Zambia \value Zambia
\value Zimbabwe \value Zimbabwe
\omitvalue LastCountry \omitvalue LastCountry Osbolete alias for \c LastTerritory
\omitvalue LastTerritory
\sa country(), countryToString() \note Use the Territory alias for this enumeration where possible.
The Country enum shall be renamed to Territory at a later release.
\sa territory(), territoryToString(), codeToTerritory(), territoryToCode()
*/ */
/*! /*!
@ -1011,7 +1039,7 @@
otherwise returns \c false. otherwise returns \c false.
\note The system locale is not equal to the QLocale object constructed from \note The system locale is not equal to the QLocale object constructed from
its language(), script() and country(), even if the two agree in all data its language(), script() and territory(), even if the two agree in all data
fields. Nor are two locales with different number options equal. fields. Nor are two locales with different number options equal.
\sa operator!=(), setNumberOptions() \sa operator!=(), setNumberOptions()
@ -1024,7 +1052,7 @@
otherwise returns \c false. otherwise returns \c false.
\note The system locale is not equal to the QLocale object constructed from \note The system locale is not equal to the QLocale object constructed from
its language(), script() and country(), even if the two agree in all data its language(), script() and territory(), even if the two agree in all data
fields. Nor are two locales with different number options equal. fields. Nor are two locales with different number options equal.
\sa operator==(), setNumberOptions() \sa operator==(), setNumberOptions()
@ -1072,7 +1100,7 @@
\value LanguageId a uint specifying the language. \value LanguageId a uint specifying the language.
\value ScriptId a uint specifying the script. \value ScriptId a uint specifying the script.
\value CountryId a uint specifying the country. \value TerritoryId a uint specifying the territory.
\value DecimalPoint a QString specifying the decimal point. \value DecimalPoint a QString specifying the decimal point.
\value GroupSeparator a QString specifying the group separator. \value GroupSeparator a QString specifying the group separator.
\value ZeroDigit a QString specifying the zero digit. \value ZeroDigit a QString specifying the zero digit.
@ -1107,7 +1135,7 @@
\value LocaleChanged this type is queried whenever the system locale is changed. \value LocaleChanged this type is queried whenever the system locale is changed.
\value ListToSeparatedString a string that represents a join of a given QStringList with a locale-defined separator. \value ListToSeparatedString a string that represents a join of a given QStringList with a locale-defined separator.
\value NativeLanguageName a string that represents the name of the native language. \value NativeLanguageName a string that represents the name of the native language.
\value NativeCountryName a string that represents the name of the native country. \value NativeTerritoryName a string that represents the name of the native territory.
\sa FormatType \sa FormatType
*/ */

View File

@ -58,13 +58,13 @@ QT_BEGIN_NAMESPACE
/* This part of the file isn't generated, but written by hand since /* This part of the file isn't generated, but written by hand since
* Unicode CLDR doesn't contain measurement system information. * Unicode CLDR doesn't contain measurement system information.
*/ */
struct CountryLanguage struct TerritoryLanguage
{ {
quint16 languageId; quint16 languageId;
quint16 countryId; quint16 territoryId;
QLocale::MeasurementSystem system; QLocale::MeasurementSystem system;
}; };
static const CountryLanguage ImperialMeasurementSystems[] = { static const TerritoryLanguage ImperialMeasurementSystems[] = {
{ QLocale::English, QLocale::UnitedStates, QLocale::ImperialUSSystem }, { QLocale::English, QLocale::UnitedStates, QLocale::ImperialUSSystem },
{ QLocale::English, QLocale::UnitedStatesMinorOutlyingIslands, QLocale::ImperialUSSystem }, { QLocale::English, QLocale::UnitedStatesMinorOutlyingIslands, QLocale::ImperialUSSystem },
{ QLocale::Spanish, QLocale::UnitedStates, QLocale::ImperialUSSystem }, { QLocale::Spanish, QLocale::UnitedStates, QLocale::ImperialUSSystem },
@ -77,7 +77,7 @@ static const int ImperialMeasurementSystemsCount =
// GENERATED PART STARTS HERE // GENERATED PART STARTS HERE
/* /*
This part of the file was generated on 2020-11-12 from the This part of the file was generated on 2021-03-12 from the
Common Locale Data Repository v38 Common Locale Data Repository v38
http://www.unicode.org/cldr/ http://www.unicode.org/cldr/
@ -1152,7 +1152,7 @@ static const quint16 locale_index[] = {
static const QLocaleData locale_data[] = { static const QLocaleData locale_data[] = {
// lang script terr lStrt lpMid lpEnd lPair lDelm dec group prcnt zero minus plus exp qtOpn qtEnd altQO altQE lDFmt sDFmt lTFmt sTFmt slDay lDays ssDys sDays snDay nDays am pm byte siQnt iecQn crSym crDsp crFmt crFNg ntLng ntTer currISO curDgt curRnd dow1st wknd+ wknd- grpTop grpMid grpEnd // lang script terr lStrt lpMid lpEnd lPair lDelm dec group prcnt zero minus plus exp qtOpn qtEnd altQO altQE lDFmt sDFmt lTFmt sTFmt slDay lDays ssDys sDays snDay nDays am pm byte siQnt iecQn crSym crDsp crFmt crFNg ntLng ntTer currISO curDgt curRnd dow1st wknd+ wknd- grpTop grpMid grpEnd
{ 1, 0, 0, 0, 0, 0, 0, 6, 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 8, 0, 17, 0, 0, 0, 0, 56, 56, 83, 96, 0, 0, 0, 5, 22, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 8, 56, 56, 27, 27, 13, 13, 2, 2, 5, 17, 23, 0, 0, 4, 0, 0, 0, {0,0,0}, 2, 1, 1, 6, 7, 1, 3, 3 }, // C/AnyScript/AnyCountry { 1, 0, 0, 0, 0, 0, 0, 6, 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 8, 0, 17, 0, 0, 0, 0, 56, 56, 83, 96, 0, 0, 0, 5, 22, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 8, 56, 56, 27, 27, 13, 13, 2, 2, 5, 17, 23, 0, 0, 4, 0, 0, 0, {0,0,0}, 2, 1, 1, 6, 7, 1, 3, 3 }, // C/AnyScript/AnyTerritory
{ 3, 66, 77, 0, 0, 0, 0, 6, 0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 27, 44, 0, 0, 56, 56, 56, 56, 83, 83, 0, 0, 0, 5, 22, 0, 0, 4, 0, 0, 0, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 5, 27, 27, 27, 27, 13, 13, 2, 2, 4, 17, 23, 0, 0, 5, 0, 0, 0, {69,84,66}, 2, 1, 7, 6, 7, 1, 3, 3 }, // Afar/Latin/Ethiopia { 3, 66, 77, 0, 0, 0, 0, 6, 0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 27, 44, 0, 0, 56, 56, 56, 56, 83, 83, 0, 0, 0, 5, 22, 0, 0, 4, 0, 0, 0, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 5, 27, 27, 27, 27, 13, 13, 2, 2, 4, 17, 23, 0, 0, 5, 0, 0, 0, {69,84,66}, 2, 1, 7, 6, 7, 1, 3, 3 }, // Afar/Latin/Ethiopia
{ 4, 66, 216, 0, 0, 7, 7, 6, 1, 14, 2, 3, 4, 5, 9, 10, 11, 12, 13, 54, 44, 0, 0, 109, 109, 166, 166, 193, 193, 2, 2, 45, 5, 22, 0, 0, 9, 13, 0, 9, 6, 6, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 5, 57, 57, 27, 27, 13, 13, 3, 3, 5, 17, 23, 1, 20, 4, 6, 9, 11, {90,65,82}, 2, 1, 7, 6, 7, 1, 3, 3 }, // Afrikaans/Latin/South Africa { 4, 66, 216, 0, 0, 7, 7, 6, 1, 14, 2, 3, 4, 5, 9, 10, 11, 12, 13, 54, 44, 0, 0, 109, 109, 166, 166, 193, 193, 2, 2, 45, 5, 22, 0, 0, 9, 13, 0, 9, 6, 6, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 10, 10, 5, 57, 57, 27, 27, 13, 13, 3, 3, 5, 17, 23, 1, 20, 4, 6, 9, 11, {90,65,82}, 2, 1, 7, 6, 7, 1, 3, 3 }, // Afrikaans/Latin/South Africa
{ 4, 66, 162, 0, 0, 7, 7, 6, 1, 14, 2, 3, 4, 5, 9, 10, 11, 12, 13, 71, 44, 10, 22, 109, 109, 166, 166, 193, 193, 2, 2, 45, 5, 22, 1, 20, 9, 13, 0, 20, 6, 6, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 10, 12, 7, 57, 57, 27, 27, 13, 13, 3, 3, 5, 17, 23, 1, 16, 4, 6, 9, 7, {78,65,68}, 2, 1, 1, 6, 7, 1, 3, 3 }, // Afrikaans/Latin/Namibia { 4, 66, 162, 0, 0, 7, 7, 6, 1, 14, 2, 3, 4, 5, 9, 10, 11, 12, 13, 71, 44, 10, 22, 109, 109, 166, 166, 193, 193, 2, 2, 45, 5, 22, 1, 20, 9, 13, 0, 20, 6, 6, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 10, 12, 7, 57, 57, 27, 27, 13, 13, 3, 3, 5, 17, 23, 1, 16, 4, 6, 9, 7, {78,65,68}, 2, 1, 1, 6, 7, 1, 3, 3 }, // Afrikaans/Latin/Namibia
@ -4775,7 +4775,7 @@ static const quint16 script_name_index[] = {
1312, // Yi 1312, // Yi
}; };
static const char country_name_list[] = static const char territory_name_list[] =
"Default\0" "Default\0"
"Afghanistan\0" "Afghanistan\0"
"Aland Islands\0" "Aland Islands\0"
@ -5040,8 +5040,8 @@ static const char country_name_list[] =
"Zimbabwe\0" "Zimbabwe\0"
; ;
static const quint16 country_name_index[] = { static const quint16 territory_name_index[] = {
0, // AnyCountry 0, // AnyTerritory
8, // Afghanistan 8, // Afghanistan
20, // Aland Islands 20, // Aland Islands
34, // Albania 34, // Albania
@ -5781,8 +5781,8 @@ static const unsigned char script_code_list[] =
"Yiii" // Yi "Yiii" // Yi
; ;
static const unsigned char country_code_list[] = static const unsigned char territory_code_list[] =
"ZZ\0" // AnyCountry "ZZ\0" // AnyTerritory
"AF\0" // Afghanistan "AF\0" // Afghanistan
"AX\0" // Aland Islands "AX\0" // Aland Islands
"AL\0" // Albania "AL\0" // Albania

View File

@ -426,8 +426,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
switch(type) { switch(type) {
case LanguageId: case LanguageId:
return getLocaleValue<QLocalePrivate::codeToLanguage>(kCFLocaleLanguageCode); return getLocaleValue<QLocalePrivate::codeToLanguage>(kCFLocaleLanguageCode);
case CountryId: case TerritoryId:
return getLocaleValue<QLocalePrivate::codeToCountry>(kCFLocaleCountryCode); return getLocaleValue<QLocalePrivate::codeToTerritory>(kCFLocaleCountryCode);
case ScriptId: case ScriptId:
return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode); return getLocaleValue<QLocalePrivate::codeToScript>(kCFLocaleScriptCode);
case DecimalPoint: case DecimalPoint:

View File

@ -85,7 +85,7 @@ public:
enum QueryType { enum QueryType {
LanguageId, // uint LanguageId, // uint
CountryId, // uint TerritoryId, // uint
DecimalPoint, // QString DecimalPoint, // QString
GroupSeparator, // QString (empty QString means: don't group digits) GroupSeparator, // QString (empty QString means: don't group digits)
ZeroDigit, // QString ZeroDigit, // QString
@ -122,7 +122,7 @@ public:
ListToSeparatedString, // QString ListToSeparatedString, // QString
LocaleChanged, // system locale changed LocaleChanged, // system locale changed
NativeLanguageName, // QString NativeLanguageName, // QString
NativeCountryName, // QString NativeTerritoryName, // QString
StandaloneMonthNameLong, // QString, in: int StandaloneMonthNameLong, // QString, in: int
StandaloneMonthNameShort // QString, in: int StandaloneMonthNameShort // QString, in: int
}; };
@ -150,17 +150,17 @@ struct QLocaleId
{ {
Q_CORE_EXPORT static QLocaleId fromName(const QString &name); Q_CORE_EXPORT static QLocaleId fromName(const QString &name);
inline bool operator==(QLocaleId other) const inline bool operator==(QLocaleId other) const
{ return language_id == other.language_id && script_id == other.script_id && country_id == other.country_id; } { return language_id == other.language_id && script_id == other.script_id && territory_id == other.territory_id; }
inline bool operator!=(QLocaleId other) const inline bool operator!=(QLocaleId other) const
{ return !operator==(other); } { return !operator==(other); }
inline bool isValid() const inline bool isValid() const
{ {
return language_id <= QLocale::LastLanguage && script_id <= QLocale::LastScript return language_id <= QLocale::LastLanguage && script_id <= QLocale::LastScript
&& country_id <= QLocale::LastCountry; && territory_id <= QLocale::LastTerritory;
} }
inline bool matchesAll() const inline bool matchesAll() const
{ {
return !language_id && !script_id && !country_id; return !language_id && !script_id && !territory_id;
} }
// Use as: filter.accept...(candidate) // Use as: filter.accept...(candidate)
inline bool acceptLanguage(quint16 lang) const inline bool acceptLanguage(quint16 lang) const
@ -169,9 +169,9 @@ struct QLocaleId
// So, when searching for AnyLanguage, accept everything *but* AnyLanguage. // So, when searching for AnyLanguage, accept everything *but* AnyLanguage.
return language_id ? lang == language_id : lang; return language_id ? lang == language_id : lang;
} }
inline bool acceptScriptCountry(QLocaleId other) const inline bool acceptScriptTerritory(QLocaleId other) const
{ {
return (!country_id || other.country_id == country_id) return (!territory_id || other.territory_id == territory_id)
&& (!script_id || other.script_id == script_id); && (!script_id || other.script_id == script_id);
} }
@ -180,7 +180,7 @@ struct QLocaleId
QByteArray name(char separator = '-') const; QByteArray name(char separator = '-') const;
ushort language_id = 0, script_id = 0, country_id = 0; ushort language_id = 0, script_id = 0, territory_id = 0;
}; };
Q_DECLARE_TYPEINFO(QLocaleId, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QLocaleId, Q_PRIMITIVE_TYPE);
@ -288,7 +288,7 @@ public:
QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const; QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const;
// Access to assorted data members: // Access to assorted data members:
QLocaleId id() const { return QLocaleId { m_language_id, m_script_id, m_country_id }; } QLocaleId id() const { return QLocaleId { m_language_id, m_script_id, m_territory_id }; }
QString decimalPoint() const; QString decimalPoint() const;
QString groupSeparator() const; QString groupSeparator() const;
@ -359,7 +359,7 @@ public:
X(byteCount) X(byteAmountSI) X(byteAmountIEC) \ X(byteCount) X(byteAmountSI) X(byteAmountIEC) \
X(currencySymbol) X(currencyDisplayName) \ X(currencySymbol) X(currencyDisplayName) \
X(currencyFormat) X(currencyFormatNegative) \ X(currencyFormat) X(currencyFormatNegative) \
X(endonymLanguage) X(endonymCountry) X(endonymLanguage) X(endonymTerritory)
#define rangeGetter(name) \ #define rangeGetter(name) \
DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; } DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; }
@ -367,7 +367,7 @@ public:
#undef rangeGetter #undef rangeGetter
public: public:
quint16 m_language_id, m_script_id, m_country_id; quint16 m_language_id, m_script_id, m_territory_id;
// Offsets, then sizes, for each range: // Offsets, then sizes, for each range:
#define rangeIndex(name) quint16 m_ ## name ## _idx; #define rangeIndex(name) quint16 m_ ## name ## _idx;
@ -401,22 +401,22 @@ public:
m_index(index), m_numberOptions(numberOptions) {} m_index(index), m_numberOptions(numberOptions) {}
quint16 languageId() const { return m_data->m_language_id; } quint16 languageId() const { return m_data->m_language_id; }
quint16 countryId() const { return m_data->m_country_id; } quint16 territoryId() const { return m_data->m_territory_id; }
QByteArray bcp47Name(char separator = '-') const; QByteArray bcp47Name(char separator = '-') const;
QByteArray rawName(char separator = '-') const; QByteArray rawName(char separator = '-') const;
inline QLatin1String languageCode() const { return languageToCode(QLocale::Language(m_data->m_language_id)); } inline QLatin1String languageCode() const { return languageToCode(QLocale::Language(m_data->m_language_id)); }
inline QLatin1String scriptCode() const { return scriptToCode(QLocale::Script(m_data->m_script_id)); } inline QLatin1String scriptCode() const { return scriptToCode(QLocale::Script(m_data->m_script_id)); }
inline QLatin1String countryCode() const { return countryToCode(QLocale::Country(m_data->m_country_id)); } inline QLatin1String territoryCode() const { return territoryToCode(QLocale::Territory(m_data->m_territory_id)); }
static const QLocalePrivate *get(const QLocale &l) { return l.d; } static const QLocalePrivate *get(const QLocale &l) { return l.d; }
static QLatin1String languageToCode(QLocale::Language language); static QLatin1String languageToCode(QLocale::Language language);
static QLatin1String scriptToCode(QLocale::Script script); static QLatin1String scriptToCode(QLocale::Script script);
static QLatin1String countryToCode(QLocale::Country country); static QLatin1String territoryToCode(QLocale::Territory territory);
static QLocale::Language codeToLanguage(QStringView code) noexcept; static QLocale::Language codeToLanguage(QStringView code) noexcept;
static QLocale::Script codeToScript(QStringView code) noexcept; static QLocale::Script codeToScript(QStringView code) noexcept;
static QLocale::Country codeToCountry(QStringView code) noexcept; static QLocale::Territory codeToTerritory(QStringView code) noexcept;
QLocale::MeasurementSystem measurementSystem() const; QLocale::MeasurementSystem measurementSystem() const;

View File

@ -130,7 +130,7 @@ static bool contradicts(const QString &maybe, const QString &known)
*/ */
QLocaleId knownId = QLocaleId::fromName(known); QLocaleId knownId = QLocaleId::fromName(known);
QLocaleId maybeId = QLocaleId::fromName(maybe); QLocaleId maybeId = QLocaleId::fromName(maybe);
return !(maybeId.acceptLanguage(knownId.language_id) && maybeId.acceptScriptCountry(knownId)); return !(maybeId.acceptLanguage(knownId.language_id) && maybeId.acceptScriptTerritory(knownId));
} }
QLocale QSystemLocale::fallbackLocale() const QLocale QSystemLocale::fallbackLocale() const

View File

@ -107,7 +107,7 @@ struct QSystemLocalePrivate
QVariant toCurrencyString(const QSystemLocale::CurrencyToStringArgument &); QVariant toCurrencyString(const QSystemLocale::CurrencyToStringArgument &);
QVariant uiLanguages(); QVariant uiLanguages();
QVariant nativeLanguageName(); QVariant nativeLanguageName();
QVariant nativeCountryName(); QVariant nativeTerritoryName();
void update(); void update();
@ -625,7 +625,7 @@ QVariant QSystemLocalePrivate::nativeLanguageName()
return getLocaleInfo(LOCALE_SNATIVELANGUAGENAME); return getLocaleInfo(LOCALE_SNATIVELANGUAGENAME);
} }
QVariant QSystemLocalePrivate::nativeCountryName() QVariant QSystemLocalePrivate::nativeTerritoryName()
{ {
return getLocaleInfo(LOCALE_SNATIVECOUNTRYNAME); return getLocaleInfo(LOCALE_SNATIVECOUNTRYNAME);
} }
@ -757,13 +757,13 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
return d->zeroDigit(); return d->zeroDigit();
case LanguageId: case LanguageId:
case ScriptId: case ScriptId:
case CountryId: { case TerritoryId: {
QLocaleId lid = QLocaleId::fromName(QString::fromLatin1(getWinLocaleName())); QLocaleId lid = QLocaleId::fromName(QString::fromLatin1(getWinLocaleName()));
if (type == LanguageId) if (type == LanguageId)
return lid.language_id; return lid.language_id;
if (type == ScriptId) if (type == ScriptId)
return lid.script_id ? lid.script_id : ushort(fallbackLocale().script()); return lid.script_id ? lid.script_id : ushort(fallbackLocale().script());
return lid.country_id ? lid.country_id : ushort(fallbackLocale().country()); return lid.territory_id ? lid.territory_id : ushort(fallbackLocale().territory());
} }
case MeasurementSystem: case MeasurementSystem:
return d->measurementSystem(); return d->measurementSystem();
@ -786,8 +786,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
break; break;
case NativeLanguageName: case NativeLanguageName:
return d->nativeLanguageName(); return d->nativeLanguageName();
case NativeCountryName: case NativeTerritoryName:
return d->nativeCountryName(); return d->nativeTerritoryName();
default: default:
break; break;
} }

View File

@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE
// Locale-related parts, mostly handled in ../text/qlocale.cpp // Locale-related parts, mostly handled in ../text/qlocale.cpp
struct QCalendarLocale { struct QCalendarLocale {
quint16 m_language_id, m_script_id, m_country_id; quint16 m_language_id, m_script_id, m_territory_id;
#define rangeGetter(name) \ #define rangeGetter(name) \
QLocaleData::DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; } QLocaleData::DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; }

View File

@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
// GENERATED PART STARTS HERE // GENERATED PART STARTS HERE
/* /*
This part of the file was generated on 2020-10-30 from the This part of the file was generated on 2021-03-12 from the
Common Locale Data Repository v38 Common Locale Data Repository v38
http://www.unicode.org/cldr/ http://www.unicode.org/cldr/
@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
static const QCalendarLocale locale_data[] = { static const QCalendarLocale locale_data[] = {
// lang script terr sLong long sShrt short sNarw narow Sizes... // lang script terr sLong long sShrt short sNarw narow Sizes...
{ 1, 0, 0, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// C/AnyScript/AnyCountry { 1, 0, 0, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// C/AnyScript/AnyTerritory
{ 3, 66, 77, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afar/Latin/Ethiopia { 3, 66, 77, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afar/Latin/Ethiopia
{ 4, 66, 216, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afrikaans/Latin/South Africa { 4, 66, 216, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afrikaans/Latin/South Africa
{ 4, 66, 162, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afrikaans/Latin/Namibia { 4, 66, 162, 0, 0, 106, 106, 184, 184,106,106, 78, 78, 26, 26 },// Afrikaans/Latin/Namibia

View File

@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
// GENERATED PART STARTS HERE // GENERATED PART STARTS HERE
/* /*
This part of the file was generated on 2020-10-30 from the This part of the file was generated on 2021-03-12 from the
Common Locale Data Repository v38 Common Locale Data Repository v38
http://www.unicode.org/cldr/ http://www.unicode.org/cldr/
@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
static const QCalendarLocale locale_data[] = { static const QCalendarLocale locale_data[] = {
// lang script terr sLong long sShrt short sNarw narow Sizes... // lang script terr sLong long sShrt short sNarw narow Sizes...
{ 1, 0, 0, 0, 0, 83, 83, 130, 153, 83, 83, 47, 47, 23, 26 },// C/AnyScript/AnyCountry { 1, 0, 0, 0, 0, 83, 83, 130, 153, 83, 83, 47, 47, 23, 26 },// C/AnyScript/AnyTerritory
{ 3, 66, 77, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afar/Latin/Ethiopia { 3, 66, 77, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afar/Latin/Ethiopia
{ 4, 66, 216, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afrikaans/Latin/South Africa { 4, 66, 216, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afrikaans/Latin/South Africa
{ 4, 66, 162, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afrikaans/Latin/Namibia { 4, 66, 162, 0, 0, 0, 0, 153, 153, 83, 83, 83, 83, 26, 26 },// Afrikaans/Latin/Namibia

View File

@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
// GENERATED PART STARTS HERE // GENERATED PART STARTS HERE
/* /*
This part of the file was generated on 2020-10-30 from the This part of the file was generated on 2021-03-12 from the
Common Locale Data Repository v38 Common Locale Data Repository v38
http://www.unicode.org/cldr/ http://www.unicode.org/cldr/
@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
static const QCalendarLocale locale_data[] = { static const QCalendarLocale locale_data[] = {
// lang script terr sLong long sShrt short sNarw narow Sizes... // lang script terr sLong long sShrt short sNarw narow Sizes...
{ 1, 0, 0, 0, 0, 85, 85, 132, 155, 85, 85, 47, 47, 23, 26 },// C/AnyScript/AnyCountry { 1, 0, 0, 0, 0, 85, 85, 132, 155, 85, 85, 47, 47, 23, 26 },// C/AnyScript/AnyTerritory
{ 3, 66, 77, 181, 181, 181, 181, 155, 155, 47, 47, 47, 47, 26, 26 },// Afar/Latin/Ethiopia { 3, 66, 77, 181, 181, 181, 181, 155, 155, 47, 47, 47, 47, 26, 26 },// Afar/Latin/Ethiopia
{ 4, 66, 216, 228, 228, 319, 319, 132, 132, 91, 91, 58, 58, 23, 23 },// Afrikaans/Latin/South Africa { 4, 66, 216, 228, 228, 319, 319, 132, 132, 91, 91, 58, 58, 23, 23 },// Afrikaans/Latin/South Africa
{ 4, 66, 162, 228, 228, 319, 319, 132, 132, 91, 91, 58, 58, 23, 23 },// Afrikaans/Latin/Namibia { 4, 66, 162, 228, 228, 319, 319, 132, 132, 91, 91, 58, 58, 23, 23 },// Afrikaans/Latin/Namibia

View File

@ -373,23 +373,23 @@ QTimeZone::QTimeZone(int offsetSeconds)
Creates a custom time zone with an ID of \a ianaId and an offset from UTC Creates a custom time zone with an ID of \a ianaId and an offset from UTC
of \a offsetSeconds. The \a name will be the name used by displayName() of \a offsetSeconds. The \a name will be the name used by displayName()
for the LongName, the \a abbreviation will be used by displayName() for the for the LongName, the \a abbreviation will be used by displayName() for the
ShortName and by abbreviation(), and the optional \a country will be used ShortName and by abbreviation(), and the optional \a territory will be used
by country(). The \a comment is an optional note that may be displayed in by territory(). The \a comment is an optional note that may be displayed in
a GUI to assist users in selecting a time zone. a GUI to assist users in selecting a time zone.
The \a ianaId must not be one of the available system IDs returned by The \a ianaId must not be one of the available system IDs returned by
availableTimeZoneIds(). The \a offsetSeconds from UTC must be in the range availableTimeZoneIds(). The \a offsetSeconds from UTC must be in the range
-14 hours to +14 hours. -14 hours to +14 hours.
If the custom time zone does not have a specific country then set it to the If the custom time zone does not have a specific territory then set it to the
default value of QLocale::AnyCountry. default value of QLocale::AnyTerritory.
*/ */
QTimeZone::QTimeZone(const QByteArray &ianaId, int offsetSeconds, const QString &name, QTimeZone::QTimeZone(const QByteArray &ianaId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &comment) const QString &abbreviation, QLocale::Territory territory, const QString &comment)
{ {
if (!isTimeZoneIdAvailable(ianaId)) if (!isTimeZoneIdAvailable(ianaId))
d = new QUtcTimeZonePrivate(ianaId, offsetSeconds, name, abbreviation, country, comment); d = new QUtcTimeZonePrivate(ianaId, offsetSeconds, name, abbreviation, territory, comment);
} }
/*! /*!
@ -482,7 +482,7 @@ bool QTimeZone::isValid() const
Returns the IANA ID for the time zone. Returns the IANA ID for the time zone.
IANA IDs are used on all platforms. On Windows these are translated IANA IDs are used on all platforms. On Windows these are translated
from the Windows ID into the closest IANA ID for the time zone and country. from the Windows ID into the closest IANA ID for the time zone and territory.
*/ */
QByteArray QTimeZone::id() const QByteArray QTimeZone::id() const
@ -491,13 +491,27 @@ QByteArray QTimeZone::id() const
} }
/*! /*!
Returns the country for the time zone. \since 6.2
Returns the territory for the time zone.
*/
QLocale::Territory QTimeZone::territory() const
{
return isValid() ? d->territory() : QLocale::AnyTerritory;
}
#if QT_DEPRECATED_SINCE(6, 6)
/*!
\obsolete Use territory() instead.
Returns the territory for the time zone.
*/ */
QLocale::Country QTimeZone::country() const QLocale::Country QTimeZone::country() const
{ {
return isValid() ? d->country() : QLocale::AnyCountry; return territory();
} }
#endif
/*! /*!
Returns any comment for the time zone. Returns any comment for the time zone.
@ -841,20 +855,20 @@ QList<QByteArray> QTimeZone::availableTimeZoneIds()
} }
/*! /*!
Returns a list of all available IANA time zone IDs for a given \a country. Returns a list of all available IANA time zone IDs for a given \a territory.
As a special case, a \a country of Qt::AnyCountry returns those time zones As a special case, a \a territory of Qt::AnyTerritory returns those time zones
that do not have any country related to them, such as UTC. If you require that do not have any territory related to them, such as UTC. If you require
a list of all time zone IDs for all countries then use the standard a list of all time zone IDs for all countries then use the standard
availableTimeZoneIds() method. availableTimeZoneIds() method.
\sa isTimeZoneIdAvailable() \sa isTimeZoneIdAvailable()
*/ */
QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Country country) QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Territory territory)
{ {
return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(country), return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(territory),
global_tz->backend->availableTimeZoneIds(country)); global_tz->backend->availableTimeZoneIds(territory));
} }
/*! /*!
@ -898,21 +912,20 @@ QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId)
} }
/*! /*!
Returns the default IANA ID for a given \a windowsId and \a country. Returns the default IANA ID for a given \a windowsId and \a territory.
Because a Windows ID can cover several IANA IDs within a given country, Because a Windows ID can cover several IANA IDs within a given territory,
the most frequently used IANA ID in that country is returned. the most frequently used IANA ID in that territory is returned.
As a special case, QLocale::AnyCountry returns the default of those IANA IDs As a special case, QLocale::AnyTerritory returns the default of those IANA IDs
that do not have any specific country. that do not have any specific territory.
\sa ianaIdToWindowsId(), windowsIdToIanaIds() \sa ianaIdToWindowsId(), windowsIdToIanaIds()
*/ */
QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId, QByteArray QTimeZone::windowsIdToDefaultIanaId(const QByteArray &windowsId, QLocale::Territory territory)
QLocale::Country country)
{ {
return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId, country); return QTimeZonePrivate::windowsIdToDefaultIanaId(windowsId, territory);
} }
/*! /*!
@ -929,21 +942,20 @@ QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId)
} }
/*! /*!
Returns all the IANA IDs for a given \a windowsId and \a country. Returns all the IANA IDs for a given \a windowsId and \a territory.
As a special case QLocale::AnyCountry returns those IANA IDs that do As a special case QLocale::AnyTerritory returns those IANA IDs that do
not have any specific country. not have any specific territory.
The returned list is in order of frequency of usage, i.e. larger zones The returned list is in order of frequency of usage, i.e. larger zones
within a country are listed first. within a territory are listed first.
\sa ianaIdToWindowsId(), windowsIdToDefaultIanaId() \sa ianaIdToWindowsId(), windowsIdToDefaultIanaId()
*/ */
QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId, QList<QByteArray> QTimeZone::windowsIdToIanaIds(const QByteArray &windowsId, QLocale::Territory territory)
QLocale::Country country)
{ {
return QTimeZonePrivate::windowsIdToIanaIds(windowsId, country); return QTimeZonePrivate::windowsIdToIanaIds(windowsId, territory);
} }
#ifndef QT_NO_DATASTREAM #ifndef QT_NO_DATASTREAM
@ -969,16 +981,16 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz)
int utcOffset; int utcOffset;
QString name; QString name;
QString abbreviation; QString abbreviation;
int country; int territory;
QString comment; QString comment;
ds >> ianaId >> utcOffset >> name >> abbreviation >> country >> comment; ds >> ianaId >> utcOffset >> name >> abbreviation >> territory >> comment;
// Try creating as a system timezone, which succeeds (producing a valid // Try creating as a system timezone, which succeeds (producing a valid
// zone) iff ianaId is valid; we can then ignore the other data. // zone) iff ianaId is valid; we can then ignore the other data.
tz = QTimeZone(ianaId.toUtf8()); tz = QTimeZone(ianaId.toUtf8());
// If not, then construct a custom timezone using all the saved values: // If not, then construct a custom timezone using all the saved values:
if (!tz.isValid()) if (!tz.isValid())
tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation,
QLocale::Country(country), comment); QLocale::Territory(territory), comment);
} else { } else {
tz = QTimeZone(ianaId.toUtf8()); tz = QTimeZone(ianaId.toUtf8());
} }

View File

@ -93,7 +93,7 @@ public:
explicit QTimeZone(const QByteArray &ianaId); explicit QTimeZone(const QByteArray &ianaId);
explicit QTimeZone(int offsetSeconds); explicit QTimeZone(int offsetSeconds);
QTimeZone(const QByteArray &zoneId, int offsetSeconds, const QString &name, QTimeZone(const QByteArray &zoneId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country = QLocale::AnyCountry, const QString &abbreviation, QLocale::Territory territory = QLocale::AnyTerritory,
const QString &comment = QString()); const QString &comment = QString());
QTimeZone(const QTimeZone &other); QTimeZone(const QTimeZone &other);
~QTimeZone(); ~QTimeZone();
@ -110,7 +110,11 @@ public:
bool isValid() const; bool isValid() const;
QByteArray id() const; QByteArray id() const;
QLocale::Territory territory() const;
#if QT_DEPRECATED_SINCE(6, 6)
QT_DEPRECATED_VERSION_X_6_6("Use territory() instead")
QLocale::Country country() const; QLocale::Country country() const;
#endif
QString comment() const; QString comment() const;
QString displayName(const QDateTime &atDateTime, QString displayName(const QDateTime &atDateTime,
@ -142,16 +146,16 @@ public:
static bool isTimeZoneIdAvailable(const QByteArray &ianaId); static bool isTimeZoneIdAvailable(const QByteArray &ianaId);
static QList<QByteArray> availableTimeZoneIds(); static QList<QByteArray> availableTimeZoneIds();
static QList<QByteArray> availableTimeZoneIds(QLocale::Country country); static QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory);
static QList<QByteArray> availableTimeZoneIds(int offsetSeconds); static QList<QByteArray> availableTimeZoneIds(int offsetSeconds);
static QByteArray ianaIdToWindowsId(const QByteArray &ianaId); static QByteArray ianaIdToWindowsId(const QByteArray &ianaId);
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId); static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId);
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId, static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId,
QLocale::Country country); QLocale::Territory territory);
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId); static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId);
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId, static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Country country); QLocale::Territory territory);
#if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE) #if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE)
static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone); static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);

View File

@ -171,7 +171,7 @@ QByteArray QTimeZonePrivate::id() const
return m_id; return m_id;
} }
QLocale::Country QTimeZonePrivate::country() const QLocale::Territory QTimeZonePrivate::territory() const
{ {
// Default fall-back mode, use the zoneTable to find Region of known Zones // Default fall-back mode, use the zoneTable to find Region of known Zones
for (int i = 0; i < zoneDataTableSize; ++i) { for (int i = 0; i < zoneDataTableSize; ++i) {
@ -181,11 +181,11 @@ QLocale::Country QTimeZonePrivate::country() const
qsizetype index = idView.indexOf(' '); qsizetype index = idView.indexOf(' ');
QByteArrayView next = index == -1 ? idView : idView.first(index); QByteArrayView next = index == -1 ? idView : idView.first(index);
if (next == m_id) if (next == m_id)
return (QLocale::Country)data->country; return (QLocale::Territory)data->territory;
idView = index == -1 ? QByteArrayView() : idView.sliced(index + 1); idView = index == -1 ? QByteArrayView() : idView.sliced(index + 1);
} }
} }
return QLocale::AnyCountry; return QLocale::AnyTerritory;
} }
QString QTimeZonePrivate::comment() const QString QTimeZonePrivate::comment() const
@ -524,14 +524,14 @@ QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds() const
return QList<QByteArray>(); return QList<QByteArray>();
} }
QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Territory territory) const
{ {
// Default fall-back mode, use the zoneTable to find Region of know Zones // Default fall-back mode, use the zoneTable to find Region of know Zones
QList<QByteArray> regions; QList<QByteArray> regions;
// First get all Zones in the Zones table belonging to the Region // First get all Zones in the Zones table belonging to the Region
for (int i = 0; i < zoneDataTableSize; ++i) { for (int i = 0; i < zoneDataTableSize; ++i) {
if (zoneData(i)->country == country) if (zoneData(i)->territory == territory)
regions += ianaId(zoneData(i)).split(' '); regions += ianaId(zoneData(i)).split(' ');
} }
@ -739,9 +739,9 @@ QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsI
} }
QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsId, QByteArray QTimeZonePrivate::windowsIdToDefaultIanaId(const QByteArray &windowsId,
QLocale::Country country) QLocale::Territory territory)
{ {
const QList<QByteArray> list = windowsIdToIanaIds(windowsId, country); const QList<QByteArray> list = windowsIdToIanaIds(windowsId, territory);
if (list.count() > 0) if (list.count() > 0)
return list.first(); return list.first();
else else
@ -765,13 +765,13 @@ QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windows
} }
QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windowsId, QList<QByteArray> QTimeZonePrivate::windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Country country) QLocale::Territory territory)
{ {
const quint16 windowsIdKey = toWindowsIdKey(windowsId); const quint16 windowsIdKey = toWindowsIdKey(windowsId);
for (int i = 0; i < zoneDataTableSize; ++i) { for (int i = 0; i < zoneDataTableSize; ++i) {
const QZoneData *data = zoneData(i); const QZoneData *data = zoneData(i);
// Return the region matches in preference order // Return the region matches in preference order
if (data->windowsIdKey == windowsIdKey && data->country == (quint16) country) if (data->windowsIdKey == windowsIdKey && data->territory == static_cast<quint16>(territory))
return ianaId(data).split(' '); return ianaId(data).split(' ');
} }
@ -793,7 +793,7 @@ template<> QTimeZonePrivate *QSharedDataPointer<QTimeZonePrivate>::clone()
QUtcTimeZonePrivate::QUtcTimeZonePrivate() QUtcTimeZonePrivate::QUtcTimeZonePrivate()
{ {
const QString name = utcQString(); const QString name = utcQString();
init(utcQByteArray(), 0, name, name, QLocale::AnyCountry, name); init(utcQByteArray(), 0, name, name, QLocale::AnyTerritory, name);
} }
// Create a named UTC time zone // Create a named UTC time zone
@ -805,7 +805,7 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &id)
const QByteArray uid = utcId(data); const QByteArray uid = utcId(data);
if (uid == id) { if (uid == id) {
QString name = QString::fromUtf8(id); QString name = QString::fromUtf8(id);
init(id, data->offsetFromUtc, name, name, QLocale::AnyCountry, name); init(id, data->offsetFromUtc, name, name, QLocale::AnyTerritory, name);
break; break;
} }
} }
@ -848,21 +848,21 @@ qint64 QUtcTimeZonePrivate::offsetFromUtcString(const QByteArray &id)
QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds) QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds)
{ {
QString utcId = isoOffsetFormat(offsetSeconds, QTimeZone::ShortName); QString utcId = isoOffsetFormat(offsetSeconds, QTimeZone::ShortName);
init(utcId.toUtf8(), offsetSeconds, utcId, utcId, QLocale::AnyCountry, utcId); init(utcId.toUtf8(), offsetSeconds, utcId, utcId, QLocale::AnyTerritory, utcId);
} }
QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSeconds, QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSeconds,
const QString &name, const QString &abbreviation, const QString &name, const QString &abbreviation,
QLocale::Country country, const QString &comment) QLocale::Territory territory, const QString &comment)
{ {
init(zoneId, offsetSeconds, name, abbreviation, country, comment); init(zoneId, offsetSeconds, name, abbreviation, territory, comment);
} }
QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other) QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other)
: QTimeZonePrivate(other), m_name(other.m_name), : QTimeZonePrivate(other), m_name(other.m_name),
m_abbreviation(other.m_abbreviation), m_abbreviation(other.m_abbreviation),
m_comment(other.m_comment), m_comment(other.m_comment),
m_country(other.m_country), m_territory(other.m_territory),
m_offsetFromUtc(other.m_offsetFromUtc) m_offsetFromUtc(other.m_offsetFromUtc)
{ {
} }
@ -892,20 +892,20 @@ void QUtcTimeZonePrivate::init(const QByteArray &zoneId)
} }
void QUtcTimeZonePrivate::init(const QByteArray &zoneId, int offsetSeconds, const QString &name, void QUtcTimeZonePrivate::init(const QByteArray &zoneId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &abbreviation, QLocale::Territory territory,
const QString &comment) const QString &comment)
{ {
m_id = zoneId; m_id = zoneId;
m_offsetFromUtc = offsetSeconds; m_offsetFromUtc = offsetSeconds;
m_name = name; m_name = name;
m_abbreviation = abbreviation; m_abbreviation = abbreviation;
m_country = country; m_territory = territory;
m_comment = comment; m_comment = comment;
} }
QLocale::Country QUtcTimeZonePrivate::country() const QLocale::Territory QUtcTimeZonePrivate::territory() const
{ {
return m_country; return m_territory;
} }
QString QUtcTimeZonePrivate::comment() const QString QUtcTimeZonePrivate::comment() const
@ -974,10 +974,10 @@ QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const
return result; return result;
} }
QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Territory country) const
{ {
// If AnyCountry then is request for all non-region offset codes // If AnyTerritory then is request for all non-region offset codes
if (country == QLocale::AnyCountry) if (country == QLocale::AnyTerritory)
return availableTimeZoneIds(); return availableTimeZoneIds();
return QList<QByteArray>(); return QList<QByteArray>();
} }
@ -1002,7 +1002,7 @@ QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds
void QUtcTimeZonePrivate::serialize(QDataStream &ds) const void QUtcTimeZonePrivate::serialize(QDataStream &ds) const
{ {
ds << QStringLiteral("OffsetFromUtc") << QString::fromUtf8(m_id) << m_offsetFromUtc << m_name ds << QStringLiteral("OffsetFromUtc") << QString::fromUtf8(m_id) << m_offsetFromUtc << m_name
<< m_abbreviation << (qint32) m_country << m_comment; << m_abbreviation << static_cast<qint32>(m_territory) << m_comment;
} }
#endif // QT_NO_DATASTREAM #endif // QT_NO_DATASTREAM

View File

@ -90,14 +90,14 @@ static QJniObject getDisplayName(QJniObject zone, jint style, jboolean dst,
{ {
QJniObject jlanguage QJniObject jlanguage
= QJniObject::fromString(QLocale::languageToString(locale.language())); = QJniObject::fromString(QLocale::languageToString(locale.language()));
QJniObject jcountry QJniObject jterritory
= QJniObject::fromString(QLocale::countryToString(locale.country())); = QJniObject::fromString(QLocale::territoryToString(locale.territory()));
QJniObject QJniObject
jvariant = QJniObject::fromString(QLocale::scriptToString(locale.script())); jvariant = QJniObject::fromString(QLocale::scriptToString(locale.script()));
QJniObject jlocale("java.util.Locale", QJniObject jlocale("java.util.Locale",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
static_cast<jstring>(jlanguage.object()), static_cast<jstring>(jlanguage.object()),
static_cast<jstring>(jcountry.object()), static_cast<jstring>(jterritory.object()),
static_cast<jstring>(jvariant.object())); static_cast<jstring>(jvariant.object()));
return zone.callObjectMethod("getDisplayName", return zone.callObjectMethod("getDisplayName",

View File

@ -75,7 +75,7 @@ QT_BEGIN_NAMESPACE
struct QZoneData { struct QZoneData {
quint16 windowsIdKey; // Windows ID Key quint16 windowsIdKey; // Windows ID Key
quint16 country; // Country of IANA ID's, AnyCountry means No Country quint16 territory; // Territory of IANA ID's, AnyTerritory means No Territory
quint16 ianaIdIndex; // All IANA ID's for the Windows ID and Country, space separated quint16 ianaIdIndex; // All IANA ID's for the Windows ID and Country, space separated
}; };

View File

@ -475,9 +475,9 @@ QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds() const
return result; return result;
} }
QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Territory territory) const
{ {
const QLatin1String regionCode = QLocalePrivate::countryToCode(country); const QLatin1String regionCode = QLocalePrivate::territoryToCode(territory);
const QByteArray regionCodeUtf8 = QString(regionCode).toUtf8(); const QByteArray regionCodeUtf8 = QString(regionCode).toUtf8();
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
UEnumeration *uenum = ucal_openCountryTimeZones(regionCodeUtf8.data(), &status); UEnumeration *uenum = ucal_openCountryTimeZones(regionCodeUtf8.data(), &status);

View File

@ -101,7 +101,7 @@ public:
bool isValid() const; bool isValid() const;
QByteArray id() const; QByteArray id() const;
virtual QLocale::Country country() const; virtual QLocale::Territory territory() const;
virtual QString comment() const; virtual QString comment() const;
virtual QString displayName(qint64 atMSecsSinceEpoch, virtual QString displayName(qint64 atMSecsSinceEpoch,
@ -131,7 +131,7 @@ public:
virtual bool isTimeZoneIdAvailable(const QByteArray &ianaId) const; virtual bool isTimeZoneIdAvailable(const QByteArray &ianaId) const;
virtual QList<QByteArray> availableTimeZoneIds() const; virtual QList<QByteArray> availableTimeZoneIds() const;
virtual QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const; virtual QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory) const;
virtual QList<QByteArray> availableTimeZoneIds(int utcOffset) const; virtual QList<QByteArray> availableTimeZoneIds(int utcOffset) const;
virtual void serialize(QDataStream &ds) const; virtual void serialize(QDataStream &ds) const;
@ -151,10 +151,10 @@ public:
static QByteArray ianaIdToWindowsId(const QByteArray &ianaId); static QByteArray ianaIdToWindowsId(const QByteArray &ianaId);
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId); static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId);
static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId, static QByteArray windowsIdToDefaultIanaId(const QByteArray &windowsId,
QLocale::Country country); QLocale::Territory territory);
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId); static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId);
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId, static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Country country); QLocale::Territory territory);
// returns "UTC" QString and QByteArray // returns "UTC" QString and QByteArray
[[nodiscard]] static inline QString utcQString() [[nodiscard]] static inline QString utcQString()
@ -185,7 +185,7 @@ public:
QUtcTimeZonePrivate(qint32 offsetSeconds); QUtcTimeZonePrivate(qint32 offsetSeconds);
// Create custom offset from UTC // Create custom offset from UTC
QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSeconds, const QString &name, QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &abbreviation, QLocale::Territory territory,
const QString &comment); const QString &comment);
QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other); QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other);
virtual ~QUtcTimeZonePrivate(); virtual ~QUtcTimeZonePrivate();
@ -197,7 +197,7 @@ public:
Data data(qint64 forMSecsSinceEpoch) const override; Data data(qint64 forMSecsSinceEpoch) const override;
QLocale::Country country() const override; QLocale::Territory territory() const override;
QString comment() const override; QString comment() const override;
QString displayName(QTimeZone::TimeType timeType, QString displayName(QTimeZone::TimeType timeType,
@ -212,7 +212,7 @@ public:
bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override; bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override;
QList<QByteArray> availableTimeZoneIds() const override; QList<QByteArray> availableTimeZoneIds() const override;
QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const override; QList<QByteArray> availableTimeZoneIds(QLocale::Territory country) const override;
QList<QByteArray> availableTimeZoneIds(int utcOffset) const override; QList<QByteArray> availableTimeZoneIds(int utcOffset) const override;
void serialize(QDataStream &ds) const override; void serialize(QDataStream &ds) const override;
@ -220,13 +220,13 @@ public:
private: private:
void init(const QByteArray &zoneId); void init(const QByteArray &zoneId);
void init(const QByteArray &zoneId, int offsetSeconds, const QString &name, void init(const QByteArray &zoneId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &abbreviation, QLocale::Territory territory,
const QString &comment); const QString &comment);
QString m_name; QString m_name;
QString m_abbreviation; QString m_abbreviation;
QString m_comment; QString m_comment;
QLocale::Country m_country; QLocale::Territory m_territory;
int m_offsetFromUtc; int m_offsetFromUtc;
}; };
@ -263,7 +263,7 @@ public:
QByteArray systemTimeZoneId() const override; QByteArray systemTimeZoneId() const override;
QList<QByteArray> availableTimeZoneIds() const override; QList<QByteArray> availableTimeZoneIds() const override;
QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const override; QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory) const override;
QList<QByteArray> availableTimeZoneIds(int offsetFromUtc) const override; QList<QByteArray> availableTimeZoneIds(int offsetFromUtc) const override;
private: private:
@ -315,7 +315,7 @@ public:
QTzTimeZonePrivate *clone() const override; QTzTimeZonePrivate *clone() const override;
QLocale::Country country() const override; QLocale::Territory territory() const override;
QString comment() const override; QString comment() const override;
QString displayName(qint64 atMSecsSinceEpoch, QString displayName(qint64 atMSecsSinceEpoch,
@ -343,7 +343,7 @@ public:
bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override; bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override;
QList<QByteArray> availableTimeZoneIds() const override; QList<QByteArray> availableTimeZoneIds() const override;
QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const override; QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory) const override;
private: private:
void init(const QByteArray &ianaId); void init(const QByteArray &ianaId);

View File

@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE
*/ */
struct QTzTimeZone { struct QTzTimeZone {
QLocale::Country country; QLocale::Territory territory;
QByteArray comment; QByteArray comment;
}; };
@ -98,7 +98,7 @@ static QTzTimeZoneHash loadTzTimeZones()
if (Q_LIKELY(cut > 0)) { if (Q_LIKELY(cut > 0)) {
QTzTimeZone zone; QTzTimeZone zone;
// TODO: QLocale & friends could do this look-up without UTF8-conversion: // TODO: QLocale & friends could do this look-up without UTF8-conversion:
zone.country = QLocalePrivate::codeToCountry(QString::fromUtf8(text.first(cut))); zone.territory = QLocalePrivate::codeToTerritory(QString::fromUtf8(text.first(cut)));
text = text.sliced(cut + 1); text = text.sliced(cut + 1);
cut = text.indexOf('\t'); cut = text.indexOf('\t');
if (Q_LIKELY(cut >= 0)) { // Skip over Coordinates, read ID and comment if (Q_LIKELY(cut >= 0)) { // Skip over Coordinates, read ID and comment
@ -916,9 +916,9 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId)
} }
} }
QLocale::Country QTzTimeZonePrivate::country() const QLocale::Territory QTzTimeZonePrivate::territory() const
{ {
return tzZones->value(m_id).country; return tzZones->value(m_id).territory;
} }
QString QTzTimeZonePrivate::comment() const QString QTzTimeZonePrivate::comment() const
@ -1165,12 +1165,12 @@ QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const
return result; return result;
} }
QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Territory territory) const
{ {
// TODO AnyCountry // TODO AnyTerritory
QList<QByteArray> result; QList<QByteArray> result;
for (auto it = tzZones->cbegin(), end = tzZones->cend(); it != end; ++it) { for (auto it = tzZones->cbegin(), end = tzZones->cend(); it != end; ++it) {
if (it.value().country == country) if (it.value().territory == territory)
result << it.key(); result << it.key();
} }
std::sort(result.begin(), result.end()); std::sort(result.begin(), result.end());

View File

@ -376,13 +376,13 @@ int yearEndOffset(const QWinTimeZonePrivate::QWinTransitionRule &rule, int year)
return offset; return offset;
} }
QLocale::Country userCountry() QLocale::Territory userTerritory()
{ {
const GEOID id = GetUserGeoID(GEOCLASS_NATION); const GEOID id = GetUserGeoID(GEOCLASS_NATION);
wchar_t code[3]; wchar_t code[3];
const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0); const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0);
return (size == 3) ? QLocalePrivate::codeToCountry(QStringView(code, size)) return (size == 3) ? QLocalePrivate::codeToTerritory(QStringView(code, size))
: QLocale::AnyCountry; : QLocale::AnyTerritory;
} }
// Index of last rule in rules with .startYear <= year: // Index of last rule in rules with .startYear <= year:
@ -727,13 +727,13 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec
QByteArray QWinTimeZonePrivate::systemTimeZoneId() const QByteArray QWinTimeZonePrivate::systemTimeZoneId() const
{ {
const QLocale::Country country = userCountry(); const QLocale::Territory territory = userTerritory();
const QByteArray windowsId = windowsSystemZoneId(); const QByteArray windowsId = windowsSystemZoneId();
QByteArray ianaId; QByteArray ianaId;
// If we have a real country, then try get a specific match for that country // If we have a real territory, then try get a specific match for that territory
if (country != QLocale::AnyCountry) if (territory != QLocale::AnyTerritory)
ianaId = windowsIdToDefaultIanaId(windowsId, country); ianaId = windowsIdToDefaultIanaId(windowsId, territory);
// If we don't have a real country, or there wasn't a specific match, try the global default // If we don't have a real territory, or there wasn't a specific match, try the global default
if (ianaId.isEmpty()) if (ianaId.isEmpty())
ianaId = windowsIdToDefaultIanaId(windowsId); ianaId = windowsIdToDefaultIanaId(windowsId);
return ianaId; return ianaId;

View File

@ -108,7 +108,7 @@ public:
RCCFileInfo(const QString &name = QString(), const QFileInfo &fileInfo = QFileInfo(), RCCFileInfo(const QString &name = QString(), const QFileInfo &fileInfo = QFileInfo(),
QLocale::Language language = QLocale::C, QLocale::Language language = QLocale::C,
QLocale::Country country = QLocale::AnyCountry, QLocale::Territory territory = QLocale::AnyTerritory,
uint flags = NoFlags, uint flags = NoFlags,
RCCResourceLibrary::CompressionAlgorithm compressAlgo = CONSTANT_COMPRESSALGO_DEFAULT, RCCResourceLibrary::CompressionAlgorithm compressAlgo = CONSTANT_COMPRESSALGO_DEFAULT,
int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT, int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT,
@ -126,7 +126,7 @@ public:
int m_flags; int m_flags;
QString m_name; QString m_name;
QLocale::Language m_language; QLocale::Language m_language;
QLocale::Country m_country; QLocale::Territory m_territory;
QFileInfo m_fileInfo; QFileInfo m_fileInfo;
RCCFileInfo *m_parent; RCCFileInfo *m_parent;
QMultiHash<QString, RCCFileInfo *> m_children; QMultiHash<QString, RCCFileInfo *> m_children;
@ -141,14 +141,14 @@ public:
}; };
RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo, RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo,
QLocale::Language language, QLocale::Country country, uint flags, QLocale::Language language, QLocale::Territory territory, uint flags,
RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, int compressThreshold, RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, int compressThreshold,
bool noZstd) bool noZstd)
{ {
m_name = name; m_name = name;
m_fileInfo = fileInfo; m_fileInfo = fileInfo;
m_language = language; m_language = language;
m_country = country; m_territory = territory;
m_flags = flags; m_flags = flags;
m_parent = nullptr; m_parent = nullptr;
m_nameOffset = 0; m_nameOffset = 0;
@ -184,7 +184,7 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib)
lib.writeString(" // "); lib.writeString(" // ");
lib.writeByteArray(resourceName().toLocal8Bit()); lib.writeByteArray(resourceName().toLocal8Bit());
lib.writeString(" ["); lib.writeString(" [");
lib.writeByteArray(QByteArray::number(m_country)); lib.writeByteArray(QByteArray::number(m_territory));
lib.writeString("::"); lib.writeString("::");
lib.writeByteArray(QByteArray::number(m_language)); lib.writeByteArray(QByteArray::number(m_language));
lib.writeString("[\n "); lib.writeString("[\n ");
@ -216,7 +216,7 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib)
lib.writeNumber2(m_flags); lib.writeNumber2(m_flags);
// locale // locale
lib.writeNumber2(m_country); lib.writeNumber2(m_territory);
lib.writeNumber2(m_language); lib.writeNumber2(m_language);
//data offset //data offset
@ -508,7 +508,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
QString prefix; QString prefix;
QLocale::Language language = QLocale::c().language(); QLocale::Language language = QLocale::c().language();
QLocale::Country country = QLocale::c().country(); QLocale::Territory territory = QLocale::c().territory();
QString alias; QString alias;
auto compressAlgo = m_compressionAlgo; auto compressAlgo = m_compressionAlgo;
int compressLevel = m_compressLevel; int compressLevel = m_compressLevel;
@ -531,7 +531,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
QXmlStreamAttributes attributes = reader.attributes(); QXmlStreamAttributes attributes = reader.attributes();
language = QLocale::c().language(); language = QLocale::c().language();
country = QLocale::c().country(); territory = QLocale::c().territory();
if (attributes.hasAttribute(m_strings.ATTRIBUTE_LANG)) { if (attributes.hasAttribute(m_strings.ATTRIBUTE_LANG)) {
QString attribute = attributes.value(m_strings.ATTRIBUTE_LANG).toString(); QString attribute = attributes.value(m_strings.ATTRIBUTE_LANG).toString();
@ -539,9 +539,9 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
language = lang.language(); language = lang.language();
if (2 == attribute.length()) { if (2 == attribute.length()) {
// Language only // Language only
country = QLocale::AnyCountry; territory = QLocale::AnyTerritory;
} else { } else {
country = lang.country(); territory = lang.territory();
} }
} }
@ -656,7 +656,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
QFileInfo child(filePath); QFileInfo child(filePath);
const bool arc = const bool arc =
addFile(alias + child.fileName(), addFile(alias + child.fileName(),
RCCFileInfo(child.fileName(), child, language, country, RCCFileInfo(child.fileName(), child, language, territory,
child.isDir() ? RCCFileInfo::Directory child.isDir() ? RCCFileInfo::Directory
: RCCFileInfo::NoFlags, : RCCFileInfo::NoFlags,
compressAlgo, compressLevel, compressThreshold, compressAlgo, compressLevel, compressThreshold,
@ -670,7 +670,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
RCCFileInfo(alias.section(slash, -1), RCCFileInfo(alias.section(slash, -1),
file, file,
language, language,
country, territory,
RCCFileInfo::NoFlags, RCCFileInfo::NoFlags,
compressAlgo, compressAlgo,
compressLevel, compressLevel,
@ -715,7 +715,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
if (!listMode && m_format == Binary) { if (!listMode && m_format == Binary) {
// create dummy entry, otherwise loading with QResource will crash // create dummy entry, otherwise loading with QResource will crash
m_root = new RCCFileInfo(QString(), QFileInfo(), m_root = new RCCFileInfo(QString(), QFileInfo(),
QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); QLocale::C, QLocale::AnyTerritory, RCCFileInfo::Directory);
} }
} }
@ -731,7 +731,7 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file)
return false; return false;
} }
if (!m_root) if (!m_root)
m_root = new RCCFileInfo(QString(), QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); m_root = new RCCFileInfo(QString(), QFileInfo(), QLocale::C, QLocale::AnyTerritory, RCCFileInfo::Directory);
RCCFileInfo *parent = m_root; RCCFileInfo *parent = m_root;
const QStringList nodes = alias.split(QLatin1Char('/')); const QStringList nodes = alias.split(QLatin1Char('/'));
@ -740,7 +740,7 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file)
if (node.isEmpty()) if (node.isEmpty())
continue; continue;
if (!parent->m_children.contains(node)) { if (!parent->m_children.contains(node)) {
RCCFileInfo *s = new RCCFileInfo(node, QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); RCCFileInfo *s = new RCCFileInfo(node, QFileInfo(), QLocale::C, QLocale::AnyTerritory, RCCFileInfo::Directory);
s->m_parent = parent; s->m_parent = parent;
parent->m_children.insert(node, s); parent->m_children.insert(node, s);
parent = s; parent = s;
@ -756,7 +756,7 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file)
auto cend = parent->m_children.constEnd(); auto cend = parent->m_children.constEnd();
for (auto it = cbegin; it != cend; ++it) { for (auto it = cbegin; it != cend; ++it) {
if (it.key() == filename && it.value()->m_language == s->m_language && if (it.key() == filename && it.value()->m_language == s->m_language &&
it.value()->m_country == s->m_country) { it.value()->m_territory == s->m_territory) {
for (const QString &name : qAsConst(m_fileNames)) { for (const QString &name : qAsConst(m_fileNames)) {
qWarning("%s: Warning: potential duplicate alias detected: '%s'", qWarning("%s: Warning: potential duplicate alias detected: '%s'",
qPrintable(name), qPrintable(filename)); qPrintable(name), qPrintable(filename));

View File

@ -225,15 +225,15 @@ void tst_QLocale::ctor()
{ {
QLocale default_locale = QLocale::system(); QLocale default_locale = QLocale::system();
QLocale::Language default_lang = default_locale.language(); QLocale::Language default_lang = default_locale.language();
QLocale::Country default_country = default_locale.country(); QLocale::Territory default_country = default_locale.territory();
qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(), qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(),
QLocale::countryToString(default_country).toLatin1().constData()); QLocale::territoryToString(default_country).toLatin1().constData());
{ {
QLocale l; QLocale l;
QVERIFY(l.language() == default_lang); QVERIFY(l.language() == default_lang);
QVERIFY(l.country() == default_country); QVERIFY(l.territory() == default_country);
} }
#define TEST_CTOR(req_lang, req_script, req_country, exp_lang, exp_script, exp_country) \ #define TEST_CTOR(req_lang, req_script, req_country, exp_lang, exp_script, exp_country) \
@ -241,7 +241,7 @@ void tst_QLocale::ctor()
QLocale l(QLocale::req_lang, QLocale::req_script, QLocale::req_country); \ QLocale l(QLocale::req_lang, QLocale::req_script, QLocale::req_country); \
QCOMPARE(l.language(), QLocale::exp_lang); \ QCOMPARE(l.language(), QLocale::exp_lang); \
QCOMPARE(l.script(), QLocale::exp_script); \ QCOMPARE(l.script(), QLocale::exp_script); \
QCOMPARE(l.country(), QLocale::exp_country); \ QCOMPARE(l.territory(), QLocale::exp_country); \
} while (false) } while (false)
// Exact matches // Exact matches
@ -252,10 +252,10 @@ void tst_QLocale::ctor()
TEST_CTOR(Chinese, TraditionalHanScript, HongKong, TEST_CTOR(Chinese, TraditionalHanScript, HongKong,
Chinese, TraditionalHanScript, HongKong); Chinese, TraditionalHanScript, HongKong);
// Best match for AnyCountry // Best match for AnyTerritory
TEST_CTOR(Chinese, SimplifiedHanScript, AnyCountry, TEST_CTOR(Chinese, SimplifiedHanScript, AnyTerritory,
Chinese, SimplifiedHanScript, China); Chinese, SimplifiedHanScript, China);
TEST_CTOR(Chinese, TraditionalHanScript, AnyCountry, TEST_CTOR(Chinese, TraditionalHanScript, AnyTerritory,
Chinese, TraditionalHanScript, Taiwan); Chinese, TraditionalHanScript, Taiwan);
// Best match for AnyScript (and change country to supported one, if necessary) // Best match for AnyScript (and change country to supported one, if necessary)
@ -295,36 +295,36 @@ void tst_QLocale::defaulted_ctor()
{ {
QLocale default_locale = QLocale::system(); QLocale default_locale = QLocale::system();
QLocale::Language default_lang = default_locale.language(); QLocale::Language default_lang = default_locale.language();
QLocale::Country default_country = default_locale.country(); QLocale::Territory default_country = default_locale.territory();
qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(), qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(),
QLocale::countryToString(default_country).toLatin1().constData()); QLocale::territoryToString(default_country).toLatin1().constData());
{ {
QLocale l(QLocale::C, QLocale::AnyCountry); QLocale l(QLocale::C, QLocale::AnyTerritory);
QCOMPARE(l.language(), QLocale::C); QCOMPARE(l.language(), QLocale::C);
QCOMPARE(l.country(), QLocale::AnyCountry); QCOMPARE(l.territory(), QLocale::AnyTerritory);
} }
#define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \ #define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \
{ \ { \
QLocale l(QLocale::req_lang, QLocale::req_country); \ QLocale l(QLocale::req_lang, QLocale::req_country); \
QCOMPARE((int)l.language(), (int)exp_lang); \ QCOMPARE((int)l.language(), (int)exp_lang); \
QCOMPARE((int)l.country(), (int)exp_country); \ QCOMPARE((int)l.territory(), (int)exp_country); \
} }
TEST_CTOR(AnyLanguage, AnyCountry, default_lang, default_country) TEST_CTOR(AnyLanguage, AnyTerritory, default_lang, default_country)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyTerritory, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(Aymara, AnyCountry, default_lang, default_country) TEST_CTOR(Aymara, AnyTerritory, default_lang, default_country)
TEST_CTOR(Aymara, France, default_lang, default_country) TEST_CTOR(Aymara, France, default_lang, default_country)
TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, AnyTerritory, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(Spanish, LatinAmerica, QLocale::Spanish, TEST_CTOR(Spanish, LatinAmerica, QLocale::Spanish,
QLocale::LatinAmerica) QLocale::LatinAmerica)
@ -333,94 +333,94 @@ void tst_QLocale::defaulted_ctor()
{ {
QLocale l; QLocale l;
QVERIFY(l.language() == QLocale::English); QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedStates); QVERIFY(l.territory() == QLocale::UnitedStates);
} }
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyTerritory, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(Aymara, AnyTerritory, QLocale::English, QLocale::UnitedStates)
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom)); QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom));
{ {
QLocale l; QLocale l;
QVERIFY(l.language() == QLocale::English); QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom); QVERIFY(l.territory() == QLocale::UnitedKingdom);
} }
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyTerritory, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyTerritory)
QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::France)); QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::France));
{ {
QLocale l; QLocale l;
QVERIFY(l.language() == QLocale::English); QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom); QVERIFY(l.territory() == QLocale::UnitedKingdom);
} }
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(Aymara, AnyTerritory, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, AnyTerritory, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyTerritory, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyTerritory)
QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::AnyCountry)); QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::AnyTerritory));
{ {
QLocale l; QLocale l;
QVERIFY(l.language() == QLocale::English); QVERIFY(l.language() == QLocale::English);
QVERIFY(l.country() == QLocale::UnitedKingdom); QVERIFY(l.territory() == QLocale::UnitedKingdom);
} }
TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(Aymara, AnyTerritory, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, AnyTerritory, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates) TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom) TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(French, France, QLocale::French, QLocale::France)
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, AnyTerritory, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) TEST_CTOR(C, France, QLocale::C, QLocale::AnyTerritory)
TEST_CTOR(Arabic, AnyCountry, QLocale::Arabic, QLocale::Egypt) TEST_CTOR(Arabic, AnyTerritory, QLocale::Arabic, QLocale::Egypt)
TEST_CTOR(Dutch, AnyCountry, QLocale::Dutch, QLocale::Netherlands) TEST_CTOR(Dutch, AnyTerritory, QLocale::Dutch, QLocale::Netherlands)
TEST_CTOR(German, AnyCountry, QLocale::German, QLocale::Germany) TEST_CTOR(German, AnyTerritory, QLocale::German, QLocale::Germany)
TEST_CTOR(Greek, AnyCountry, QLocale::Greek, QLocale::Greece) TEST_CTOR(Greek, AnyTerritory, QLocale::Greek, QLocale::Greece)
TEST_CTOR(Malay, AnyCountry, QLocale::Malay, QLocale::Malaysia) TEST_CTOR(Malay, AnyTerritory, QLocale::Malay, QLocale::Malaysia)
TEST_CTOR(Persian, AnyCountry, QLocale::Persian, QLocale::Iran) TEST_CTOR(Persian, AnyTerritory, QLocale::Persian, QLocale::Iran)
TEST_CTOR(Portuguese, AnyCountry, QLocale::Portuguese, QLocale::Brazil) TEST_CTOR(Portuguese, AnyTerritory, QLocale::Portuguese, QLocale::Brazil)
TEST_CTOR(Serbian, AnyCountry, QLocale::Serbian, QLocale::Serbia) TEST_CTOR(Serbian, AnyTerritory, QLocale::Serbian, QLocale::Serbia)
TEST_CTOR(Somali, AnyCountry, QLocale::Somali, QLocale::Somalia) TEST_CTOR(Somali, AnyTerritory, QLocale::Somali, QLocale::Somalia)
TEST_CTOR(Spanish, AnyCountry, QLocale::Spanish, QLocale::Spain) TEST_CTOR(Spanish, AnyTerritory, QLocale::Spanish, QLocale::Spain)
TEST_CTOR(Swedish, AnyCountry, QLocale::Swedish, QLocale::Sweden) TEST_CTOR(Swedish, AnyTerritory, QLocale::Swedish, QLocale::Sweden)
TEST_CTOR(Uzbek, AnyCountry, QLocale::Uzbek, QLocale::Uzbekistan) TEST_CTOR(Uzbek, AnyTerritory, QLocale::Uzbek, QLocale::Uzbekistan)
#undef TEST_CTOR #undef TEST_CTOR
#define TEST_CTOR(req_lc, exp_lang, exp_country) \ #define TEST_CTOR(req_lc, exp_lang, exp_country) \
{ \ { \
QLocale l(req_lc); \ QLocale l(req_lc); \
QVERIFY2(l.language() == QLocale::exp_lang \ QVERIFY2(l.language() == QLocale::exp_lang \
&& l.country() == QLocale::exp_country, \ && l.territory() == QLocale::exp_country, \
QString("requested: \"" + QString(req_lc) + "\", got: " \ QString("requested: \"" + QString(req_lc) + "\", got: " \
+ QLocale::languageToString(l.language()) \ + QLocale::languageToString(l.language()) \
+ QLatin1Char('/') \ + QLatin1Char('/') \
+ QLocale::countryToString(l.country())).toLatin1().constData()); \ + QLocale::territoryToString(l.territory())).toLatin1().constData()); \
QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \ QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \
QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \ QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \
} }
@ -428,14 +428,14 @@ void tst_QLocale::defaulted_ctor()
QLocale::setDefault(QLocale(QLocale::C)); QLocale::setDefault(QLocale(QLocale::C));
const QString empty; const QString empty;
TEST_CTOR("C", C, AnyCountry) TEST_CTOR("C", C, AnyTerritory)
TEST_CTOR("bla", C, AnyCountry) TEST_CTOR("bla", C, AnyTerritory)
TEST_CTOR("zz", C, AnyCountry) TEST_CTOR("zz", C, AnyTerritory)
TEST_CTOR("zz_zz", C, AnyCountry) TEST_CTOR("zz_zz", C, AnyTerritory)
TEST_CTOR("zz...", C, AnyCountry) TEST_CTOR("zz...", C, AnyTerritory)
TEST_CTOR("", C, AnyCountry) TEST_CTOR("", C, AnyTerritory)
TEST_CTOR("en/", C, AnyCountry) TEST_CTOR("en/", C, AnyTerritory)
TEST_CTOR(empty, C, AnyCountry) TEST_CTOR(empty, C, AnyTerritory)
TEST_CTOR("en", English, UnitedStates) TEST_CTOR("en", English, UnitedStates)
TEST_CTOR("en", English, UnitedStates) TEST_CTOR("en", English, UnitedStates)
TEST_CTOR("en.", English, UnitedStates) TEST_CTOR("en.", English, UnitedStates)
@ -480,11 +480,11 @@ void tst_QLocale::defaulted_ctor()
QLocale l(req_lc); \ QLocale l(req_lc); \
QVERIFY2(l.language() == QLocale::exp_lang \ QVERIFY2(l.language() == QLocale::exp_lang \
&& l.script() == QLocale::exp_script \ && l.script() == QLocale::exp_script \
&& l.country() == QLocale::exp_country, \ && l.territory() == QLocale::exp_country, \
QString("requested: \"" + QString(req_lc) + "\", got: " \ QString("requested: \"" + QString(req_lc) + "\", got: " \
+ QLocale::languageToString(l.language()) \ + QLocale::languageToString(l.language()) \
+ QLatin1Char('/') + QLocale::scriptToString(l.script()) \ + QLatin1Char('/') + QLocale::scriptToString(l.script()) \
+ QLatin1Char('/') + QLocale::countryToString(l.country())).toLatin1().constData()); \ + QLatin1Char('/') + QLocale::territoryToString(l.territory())).toLatin1().constData()); \
} }
TEST_CTOR("zh_CN", Chinese, SimplifiedHanScript, China) TEST_CTOR("zh_CN", Chinese, SimplifiedHanScript, China)
@ -664,11 +664,11 @@ void tst_QLocale::legacyNames()
{ \ { \
QLocale l(req_lc); \ QLocale l(req_lc); \
QVERIFY2(l.language() == QLocale::exp_lang \ QVERIFY2(l.language() == QLocale::exp_lang \
&& l.country() == QLocale::exp_country, \ && l.territory() == QLocale::exp_country, \
QString("requested: \"" + QString(req_lc) + "\", got: " \ QString("requested: \"" + QString(req_lc) + "\", got: " \
+ QLocale::languageToString(l.language()) \ + QLocale::languageToString(l.language()) \
+ QLatin1Char('/') \ + QLatin1Char('/') \
+ QLocale::countryToString(l.country())).toLatin1().constData()); \ + QLocale::territoryToString(l.territory())).toLatin1().constData()); \
} }
TEST_CTOR("mo_MD", Romanian, Moldova) TEST_CTOR("mo_MD", Romanian, Moldova)
@ -684,9 +684,9 @@ void tst_QLocale::consistentC()
{ {
const QLocale c(QLocale::C); const QLocale c(QLocale::C);
QCOMPARE(c, QLocale::c()); QCOMPARE(c, QLocale::c());
QCOMPARE(c, QLocale(QLocale::C, QLocale::AnyScript, QLocale::AnyCountry)); QCOMPARE(c, QLocale(QLocale::C, QLocale::AnyScript, QLocale::AnyTerritory));
QVERIFY(QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QVERIFY(QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript,
QLocale::AnyCountry).contains(c)); QLocale::AnyTerritory).contains(c));
} }
void tst_QLocale::matchingLocales() void tst_QLocale::matchingLocales()
@ -694,7 +694,7 @@ void tst_QLocale::matchingLocales()
const QLocale c(QLocale::C); const QLocale c(QLocale::C);
const QLocale ru_RU(QLocale::Russian, QLocale::Russia); const QLocale ru_RU(QLocale::Russian, QLocale::Russia);
QList<QLocale> locales = QLocale::matchingLocales(QLocale::C, QLocale::AnyScript, QLocale::AnyCountry); QList<QLocale> locales = QLocale::matchingLocales(QLocale::C, QLocale::AnyScript, QLocale::AnyTerritory);
QCOMPARE(locales.size(), 1); QCOMPARE(locales.size(), 1);
QVERIFY(locales.contains(c)); QVERIFY(locales.contains(c));
@ -702,12 +702,12 @@ void tst_QLocale::matchingLocales()
QCOMPARE(locales.size(), 1); QCOMPARE(locales.size(), 1);
QVERIFY(locales.contains(ru_RU)); QVERIFY(locales.contains(ru_RU));
locales = QLocale::matchingLocales(QLocale::Russian, QLocale::AnyScript, QLocale::AnyCountry); locales = QLocale::matchingLocales(QLocale::Russian, QLocale::AnyScript, QLocale::AnyTerritory);
QVERIFY(!locales.isEmpty()); QVERIFY(!locales.isEmpty());
QVERIFY(!locales.contains(c)); QVERIFY(!locales.contains(c));
QVERIFY(locales.contains(ru_RU)); QVERIFY(locales.contains(ru_RU));
locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::CyrillicScript, QLocale::AnyCountry); locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::CyrillicScript, QLocale::AnyTerritory);
QVERIFY(!locales.isEmpty()); QVERIFY(!locales.isEmpty());
QVERIFY(!locales.contains(c)); QVERIFY(!locales.contains(c));
QVERIFY(locales.contains(ru_RU)); QVERIFY(locales.contains(ru_RU));
@ -721,14 +721,14 @@ void tst_QLocale::matchingLocales()
void tst_QLocale::unixLocaleName_data() void tst_QLocale::unixLocaleName_data()
{ {
QTest::addColumn<QLocale::Language>("lang"); QTest::addColumn<QLocale::Language>("lang");
QTest::addColumn<QLocale::Country>("land"); QTest::addColumn<QLocale::Territory>("land");
QTest::addColumn<QString>("expect"); QTest::addColumn<QString>("expect");
#define ADDROW(nom, lang, land, name) \ #define ADDROW(nom, lang, land, name) \
QTest::newRow(nom) << QLocale::lang << QLocale::land << QStringLiteral(name) QTest::newRow(nom) << QLocale::lang << QLocale::land << QStringLiteral(name)
ADDROW("C_any", C, AnyCountry, "C"); ADDROW("C_any", C, AnyTerritory, "C");
ADDROW("en_any", English, AnyCountry, "en_US"); ADDROW("en_any", English, AnyTerritory, "en_US");
ADDROW("en_GB", English, UnitedKingdom, "en_GB"); ADDROW("en_GB", English, UnitedKingdom, "en_GB");
ADDROW("ay_GB", Aymara, UnitedKingdom, "C"); ADDROW("ay_GB", Aymara, UnitedKingdom, "C");
#undef ADDROW #undef ADDROW
@ -737,7 +737,7 @@ void tst_QLocale::unixLocaleName_data()
void tst_QLocale::unixLocaleName() void tst_QLocale::unixLocaleName()
{ {
QFETCH(QLocale::Language, lang); QFETCH(QLocale::Language, lang);
QFETCH(QLocale::Country, land); QFETCH(QLocale::Territory, land);
QFETCH(QString, expect); QFETCH(QString, expect);
QLocale::setDefault(QLocale(QLocale::C)); QLocale::setDefault(QLocale(QLocale::C));
@ -1456,17 +1456,17 @@ void tst_QLocale::negativeZero_data()
{ {
QTest::addColumn<QLocale::Language>("language"); QTest::addColumn<QLocale::Language>("language");
QTest::addColumn<QLocale::Script>("script"); QTest::addColumn<QLocale::Script>("script");
QTest::addColumn<QLocale::Country>("territory"); QTest::addColumn<QLocale::Territory>("territory");
QTest::addColumn<QStringView>("expect"); QTest::addColumn<QStringView>("expect");
QTest::newRow("C") QTest::newRow("C")
<< QLocale::C << QLocale::AnyScript << QLocale::AnyCountry << QLocale::C << QLocale::AnyScript << QLocale::AnyTerritory
<< QStringView(u"0"); << QStringView(u"0");
QTest::newRow("Arabic") QTest::newRow("Arabic")
<< QLocale::Arabic << QLocale::ArabicScript << QLocale::AnyCountry << QLocale::Arabic << QLocale::ArabicScript << QLocale::AnyTerritory
<< QStringView(u"\u0660"); << QStringView(u"\u0660");
QTest::newRow("Chakma") QTest::newRow("Chakma")
<< QLocale::Chakma << QLocale::ChakmaScript << QLocale::AnyCountry << QLocale::Chakma << QLocale::ChakmaScript << QLocale::AnyTerritory
<< QStringView(u"\xD804\xDD36"); // A surrogate pair. << QStringView(u"\xD804\xDD36"); // A surrogate pair.
} }
@ -1474,7 +1474,7 @@ void tst_QLocale::negativeZero()
{ {
QFETCH(QLocale::Language, language); QFETCH(QLocale::Language, language);
QFETCH(QLocale::Script, script); QFETCH(QLocale::Script, script);
QFETCH(QLocale::Country, territory); QFETCH(QLocale::Territory, territory);
QFETCH(QStringView, expect); QFETCH(QStringView, expect);
QLocale locale(language, script, territory); QLocale locale(language, script, territory);
QCOMPARE(locale.toString(std::copysign(0.0, -1.0)), expect); QCOMPARE(locale.toString(std::copysign(0.0, -1.0)), expect);
@ -2315,7 +2315,7 @@ static const int locale_data_count = sizeof(locale_data)/sizeof(locale_data[0]);
void tst_QLocale::testNames_data() void tst_QLocale::testNames_data()
{ {
QTest::addColumn<QLocale::Language>("language"); QTest::addColumn<QLocale::Language>("language");
QTest::addColumn<QLocale::Country>("country"); QTest::addColumn<QLocale::Territory>("country");
QLocale::setDefault(QLocale(QLocale::C)); // Ensures predictable fall-backs QLocale::setDefault(QLocale(QLocale::C)); // Ensures predictable fall-backs
@ -2324,39 +2324,39 @@ void tst_QLocale::testNames_data()
const QByteArray lang = const QByteArray lang =
QLocale::languageToString(QLocale::Language(item.m_language_id)).toLatin1(); QLocale::languageToString(QLocale::Language(item.m_language_id)).toLatin1();
const QByteArray land = const QByteArray land =
QLocale::countryToString(QLocale::Country(item.m_country_id)).toLatin1(); QLocale::territoryToString(QLocale::Territory(item.m_territory_id)).toLatin1();
QTest::addRow("data_%d (%s/%s)", i, lang.constData(), land.constData()) QTest::addRow("data_%d (%s/%s)", i, lang.constData(), land.constData())
<< QLocale::Language(item.m_language_id) << QLocale::Country(item.m_country_id); << QLocale::Language(item.m_language_id) << QLocale::Territory(item.m_territory_id);
} }
} }
void tst_QLocale::testNames() void tst_QLocale::testNames()
{ {
QFETCH(QLocale::Language, language); QFETCH(QLocale::Language, language);
QFETCH(const QLocale::Country, country); QFETCH(const QLocale::Territory, country);
const QLocale l1(language, country); const QLocale l1(language, country);
if (language == QLocale::AnyLanguage && country == QLocale::AnyCountry) if (language == QLocale::AnyLanguage && country == QLocale::AnyTerritory)
language = QLocale::C; language = QLocale::C;
QCOMPARE(l1.language(), language); QCOMPARE(l1.language(), language);
QCOMPARE(l1.country(), country); QCOMPARE(l1.territory(), country);
const QString name = l1.name(); const QString name = l1.name();
const QLocale l2(name); const QLocale l2(name);
QCOMPARE(l2.language(), language); QCOMPARE(l2.language(), language);
QCOMPARE(l2.country(), country); QCOMPARE(l2.territory(), country);
QCOMPARE(l2.name(), name); QCOMPARE(l2.name(), name);
const QLocale l3(name + QLatin1String("@foo")); const QLocale l3(name + QLatin1String("@foo"));
QCOMPARE(l3.language(), language); QCOMPARE(l3.language(), language);
QCOMPARE(l3.country(), country); QCOMPARE(l3.territory(), country);
QCOMPARE(l3.name(), name); QCOMPARE(l3.name(), name);
const QLocale l4(name + QLatin1String(".foo")); const QLocale l4(name + QLatin1String(".foo"));
QCOMPARE(l4.language(), language); QCOMPARE(l4.language(), language);
QCOMPARE(l4.country(), country); QCOMPARE(l4.territory(), country);
QCOMPARE(l4.name(), name); QCOMPARE(l4.name(), name);
if (language != QLocale::C) { if (language != QLocale::C) {
@ -2915,7 +2915,7 @@ void tst_QLocale::textDirection()
QFETCH(int, script); QFETCH(int, script);
QFETCH(bool, rightToLeft); QFETCH(bool, rightToLeft);
QLocale locale(QLocale::Language(language), QLocale::Script(script), QLocale::AnyCountry); QLocale locale(QLocale::Language(language), QLocale::Script(script), QLocale::AnyTerritory);
QCOMPARE(locale.textDirection() == Qt::RightToLeft, rightToLeft); QCOMPARE(locale.textDirection() == Qt::RightToLeft, rightToLeft);
} }
@ -3243,9 +3243,9 @@ void tst_QLocale::lcsToCode()
QCOMPARE(QLocale::languageToCode(QLocale::C), QString("C")); QCOMPARE(QLocale::languageToCode(QLocale::C), QString("C"));
QCOMPARE(QLocale::languageToCode(QLocale::English), QString("en")); QCOMPARE(QLocale::languageToCode(QLocale::English), QString("en"));
QCOMPARE(QLocale::countryToCode(QLocale::AnyCountry), QString()); QCOMPARE(QLocale::territoryToCode(QLocale::AnyTerritory), QString());
QCOMPARE(QLocale::countryToCode(QLocale::UnitedStates), QString("US")); QCOMPARE(QLocale::territoryToCode(QLocale::UnitedStates), QString("US"));
QCOMPARE(QLocale::countryToCode(QLocale::EuropeanUnion), QString("EU")); QCOMPARE(QLocale::territoryToCode(QLocale::EuropeanUnion), QString("EU"));
QCOMPARE(QLocale::scriptToCode(QLocale::AnyScript), QString()); QCOMPARE(QLocale::scriptToCode(QLocale::AnyScript), QString());
QCOMPARE(QLocale::scriptToCode(QLocale::SimplifiedHanScript), QString("Hans")); QCOMPARE(QLocale::scriptToCode(QLocale::SimplifiedHanScript), QString("Hans"));
@ -3263,14 +3263,14 @@ void tst_QLocale::codeToLcs()
QCOMPARE(QLocale::codeToLanguage(QString("ha")), QLocale::Hausa); QCOMPARE(QLocale::codeToLanguage(QString("ha")), QLocale::Hausa);
QCOMPARE(QLocale::codeToLanguage(QString("haw")), QLocale::Hawaiian); QCOMPARE(QLocale::codeToLanguage(QString("haw")), QLocale::Hawaiian);
QCOMPARE(QLocale::codeToCountry(QString()), QLocale::AnyCountry); QCOMPARE(QLocale::codeToTerritory(QString()), QLocale::AnyTerritory);
QCOMPARE(QLocale::codeToCountry(QString("ZZ")), QLocale::AnyCountry); QCOMPARE(QLocale::codeToTerritory(QString("ZZ")), QLocale::AnyTerritory);
QCOMPARE(QLocale::codeToCountry(QString("US")), QLocale::UnitedStates); QCOMPARE(QLocale::codeToTerritory(QString("US")), QLocale::UnitedStates);
QCOMPARE(QLocale::codeToCountry(QString("us")), QLocale::UnitedStates); QCOMPARE(QLocale::codeToTerritory(QString("us")), QLocale::UnitedStates);
QCOMPARE(QLocale::codeToCountry(QString("USA")), QLocale::AnyCountry); QCOMPARE(QLocale::codeToTerritory(QString("USA")), QLocale::AnyTerritory);
QCOMPARE(QLocale::codeToCountry(QString("EU")), QLocale::EuropeanUnion); QCOMPARE(QLocale::codeToTerritory(QString("EU")), QLocale::EuropeanUnion);
QCOMPARE(QLocale::codeToCountry(QString("001")), QLocale::World); QCOMPARE(QLocale::codeToTerritory(QString("001")), QLocale::World);
QCOMPARE(QLocale::codeToCountry(QString("150")), QLocale::Europe); QCOMPARE(QLocale::codeToTerritory(QString("150")), QLocale::Europe);
QCOMPARE(QLocale::codeToScript(QString()), QLocale::AnyScript); QCOMPARE(QLocale::codeToScript(QString()), QLocale::AnyScript);
QCOMPARE(QLocale::codeToScript(QString("Zzzz")), QLocale::AnyScript); QCOMPARE(QLocale::codeToScript(QString("Zzzz")), QLocale::AnyScript);

View File

@ -103,7 +103,7 @@ void tst_QTimeZone::printTimeZone(const QTimeZone &tz)
qDebug() << "Is Valid = " << tz.isValid(); qDebug() << "Is Valid = " << tz.isValid();
qDebug() << ""; qDebug() << "";
qDebug() << "Zone ID = " << tz.id(); qDebug() << "Zone ID = " << tz.id();
qDebug() << "Country = " << QLocale::countryToString(tz.country()); qDebug() << "Territory = " << QLocale::territoryToString(tz.territory());
qDebug() << "Comment = " << tz.comment(); qDebug() << "Comment = " << tz.comment();
qDebug() << ""; qDebug() << "";
qDebug() << "Locale = " << QLocale().name(); qDebug() << "Locale = " << QLocale().name();
@ -178,7 +178,7 @@ void tst_QTimeZone::createTest()
QCOMPARE((tz == other), false); QCOMPARE((tz == other), false);
QCOMPARE((tz != other), true); QCOMPARE((tz != other), true);
QCOMPARE(tz.country(), QLocale::NewZealand); QCOMPARE(tz.territory(), QLocale::NewZealand);
QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC); QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC); QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC);
@ -275,7 +275,7 @@ void tst_QTimeZone::nullTest()
QCOMPARE(utc.isValid(), false); QCOMPARE(utc.isValid(), false);
QCOMPARE(nullTz1.id(), QByteArray()); QCOMPARE(nullTz1.id(), QByteArray());
QCOMPARE(nullTz1.country(), QLocale::AnyCountry); QCOMPARE(nullTz1.territory(), QLocale::AnyTerritory);
QCOMPARE(nullTz1.comment(), QString()); QCOMPARE(nullTz1.comment(), QString());
QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC); QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
@ -359,7 +359,7 @@ void tst_QTimeZone::dataStreamTest()
} }
QCOMPARE(tz2.id(), QByteArray("QST")); QCOMPARE(tz2.id(), QByteArray("QST"));
QCOMPARE(tz2.comment(), QString("Qt Testing")); QCOMPARE(tz2.comment(), QString("Qt Testing"));
QCOMPARE(tz2.country(), QLocale::Norway); QCOMPARE(tz2.territory(), QLocale::Norway);
QCOMPARE(tz2.abbreviation(QDateTime::currentDateTime()), QString("QST")); QCOMPARE(tz2.abbreviation(QDateTime::currentDateTime()), QString("QST"));
QCOMPARE(tz2.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), QCOMPARE(tz2.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()),
QString("Qt Standard Time")); QString("Qt Standard Time"));
@ -642,7 +642,7 @@ void tst_QTimeZone::transitionEachZone()
if (here * 1000 != stamp) { if (here * 1000 != stamp) {
// (The +1 is due to using _1_:30 as baseSecs.) // (The +1 is due to using _1_:30 as baseSecs.)
qDebug("Failing at half past %d UTC (offset %d in %s)", i + 1, when.offsetFromUtc(), qDebug("Failing at half past %d UTC (offset %d in %s)", i + 1, when.offsetFromUtc(),
QLocale::countryToString(named.country()).toUtf8().constData()); QLocale::territoryToString(named.territory()).toUtf8().constData());
} }
QCOMPARE(stamp % 1000, 0); QCOMPARE(stamp % 1000, 0);
QCOMPARE(here - stamp / 1000, 0); QCOMPARE(here - stamp / 1000, 0);
@ -732,7 +732,7 @@ void tst_QTimeZone::stressTest()
QCOMPARE(testZone.isValid(), true); QCOMPARE(testZone.isValid(), true);
QCOMPARE(testZone.id(), id); QCOMPARE(testZone.id(), id);
QDateTime testDate = QDateTime(QDate(2015, 1, 1), QTime(0, 0, 0), Qt::UTC); QDateTime testDate = QDateTime(QDate(2015, 1, 1), QTime(0, 0, 0), Qt::UTC);
testZone.country(); testZone.territory();
testZone.comment(); testZone.comment();
testZone.displayName(testDate); testZone.displayName(testDate);
testZone.displayName(QTimeZone::DaylightTime); testZone.displayName(QTimeZone::DaylightTime);
@ -783,7 +783,7 @@ void tst_QTimeZone::windowsId()
USA "America/Chicago America/Indiana/Knox America/Indiana/Tell_City America/Menominee" USA "America/Chicago America/Indiana/Knox America/Indiana/Tell_City America/Menominee"
"America/North_Dakota/Beulah America/North_Dakota/Center" "America/North_Dakota/Beulah America/North_Dakota/Center"
"America/North_Dakota/New_Salem" "America/North_Dakota/New_Salem"
AnyCountry "CST6CDT" AnyTerritory "CST6CDT"
*/ */
QCOMPARE(QTimeZone::ianaIdToWindowsId("America/Chicago"), QCOMPARE(QTimeZone::ianaIdToWindowsId("America/Chicago"),
QByteArray("Central Standard Time")); QByteArray("Central Standard Time"));
@ -800,7 +800,7 @@ void tst_QTimeZone::windowsId()
QByteArray("America/Chicago")); QByteArray("America/Chicago"));
QCOMPARE(QTimeZone::windowsIdToDefaultIanaId("Central Standard Time", QLocale::Canada), QCOMPARE(QTimeZone::windowsIdToDefaultIanaId("Central Standard Time", QLocale::Canada),
QByteArray("America/Winnipeg")); QByteArray("America/Winnipeg"));
QCOMPARE(QTimeZone::windowsIdToDefaultIanaId("Central Standard Time", QLocale::AnyCountry), QCOMPARE(QTimeZone::windowsIdToDefaultIanaId("Central Standard Time", QLocale::AnyTerritory),
QByteArray("CST6CDT")); QByteArray("CST6CDT"));
QCOMPARE(QTimeZone::windowsIdToDefaultIanaId(QByteArray()), QByteArray()); QCOMPARE(QTimeZone::windowsIdToDefaultIanaId(QByteArray()), QByteArray());
@ -837,13 +837,13 @@ void tst_QTimeZone::windowsId()
list.clear(); list.clear();
list << "CST6CDT"; list << "CST6CDT";
QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::AnyCountry), QCOMPARE(QTimeZone::windowsIdToIanaIds("Central Standard Time", QLocale::AnyTerritory),
list); list);
// Check no windowsId return empty // Check no windowsId return empty
list.clear(); list.clear();
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray()), list); QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray()), list);
QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray(), QLocale::AnyCountry), list); QCOMPARE(QTimeZone::windowsIdToIanaIds(QByteArray(), QLocale::AnyTerritory), list);
} }
void tst_QTimeZone::isValidId_data() void tst_QTimeZone::isValidId_data()
@ -1009,7 +1009,7 @@ void tst_QTimeZone::utcTest()
QUtcTimeZonePrivate tzp; QUtcTimeZonePrivate tzp;
QCOMPARE(tzp.isValid(), true); QCOMPARE(tzp.isValid(), true);
QCOMPARE(tzp.id(), QByteArray("UTC")); QCOMPARE(tzp.id(), QByteArray("UTC"));
QCOMPARE(tzp.country(), QLocale::AnyCountry); QCOMPARE(tzp.territory(), QLocale::AnyTerritory);
QCOMPARE(tzp.abbreviation(0), QString("UTC")); QCOMPARE(tzp.abbreviation(0), QString("UTC"));
QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), QString("UTC")); QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), QString("UTC"));
QCOMPARE(tzp.offsetFromUtc(0), 0); QCOMPARE(tzp.offsetFromUtc(0), 0);
@ -1050,7 +1050,7 @@ void tst_QTimeZone::utcTest()
QCOMPARE(tz.isValid(), true); QCOMPARE(tz.isValid(), true);
QCOMPARE(tz.id(), QByteArray("QST")); QCOMPARE(tz.id(), QByteArray("QST"));
QCOMPARE(tz.comment(), QString("Qt Testing")); QCOMPARE(tz.comment(), QString("Qt Testing"));
QCOMPARE(tz.country(), QLocale::Norway); QCOMPARE(tz.territory(), QLocale::Norway);
QCOMPARE(tz.abbreviation(now), QString("QST")); QCOMPARE(tz.abbreviation(now), QString("QST"));
QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()), QCOMPARE(tz.displayName(QTimeZone::StandardTime, QTimeZone::LongName, QLocale()),
QString("Qt Standard Time")); QString("Qt Standard Time"));

View File

@ -430,7 +430,7 @@ void tst_QDateTimeEdit::initTestCase()
if (system.language() != QLocale::C && system.language() != QLocale::English) if (system.language() != QLocale::C && system.language() != QLocale::English)
qWarning("Running under locale %s/%s -- this test may generate failures due to language differences", qWarning("Running under locale %s/%s -- this test may generate failures due to language differences",
qPrintable(QLocale::languageToString(system.language())), qPrintable(QLocale::languageToString(system.language())),
qPrintable(QLocale::countryToString(system.country()))); qPrintable(QLocale::territoryToString(system.territory())));
testWidget = new EditorDateEdit(0); testWidget = new EditorDateEdit(0);
testFocusWidget = new QWidget(0); testFocusWidget = new QWidget(0);
testFocusWidget->resize(200, 100); testFocusWidget->resize(200, 100);
@ -3881,7 +3881,7 @@ void tst_QDateTimeEdit::setLocaleOnCalendarWidget()
QList<QLocale> allLocales = QLocale::matchingLocales( QList<QLocale> allLocales = QLocale::matchingLocales(
QLocale::AnyLanguage, QLocale::AnyLanguage,
QLocale::AnyScript, QLocale::AnyScript,
QLocale::AnyCountry); QLocale::AnyTerritory);
QLocale c = QLocale::c(); QLocale c = QLocale::c();
dateEdit.setCalendarPopup(true); dateEdit.setCalendarPopup(true);
dateEdit.setLocale(c); dateEdit.setLocale(c);

View File

@ -1208,7 +1208,7 @@ void tst_QDoubleSpinBox::taskQTBUG_6496_fiddlingWithPrecision()
void tst_QDoubleSpinBox::setGroupSeparatorShown_data() void tst_QDoubleSpinBox::setGroupSeparatorShown_data()
{ {
QTest::addColumn<QLocale::Language>("lang"); QTest::addColumn<QLocale::Language>("lang");
QTest::addColumn<QLocale::Country>("country"); QTest::addColumn<QLocale::Territory>("country");
QTest::newRow("data0") << QLocale::English << QLocale::UnitedStates; QTest::newRow("data0") << QLocale::English << QLocale::UnitedStates;
QTest::newRow("data1") << QLocale::Swedish << QLocale::Sweden; QTest::newRow("data1") << QLocale::Swedish << QLocale::Sweden;
@ -1220,7 +1220,7 @@ void tst_QDoubleSpinBox::setGroupSeparatorShown_data()
void tst_QDoubleSpinBox::setGroupSeparatorShown() void tst_QDoubleSpinBox::setGroupSeparatorShown()
{ {
QFETCH(QLocale::Language, lang); QFETCH(QLocale::Language, lang);
QFETCH(QLocale::Country, country); QFETCH(QLocale::Territory, country);
QLocale loc(lang, country); QLocale loc(lang, country);
QLocale::setDefault(loc); QLocale::setDefault(loc);

View File

@ -1310,7 +1310,7 @@ void tst_QSpinBox::interpretOnLosingFocus()
void tst_QSpinBox::setGroupSeparatorShown_data() void tst_QSpinBox::setGroupSeparatorShown_data()
{ {
QTest::addColumn<QLocale::Language>("lang"); QTest::addColumn<QLocale::Language>("lang");
QTest::addColumn<QLocale::Country>("country"); QTest::addColumn<QLocale::Territory>("country");
QTest::newRow("data0") << QLocale::English << QLocale::UnitedStates; QTest::newRow("data0") << QLocale::English << QLocale::UnitedStates;
QTest::newRow("data1") << QLocale::Swedish << QLocale::Sweden; QTest::newRow("data1") << QLocale::Swedish << QLocale::Sweden;
@ -1322,7 +1322,7 @@ void tst_QSpinBox::setGroupSeparatorShown_data()
void tst_QSpinBox::setGroupSeparatorShown() void tst_QSpinBox::setGroupSeparatorShown()
{ {
QFETCH(QLocale::Language, lang); QFETCH(QLocale::Language, lang);
QFETCH(QLocale::Country, country); QFETCH(QLocale::Territory, country);
QLocale loc(lang, country); QLocale loc(lang, country);
QLocale::setDefault(loc); QLocale::setDefault(loc);

View File

@ -111,11 +111,11 @@ void tst_QLocale::fromTags_data()
{ {
QTest::addColumn<QLocale::Language>("language"); QTest::addColumn<QLocale::Language>("language");
QTest::addColumn<QLocale::Script>("script"); QTest::addColumn<QLocale::Script>("script");
QTest::addColumn<QLocale::Country>("territory"); QTest::addColumn<QLocale::Territory>("territory");
#define ROW(name, lang, text, land) \ #define ROW(name, lang, text, land) \
QTest::newRow(name) << QLocale::lang << QLocale::text << QLocale::land QTest::newRow(name) << QLocale::lang << QLocale::text << QLocale::land
ROW("C", C, AnyScript, AnyCountry); ROW("C", C, AnyScript, AnyTerritory);
ROW("en-Latn-DE", English, LatinScript, Germany); ROW("en-Latn-DE", English, LatinScript, Germany);
ROW("sd-Deva-IN", Sindhi, DevanagariScript, India); ROW("sd-Deva-IN", Sindhi, DevanagariScript, India);
ROW("az-Cyrl-AZ", Azerbaijani, CyrillicScript, Azerbaijan); ROW("az-Cyrl-AZ", Azerbaijani, CyrillicScript, Azerbaijan);
@ -151,7 +151,7 @@ void tst_QLocale::fromTags()
{ {
QFETCH(const QLocale::Language, language); QFETCH(const QLocale::Language, language);
QFETCH(const QLocale::Script, script); QFETCH(const QLocale::Script, script);
QFETCH(const QLocale::Country, territory); QFETCH(const QLocale::Territory, territory);
QBENCHMARK { LOOP(QLocale loc(language, script, territory)) } QBENCHMARK { LOOP(QLocale loc(language, script, territory)) }
} }
@ -192,17 +192,17 @@ void tst_QLocale::fromLangScript()
{ {
QFETCH(const QLocale::Language, language); QFETCH(const QLocale::Language, language);
QFETCH(const QLocale::Script, script); QFETCH(const QLocale::Script, script);
QBENCHMARK { LOOP(QLocale loc(language, script, QLocale::AnyCountry)) } QBENCHMARK { LOOP(QLocale loc(language, script, QLocale::AnyTerritory)) }
} }
void tst_QLocale::fromLangLand_data() void tst_QLocale::fromLangLand_data()
{ {
QTest::addColumn<QLocale::Language>("language"); QTest::addColumn<QLocale::Language>("language");
QTest::addColumn<QLocale::Country>("territory"); QTest::addColumn<QLocale::Territory>("territory");
#define ROW(name, lang, land) \ #define ROW(name, lang, land) \
QTest::newRow(name) << QLocale::lang << QLocale::land QTest::newRow(name) << QLocale::lang << QLocale::land
ROW("C", C, AnyCountry); ROW("C", C, AnyTerritory);
ROW("en-DE", English, Germany); ROW("en-DE", English, Germany);
ROW("sd-IN", Sindhi, India); ROW("sd-IN", Sindhi, India);
ROW("az-AZ", Azerbaijani, Azerbaijan); ROW("az-AZ", Azerbaijani, Azerbaijan);
@ -230,18 +230,18 @@ void tst_QLocale::fromLangLand_data()
void tst_QLocale::fromLangLand() void tst_QLocale::fromLangLand()
{ {
QFETCH(const QLocale::Language, language); QFETCH(const QLocale::Language, language);
QFETCH(const QLocale::Country, territory); QFETCH(const QLocale::Territory, territory);
QBENCHMARK { LOOP(QLocale loc(language, territory)) } QBENCHMARK { LOOP(QLocale loc(language, territory)) }
} }
void tst_QLocale::fromScriptLand_data() void tst_QLocale::fromScriptLand_data()
{ {
QTest::addColumn<QLocale::Script>("script"); QTest::addColumn<QLocale::Script>("script");
QTest::addColumn<QLocale::Country>("territory"); QTest::addColumn<QLocale::Territory>("territory");
#define ROW(name, text, land) \ #define ROW(name, text, land) \
QTest::newRow(name) << QLocale::text << QLocale::land QTest::newRow(name) << QLocale::text << QLocale::land
ROW("Any", AnyScript, AnyCountry); ROW("Any", AnyScript, AnyTerritory);
ROW("Latn-DE", LatinScript, Germany); ROW("Latn-DE", LatinScript, Germany);
ROW("Deva-IN", DevanagariScript, India); ROW("Deva-IN", DevanagariScript, India);
ROW("Cyrl-AZ", CyrillicScript, Azerbaijan); ROW("Cyrl-AZ", CyrillicScript, Azerbaijan);
@ -276,7 +276,7 @@ void tst_QLocale::fromScriptLand_data()
void tst_QLocale::fromScriptLand() void tst_QLocale::fromScriptLand()
{ {
QFETCH(const QLocale::Script, script); QFETCH(const QLocale::Script, script);
QFETCH(const QLocale::Country, territory); QFETCH(const QLocale::Territory, territory);
QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, territory)) } QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, territory)) }
} }
@ -330,16 +330,16 @@ void tst_QLocale::fromScript_data()
void tst_QLocale::fromScript() void tst_QLocale::fromScript()
{ {
QFETCH(const QLocale::Script, script); QFETCH(const QLocale::Script, script);
QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, QLocale::AnyCountry)) } QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, QLocale::AnyTerritory)) }
} }
void tst_QLocale::fromLand_data() void tst_QLocale::fromLand_data()
{ {
QTest::addColumn<QLocale::Country>("territory"); QTest::addColumn<QLocale::Territory>("territory");
#define ROW(name, land) \ #define ROW(name, land) \
QTest::newRow(name) << QLocale::land QTest::newRow(name) << QLocale::land
ROW("Any", AnyCountry); ROW("Any", AnyTerritory);
ROW("DE", Germany); ROW("DE", Germany);
ROW("IN", India); ROW("IN", India);
ROW("AZ", Azerbaijan); ROW("AZ", Azerbaijan);
@ -361,7 +361,7 @@ void tst_QLocale::fromLand_data()
void tst_QLocale::fromLand() void tst_QLocale::fromLand()
{ {
QFETCH(const QLocale::Country, territory); QFETCH(const QLocale::Territory, territory);
QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, territory)) } QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, territory)) }
} }

View File

@ -53,8 +53,8 @@ InfoWidget::InfoWidget()
languageName = addItem("Language name:"); languageName = addItem("Language name:");
nativeLanguageName = addItem("Native language name:"); nativeLanguageName = addItem("Native language name:");
scriptName = addItem("Script name:"); scriptName = addItem("Script name:");
countryName = addItem("Country name:"); territoryName = addItem("Territory name:");
nativeCountryName = addItem("Native country name:"); nativeTerritoryName = addItem("Native territory name:");
} }
void InfoWidget::localeChanged(QLocale locale) void InfoWidget::localeChanged(QLocale locale)
@ -65,8 +65,8 @@ void InfoWidget::localeChanged(QLocale locale)
languageName->setText(QLocale::languageToString(locale.language())); languageName->setText(QLocale::languageToString(locale.language()));
nativeLanguageName->setText(locale.nativeLanguageName()); nativeLanguageName->setText(locale.nativeLanguageName());
scriptName->setText(QLocale::scriptToString(locale.script())); scriptName->setText(QLocale::scriptToString(locale.script()));
countryName->setText(QLocale::countryToString(locale.country())); territoryName->setText(QLocale::territoryToString(locale.territory()));
nativeCountryName->setText(locale.nativeCountryName()); nativeTerritoryName->setText(locale.nativeTerritoryName());
} }
void InfoWidget::addItem(const QString &label, QWidget *w) void InfoWidget::addItem(const QString &label, QWidget *w)

View File

@ -55,8 +55,8 @@ private:
QLineEdit *languageName; QLineEdit *languageName;
QLineEdit *nativeLanguageName; QLineEdit *nativeLanguageName;
QLineEdit *scriptName; QLineEdit *scriptName;
QLineEdit *countryName; QLineEdit *territoryName;
QLineEdit *nativeCountryName; QLineEdit *nativeTerritoryName;
private slots: private slots:
void localeChanged(QLocale locale); void localeChanged(QLocale locale);

View File

@ -53,7 +53,7 @@ void LanguagesWidget::localeChanged(QLocale locale)
QLocale l(lang); QLocale l(lang);
if (l.language() != QLocale::C) { if (l.language() != QLocale::C) {
QString language = QLocale::languageToString(l.language()); QString language = QLocale::languageToString(l.language());
QString country = QLocale::countryToString(l.country()); QString country = QLocale::territoryToString(l.territory());
QString tooltip = QString(QLatin1String("%1: %2/%3")).arg(l.name(), language, country); QString tooltip = QString(QLatin1String("%1: %2/%3")).arg(l.name(), language, country);
item->setToolTip(tooltip); item->setToolTip(tooltip);
} }

View File

@ -41,7 +41,7 @@ Window::Window()
localeCombo->addItem("System", QLocale::system()); localeCombo->addItem("System", QLocale::system());
QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); QList<QLocale> locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyTerritory);
foreach (const QLocale &locale, locales) { foreach (const QLocale &locale, locales) {
QString label = QLocale::languageToString(locale.language()); QString label = QLocale::languageToString(locale.language());
label += QLatin1Char('/'); label += QLatin1Char('/');
@ -49,7 +49,7 @@ Window::Window()
label += QLocale::scriptToString(locale.script()); label += QLocale::scriptToString(locale.script());
label += QLatin1Char('/'); label += QLatin1Char('/');
} }
label += QLocale::countryToString(locale.country()); label += QLocale::territoryToString(locale.territory());
localeCombo->addItem(label, locale); localeCombo->addItem(label, locale);
} }
@ -103,11 +103,11 @@ void Window::systemLocaleChanged()
QLocale l = QLocale::system(); QLocale l = QLocale::system();
QString lang = QLocale::languageToString(l.language()); QString lang = QLocale::languageToString(l.language());
QString script = QLocale::scriptToString(l.script()); QString script = QLocale::scriptToString(l.script());
QString country = QLocale::countryToString(l.country()); QString territory = QLocale::territoryToString(l.territory());
if (l.script() != QLocale::AnyScript) if (l.script() != QLocale::AnyScript)
localeCombo->setItemText(0, QString("System: %1-%2-%3").arg(lang, script, country)); localeCombo->setItemText(0, QString("System: %1-%2-%3").arg(lang, script, territory));
else else
localeCombo->setItemText(0, QString("System: %1-%2").arg(lang, country)); localeCombo->setItemText(0, QString("System: %1-%2").arg(lang, territory));
emit localeChanged(0); emit localeChanged(0);
} }

View File

@ -87,7 +87,7 @@ class CldrReader (object):
give = (give[0], give = (give[0],
# Substitute according to http://www.unicode.org/reports/tr35/#Likely_Subtags # Substitute according to http://www.unicode.org/reports/tr35/#Likely_Subtags
have[1] if give[1] == 'AnyScript' else give[1], have[1] if give[1] == 'AnyScript' else give[1],
have[2] if give[2] == 'AnyCountry' else give[2], have[2] if give[2] == 'AnyTerritory' else give[2],
give[3]) # AnyVariant similarly ? give[3]) # AnyVariant similarly ?
yield have, give yield have, give
@ -676,7 +676,7 @@ enumdata.py (keeping the old name as an alias):
from enumdata import language_list, script_list, country_list from enumdata import language_list, script_list, country_list
for form, book, empty in (('language', language_list, 'AnyLanguage'), for form, book, empty in (('language', language_list, 'AnyLanguage'),
('script', script_list, 'AnyScript'), ('script', script_list, 'AnyScript'),
('country', country_list, 'AnyCountry')): ('country', country_list, 'AnyTerritory')):
cache[form] = dict((pair[1], (num, pair[0])) cache[form] = dict((pair[1], (num, pair[0]))
for num, pair in book.items() if pair[0] != 'C') for num, pair in book.items() if pair[0] != 'C')
# (Have to filter out the C locale, as we give it the # (Have to filter out the C locale, as we give it the

View File

@ -409,7 +409,7 @@ language_aliases = {
} }
country_list = { country_list = {
0: ("AnyCountry", "ZZ"), 0: ("AnyTerritory", "ZZ"),
1: ("Afghanistan", "AF"), 1: ("Afghanistan", "AF"),
2: ("Aland Islands", "AX"), 2: ("Aland Islands", "AX"),
@ -700,6 +700,12 @@ country_aliases = {
'UnitedStatesMinorOutlyingIslands': 'UnitedStatesOutlyingIslands', 'UnitedStatesMinorOutlyingIslands': 'UnitedStatesOutlyingIslands',
'CuraSao': 'Curacao', 'CuraSao': 'Curacao',
'CzechRepublic': 'Czechia', 'CzechRepublic': 'Czechia',
# Backwards compatibility with old Country enum, prior to Qt 6.2:
'AnyCountry': 'AnyTerritory',
'NauruCountry': 'NauruTerritory',
'TokelauCountry': 'TokelauTerritory',
'TuvaluCountry': 'TuvaluTerritory',
} }
script_list = { script_list = {

View File

@ -155,7 +155,7 @@ class QLocaleXmlReader (object):
try: try:
to = likely[(locale.language, 'AnyScript', locale.country)] to = likely[(locale.language, 'AnyScript', locale.country)]
except KeyError: except KeyError:
to = likely[(locale.language, 'AnyScript', 'AnyCountry')] to = likely[(locale.language, 'AnyScript', 'AnyTerritory')]
except KeyError: except KeyError:
pass pass
else: else:
@ -196,7 +196,7 @@ class QLocaleXmlReader (object):
sub-tags mapping says language's default locale uses the given sub-tags mapping says language's default locale uses the given
script and country.""" script and country."""
for have, give in self.__likely: for have, give in self.__likely:
if have[1:] == ('AnyScript', 'AnyCountry') and give[2] != 'AnyCountry': if have[1:] == ('AnyScript', 'AnyTerritory') and give[2] != 'AnyTerritory':
assert have[0] == give[0], (have, give) assert have[0] == give[0], (have, give)
yield ((self.__langByName[give[0]][0], yield ((self.__langByName[give[0]][0],
self.__textByName[give[1]][0]), self.__textByName[give[1]][0]),
@ -590,7 +590,7 @@ class Locale (object):
return cls(cls.__monthNames(calendars), return cls(cls.__monthNames(calendars),
language='C', language_code='0', languageEndonym='', language='C', language_code='0', languageEndonym='',
script='AnyScript', script_code='0', script='AnyScript', script_code='0',
country='AnyCountry', country_code='0', countryEndonym='', country='AnyTerritory', country_code='0', countryEndonym='',
groupSizes=(3, 3, 1), groupSizes=(3, 3, 1),
decimal='.', group=',', list=';', percent='%', decimal='.', group=',', list=';', percent='%',
zero='0', minus='-', plus='+', exp='e', zero='0', minus='-', plus='+', exp='e',

View File

@ -394,7 +394,7 @@ class LocaleDataWriter (LocaleSourceEditor):
self.__writeNameData(self.writer.write, scripts, 'script') self.__writeNameData(self.writer.write, scripts, 'script')
def countryNames(self, countries): def countryNames(self, countries):
self.__writeNameData(self.writer.write, countries, 'country') self.__writeNameData(self.writer.write, countries, 'territory')
# TODO: unify these next three into the previous three; kept # TODO: unify these next three into the previous three; kept
# separate for now to verify we're not changing data. # separate for now to verify we're not changing data.
@ -406,7 +406,7 @@ class LocaleDataWriter (LocaleSourceEditor):
self.__writeCodeList(self.writer.write, scripts, 'script', 4) self.__writeCodeList(self.writer.write, scripts, 'script', 4)
def countryCodes(self, countries): # TODO: unify with countryNames() def countryCodes(self, countries): # TODO: unify with countryNames()
self.__writeCodeList(self.writer.write, countries, 'country', 3) self.__writeCodeList(self.writer.write, countries, 'territory', 3)
class CalendarDataWriter (LocaleSourceEditor): class CalendarDataWriter (LocaleSourceEditor):
formatCalendar = ( formatCalendar = (
@ -469,7 +469,8 @@ class LocaleHeaderWriter (SourceFileEditor):
self.writer.write('\n') self.writer.write('\n')
def countries(self, countries): def countries(self, countries):
self.__enum('Country', countries, self.__country) self.writer.write(" // ### Qt 7: Rename to Territory\n")
self.__enum('Country', countries, self.__country, 'Territory')
def scripts(self, scripts): def scripts(self, scripts):
self.__enum('Script', scripts, self.__script) self.__enum('Script', scripts, self.__script)
@ -480,8 +481,12 @@ class LocaleHeaderWriter (SourceFileEditor):
country_aliases as __country, country_aliases as __country,
script_aliases as __script) script_aliases as __script)
def __enum(self, name, book, alias): def __enum(self, name, book, alias, suffix = None):
assert book assert book
if suffix is None:
suffix = name
out, dupes = self.writer.write, self.__dupes out, dupes = self.writer.write, self.__dupes
out(' enum {} : ushort {{\n'.format(name)) out(' enum {} : ushort {{\n'.format(name))
for key, value in book.items(): for key, value in book.items():
@ -495,13 +500,20 @@ class LocaleHeaderWriter (SourceFileEditor):
raise Error('The script name "{}" is messy'.format(member)) raise Error('The script name "{}" is messy'.format(member))
else: else:
member = ''.join(member.split()) member = ''.join(member.split())
member = member + name if member in dupes else member member = member + suffix if member in dupes else member
out(' {} = {},\n'.format(member, key)) out(' {} = {},\n'.format(member, key))
out('\n ' out('\n '
+ ',\n '.join('{} = {}'.format(*pair) + ',\n '.join('{} = {}'.format(*pair)
for pair in sorted(alias.items())) for pair in sorted(alias.items()))
+ ',\n\n Last{} = {}\n }};\n'.format(name, member)) + ',\n\n Last{} = {}'.format(suffix, member))
# for "LastCountry = LastTerritory"
# ### Qt 7: Remove
if suffix != name:
out(',\n Last{} = Last{}'.format(name, suffix))
out('\n };\n')
def usage(name, err, message = ''): def usage(name, err, message = ''):
err.write("""Usage: {} path/to/qlocale.xml root/of/qtbase err.write("""Usage: {} path/to/qlocale.xml root/of/qtbase

View File

@ -36,11 +36,11 @@ static const int g_model_cols = 6;
struct LocaleListItem struct LocaleListItem
{ {
int language; int language;
int country; int territory;
}; };
const LocaleListItem g_locale_list[] = { const LocaleListItem g_locale_list[] = {
{ 1, 0 }, // C/AnyCountry { 1, 0 }, // C/AnyTerritory
{ 3, 69 }, // Afan/Ethiopia { 3, 69 }, // Afan/Ethiopia
{ 3, 111 }, // Afan/Kenya { 3, 111 }, // Afan/Kenya
{ 4, 59 }, // Afar/Djibouti { 4, 59 }, // Afar/Djibouti
@ -317,7 +317,7 @@ QVariant LocaleModel::data(const QModelIndex &index, int role) const
locale = QLocale::system(); locale = QLocale::system();
} else { } else {
LocaleListItem item = g_locale_list[index.row() - 2]; LocaleListItem item = g_locale_list[index.row() - 2];
locale = QLocale((QLocale::Language)item.language, (QLocale::Country)item.country); locale = QLocale((QLocale::Language)item.language, (QLocale::Territory)item.territory);
} }
switch (index.column()) { switch (index.column()) {
@ -386,7 +386,7 @@ QVariant LocaleModel::headerData(int section, Qt::Orientation orientation, int r
LocaleListItem item = g_locale_list[section - 2]; LocaleListItem item = g_locale_list[section - 2];
return QLocale::languageToString((QLocale::Language)item.language) return QLocale::languageToString((QLocale::Language)item.language)
+ QLatin1Char('/') + QLatin1Char('/')
+ QLocale::countryToString((QLocale::Country)item.country); + QLocale::territoryToString((QLocale::Territory)item.territory);
} }
} }

View File

@ -450,7 +450,7 @@ int main(int argc, char **argv)
" const char *variant; // 0 means any variant\n" " const char *variant; // 0 means any variant\n"
" Qt::LayoutDirection direction;\n" " Qt::LayoutDirection direction;\n"
" QLocale::Language language;\n" " QLocale::Language language;\n"
" QLocale::Country country;\n" " QLocale::Territory territory;\n"
"} xkbLayoutData[] = {\n"); "} xkbLayoutData[] = {\n");
// contents // contents
@ -485,7 +485,7 @@ int main(int argc, char **argv)
} }
// wrapping up // wrapping up
printf(" { 0, 0, Qt::LeftToRight, QLocale::C, QLocale::AnyCountry }\n" printf(" { 0, 0, Qt::LeftToRight, QLocale::C, QLocale::AnyTerritory }\n"
"};\n"); "};\n");
return 0; return 0;