From f254b0aa67a4656d25c7ea240efcd00084772f00 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 18 Dec 2017 19:43:56 +0100 Subject: Add a feature for QML locale support Change-Id: I1cfb2da317f52709011b67a68e87a73ed24ef6d6 Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- src/qml/configure.json | 9 ++++++++- src/qml/jsruntime/qv4engine.cpp | 6 ++++++ src/qml/qml/qml.pri | 10 ++++++++-- src/qml/qml/qqmlengine.cpp | 6 ++++++ src/qml/qml/qqmllocale_p.h | 2 ++ src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 6 ++++++ src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 2 ++ src/qml/qml/v8/qv8engine.cpp | 4 ++++ 8 files changed, 42 insertions(+), 3 deletions(-) (limited to 'src/qml') diff --git a/src/qml/configure.json b/src/qml/configure.json index cf40049ee1..95a4dd5240 100644 --- a/src/qml/configure.json +++ b/src/qml/configure.json @@ -67,6 +67,12 @@ "features.qml-network" ], "output": [ "privateFeature" ] + }, + "qml-locale": { + "label": "QML Locale", + "purpose": "Provides support for locales in QML.", + "section": "QML", + "output": [ "privateFeature" ] } }, @@ -78,7 +84,8 @@ "qml-debug", "qml-sequence-object", "qml-list-model", - "qml-xml-http-request" + "qml-xml-http-request", + "qml-locale" ] } ] diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index c033a7d805..06b71c5cf7 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -80,7 +80,9 @@ #include #include #include +#if QT_CONFIG(qml_locale) #include +#endif #include #include @@ -1201,8 +1203,10 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, int return str.at(0); return str; } +#if QT_CONFIG(qml_locale) if (const QV4::QQmlLocaleData *ld = value.as()) return *ld->d()->locale; +#endif if (const QV4::DateObject *d = value.as()) return d->toQDateTime(); if (const ArrayBuffer *d = value.as()) @@ -1379,8 +1383,10 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant) return QV4::JsonObject::fromJsonObject(this, *reinterpret_cast(ptr)); case QMetaType::QJsonArray: return QV4::JsonObject::fromJsonArray(this, *reinterpret_cast(ptr)); +#if QT_CONFIG(qml_locale) case QMetaType::QLocale: return QQmlLocale::wrap(this, *reinterpret_cast(ptr)); +#endif default: break; } diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index 05cc741582..6d69294c17 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -30,7 +30,6 @@ SOURCES += \ $$PWD/qqmlextensionplugin.cpp \ $$PWD/qqmlimport.cpp \ $$PWD/qqmllist.cpp \ - $$PWD/qqmllocale.cpp \ $$PWD/qqmljavascriptexpression.cpp \ $$PWD/qqmlabstractbinding.cpp \ $$PWD/qqmlvaluetypeproxybinding.cpp \ @@ -97,7 +96,6 @@ HEADERS += \ $$PWD/qqmlimport_p.h \ $$PWD/qqmlextensionplugin.h \ $$PWD/qqmlscriptstring_p.h \ - $$PWD/qqmllocale_p.h \ $$PWD/qqmlcomponentattached_p.h \ $$PWD/qqmljavascriptexpression_p.h \ $$PWD/qqmlabstractbinding_p.h \ @@ -127,5 +125,13 @@ qtConfig(qml-xml-http-request) { } +qtConfig(qml-locale) { + HEADERS += \ + $$PWD/qqmllocale_p.h + + SOURCES += \ + $$PWD/qqmllocale.cpp +} + include(ftw/ftw.pri) include(v8/v8.pri) diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 3ed65eab9f..6d289b3c9e 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -78,7 +78,9 @@ #include #include +#if QT_CONFIG(qml_locale) #include +#endif #include #include #if QT_CONFIG(animation) @@ -255,7 +257,9 @@ void QQmlEnginePrivate::defineQtQuick2Module() // register the QtQuick2 types which are implemented in the QtQml module. registerQtQuick2Types("QtQuick",2,0); +#if QT_CONFIG(qml_locale) qmlRegisterUncreatableType("QtQuick", 2, 0, "Locale", QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); +#endif } bool QQmlEnginePrivate::designerMode() @@ -941,7 +945,9 @@ void QQmlEnginePrivate::init() if (baseModulesUninitialized) { qmlRegisterType("QML", 1, 0, "Component"); // required for the Compiler. registerBaseTypes("QtQml", 2, 0); // import which provides language building blocks. +#if QT_CONFIG(qml_locale) qmlRegisterUncreatableType("QtQml", 2, 2, "Locale", QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); +#endif QQmlData::init(); baseModulesUninitialized = false; diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h index 57666c64f1..4ad9d6dbf6 100644 --- a/src/qml/qml/qqmllocale_p.h +++ b/src/qml/qml/qqmllocale_p.h @@ -58,6 +58,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_locale); + QT_BEGIN_NAMESPACE diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 44ad174f37..98cf443252 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -44,7 +44,9 @@ #include #include #include +#if QT_CONFIG(qml_locale) #include +#endif #include #include #include @@ -138,7 +140,9 @@ void Heap::QtObject::init(QQmlEngine *qmlEngine) o->defineDefaultProperty(QStringLiteral("btoa"), QV4::QtObject::method_btoa); o->defineDefaultProperty(QStringLiteral("atob"), QV4::QtObject::method_atob); o->defineDefaultProperty(QStringLiteral("resolvedUrl"), QV4::QtObject::method_resolvedUrl); +#if QT_CONFIG(qml_locale) o->defineDefaultProperty(QStringLiteral("locale"), QV4::QtObject::method_locale); +#endif o->defineDefaultProperty(QStringLiteral("binding"), QV4::QtObject::method_binding); if (qmlEngine) { @@ -1299,6 +1303,7 @@ ReturnedValue QtObject::method_createComponent(const FunctionObject *b, const Va return QV4::QObjectWrapper::wrap(scope.engine, c); } +#if QT_CONFIG(qml_locale) /*! \qmlmethod Qt::locale(name) @@ -1333,6 +1338,7 @@ ReturnedValue QtObject::method_locale(const FunctionObject *b, const Value *, co return QQmlLocale::locale(scope.engine, code); } +#endif void Heap::QQmlBindingFunction::init(const QV4::FunctionObject *originalFunction) { diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index 104dae5d79..993e323e51 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -123,7 +123,9 @@ struct QtObject : Object static ReturnedValue method_resolvedUrl(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); static ReturnedValue method_createQmlObject(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); static ReturnedValue method_createComponent(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); +#if QT_CONFIG(qml_locale) static ReturnedValue method_locale(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); +#endif static ReturnedValue method_binding(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); static ReturnedValue method_get_platform(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 423edc3559..da3668d910 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -51,7 +51,9 @@ #if QT_CONFIG(qml_xml_http_request) #include #endif +#if QT_CONFIG(qml_locale) #include +#endif #include #include #include @@ -189,9 +191,11 @@ void QV8Engine::initializeGlobal() QV4::ScopedObject qt(scope, m_v4Engine->memoryManager->allocObject(m_engine)); m_v4Engine->globalObject->defineDefaultProperty(QStringLiteral("Qt"), qt); +#if QT_CONFIG(qml_locale) QQmlLocale::registerStringLocaleCompare(m_v4Engine); QQmlDateExtension::registerExtension(m_v4Engine); QQmlNumberExtension::registerExtension(m_v4Engine); +#endif #if QT_CONFIG(qml_xml_http_request) qt_add_domexceptions(m_v4Engine); -- cgit v1.2.3