aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2022-03-14 16:07:47 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2022-03-15 10:45:24 +0000
commit72e4287ac34b86bf5dbda5b162eef4c8e2f64e3d (patch)
treedb8e2e15ba226224c167ea998bef042b138618f5 /share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d
parent82534fc979a7710e460815de87a7f21becd05f05 (diff)
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: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp21
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
index 66cd2d80b8..dcd0a98549 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
@@ -42,6 +42,7 @@
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
#include <QtQuick3DUtils/private/qssgutils_p.h>
+#include <QtQml/qqml.h>
#include <QtQuick/qquickwindow.h>
#include <QtQuick/qquickitem.h>
#include <QtCore/qmath.h>
@@ -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 &currentPos)
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
index ac67172ab3..562848c772 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
@@ -33,6 +33,7 @@
#include <QPointer>
#include <QQuaternion>
#include <QTimer>
+#include <QUrl>
#include <QVariant>
#include <QVector3D>
#include <QtQuick3D/private/qquick3dpickresult_p.h>
@@ -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,