From 41f96fe05b176544606b0a4097a050cffdd70548 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 18 Oct 2021 16:14:28 +0300 Subject: [PATCH] QmlDesigner: Reset puppet on repeater model change when necessary This is a workaround for Qt bugs QTBUG-97583 and QTBUG-97586. Fixes: QDS-5235 Change-Id: I37de4829fea63b0c488815975ae2dd58ceb36b71 Reviewed-by: Qt CI Bot Reviewed-by: Thomas Hartmann Reviewed-by: Mahmoud Badri Reviewed-by: Samuel Ghinet --- .../designercore/include/nodeinstanceview.h | 2 + .../instances/nodeinstanceview.cpp | 40 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h index f237bcf0d41..0bb481d22ce 100644 --- a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h @@ -225,6 +225,8 @@ private: // functions void updateWatcher(const QString &path); void updateRotationBlocks(); + void maybeResetOnPropertyChange(const PropertyName &name, const ModelNode &node, + PropertyChangeFlags flags); private: QHash m_imageDataMap; diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index 078a74a534d..3032ac12d94 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -473,8 +473,9 @@ void NodeInstanceView::propertiesAboutToBeRemoved(const QList& resetVerticalAnchors(property.parentModelNode()); } else if (name == "anchors.baseline") { resetVerticalAnchors(property.parentModelNode()); - } else if (name == "shader" && property.parentModelNode().isSubclassOf("QtQuick3D.Shader")) { - m_resetTimer.start(); + } else { + maybeResetOnPropertyChange(name, property.parentModelNode(), + AbstractView::EmptyPropertiesRemoved); } } @@ -503,10 +504,14 @@ void NodeInstanceView::nodeTypeChanged(const ModelNode &, const TypeName &, int, restartProcess(); } -void NodeInstanceView::bindingPropertiesChanged(const QList& propertyList, PropertyChangeFlags /*propertyChange*/) +void NodeInstanceView::bindingPropertiesChanged(const QList& propertyList, + PropertyChangeFlags propertyChange) { QTC_ASSERT(m_nodeInstanceServer, return); m_nodeInstanceServer->changePropertyBindings(createChangeBindingCommand(propertyList)); + + for (const auto &property : propertyList) + maybeResetOnPropertyChange(property.name(), property.parentModelNode(), propertyChange); } /*! @@ -518,18 +523,15 @@ void NodeInstanceView::bindingPropertiesChanged(const QList& pr \sa AbstractProperty, NodeInstance, ModelNode */ -void NodeInstanceView::variantPropertiesChanged(const QList& propertyList, PropertyChangeFlags /*propertyChange*/) +void NodeInstanceView::variantPropertiesChanged(const QList& propertyList, + PropertyChangeFlags propertyChange) { QTC_ASSERT(m_nodeInstanceServer, return); updatePosition(propertyList); m_nodeInstanceServer->changePropertyValues(createChangeValueCommand(propertyList)); - for (const auto &property : propertyList) { - if (property.name() == "shader" && property.parentModelNode().isSubclassOf("QtQuick3D.Shader")) { - m_resetTimer.start(); - break; - } - } + for (const auto &property : propertyList) + maybeResetOnPropertyChange(property.name(), property.parentModelNode(), propertyChange); } /*! Notifies the view that the property parent of the model node \a node has @@ -1908,4 +1910,22 @@ void NodeInstanceView::updateRotationBlocks() } } +void NodeInstanceView::maybeResetOnPropertyChange(const PropertyName &name, const ModelNode &node, + PropertyChangeFlags flags) +{ + bool reset = false; + if (flags & AbstractView::PropertiesAdded + && name == "model" && (node.isSubclassOf("QtQuick.Repeater") + || node.isSubclassOf("QtQuick3D.Repeater3D"))) { + // TODO: This is a workaround for QTBUG-97583 (2D) and QTBUG-97586 (3D): + // Reset puppet when repeater model is first added, if there is already a delegate + if (node.hasProperty("delegate")) + reset = true; + } else if (name == "shader" && node.isSubclassOf("QtQuick3D.Shader")) { + reset = true; + } + if (reset) + resetPuppet(); +} + }