From 65ca1301dea113e58b7894318b62ad5afe9d401d Mon Sep 17 00:00:00 2001 From: Aleksei German Date: Wed, 7 Oct 2020 17:39:29 +0200 Subject: [PATCH] QmlDesigner: MCU Metadata improvements - Introduced allowChildren switch Task: QDS-2794 Change-Id: Ie992fb173e8eacb27b10679d5ff28238277aa346 Reviewed-by: Thomas Hartmann --- share/qtcreator/qmldesigner/qt4mcu/qul-14.qml | 2 ++ .../propertyeditor/propertyeditorvalue.cpp | 15 ++++++++++++--- src/plugins/qmldesigner/designermcumanager.cpp | 13 ++++++++++--- src/plugins/qmldesigner/designermcumanager.h | 9 +++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qmldesigner/qt4mcu/qul-14.qml b/share/qtcreator/qmldesigner/qt4mcu/qul-14.qml index f01f3b53ced..8b9ffed3b88 100644 --- a/share/qtcreator/qmldesigner/qt4mcu/qul-14.qml +++ b/share/qtcreator/qmldesigner/qt4mcu/qul-14.qml @@ -98,12 +98,14 @@ VersionData { } QtQuick.Image { + allowChildren: false allowedProperties: ["rotation", "scale", "transformOrigin"] bannedProperties: ["mirror", "mipmap", "cache", "autoTransform", "asynchronous", "sourceSize", "smooth"] } QtQuick.Text { + allowChildren: false allowedProperties: ["rotation", "scale", "transformOrigin"] bannedProperties: ["elide", "lineHeight", "lineHeightMode", "wrapMode", "style", "styleColor", "minimumPointSize", "minimumPixelSize", "styleColor", diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp index 7c0b75c4e80..dd507df5ea7 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -292,9 +293,17 @@ bool PropertyEditorValue::isAvailable() const //allowed item properties: const auto itemTypes = mcuAllowedItemProperties.keys(); for (const auto &itemType : itemTypes) { - if (isAllowedSubclassType(itemType, m_modelNode.metaInfo()) - && mcuAllowedItemProperties.value(itemType).contains(pureNameStr)) { - return true; + if (isAllowedSubclassType(itemType, m_modelNode.metaInfo())) { + const QmlDesigner::DesignerMcuManager::ItemProperties allowedItemProps = + mcuAllowedItemProperties.value(itemType); + if (allowedItemProps.properties.contains(pureNameStr)) { + if (QmlDesigner::QmlItemNode::isValidQmlItemNode(m_modelNode)) { + const bool itemHasChildren = QmlDesigner::QmlItemNode(m_modelNode).hasChildren(); + + if (allowedItemProps.allowChildren == itemHasChildren) + return true; + } + } } } diff --git a/src/plugins/qmldesigner/designermcumanager.cpp b/src/plugins/qmldesigner/designermcumanager.cpp index dccdd140840..d173ab6766c 100644 --- a/src/plugins/qmldesigner/designermcumanager.cpp +++ b/src/plugins/qmldesigner/designermcumanager.cpp @@ -170,9 +170,16 @@ void DesignerMcuManager::readVersionData(const DesignerMcuManager::Version &vers //handling allowed properties: if (child->propertyNames().contains("allowedProperties")) { - const QStringList allowedProperties(readPropertyList("allowedProperties", child)); + ItemProperties allowedProperties; - if (!allowedProperties.isEmpty()) + const QVariant childrenPropertyVar = child->property("allowChildren"); + + if (!childrenPropertyVar.isNull() && childrenPropertyVar.isValid()) + allowedProperties.allowChildren = childrenPropertyVar.toBool(); + + allowedProperties.properties = readPropertyList("allowedProperties", child); + + if (!allowedProperties.properties.isEmpty()) m_allowedItemProperties.insert(child->name(), allowedProperties); } @@ -235,7 +242,7 @@ QStringList DesignerMcuManager::bannedImports() const return m_bannedImports; } -QHash DesignerMcuManager::allowedItemProperties() const +QHash DesignerMcuManager::allowedItemProperties() const { return m_allowedItemProperties; } diff --git a/src/plugins/qmldesigner/designermcumanager.h b/src/plugins/qmldesigner/designermcumanager.h index 63b5e54ff87..74f578afae2 100644 --- a/src/plugins/qmldesigner/designermcumanager.h +++ b/src/plugins/qmldesigner/designermcumanager.h @@ -43,6 +43,11 @@ public: }; using VersionsList = QList; + struct ItemProperties { + QStringList properties; + bool allowChildren = true; + }; + static DesignerMcuManager& instance(); static QString mcuResourcesPath(); @@ -62,7 +67,7 @@ public: QStringList allowedImports() const; QStringList bannedImports() const; - QHash allowedItemProperties() const; + QHash allowedItemProperties() const; QHash bannedComplexProperties() const; DesignerMcuManager(DesignerMcuManager const&) = delete; @@ -80,7 +85,7 @@ private: QSet m_bannedProperties; QStringList m_allowedImports; QStringList m_bannedImports; - QHash m_allowedItemProperties; + QHash m_allowedItemProperties; QHash m_bannedComplexProperties; DesignerMcuManager::VersionsList m_versionsList;