From 43e3c21a0bad9141b6c35cc4ee4a58b4d824462a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Siret Date: Fri, 20 Dec 2019 01:51:39 +0100 Subject: Add Q_GADGET Wrapper for QQmlProperty This enable exposing a QQmlProperty as a value type to QML code. Only object and name are exposed as a properties to keep it simple. We might want later to expose the property of a Binding or a Behavior as a property for complex usecases. This permits exposing it as one self contained value instead of a pair of unrelated object and name. Task-number: QTBUG-70964 Task-number: QTBUG-73892 Change-Id: I3a46212446f43f3a7e301943cb49d3a48c377de3 Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlengine.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/qml/qml/qqmlengine.cpp') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index d7001dbbe3..73d3ba1863 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -101,8 +101,6 @@ # endif #endif // Q_OS_WIN -Q_DECLARE_METATYPE(QQmlProperty) - QT_BEGIN_NAMESPACE // Declared in qqml.h -- cgit v1.2.3 From 020a6e67766595351bcf911e965b26952a7c81b8 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 22 Jan 2020 13:37:48 +0100 Subject: Add Qt.uiLanguage and QJSEngine::uiLanguage properties [ChangeLog][QtQml] Added Qt.uiLanguage and QJSEngine::uiLanguage properties These properties mirror the same value in QML and C++ and can be used freely. They also provide API symmetry to Qt for MCUs. QQmlApplicationEngine binds to this property and applies translations accordingly by constructing a QLocale with the value and using QTranslator::load(locale). Change-Id: Id87d6ee64679b07ff3cb47844594e8eeebd8c8b6 Reviewed-by: Ulf Hermann Reviewed-by: Christian Kamm --- src/qml/qml/qqmlengine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/qml/qml/qqmlengine.cpp') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 73d3ba1863..3345fcb19e 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1335,6 +1335,21 @@ void QQmlEngine::setOutputWarningsToStandardError(bool enabled) d->outputWarningsToMsgLog = enabled; } +/*! + \qmlproperty string Qt::uiLanguage + \since 5.15 + + The uiLanguage holds the name of the language to be used for user interface + string translations. It is exposed in C++ as QQmlEngine::uiLanguage property. + + You can set the value freely and use it in bindings. It is recommended to set it + after installing translators in your application. By convention, an empty string + means no translation from the language used in the source code is intended to occur. + + If you're using QQmlApplicationEngine and the value changes, QQmlEngine::retranslate() + will be called. +*/ + /*! \fn template T QQmlEngine::singletonInstance(int qmlTypeId) -- cgit v1.2.3 From 684f9df7849bc79f1f02a60844fb43c7a3927d2f Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 15 Jan 2020 14:47:35 +0100 Subject: Long live QML inline components [ChangeLog][QtQml] It is now possible to declare new QML components in a QML file via the component keyword. They can be used just as if they were declared in another file, with the only difference that the type name needs to be prefixed with the name of the containing type outside of the file were the inline component has been declared. Notably, inline components are not closures: In the following example, the output would be 42 // MyItem.qml Item { property int i: 33 component IC: Item { Component.onCompleted: console.log(i) } } // user.qml Item { property int i: 42 MyItem.IC {} } Fixes: QTBUG-79382 Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5 Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlengine.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/qml/qml/qqmlengine.cpp') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 3345fcb19e..07d5429423 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2383,12 +2383,23 @@ int QQmlEnginePrivate::listType(int t) const return QQmlMetaType::listType(t); } + +static QQmlPropertyCache *propertyCacheForPotentialInlineComponentType(int t, const QHash::const_iterator &iter) { + if (t != (*iter)->metaTypeId) { + // this is an inline component, and what we have in the iterator is currently the parent compilation unit + for (auto &&icDatum: (*iter)->inlineComponentData) + if (icDatum.typeIds.id == t) + return (*iter)->propertyCaches.at(icDatum.objectIndex); + } + return (*iter)->rootPropertyCache().data(); +} + QQmlMetaObject QQmlEnginePrivate::rawMetaObjectForType(int t) const { Locker locker(this); auto iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return QQmlMetaObject((*iter)->rootPropertyCache().data()); + return propertyCacheForPotentialInlineComponentType(t, iter); } else { QQmlType type = QQmlMetaType::qmlType(t); return QQmlMetaObject(type.baseMetaObject()); @@ -2400,7 +2411,7 @@ QQmlMetaObject QQmlEnginePrivate::metaObjectForType(int t) const Locker locker(this); auto iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return QQmlMetaObject((*iter)->rootPropertyCache().data()); + return propertyCacheForPotentialInlineComponentType(t, iter); } else { QQmlType type = QQmlMetaType::qmlType(t); return QQmlMetaObject(type.metaObject()); @@ -2412,7 +2423,7 @@ QQmlPropertyCache *QQmlEnginePrivate::propertyCacheForType(int t) Locker locker(this); auto iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return (*iter)->rootPropertyCache().data(); + return propertyCacheForPotentialInlineComponentType(t, iter); } else { QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); @@ -2425,7 +2436,7 @@ QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t, int minorVe Locker locker(this); auto iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return (*iter)->rootPropertyCache().data(); + return propertyCacheForPotentialInlineComponentType(t, iter); } else { QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); @@ -2445,6 +2456,9 @@ void QQmlEnginePrivate::registerInternalCompositeType(QV4::ExecutableCompilation // The QQmlCompiledData is not referenced here, but it is removed from this // hash in the QQmlCompiledData destructor m_compositeTypes.insert(compilationUnit->metaTypeId, compilationUnit); + for (auto &&data: compilationUnit->inlineComponentData) { + m_compositeTypes.insert(data.typeIds.id, compilationUnit); + } } void QQmlEnginePrivate::unregisterInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit) @@ -2453,6 +2467,14 @@ void QQmlEnginePrivate::unregisterInternalCompositeType(QV4::ExecutableCompilati Locker locker(this); m_compositeTypes.remove(compilationUnit->metaTypeId); + for (auto&& icDatum: compilationUnit->inlineComponentData) + m_compositeTypes.remove(icDatum.typeIds.id); +} + +QV4::ExecutableCompilationUnit *QQmlEnginePrivate::obtainExecutableCompilationUnit(int typeId) +{ + Locker locker(this); + return m_compositeTypes.value(typeId, nullptr); } template<> -- cgit v1.2.3