QmlDesigner: MCU Metadata improvements

- Introduced allowChildren switch

Task: QDS-2794

Change-Id: Ie992fb173e8eacb27b10679d5ff28238277aa346
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Aleksei German
2020-10-07 17:39:29 +02:00
parent 3f085cd765
commit 65ca1301de
4 changed files with 31 additions and 8 deletions

View File

@@ -98,12 +98,14 @@ VersionData {
} }
QtQuick.Image { QtQuick.Image {
allowChildren: false
allowedProperties: ["rotation", "scale", "transformOrigin"] allowedProperties: ["rotation", "scale", "transformOrigin"]
bannedProperties: ["mirror", "mipmap", "cache", "autoTransform", "asynchronous", bannedProperties: ["mirror", "mipmap", "cache", "autoTransform", "asynchronous",
"sourceSize", "smooth"] "sourceSize", "smooth"]
} }
QtQuick.Text { QtQuick.Text {
allowChildren: false
allowedProperties: ["rotation", "scale", "transformOrigin"] allowedProperties: ["rotation", "scale", "transformOrigin"]
bannedProperties: ["elide", "lineHeight", "lineHeightMode", "wrapMode", "style", bannedProperties: ["elide", "lineHeight", "lineHeightMode", "wrapMode", "style",
"styleColor", "minimumPointSize", "minimumPixelSize", "styleColor", "styleColor", "minimumPointSize", "minimumPixelSize", "styleColor",

View File

@@ -33,6 +33,7 @@
#include <qmldesignerplugin.h> #include <qmldesignerplugin.h>
#include <qmlobjectnode.h> #include <qmlobjectnode.h>
#include <designermcumanager.h> #include <designermcumanager.h>
#include <qmlitemnode.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -292,11 +293,19 @@ bool PropertyEditorValue::isAvailable() const
//allowed item properties: //allowed item properties:
const auto itemTypes = mcuAllowedItemProperties.keys(); const auto itemTypes = mcuAllowedItemProperties.keys();
for (const auto &itemType : itemTypes) { for (const auto &itemType : itemTypes) {
if (isAllowedSubclassType(itemType, m_modelNode.metaInfo()) if (isAllowedSubclassType(itemType, m_modelNode.metaInfo())) {
&& mcuAllowedItemProperties.value(itemType).contains(pureNameStr)) { 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; return true;
} }
} }
}
}
//banned properties: //banned properties:
//with prefixes: //with prefixes:

View File

@@ -170,9 +170,16 @@ void DesignerMcuManager::readVersionData(const DesignerMcuManager::Version &vers
//handling allowed properties: //handling allowed properties:
if (child->propertyNames().contains("allowedProperties")) { 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); m_allowedItemProperties.insert(child->name(), allowedProperties);
} }
@@ -235,7 +242,7 @@ QStringList DesignerMcuManager::bannedImports() const
return m_bannedImports; return m_bannedImports;
} }
QHash<QString, QStringList> DesignerMcuManager::allowedItemProperties() const QHash<QString, DesignerMcuManager::ItemProperties> DesignerMcuManager::allowedItemProperties() const
{ {
return m_allowedItemProperties; return m_allowedItemProperties;
} }

View File

@@ -43,6 +43,11 @@ public:
}; };
using VersionsList = QList<Version>; using VersionsList = QList<Version>;
struct ItemProperties {
QStringList properties;
bool allowChildren = true;
};
static DesignerMcuManager& instance(); static DesignerMcuManager& instance();
static QString mcuResourcesPath(); static QString mcuResourcesPath();
@@ -62,7 +67,7 @@ public:
QStringList allowedImports() const; QStringList allowedImports() const;
QStringList bannedImports() const; QStringList bannedImports() const;
QHash<QString, QStringList> allowedItemProperties() const; QHash<QString, ItemProperties> allowedItemProperties() const;
QHash<QString, QStringList> bannedComplexProperties() const; QHash<QString, QStringList> bannedComplexProperties() const;
DesignerMcuManager(DesignerMcuManager const&) = delete; DesignerMcuManager(DesignerMcuManager const&) = delete;
@@ -80,7 +85,7 @@ private:
QSet<QString> m_bannedProperties; QSet<QString> m_bannedProperties;
QStringList m_allowedImports; QStringList m_allowedImports;
QStringList m_bannedImports; QStringList m_bannedImports;
QHash<QString, QStringList> m_allowedItemProperties; QHash<QString, ItemProperties> m_allowedItemProperties;
QHash<QString, QStringList> m_bannedComplexProperties; QHash<QString, QStringList> m_bannedComplexProperties;
DesignerMcuManager::VersionsList m_versionsList; DesignerMcuManager::VersionsList m_versionsList;