From 72e4287ac34b86bf5dbda5b162eef4c8e2f64e3d Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 14 Mar 2022 16:07:47 +0200 Subject: [PATCH] QmlDesigner: Fix navigator preview of Models Now we resolve absolute source url for our preview model, so it will always find the custom mesh files. Also always use the Node type preview if the instance is a component, even if the root node is Model. This ensures the preview works properly in case there are child nodes inside the component. Fixes: QDS-6204 Change-Id: I48ef273e5a5dca13abe25816b5edf0be7dd217ff Reviewed-by: Reviewed-by: Mahmoud Badri Reviewed-by: Thomas Hartmann --- .../qmlpuppet/mockfiles/qt6/ModelNodeView.qml | 4 ++-- .../qml2puppet/editor3d/generalhelper.cpp | 21 +++++++++++++++++++ .../qml2puppet/editor3d/generalhelper.h | 2 ++ .../qt5informationnodeinstanceserver.cpp | 12 ++++++++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/ModelNodeView.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/ModelNodeView.qml index d6574f660ca..19b3c4c35d7 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/ModelNodeView.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/qt6/ModelNodeView.qml @@ -37,7 +37,7 @@ View3D { function fitToViewPort() { // The magic number is the distance from camera default pos to origin - _generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, importScene, root, + _generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, sourceModel, root, 1040); } @@ -65,7 +65,7 @@ View3D { Model { id: model - source: sourceModel.source + source: _generalHelper.resolveAbsoluteSourceUrl(sourceModel) geometry: sourceModel.geometry materials: [ diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp index 66cd2d80b8e..dcd0a98549b 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +94,26 @@ QString GeneralHelper::generateUniqueName(const QString &nameRoot) return QStringLiteral("%1_%2").arg(nameRoot).arg(count); } +// Resolves absolute model source path +QUrl GeneralHelper::resolveAbsoluteSourceUrl(const QQuick3DModel *sourceModel) +{ + if (!sourceModel) + return {}; + + const QUrl source = sourceModel->source(); + if (source.hasFragment()) { + // Fragment is part of the url separated by '#', check if it is an index or primitive + bool isNumber = false; + source.fragment().toInt(&isNumber); + // If it wasn't an index, then it was a primitive and we can return it as-is + if (!isNumber) + return source; + } + + const QQmlContext *context = qmlContext(sourceModel); + return context ? context->resolvedUrl(source) : source; +} + void GeneralHelper::orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation, const QVector3D &lookAtPoint, const QVector3D &pressPos, const QVector3D ¤tPos) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h index ac67172ab32..562848c7720 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ public: Q_INVOKABLE void requestOverlayUpdate(); Q_INVOKABLE QString generateUniqueName(const QString &nameRoot); + Q_INVOKABLE QUrl resolveAbsoluteSourceUrl(const QQuick3DModel *sourceModel); Q_INVOKABLE void orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation, const QVector3D &lookAtPoint, const QVector3D &pressPos, diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 9656e0e5e89..0d6c069faec 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -1091,9 +1091,15 @@ void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView() m_modelNode3DImageViewData.window->resize(renderSize); m_modelNode3DImageViewData.rootItem->setSize(renderSize); - QMetaObject::invokeMethod( - m_modelNode3DImageViewData.rootItem, "createViewForObject", - Q_ARG(QVariant, objectToVariant(instanceObj))); + if (createdFromComponent) { + QMetaObject::invokeMethod( + m_modelNode3DImageViewData.rootItem, "createViewForNode", + Q_ARG(QVariant, objectToVariant(instanceObj))); + } else { + QMetaObject::invokeMethod( + m_modelNode3DImageViewData.rootItem, "createViewForObject", + Q_ARG(QVariant, objectToVariant(instanceObj))); + } // Need to render twice, first render updates spatial nodes for (int i = 0; i < 2; ++i) {