Revise deprecation of countriesForLanguage()
It was originally marked \obsolete without any comment on what was to be used to replace it, or deprecation markings in the declaration, so it got missed at 6.0. More recently it's been deprecated in favor of a territory-based name; but actually it was obsoleted by (iterating the territory() of each return from) matchingLocales() in Qt 4.8. So back out of adding territoriesForLanguage to replace it and, instead, mark it as deprecated in the declaration, in favor of matchingLocales(). Also rewrite the implementation to be exactly that replacement. Rewrote the one example using it. Fixes: QTBUG-92484 Change-Id: Iedaf30378446dd9adac5128b7ee5fee48aab1636 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
530e0bd469
commit
d4242b8af3
|
|
@ -237,6 +237,9 @@ void Window::createPreviewGroupBox()
|
|||
}
|
||||
//! [9]
|
||||
|
||||
// TODO: use loc.name() as label (but has underscore in place of slash)
|
||||
// TODO: use locale() == loc instead of only comparing language and territory
|
||||
// Needs someone familiar with this example to work out ramifications
|
||||
//! [10]
|
||||
void Window::createGeneralOptionsGroupBox()
|
||||
{
|
||||
|
|
@ -247,15 +250,16 @@ void Window::createGeneralOptionsGroupBox()
|
|||
int index = 0;
|
||||
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
|
||||
QLocale::Language lang = static_cast<QLocale::Language>(_lang);
|
||||
const auto territories = QLocale::territoriesForLanguage(lang);
|
||||
for (auto territory : territories) {
|
||||
const auto locales =
|
||||
QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
|
||||
for (auto loc : locales) {
|
||||
QString label = QLocale::languageToString(lang);
|
||||
auto territory = loc.territory();
|
||||
label += QLatin1Char('/');
|
||||
label += QLocale::territoryToString(territory);
|
||||
QLocale locale(lang, territory);
|
||||
if (this->locale().language() == lang && this->locale().territory() == territory)
|
||||
if (locale().language() == lang && locale().territory() == territory)
|
||||
curLocaleIndex = index;
|
||||
localeCombo->addItem(label, locale);
|
||||
localeCombo->addItem(label, loc);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2653,38 +2653,9 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language, QLocale::Scr
|
|||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
\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.
|
||||
\obsolete Use matchingLocales() instead and consult the territory() of each.
|
||||
\since 4.3
|
||||
|
||||
Returns the list of countries that have entries for \a language in Qt's locale
|
||||
|
|
@ -2695,7 +2666,12 @@ QList<QLocale::Territory> QLocale::territoriesForLanguage(QLocale::Language lang
|
|||
*/
|
||||
QList<QLocale::Country> QLocale::countriesForLanguage(Language language)
|
||||
{
|
||||
return territoriesForLanguage(language);
|
||||
const auto locales = matchingLocales(language, AnyScript, AnyCountry);
|
||||
QList<QLocale::Country> result;
|
||||
result.reserve(locales.size());
|
||||
for (const auto &locale : locales)
|
||||
result.append(locale.territory());
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1108,10 +1108,10 @@ public:
|
|||
static QLocale c() { return QLocale(C); }
|
||||
static QLocale system();
|
||||
|
||||
static QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Territory territory);
|
||||
static QList<Territory> territoriesForLanguage(Language lang);
|
||||
static QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script,
|
||||
QLocale::Territory territory);
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use territoriesForLanguage(Language) instead")
|
||||
QT_DEPRECATED_VERSION_X_6_6("Query territory() on each entry from matchingLocales() instead")
|
||||
static QList<Country> countriesForLanguage(Language lang);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue