QmlDesigner: Fix adding material to user assets

Use material index as parameter like other similar functions, as it
doesn't rely on being able to interpret QQmlDMAbstractItemModelData as
ModelNode, which doesn't appear to work anymore with project
storage builds.

Also fix typo in a related warning.

Fixes: QDS-14993
Change-Id: I41c9895352272c7134c2e00888558a66676f8f83
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2025-03-20 12:21:16 +02:00
parent faf44a6498
commit f75666a7e3
4 changed files with 8 additions and 5 deletions

View File

@@ -138,8 +138,9 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Add to Content Library")
enabled: root.targetMaterial
onTriggered: MaterialBrowserBackend.rootView.addMaterialToContentLibrary(root.targetMaterial)
onTriggered: MaterialBrowserBackend.rootView.addMaterialToContentLibrary(root.targetIndex)
}
StudioControls.MenuItem {

View File

@@ -720,7 +720,7 @@ void ContentLibraryView::addLibItem(const ModelNode &node, const QPixmap &iconPi
bundlePath = Utils::FilePath::fromString(Paths::bundlesPathSetting() + "/User/3d/");
m_bundleId = compUtils.user3DBundleId();
} else {
qWarning() << __FUNCTION__ << "Unsuppported node type";
qWarning() << __FUNCTION__ << "Unsupported node type";
return;
}

View File

@@ -371,10 +371,12 @@ void MaterialBrowserWidget::focusMaterialSection(bool focusMatSec)
}
}
void MaterialBrowserWidget::addMaterialToContentLibrary(const QVariant &material)
void MaterialBrowserWidget::addMaterialToContentLibrary(int idx)
{
ModelNode mat = m_materialBrowserModel->materialAt(idx);
QTC_ASSERT(mat, return);
QmlDesignerPlugin::instance()->mainWidget()->showDockWidget("ContentLibrary");
ModelNode mat = material.value<ModelNode>();
m_materialBrowserView->emitCustomNotification("add_material_to_content_lib", {mat},
{m_previewImageProvider->getPixmap(mat)}); // to ContentLibrary
}

View File

@@ -63,7 +63,7 @@ public:
Q_INVOKABLE void acceptAssetsDropOnMaterial(int matIndex, const QList<QUrl> &urls);
Q_INVOKABLE void acceptTextureDropOnMaterial(int matIndex, const QString &texId);
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
Q_INVOKABLE void addMaterialToContentLibrary(const QVariant &material);
Q_INVOKABLE void addMaterialToContentLibrary(int idx);
Q_INVOKABLE void importMaterial();
Q_INVOKABLE void exportMaterial(int idx);
Q_INVOKABLE void addQtQuick3D();