summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qlocale.cpp186
-rw-r--r--src/corelib/tools/qlocale.h1
-rw-r--r--src/corelib/tools/qlocale_p.h2
-rw-r--r--tests/auto/qlocale/tst_qlocale.cpp6
4 files changed, 46 insertions, 149 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 9625228..ff10fa1 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -1274,25 +1274,11 @@ QLocale QSystemLocale::fallbackLocale() const
*/
QVariant QSystemLocale::query(QueryType type, QVariant /* in */) const
{
- switch (type) {
- case MeasurementSystem:
+ if (type == MeasurementSystem) {
return QVariant(unixGetSystemMeasurementSystem());
- case LanguageId:
- case CountryId: {
- QString locale = QLatin1String(envVarLocale());
- QLocale::Language lang;
- QLocale::Country cntry;
- getLangAndCountry(locale, lang, cntry);
- if (type == LanguageId)
- return lang;
- if (cntry == QLocale::AnyCountry)
- return fallbackLocale().country();
- return cntry;
- }
- default:
- break;
+ } else {
+ return QVariant();
}
- return QVariant();
}
#elif !defined(Q_OS_SYMBIAN)
@@ -1324,10 +1310,12 @@ QVariant QSystemLocale::query(QueryType /* type */, QVariant /* in */) const
#endif
+#ifndef QT_NO_SYSTEMLOCALE
static QSystemLocale *_systemLocale = 0;
Q_GLOBAL_STATIC_WITH_ARGS(QSystemLocale, QSystemLocale_globalSystemLocale, (true))
static QLocalePrivate *system_lp = 0;
Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
+#endif
/******************************************************************************
** Default system locale behavior
@@ -1400,8 +1388,7 @@ QSystemLocale::QSystemLocale()
/*! \internal */
QSystemLocale::QSystemLocale(bool)
-{
-}
+{ }
/*!
Deletes the object.
@@ -1423,42 +1410,16 @@ static const QSystemLocale *systemLocale()
return QSystemLocale_globalSystemLocale();
}
-static const QLocalePrivate *maybeSystemPrivate();
-bool QLocalePrivate::isUninitializedSystemLocale() const
-{
- return this == maybeSystemPrivate() && m_language_id == 0;
-}
-
-QVariant QLocalePrivate::querySystemLocale(int type, const QVariant &in) const
-{
- QVariant res = systemLocale()->query(QSystemLocale::QueryType(type), in);
- if (res.isNull() && isUninitializedSystemLocale()) {
- // if we were not able to get data from the system, initialize the
- // system locale private data (which is essentially equals to this)
- // with a fallback locale.
- QLocalePrivate *system_private = globalLocalePrivate();
- *system_private = *systemLocale()->fallbackLocale().d();
- // internal cache is not initialized with values from the system, mark
- // it as not fully initialized system locale.
- system_private->m_language_id = 0;
- }
- return res;
-}
-
-// retrieves data from the system locale and caches them locally.
void QLocalePrivate::updateSystemPrivate()
{
const QSystemLocale *sys_locale = systemLocale();
if (!system_lp)
- return;
-
- // copy over the information from the fallback locale and modify
+ system_lp = globalLocalePrivate();
*system_lp = *sys_locale->fallbackLocale().d();
QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant());
if (!res.isNull())
system_lp->m_language_id = res.toInt();
-
res = sys_locale->query(QSystemLocale::CountryId, QVariant());
if (!res.isNull())
system_lp->m_country_id = res.toInt();
@@ -1485,29 +1446,19 @@ void QLocalePrivate::updateSystemPrivate()
}
#endif
-// returns the private data for the system locale. Cached data will not be
-// initialized until the updateSystemPrivate is called.
static const QLocalePrivate *systemPrivate()
{
#ifndef QT_NO_SYSTEMLOCALE
- if (!system_lp) {
- system_lp = globalLocalePrivate();
- // mark the locale as uninitialized system locale
- system_lp->m_language_id = 0;
- }
+ // copy over the information from the fallback locale and modify
+ if (!system_lp || system_lp->m_language_id == 0)
+ QLocalePrivate::updateSystemPrivate();
+
return system_lp;
#else
return locale_data;
#endif
}
-#ifndef QT_NO_SYSTEMLOCALE
-static const QLocalePrivate *maybeSystemPrivate()
-{
- return system_lp;
-}
-#endif
-
static const QLocalePrivate *defaultPrivate()
{
if (!default_lp)
@@ -2332,12 +2283,7 @@ void QLocale::setDefault(const QLocale &locale)
*/
QLocale::Language QLocale::language() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return Language(dd->languageId());
+ return Language(d()->languageId());
}
/*!
@@ -2347,12 +2293,7 @@ QLocale::Language QLocale::language() const
*/
QLocale::Country QLocale::country() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return Country(dd->countryId());
+ return Country(d()->countryId());
}
/*!
@@ -2690,8 +2631,8 @@ QString QLocale::toString(const QDate &date, FormatType format) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateToStringLong : QSystemLocale::DateToStringShort,
date);
if (!res.isNull())
@@ -2785,8 +2726,8 @@ QString QLocale::toString(const QDateTime &dateTime, FormatType format) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateTimeToStringLong
: QSystemLocale::DateTimeToStringShort,
dateTime);
@@ -2811,8 +2752,8 @@ QString QLocale::toString(const QTime &time, FormatType format) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::TimeToStringLong : QSystemLocale::TimeToStringShort,
time);
if (!res.isNull())
@@ -2838,8 +2779,8 @@ QString QLocale::toString(const QTime &time, FormatType format) const
QString QLocale::dateFormat(FormatType format) const
{
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateFormatLong : QSystemLocale::DateFormatShort,
QVariant());
if (!res.isNull())
@@ -2875,8 +2816,8 @@ QString QLocale::dateFormat(FormatType format) const
QString QLocale::timeFormat(FormatType format) const
{
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::TimeFormatLong : QSystemLocale::TimeFormatShort,
QVariant());
if (!res.isNull())
@@ -2912,8 +2853,8 @@ QString QLocale::timeFormat(FormatType format) const
QString QLocale::dateTimeFormat(FormatType format) const
{
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(format == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(format == LongFormat
? QSystemLocale::DateTimeFormatLong
: QSystemLocale::DateTimeFormatShort,
QVariant());
@@ -3080,12 +3021,7 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format) cons
*/
QChar QLocale::decimalPoint() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->decimal();
+ return d()->decimal();
}
/*!
@@ -3095,12 +3031,7 @@ QChar QLocale::decimalPoint() const
*/
QChar QLocale::groupSeparator() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->group();
+ return d()->group();
}
/*!
@@ -3110,12 +3041,7 @@ QChar QLocale::groupSeparator() const
*/
QChar QLocale::percent() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->percent();
+ return d()->percent();
}
/*!
@@ -3125,12 +3051,7 @@ QChar QLocale::percent() const
*/
QChar QLocale::zeroDigit() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->zero();
+ return d()->zero();
}
/*!
@@ -3140,12 +3061,7 @@ QChar QLocale::zeroDigit() const
*/
QChar QLocale::negativeSign() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->minus();
+ return d()->minus();
}
/*!
@@ -3155,12 +3071,7 @@ QChar QLocale::negativeSign() const
*/
QChar QLocale::positiveSign() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->plus();
+ return d()->plus();
}
/*!
@@ -3170,12 +3081,7 @@ QChar QLocale::positiveSign() const
*/
QChar QLocale::exponential() const
{
- const QLocalePrivate *dd = d();
-#ifndef QT_NO_SYSTEMLOCALE
- if (dd->isUninitializedSystemLocale())
- QLocalePrivate::updateSystemPrivate();
-#endif
- return dd->exponential();
+ return d()->exponential();
}
static bool qIsUpper(char c)
@@ -3294,8 +3200,8 @@ QString QLocale::monthName(int month, FormatType type) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(type == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(type == LongFormat
? QSystemLocale::MonthNameLong : QSystemLocale::MonthNameShort,
month);
if (!res.isNull())
@@ -3340,8 +3246,8 @@ QString QLocale::standaloneMonthName(int month, FormatType type) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(type == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(type == LongFormat
? QSystemLocale::MonthNameLong : QSystemLocale::MonthNameShort,
month);
if (!res.isNull())
@@ -3387,8 +3293,8 @@ QString QLocale::dayName(int day, FormatType type) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(type == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(type == LongFormat
? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort,
day);
if (!res.isNull())
@@ -3436,8 +3342,8 @@ QString QLocale::standaloneDayName(int day, FormatType type) const
return QString();
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(type == LongFormat
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(type == LongFormat
? QSystemLocale::DayNameLong : QSystemLocale::DayNameShort,
day);
if (!res.isNull())
@@ -3481,8 +3387,8 @@ QLocale::MeasurementSystem QLocale::measurementSystem() const
bool found = false;
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(QSystemLocale::MeasurementSystem, QVariant());
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::MeasurementSystem, QVariant());
if (!res.isNull()) {
meas = MeasurementSystem(res.toInt());
found = true;
@@ -3509,8 +3415,8 @@ QLocale::MeasurementSystem QLocale::measurementSystem() const
QString QLocale::amText() const
{
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(QSystemLocale::AMText, QVariant());
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::AMText, QVariant());
if (!res.isNull())
return res.toString();
}
@@ -3529,8 +3435,8 @@ QString QLocale::amText() const
QString QLocale::pmText() const
{
#ifndef QT_NO_SYSTEMLOCALE
- if (d() == maybeSystemPrivate()) {
- QVariant res = d()->querySystemLocale(QSystemLocale::PMText, QVariant());
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::PMText, QVariant());
if (!res.isNull())
return res.toString();
}
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index 9b7b214..e854c84 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -638,7 +638,6 @@ public:
;
private:
friend struct QLocalePrivate;
-
// ### We now use this field to pack an index into locale_data and NumberOptions.
// ### Qt 5: change to a QLocaleData *d; uint numberOptions.
union {
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index 6c0935b..ecf79e9 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -132,8 +132,6 @@ public:
CharBuff *result) const;
inline char digitToCLocale(const QChar &c) const;
- inline bool isUninitializedSystemLocale() const;
- QVariant querySystemLocale(int type, const QVariant &in) const;
static void updateSystemPrivate();
enum NumberMode { IntegerMode, DoubleStandardMode, DoubleScientificMode };
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp
index 8dd5fbb..3dc4dad 100644
--- a/tests/auto/qlocale/tst_qlocale.cpp
+++ b/tests/auto/qlocale/tst_qlocale.cpp
@@ -158,15 +158,9 @@ void tst_QLocale::ctor()
QCoreApplication app(argc, (char**)&argv);
#endif
QLocale default_locale = QLocale::system();
-
- QVERIFY(!default_locale.monthName(1, QLocale::LongFormat).isEmpty());
- QVERIFY(!default_locale.monthName(1, QLocale::ShortFormat).isEmpty());
- QVERIFY(default_locale.language() != 0);
-
QLocale::Language default_lang = default_locale.language();
QLocale::Country default_country = default_locale.country();
-
qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(),
QLocale::countryToString(default_country).toLatin1().constData());