From 6e6fc518adf0d4da2d5bbe0deaa558c192c85a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 21 May 2019 12:38:46 +0300 Subject: QML Engine patch Change-Id: I0c34762c5de069165035bf9dacbe0d1a7ec33035 Reviewed-by: Miikka Heikkinen --- src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.cpp | 14 ++++++++++++++ src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.h | 1 + src/Runtime/api/studio3d/q3dssurfaceviewer.cpp | 15 +++++++++++++++ src/Runtime/api/studio3d/q3dssurfaceviewer.h | 4 ++++ src/Runtime/api/studio3d/q3dssurfaceviewer_p.h | 2 ++ 5 files changed, 36 insertions(+) diff --git a/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.cpp b/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.cpp index caa633ac..9b8550cf 100644 --- a/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.cpp +++ b/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.cpp @@ -237,3 +237,17 @@ void Q3DSQmlStreamProxy::setPath(const QString& path) QString modPath = QFileInfo(path).path(); // path() strips filename out m_path = pathToUrl(modPath); } + +void Q3DSQmlStreamProxy::setEngine(QQmlEngine *engine) +{ + if (m_engine) + delete m_engine; + + m_engine = engine; + + // Add extra import path for binary installations + QString extraImportPath(QStringLiteral("%1/qml")); + m_engine->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath())); + + m_engine->setIncubationController(new Q3DSIncubationController(this)); +} diff --git a/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.h b/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.h index daba821b..85a1cc6d 100644 --- a/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.h +++ b/src/QtExtras/qmlstreamer/q3dsqmlstreamproxy.h @@ -52,6 +52,7 @@ public: void unregisterPresentation(const QString &presentationId); void setSettings(Q3DSSubPresentationSettings *settings); void setPath(const QString& path); + void setEngine(QQmlEngine *engine); private: void loadPresentationItem(const QString& presentationId, const QString& presentationArgs); diff --git a/src/Runtime/api/studio3d/q3dssurfaceviewer.cpp b/src/Runtime/api/studio3d/q3dssurfaceviewer.cpp index fc90e341..7fe2bfa9 100644 --- a/src/Runtime/api/studio3d/q3dssurfaceviewer.cpp +++ b/src/Runtime/api/studio3d/q3dssurfaceviewer.cpp @@ -341,6 +341,18 @@ QImage Q3DSSurfaceViewerPrivate::grab(const QRect &rect) return image; } +QQmlEngine *Q3DSSurfaceViewer::qmlEngine() const +{ + Q_D(const Q3DSSurfaceViewer); + return d->qmlEngine; +} + +void Q3DSSurfaceViewer::setQmlEngine(QQmlEngine *qmlEngine) +{ + Q_D(Q3DSSurfaceViewer); + d->qmlEngine = qmlEngine; +} + bool Q3DSSurfaceViewerPrivate::eventFilter(QObject *obj, QEvent *e) { if (m_surface && e->type() == QEvent::PlatformSurface) { @@ -371,6 +383,9 @@ bool Q3DSSurfaceViewerPrivate::initializeRuntime() if (m_autoSize) m_size = m_surface->size(); + if (nullptr != qmlEngine) + m_presentation->d_ptr->streamProxy()->setEngine(qmlEngine); + if (!m_viewerApp->InitializeApp(int(m_size.width() * m_pixelRatio), int(m_size.height() * m_pixelRatio), m_context->format(), m_fboId, localSource, diff --git a/src/Runtime/api/studio3d/q3dssurfaceviewer.h b/src/Runtime/api/studio3d/q3dssurfaceviewer.h index 90d25aa1..7ac6bda2 100644 --- a/src/Runtime/api/studio3d/q3dssurfaceviewer.h +++ b/src/Runtime/api/studio3d/q3dssurfaceviewer.h @@ -44,6 +44,7 @@ class QSurface; class QOpenGLContext; class Q3DSViewerSettings; class Q3DSPresentation; +class QQmlEngine; class Q_STUDIO3D_EXPORT Q3DSSurfaceViewer : public QObject { @@ -63,6 +64,9 @@ public: QImage grab(const QRect &rect = QRect()); + QQmlEngine *qmlEngine() const; + void setQmlEngine(QQmlEngine *qmlEngine); + // Property accessors QSize size() const; bool autoSize() const; diff --git a/src/Runtime/api/studio3d/q3dssurfaceviewer_p.h b/src/Runtime/api/studio3d/q3dssurfaceviewer_p.h index 9c56c1b5..656d139c 100644 --- a/src/Runtime/api/studio3d/q3dssurfaceviewer_p.h +++ b/src/Runtime/api/studio3d/q3dssurfaceviewer_p.h @@ -52,6 +52,7 @@ class QSurface; class QOpenGLContext; class Q3DSViewerSettings; class Q3DSPresentation; +class QQmlEngine; class Q_STUDIO3D_EXPORT Q3DSSurfaceViewerPrivate : public QObject { @@ -96,6 +97,7 @@ private: Q3DSPresentation *m_presentation; QString m_id; QElapsedTimer m_startupTimer; + QQmlEngine *qmlEngine = nullptr; }; QT_END_NAMESPACE -- cgit v1.2.3