aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/platform/android/qandroidquickviewembedding.cpp
diff options
context:
space:
mode:
authorSoheil Armin <soheil.armin@qt.io>2024-05-05 18:13:35 +0300
committerSoheil Armin <soheil.armin@qt.io>2024-05-31 02:25:47 +0300
commita8007cc3de420d42a2a02a86cb05a205f6222f86 (patch)
tree697a5ad804c5b499c1362c3660749f288b872724 /src/quick/platform/android/qandroidquickviewembedding.cpp
parent3cdf282d93b71651d59391e98a8d1b173b7dcdd7 (diff)
Android: Add QtQmlComponent loading support to QtQuickView
A QQmlComponent component implementation, can deliver app library name, module name, and the path to QML component to be loaded. It also wraps set/get/connect methods of QtQuickView with protected access. We can generate QQmlComponent concrete classes for selected components at build time. Generated implementations, will have typed set/get/connect methods, associated with properties and signals of the QML component. Alternatively, it's possible for the user to subclass QQmlComponent. We add a new ctors to QtQuickView that takes only the Context. Later, The user should instantiate and pass the QQmlComponent to loadComponent(). QtQuickView gets required lib,module and component from the implementation and loads the QML component by an internal new QQuickView instance. If the there is already a QQuickView instance available, it will be reused. Task-number: QTBUG-124846 Change-Id: Ic29beb1b3faecd9f2e70621ddcc286a1a7659cb5 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/quick/platform/android/qandroidquickviewembedding.cpp')
-rw-r--r--src/quick/platform/android/qandroidquickviewembedding.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/quick/platform/android/qandroidquickviewembedding.cpp b/src/quick/platform/android/qandroidquickviewembedding.cpp
index bf68e4d345..e7932d80ae 100644
--- a/src/quick/platform/android/qandroidquickviewembedding.cpp
+++ b/src/quick/platform/android/qandroidquickviewembedding.cpp
@@ -27,8 +27,9 @@ namespace QtAndroidQuickViewEmbedding
{
constexpr const char *uninitializedViewMessage = "because QtQuickView is not loaded or ready yet.";
- void createQuickView(JNIEnv*, jobject nativeWindow, jstring qmlUri, jint width, jint height,
- jlong parentWindowReference, QtJniTypes::StringArray qmlImportPaths)
+ void createQuickView(JNIEnv *, jobject nativeWindow, jstring qmlUri, jint width, jint height,
+ jlong parentWindowReference, jlong viewReference,
+ QtJniTypes::StringArray qmlImportPaths)
{
static_assert (sizeof(jlong) >= sizeof(void*),
"Insufficient size of Java type to hold the c++ pointer");
@@ -44,29 +45,35 @@ namespace QtAndroidQuickViewEmbedding
QMetaObject::invokeMethod(qApp, [qtViewObject = QJniObject(nativeWindow),
parentWindowReference,
+ viewReference,
width,
height,
qmlUrl,
importPaths] {
- QWindow *parentWindow = reinterpret_cast<QWindow *>(parentWindowReference);
- QAndroidQuickView *view = new QAndroidQuickView(parentWindow);
- QQmlEngine *engine = view->engine();
- QObject::connect(view, &QAndroidQuickView::statusChanged,
- [qtViewObject](QAndroidQuickView::Status status) {
- qtViewObject.callMethod<void>("handleStatusChange", status);
- });
- view->setResizeMode(QAndroidQuickView::SizeRootObjectToView);
- view->setColor(QColor(Qt::transparent));
- view->setWidth(width);
- view->setHeight(height);
- for (const QString &path : importPaths)
- engine->addImportPath(path);
-
- const QtJniTypes::QtWindow window = reinterpret_cast<jobject>(view->winId());
- qtViewObject.callMethod<void>("addQtWindow",
- window,
- reinterpret_cast<jlong>(view),
- parentWindowReference);
+ // If the view does not exists (viewReference==0) we should create and set it up.
+ // Else we only reset the source of the view.
+ QAndroidQuickView *view = reinterpret_cast<QAndroidQuickView *>(viewReference);
+ if (!view) {
+ QWindow *parentWindow = reinterpret_cast<QWindow *>(parentWindowReference);
+ view = new QAndroidQuickView(parentWindow);
+ QObject::connect(view, &QAndroidQuickView::statusChanged, view,
+ [qtViewObject](QAndroidQuickView::Status status) {
+ qtViewObject.callMethod<void>("handleStatusChange", status);
+ });
+ view->setResizeMode(QAndroidQuickView::SizeRootObjectToView);
+ view->setColor(QColor(Qt::transparent));
+ view->setWidth(width);
+ view->setHeight(height);
+ QQmlEngine *engine = view->engine();
+ for (const QString &path : importPaths)
+ engine->addImportPath(path);
+
+ const QtJniTypes::QtWindow window = reinterpret_cast<jobject>(view->winId());
+ qtViewObject.callMethod<void>("addQtWindow",
+ window,
+ reinterpret_cast<jlong>(view),
+ parentWindowReference);
+ }
view->setSource(qmlUrl);
});
}