Skip to content

Commit

Permalink
[mlocale] Remove reliance on QGuiApplication, which may not be presen…
Browse files Browse the repository at this point in the history
…t. Fixes JB#36147
  • Loading branch information
martinjones committed Sep 15, 2016
1 parent 14f05e5 commit ad5d0b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/mlocale.cpp
Expand Up @@ -40,11 +40,8 @@
#include <MDebug>
#include <QTranslator>
#include <QDir>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
# include <QGuiApplication>
#else
# include <QApplication>
#endif
#include <QMetaProperty>
#include <QCoreApplication>
#include <QMutex>
#include <QDateTime>
#include <QPointer>
Expand Down Expand Up @@ -2091,6 +2088,16 @@ struct MStaticLocaleDestroyer {
};
static MStaticLocaleDestroyer staticLocaleDestroyer;

static void setApplicationLayoutDirection(Qt::LayoutDirection layoutDirection)
{
if (QCoreApplication *app = QCoreApplication::instance()) {
int layoutDirProperty = app->metaObject()->indexOfProperty("layoutDirection");
if (layoutDirProperty != -1) {
app->metaObject()->property(layoutDirProperty).write(app, layoutDirection);
}
}
}

void MLocale::setDefault(const MLocale &locale)
{
defaultLocaleMutex.lock();
Expand Down Expand Up @@ -2127,19 +2134,18 @@ void MLocale::setDefault(const MLocale &locale)
// support in translations via %Ln, %L1, %L2, ...:
QLocale::setDefault((s_systemDefault->d_ptr)->createQLocale(MLcNumeric));
// sends QEvent::ApplicationLayoutDirectionChange to qApp:
if (qApp) {
qApp->setLayoutDirection(s_systemDefault->textDirection());
}
setApplicationLayoutDirection(s_systemDefault->textDirection());
#ifdef HAVE_ICU
_defaultLayoutDirection = MIcuConversions::parseLayoutDirectionOption(s_systemDefault->name());
#else
_defaultLayoutDirection = Qt::LeftToRight;
#endif

if ( qApp && qApp->metaObject() && qApp->metaObject()->className() == QString( "MApplication" ) )
QCoreApplication *qapp = QCoreApplication::instance();
if ( qapp && qapp->metaObject() && qapp->metaObject()->className() == QString( "MApplication" ) )
{
QObject::connect(s_systemDefault, SIGNAL(settingsChanged()),
qApp, SIGNAL(localeSettingsChanged()));
qapp, SIGNAL(localeSettingsChanged()));
}

QObject::connect(s_systemDefault, SIGNAL(settingsChanged()),
Expand Down Expand Up @@ -4607,9 +4613,7 @@ void MLocale::refreshSettings()
// Setting the default QLocale is needed to get localized number
// support in translations via %Ln, %L1, %L2, ...:
QLocale::setDefault(d->createQLocale(MLcNumeric));
if (qApp) {
qApp->setLayoutDirection(this->textDirection());
}
setApplicationLayoutDirection(this->textDirection());
#ifdef HAVE_ICU
_defaultLayoutDirection = MIcuConversions::parseLayoutDirectionOption(s_systemDefault->name());
#else
Expand Down
1 change: 1 addition & 0 deletions src/src.pro
Expand Up @@ -4,6 +4,7 @@ DEFINES += M_BUILD_MLOCALE

include(common_top.pri)
QT += xml
QT -= gui

equals(QT_MAJOR_VERSION, 4): TARGET = mlocale
equals(QT_MAJOR_VERSION, 5): TARGET = mlocale5
Expand Down

0 comments on commit ad5d0b0

Please sign in to comment.