From ce97e5ccca8c31a75c234ee477039d088be225e9 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 15 Sep 2022 15:28:48 +0200 Subject: [PATCH] QmlDesigner: Remove mcu dependency from model The function is only called in the formeditor. So moving it to the formeditor removes the dependency to the mcu manager. Change-Id: I1a1d6f65b97340206ea0d485b24046c3661daf92 Reviewed-by: Qt CI Bot Reviewed-by: Aleksei German --- .../formeditor/rotationindicator.cpp | 61 ++++++++++++++++--- .../designercore/include/qmlitemnode.h | 1 - .../designercore/model/qmlitemnode.cpp | 35 ----------- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/plugins/qmldesigner/components/formeditor/rotationindicator.cpp b/src/plugins/qmldesigner/components/formeditor/rotationindicator.cpp index a4e72183ff5..c89d166d398 100644 --- a/src/plugins/qmldesigner/components/formeditor/rotationindicator.cpp +++ b/src/plugins/qmldesigner/components/formeditor/rotationindicator.cpp @@ -5,6 +5,10 @@ #include "formeditoritem.h" +#include +#include +#include + namespace QmlDesigner { RotationIndicator::RotationIndicator(LayerItem *layerItem) @@ -34,17 +38,58 @@ void RotationIndicator::clear() { m_itemControllerHash.clear(); } +namespace { -static bool itemIsRotatable(const QmlItemNode &qmlItemNode) +bool itemIsResizable(const ModelNode &modelNode) { - return qmlItemNode.isValid() - && qmlItemNode.instanceIsResizable() - && qmlItemNode.modelIsMovable() - && qmlItemNode.modelIsRotatable() - && !qmlItemNode.instanceIsInLayoutable() - && !qmlItemNode.isFlowItem(); + if (modelNode.metaInfo().isQtQuickControlsTab()) + return false; + + return NodeHints::fromModelNode(modelNode).isResizable(); } +bool isMcuRotationAllowed([[maybe_unused]] QString itemName, [[maybe_unused]] bool hasChildren) +{ + const QString propName = "rotation"; + const DesignerMcuManager &manager = DesignerMcuManager::instance(); + if (manager.isMCUProject()) { + if (manager.allowedItemProperties().contains(itemName)) { + const DesignerMcuManager::ItemProperties properties = manager.allowedItemProperties().value( + itemName); + if (properties.properties.contains(propName)) { + if (hasChildren) + return properties.allowChildren; + return true; + } + } + + if (manager.bannedItems().contains(itemName)) + return false; + + if (manager.bannedProperties().contains(propName)) + return false; + } + + return true; +} + +bool modelIsRotatable(const QmlItemNode &itemNode) +{ + auto modelNode = itemNode.modelNode(); + return !modelNode.hasBindingProperty("rotation") && itemIsResizable(modelNode) + && !itemNode.modelIsInLayout() + && isMcuRotationAllowed(QString::fromUtf8(modelNode.type()), itemNode.hasChildren()); +} + +bool itemIsRotatable(const QmlItemNode &qmlItemNode) +{ + return qmlItemNode.isValid() && qmlItemNode.instanceIsResizable() + && qmlItemNode.modelIsMovable() && modelIsRotatable(qmlItemNode) + && !qmlItemNode.instanceIsInLayoutable() && !qmlItemNode.isFlowItem(); +} + +} // namespace + void RotationIndicator::setItems(const QList &itemList) { clear(); @@ -74,4 +119,4 @@ void RotationIndicator::updateItems(const QList &itemList) } } -} +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h index e11d8e0c594..fce9787f92f 100644 --- a/src/plugins/qmldesigner/designercore/include/qmlitemnode.h +++ b/src/plugins/qmldesigner/designercore/include/qmlitemnode.h @@ -82,7 +82,6 @@ public: bool modelIsMovable() const; bool modelIsResizable() const; - bool modelIsRotatable() const; bool modelIsInLayout() const; bool hasFormEditorItem() const; diff --git a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp index 5fe2d969e4f..e3770a3c42e 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp @@ -325,41 +325,6 @@ bool QmlItemNode::modelIsResizable() const && !modelIsInLayout(); } -static bool isMcuRotationAllowed([[maybe_unused]] QString itemName, [[maybe_unused]] bool hasChildren) -{ -#ifndef QMLDESIGNER_TEST - const QString propName = "rotation"; - const DesignerMcuManager &manager = DesignerMcuManager::instance(); - if (manager.isMCUProject()) { - if (manager.allowedItemProperties().contains(itemName)) { - const DesignerMcuManager::ItemProperties properties = - manager.allowedItemProperties().value(itemName); - if (properties.properties.contains(propName)) { - if (hasChildren) - return properties.allowChildren; - return true; - } - } - - if (manager.bannedItems().contains(itemName)) - return false; - - if (manager.bannedProperties().contains(propName)) - return false; - } -#endif - - return true; -} - -bool QmlItemNode::modelIsRotatable() const -{ - return !modelNode().hasBindingProperty("rotation") - && itemIsResizable(modelNode()) - && !modelIsInLayout() - && isMcuRotationAllowed(QString::fromUtf8(modelNode().type()), hasChildren()); -} - bool QmlItemNode::modelIsInLayout() const { if (modelNode().hasParentProperty()) {