From 34b236e7fb3ea4f10221b7693f02df59f774e3f5 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Wed, 23 Nov 2022 16:18:50 +0200 Subject: [PATCH] QmlDesigner: Disable assigning a texture to a model with no materials Disable apply texture to selected model option from texture editor's toolbar when the selected model has no material. Also relevant fixes to make sure texture assigning happens in the current state. Fixes: QDS-8395 Change-Id: Iab2e8fce4696c6bd5d50636b4077362ba04cb8a0 Reviewed-by: Miikka Heikkinen --- .../TextureEditorToolBar.qml | 2 +- .../materialbrowser/materialbrowserview.cpp | 9 ++++----- .../materialbrowser/materialbrowserview.h | 2 +- .../textureeditor/textureeditorcontextobject.cpp | 12 ++++++------ .../textureeditor/textureeditorcontextobject.h | 11 ++++++----- .../textureeditor/textureeditorview.cpp | 16 +++++++++++++++- .../designercore/include/qmlobjectnode.h | 1 + .../designercore/model/qmlobjectnode.cpp | 15 ++++++++++----- 8 files changed, 44 insertions(+), 24 deletions(-) diff --git a/share/qtcreator/qmldesigner/textureEditorQmlSource/TextureEditorToolBar.qml b/share/qtcreator/qmldesigner/textureEditorQmlSource/TextureEditorToolBar.qml index ed40b038a72..e0f0e1324d3 100644 --- a/share/qtcreator/qmldesigner/textureEditorQmlSource/TextureEditorToolBar.qml +++ b/share/qtcreator/qmldesigner/textureEditorQmlSource/TextureEditorToolBar.qml @@ -28,7 +28,7 @@ Rectangle { normalColor: StudioTheme.Values.themeSectionHeadBackground iconSize: StudioTheme.Values.bigIconFontSize buttonSize: root.height - enabled: hasTexture && hasModelSelection && hasQuick3DImport && hasMaterialLibrary + enabled: hasTexture && hasSingleModelSelection && hasQuick3DImport && hasMaterialLibrary onClicked: root.toolBarAction(ToolBarAction.ApplyToSelected) tooltip: qsTr("Apply texture to selected model's material.") } diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp index 5599cd585f9..79fc5cb4b61 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp +++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp @@ -481,9 +481,9 @@ void MaterialBrowserView::instancePropertyChanged(const QList &completedNodeList) override; void instancePropertyChanged(const QList > &propertyList) override; - void applyTextureToModel3D(const ModelNode &model3D, const ModelNode &texture); + void applyTextureToModel3D(const QmlObjectNode &model3D, const ModelNode &texture); void applyTextureToMaterial(const QList &materials, const ModelNode &texture); Q_INVOKABLE void updatePropsModel(const QString &matId); diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp index 017661bfcfc..8ccd7b8fad7 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp @@ -145,18 +145,18 @@ void TextureEditorContextObject::setHasMaterialLibrary(bool b) emit hasMaterialLibraryChanged(); } -bool TextureEditorContextObject::hasModelSelection() const +bool TextureEditorContextObject::hasSingleModelSelection() const { - return m_hasModelSelection; + return m_hasSingleModelSelection; } -void TextureEditorContextObject::setHasModelSelection(bool b) +void TextureEditorContextObject::setHasSingleModelSelection(bool b) { - if (b == m_hasModelSelection) + if (b == m_hasSingleModelSelection) return; - m_hasModelSelection = b; - emit hasModelSelectionChanged(); + m_hasSingleModelSelection = b; + emit hasSingleModelSelectionChanged(); } void TextureEditorContextObject::setSelectedMaterial(const ModelNode &matNode) diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h index c2537589a95..2ad65821281 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.h @@ -36,7 +36,8 @@ class TextureEditorContextObject : public QObject Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged) Q_PROPERTY(bool hasActiveTimeline READ hasActiveTimeline NOTIFY hasActiveTimelineChanged) Q_PROPERTY(bool hasQuick3DImport READ hasQuick3DImport WRITE setHasQuick3DImport NOTIFY hasQuick3DImportChanged) - Q_PROPERTY(bool hasModelSelection READ hasModelSelection WRITE setHasModelSelection NOTIFY hasModelSelectionChanged) + Q_PROPERTY(bool hasSingleModelSelection READ hasSingleModelSelection WRITE setHasSingleModelSelection + NOTIFY hasSingleModelSelectionChanged) Q_PROPERTY(bool hasMaterialLibrary READ hasMaterialLibrary WRITE setHasMaterialLibrary NOTIFY hasMaterialLibraryChanged) Q_PROPERTY(QQmlPropertyMap *backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged) @@ -91,8 +92,8 @@ public: bool hasMaterialLibrary() const; void setHasMaterialLibrary(bool b); - bool hasModelSelection() const; - void setHasModelSelection(bool b); + bool hasSingleModelSelection() const; + void setHasSingleModelSelection(bool b); bool hasAliasExport() const { return m_aliasExport; } @@ -124,7 +125,7 @@ signals: void hasActiveTimelineChanged(); void hasQuick3DImportChanged(); void hasMaterialLibraryChanged(); - void hasModelSelectionChanged(); + void hasSingleModelSelectionChanged(); private: QUrl m_specificsUrl; @@ -148,7 +149,7 @@ private: bool m_hasActiveTimeline = false; bool m_hasQuick3DImport = false; bool m_hasMaterialLibrary = false; - bool m_hasModelSelection = false; + bool m_hasSingleModelSelection = false; ModelNode m_selectedTexture; }; diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp index a4cc362ffbc..37dd6c3ffa9 100644 --- a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp +++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp @@ -451,6 +451,8 @@ void TextureEditorView::setupQmlBackend() currentQmlBackend->contextObject()->setHasQuick3DImport(m_hasQuick3DImport); currentQmlBackend->contextObject()->setHasMaterialLibrary(materialLibraryNode().isValid()); currentQmlBackend->contextObject()->setSpecificQmlData(specificQmlData); + bool hasValidSelection = QmlObjectNode(m_selectedModel).hasBindingProperty("materials"); + currentQmlBackend->contextObject()->setHasSingleModelSelection(hasValidSelection); m_qmlBackEnd = currentQmlBackend; @@ -554,6 +556,11 @@ void TextureEditorView::propertiesRemoved(const QList &propert setValue(m_selectedTexture, property.name(), QmlObjectNode(m_selectedTexture).instanceValue(property.name())); } + if (property.name() == "materials" && (node == m_selectedModel + || QmlObjectNode(m_selectedModel).propertyChangeForCurrentState() == node)) { + m_qmlBackEnd->contextObject()->setHasSingleModelSelection(false); + } + dynamicPropertiesModel()->dispatchPropertyChanges(property); } } @@ -598,6 +605,12 @@ void TextureEditorView::bindingPropertiesChanged(const QList &p setValue(m_selectedTexture, property.name(), QmlObjectNode(m_selectedTexture).modelValue(property.name())); } + if (property.name() == "materials" && (node == m_selectedModel + || QmlObjectNode(m_selectedModel).propertyChangeForCurrentState() == node)) { + bool hasMaterials = QmlObjectNode(m_selectedModel).hasBindingProperty("materials"); + m_qmlBackEnd->contextObject()->setHasSingleModelSelection(hasMaterials); + } + dynamicPropertiesModel()->dispatchPropertyChanges(property); } } @@ -660,7 +673,8 @@ void TextureEditorView::selectedNodesChanged(const QList &selectedNod if (selectedNodeList.size() == 1 && selectedNodeList.at(0).metaInfo().isQtQuick3DModel()) m_selectedModel = selectedNodeList.at(0); - m_qmlBackEnd->contextObject()->setHasModelSelection(m_selectedModel.isValid()); + bool hasValidSelection = QmlObjectNode(m_selectedModel).hasBindingProperty("materials"); + m_qmlBackEnd->contextObject()->setHasSingleModelSelection(hasValidSelection); } void TextureEditorView::currentStateChanged(const ModelNode &node) diff --git a/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h b/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h index 5dd4d32ecaa..0d47b7e36bc 100644 --- a/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h +++ b/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h @@ -69,6 +69,7 @@ public: QVariant modelValue(const PropertyName &name) const; bool isTranslatableText(const PropertyName &name) const; QString stripedTranslatableText(const PropertyName &name) const; + BindingProperty bindingProperty(const PropertyName &name) const; QString expression(const PropertyName &name) const; bool isInBaseState() const; bool timelineIsActive() const; diff --git a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp index c2e6ce107dc..b64cf2612ee 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp @@ -256,23 +256,28 @@ QString QmlObjectNode::stripedTranslatableText(const PropertyName &name) const return instanceValue(name).toString(); } -QString QmlObjectNode::expression(const PropertyName &name) const +BindingProperty QmlObjectNode::bindingProperty(const PropertyName &name) const { if (!isValid()) return {}; if (currentState().isBaseState()) - return modelNode().bindingProperty(name).expression(); + return modelNode().bindingProperty(name); if (!currentState().hasPropertyChanges(modelNode())) - return modelNode().bindingProperty(name).expression(); + return modelNode().bindingProperty(name); QmlPropertyChanges propertyChanges(currentState().propertyChanges(modelNode())); if (!propertyChanges.modelNode().hasProperty(name)) - return modelNode().bindingProperty(name).expression(); + return modelNode().bindingProperty(name); - return propertyChanges.modelNode().bindingProperty(name).expression(); + return propertyChanges.modelNode().bindingProperty(name); +} + +QString QmlObjectNode::expression(const PropertyName &name) const +{ + return bindingProperty(name).expression(); } /*!