Always pass index when creating a QLocalePrivate
Previously, two calls using the default locale (which has an index in the locale_data array when it isn't the system locale) neglected to pass the index and the call for the system locale had no idnex, where it should really set the index appropriate to its language, script and country, so that we get appropriate calendar data to go with the system locale. One other place that handled the default locale also neglected to revise the index it was using. Change-Id: I4cc52e2d085a99e61236c91c0ae873b3bde5f11d Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
297cbd506f
commit
7d81f21d48
@ -589,8 +589,9 @@ static QLocalePrivate *c_private()
|
||||
}
|
||||
|
||||
static const QLocaleData *systemData();
|
||||
static uint defaultIndex();
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer<QLocalePrivate>, systemLocalePrivate,
|
||||
(QLocalePrivate::create(systemData())))
|
||||
(QLocalePrivate::create(systemData(), defaultIndex())))
|
||||
|
||||
#ifndef QT_NO_SYSTEMLOCALE
|
||||
/******************************************************************************
|
||||
@ -700,6 +701,22 @@ static const QLocaleData *defaultData()
|
||||
return default_data;
|
||||
}
|
||||
|
||||
static uint defaultIndex()
|
||||
{
|
||||
const QLocaleData *const data = defaultData();
|
||||
#ifndef QT_NO_SYSTEMLOCALE
|
||||
if (data == systemData()) {
|
||||
// Work out a suitable index matching the system data, for use when
|
||||
// accessing calendar data, when not fetched from system.
|
||||
return QLocaleData::findLocaleIndex(data->id());
|
||||
}
|
||||
#endif
|
||||
|
||||
Q_ASSERT(data >= locale_data);
|
||||
Q_ASSERT(data < locale_data + std::size(locale_data));
|
||||
return data - locale_data;
|
||||
}
|
||||
|
||||
const QLocaleData *QLocaleData::c()
|
||||
{
|
||||
Q_ASSERT(locale_index[QLocale::C] == 0);
|
||||
@ -726,7 +743,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l)
|
||||
static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1;
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
|
||||
(QLocalePrivate::create(defaultData())))
|
||||
(QLocalePrivate::create(defaultData(), defaultIndex())))
|
||||
|
||||
static QLocalePrivate *localePrivateByName(const QString &name)
|
||||
{
|
||||
@ -756,6 +773,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
|
||||
if (defaultLocalePrivate.exists())
|
||||
numberOptions = defaultLocalePrivate->data()->m_numberOptions;
|
||||
data = defaultData();
|
||||
index = defaultIndex();
|
||||
}
|
||||
return QLocalePrivate::create(data, index, numberOptions);
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ class Q_CORE_EXPORT QLocalePrivate // A POD type
|
||||
{
|
||||
public:
|
||||
static QLocalePrivate *create(
|
||||
const QLocaleData *data, const uint data_offset = 0,
|
||||
const QLocaleData *data, const uint data_offset,
|
||||
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions)
|
||||
{
|
||||
auto *retval = new QLocalePrivate;
|
||||
|
Loading…
Reference in New Issue
Block a user