QLocale: merge the code for some system locale queries

QSystemLocale is now defined for QT_NO_SYSTEMLOCALE builds (bootstrap),
but no implementation will be present. That's just to get the enum
declarations.

Pick-to: 6.4
Change-Id: I3c79b7e08fa346988dfefffd171fa00fde8ab080
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2022-10-19 17:39:23 -07:00
parent 209adad078
commit 089bbfc307
2 changed files with 31 additions and 42 deletions

View File

@ -886,29 +886,41 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
return new QLocalePrivate(data, index, numberOptions); return new QLocalePrivate(data, index, numberOptions);
} }
QString QLocaleData::decimalPoint() const static std::optional<QString>
systemLocaleString(const QLocaleData *that, QSystemLocale::QueryType type)
{ {
#ifndef QT_NO_SYSTEMLOCALE #ifndef QT_NO_SYSTEMLOCALE
if (this == &systemLocaleData) { if (that != &systemLocaleData)
auto res = systemLocale()->query(QSystemLocale::DecimalPoint).toString(); return std::nullopt;
if (!res.isEmpty())
return res; QVariant v = systemLocale()->query(type);
} if (v.metaType() != QMetaType::fromType<QString>())
return std::nullopt;
return v.toString();
#else
Q_UNUSED(that)
Q_UNUSED(type)
return std::nullopt;
#endif #endif
return decimalSeparator().getData(single_character_data); }
static QString localeString(const QLocaleData *that, QSystemLocale::QueryType type,
QLocaleData::DataRange range)
{
if (auto opt = systemLocaleString(that, type))
return *opt;
return range.getData(single_character_data);
}
QString QLocaleData::decimalPoint() const
{
return localeString(this, QSystemLocale::DecimalPoint, decimalSeparator());
} }
QString QLocaleData::groupSeparator() const QString QLocaleData::groupSeparator() const
{ {
// Empty => don't do grouping return localeString(this, QSystemLocale::GroupSeparator, groupDelim());
#ifndef QT_NO_SYSTEMLOCALE
if (this == &systemLocaleData) {
QVariant res = systemLocale()->query(QSystemLocale::GroupSeparator);
if (!res.isNull())
return res.toString();
}
#endif
return groupDelim().getData(single_character_data);
} }
QString QLocaleData::percentSign() const QString QLocaleData::percentSign() const
@ -923,14 +935,7 @@ QString QLocaleData::listSeparator() const
QString QLocaleData::zeroDigit() const QString QLocaleData::zeroDigit() const
{ {
#ifndef QT_NO_SYSTEMLOCALE return localeString(this, QSystemLocale::ZeroDigit, zero());
if (this == &systemLocaleData) {
auto res = systemLocale()->query(QSystemLocale::ZeroDigit).toString();
if (!res.isEmpty())
return res;
}
#endif
return zero().getData(single_character_data);
} }
char32_t QLocaleData::zeroUcs() const char32_t QLocaleData::zeroUcs() const
@ -951,26 +956,12 @@ char32_t QLocaleData::zeroUcs() const
QString QLocaleData::negativeSign() const QString QLocaleData::negativeSign() const
{ {
#ifndef QT_NO_SYSTEMLOCALE return localeString(this, QSystemLocale::NegativeSign, minus());
if (this == &systemLocaleData) {
auto res = systemLocale()->query(QSystemLocale::NegativeSign).toString();
if (!res.isEmpty())
return res;
}
#endif
return minus().getData(single_character_data);
} }
QString QLocaleData::positiveSign() const QString QLocaleData::positiveSign() const
{ {
#ifndef QT_NO_SYSTEMLOCALE return localeString(this, QSystemLocale::PositiveSign, plus());
if (this == &systemLocaleData) {
auto res = systemLocale()->query(QSystemLocale::PositiveSign).toString();
if (!res.isEmpty())
return res;
}
#endif
return plus().getData(single_character_data);
} }
QString QLocaleData::exponentSeparator() const QString QLocaleData::exponentSeparator() const

View File

@ -31,7 +31,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#ifndef QT_NO_SYSTEMLOCALE
struct QLocaleData; struct QLocaleData;
// Subclassed by Android platform plugin: // Subclassed by Android platform plugin:
class Q_CORE_EXPORT QSystemLocale class Q_CORE_EXPORT QSystemLocale
@ -106,7 +105,6 @@ public:
}; };
Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_RELOCATABLE_TYPE); Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_RELOCATABLE_TYPE);
#endif
#if QT_CONFIG(icu) #if QT_CONFIG(icu)
namespace QIcu { namespace QIcu {