summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/text/qlocale.cpp39
-rw-r--r--src/corelib/text/qlocale_p.h1
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp3
3 files changed, 29 insertions, 14 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 89aa19404e..7fcfd3dfa6 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -695,18 +695,28 @@ static QLocalePrivate *c_private()
*/
/*!
- Constructs a QSystemLocale object.
+ \internal
+ Constructs a QSystemLocale object.
+
+ The constructor will automatically install this object as the system locale.
+ It and the destructor maintain a stack of system locales, with the
+ most-recently-created instance (that hasn't yet been deleted) used as the
+ system locale. This is only intended as a way to let a platform plugin
+ install its own system locale, overriding what might otherwise be provided
+ for its class of platform (as Android does, differing from Linux), and to
+ let tests transiently over-ride the system or plugin-supplied one. As such,
+ there should not be diverse threads creating and destroying QSystemLocale
+ instances concurrently, so no attempt is made at thread-safety in managing
+ the stack.
- The constructor will automatically install this object as the system locale,
- if there's not one active. It also resets the flag that'll prompt
- QLocale::system() to re-initialize its data, so that instantiating a
- QSystemLocale transiently (doesn't install the transient as system locale if
- there was one already and) triggers an update to the system locale's data.
+ This constructor also resets the flag that'll prompt QLocale::system() to
+ re-initialize its data, so that instantiating a QSystemLocale (even
+ transiently) triggers a refresh of the system locale's data. This is
+ exploited by some test code.
*/
-QSystemLocale::QSystemLocale()
+QSystemLocale::QSystemLocale() : next(_systemLocale)
{
- if (!_systemLocale)
- _systemLocale = this;
+ _systemLocale = this;
systemLocaleData.m_language_id = 0;
}
@@ -718,14 +728,21 @@ QSystemLocale::QSystemLocale(bool)
{ }
/*!
- Deletes the object.
+ \internal
+ Deletes the object.
*/
QSystemLocale::~QSystemLocale()
{
if (_systemLocale == this) {
- _systemLocale = nullptr;
+ _systemLocale = next;
+ // Change to system locale => force refresh.
systemLocaleData.m_language_id = 0;
+ } else {
+ for (QSystemLocale *p = _systemLocale; p; p = p->next) {
+ if (p->next == this)
+ p->next = next;
+ }
}
}
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h
index cd0590518b..b8afbd0bc8 100644
--- a/src/corelib/text/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -36,6 +36,7 @@ struct QLocaleData;
// Subclassed by Android platform plugin:
class Q_CORE_EXPORT QSystemLocale
{
+ QSystemLocale *next = nullptr; // Maintains a stack.
public:
QSystemLocale();
virtual ~QSystemLocale();
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index cd0004c341..f0fef7093a 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -3258,9 +3258,6 @@ private:
void tst_QLocale::systemLocale_data()
{
-#ifdef Q_OS_ANDROID
- QSKIP("Android already has a QSystemLocale installed, we can't override it");
-#endif
// Test uses MySystemLocale, so is platform-independent.
QTest::addColumn<QString>("name");
QTest::addColumn<QLocale::Language>("language");