From cbf71616a56a099d9f1c8d60313e0806b7a008d6 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 21 Feb 2025 12:59:46 +0200 Subject: [PATCH] QmlDesigner: Add "Edit Component" functionality to imported 3d assets Doubleclicking .q3d file in assets view will trigger edit component on the imported 3d component represented by that file. Context menu for .q3d files now also has "Edit Component" option that does the same. Fixes: QDS-14789 Change-Id: I97a041f5bfe521058c03ee717479b2752bc45ff0 Reviewed-by: Mahmoud Badri --- .../assetsLibraryQmlSources/AssetDelegate.qml | 9 +++++++-- .../assetsLibraryQmlSources/AssetsContextMenu.qml | 11 ++++++++++- .../components/assetslibrary/assetslibrarywidget.cpp | 8 ++++++++ .../components/assetslibrary/assetslibrarywidget.h | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetDelegate.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetDelegate.qml index 621841e864a..ffa12e8781f 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetDelegate.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetDelegate.qml @@ -24,6 +24,7 @@ T.TreeViewDelegate { readonly property string suffix: model.fileName.substr(-4) readonly property bool isFont: root.suffix === ".ttf" || root.suffix === ".otf" readonly property bool isEffect: root.suffix === ".qep" + readonly property bool isImported3d: root.suffix === ".q3d" property bool currFileSelected: false property int initialDepth: -1 property bool __isDirectory: assetsModel.isDirectory(model.filePath) @@ -213,8 +214,12 @@ T.TreeViewDelegate { mouseArea.forceActiveFocus() mouseArea.allowTooltip = false AssetsLibraryBackend.tooltipBackend.hideTooltip() - if (mouse.button === Qt.LeftButton && root.isEffect) - AssetsLibraryBackend.rootView.openEffectComposer(filePath) + if (mouse.button === Qt.LeftButton) { + if (root.isEffect) + AssetsLibraryBackend.rootView.openEffectComposer(filePath) + else if (root.isImported3d) + AssetsLibraryBackend.rootView.editAssetComponent(filePath) + } } StudioControls.ToolTip { diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml index 69791aa4952..cc4b0c17fce 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml @@ -129,7 +129,16 @@ StudioControls.Menu { && root.assetsModel.allFilePathsAreComposedEffects(root.__selectedAssetPathsList) && root.rootView.canCreateEffects height: editInEffectComposerItem.visible ? editInEffectComposerItem.implicitHeight : 0 - onTriggered: AssetsLibraryBackend.rootView.openEffectComposer(root.__selectedAssetPathsList[0]) + onTriggered: root.rootView.openEffectComposer(root.__selectedAssetPathsList[0]) + } + + StudioControls.MenuItem { + id: editComponent + text: qsTr("Edit Component") + visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1 + && root.rootView.assetIsImported3d(root.__selectedAssetPathsList[0]) + height: editComponent.visible ? editComponent.implicitHeight : 0 + onTriggered: root.rootView.editAssetComponent(root.__selectedAssetPathsList[0]) } StudioControls.MenuItem { diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp index 817b311b8b3..2191b1c981d 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp @@ -609,6 +609,14 @@ void AssetsLibraryWidget::openEffectComposer(const QString &filePath) ModelNodeOperations::openEffectComposer(filePath); } +void AssetsLibraryWidget::editAssetComponent(const QString &filePath) +{ + Utils::FilePath fullPath = QmlDesignerPlugin::instance()->documentManager() + .generatedComponentUtils().getImported3dQml(filePath); + if (fullPath.exists()) + DocumentManager::goIntoComponent(fullPath.toFSPathString()); +} + QString AssetsLibraryWidget::qmlSourcesPath() { #ifdef SHARE_QML_PATH diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h index c3a2e188f22..29952579af6 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.h @@ -84,6 +84,7 @@ public: const QString &targetDirPath = {}); Q_INVOKABLE QSet supportedAssetSuffixes(bool complex); Q_INVOKABLE void openEffectComposer(const QString &filePath); + Q_INVOKABLE void editAssetComponent(const QString &filePath); Q_INVOKABLE int qtVersion() const; Q_INVOKABLE void invalidateThumbnail(const QString &id); Q_INVOKABLE QSize imageSize(const QString &id);