QmlDesigner: Add "Edit Material" context menu option for material nodes

Fixes: QDS-12372
Change-Id: Ie412216514973aa6d108f3595489f92e13497576
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-04-23 17:31:24 +03:00
parent fb4e1c5a8e
commit 99e04056f1
3 changed files with 21 additions and 14 deletions

View File

@@ -1988,8 +1988,8 @@ void DesignerActionManager::createDefaultDesignerActions()
QKeySequence(), QKeySequence(),
44, 44,
&editMaterial, &editMaterial,
&modelHasMaterial, &hasEditableMaterial,
&isModel)); &isModelOrMaterial));
addDesignerAction(new ModelNodeContextMenuAction( addDesignerAction(new ModelNodeContextMenuAction(
mergeTemplateCommandId, mergeTemplateCommandId,

View File

@@ -64,16 +64,19 @@ inline bool addMouseAreaFillCheck(const SelectionContext &selectionContext)
return false; return false;
} }
inline bool isModel(const SelectionContext &selectionState) inline bool isModelOrMaterial(const SelectionContext &selectionState)
{ {
ModelNode node = selectionState.currentSingleSelectedNode(); ModelNode node = selectionState.currentSingleSelectedNode();
return node.metaInfo().isQtQuick3DModel(); return node.metaInfo().isQtQuick3DModel() || node.metaInfo().isQtQuick3DMaterial();
} }
inline bool modelHasMaterial(const SelectionContext &selectionState) inline bool hasEditableMaterial(const SelectionContext &selectionState)
{ {
ModelNode node = selectionState.currentSingleSelectedNode(); ModelNode node = selectionState.currentSingleSelectedNode();
if (node.metaInfo().isQtQuick3DMaterial())
return true;
BindingProperty prop = node.bindingProperty("materials"); BindingProperty prop = node.bindingProperty("materials");
return prop.exists() && (!prop.expression().isEmpty() || !prop.resolveToModelNodeList().empty()); return prop.exists() && (!prop.expression().isEmpty() || !prop.resolveToModelNodeList().empty());

View File

@@ -817,21 +817,25 @@ void editMaterial(const SelectionContext &selectionContext)
QTC_ASSERT(modelNode.isValid(), return); QTC_ASSERT(modelNode.isValid(), return);
BindingProperty prop = modelNode.bindingProperty("materials");
if (!prop.exists())
return;
AbstractView *view = selectionContext.view(); AbstractView *view = selectionContext.view();
ModelNode material; ModelNode material;
if (view->hasId(prop.expression())) { if (modelNode.metaInfo().isQtQuick3DMaterial()) {
material = view->modelNodeForId(prop.expression()); material = modelNode;
} else { } else {
QList<ModelNode> materials = prop.resolveToModelNodeList(); BindingProperty prop = modelNode.bindingProperty("materials");
if (!prop.exists())
return;
if (materials.size() > 0) if (view->hasId(prop.expression())) {
material = materials.first(); material = view->modelNodeForId(prop.expression());
} else {
QList<ModelNode> materials = prop.resolveToModelNodeList();
if (materials.size() > 0)
material = materials.first();
}
} }
if (material.isValid()) { if (material.isValid()) {