QmlDesigner: Generate MCU compatible design system module

Task-number: QDS-13599
Change-Id: Iff8121bd8c4df44e0700d141497792de39a29668
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
Przemyslaw Lewandowski
2024-09-11 14:27:06 +02:00
parent 322120ba8f
commit 94bc04e60e
4 changed files with 51 additions and 21 deletions

View File

@@ -150,38 +150,51 @@ void DSThemeGroup::duplicateValues(ThemeId from, ThemeId to)
} }
} }
void DSThemeGroup::decorate(ThemeId theme, ModelNode themeNode) void DSThemeGroup::decorate(ThemeId theme, ModelNode themeNode, DECORATION_CONTEXT decorationContext)
{ {
if (!count(theme)) if (!count(theme))
return; // No props for this theme in this group. return; // No props for this theme in this group.
const auto groupName = GroupId(m_type); ModelNode *targetNode = &themeNode;
const auto typeName = groupTypeName(m_type); const auto typeName = groupTypeName(m_type);
auto groupNode = themeNode.model()->createModelNode("QtObject");
auto groupProperty = themeNode.nodeProperty(groupName);
if (!groupProperty || !typeName || !groupNode) { if (decorationContext == DECORATION_CONTEXT::MPU) {
qCDebug(dsLog) << "Adding group node failed." << groupName << theme; // Create a group node
return; const auto groupName = GroupId(m_type);
auto groupNode = themeNode.model()->createModelNode("QtObject");
auto groupProperty = themeNode.nodeProperty(groupName);
if (!groupProperty || !typeName || !groupNode) {
qCDebug(dsLog) << "Adding group node failed." << groupName << theme;
return;
}
groupProperty.setDynamicTypeNameAndsetModelNode("QtObject", groupNode);
targetNode = &groupNode;
} }
// Add properties
for (auto itr = m_values.begin(); itr != m_values.end(); ++itr) { for (auto itr = m_values.begin(); itr != m_values.end(); ++itr) {
auto &[propName, values] = *itr; auto &[propName, values] = *itr;
auto themeValue = values.find(theme); auto themeValue = values.find(theme);
if (themeValue != values.end()) { if (themeValue != values.end()) {
auto &propData = themeValue->second; auto &propData = themeValue->second;
if (propData.isBinding) { if (propData.isBinding) {
auto bindingProp = groupNode.bindingProperty(propName); auto bindingProp = targetNode->bindingProperty(propName);
if (bindingProp) if (bindingProp)
bindingProp.setDynamicTypeNameAndExpression(*typeName, propData.value.toString()); bindingProp.setDynamicTypeNameAndExpression(*typeName,
propData.value.toString());
} else { } else {
auto nodeProp = groupNode.variantProperty(propName); auto nodeProp = targetNode->variantProperty(propName);
if (nodeProp) if (!nodeProp)
continue;
if (decorationContext == DECORATION_CONTEXT::MCU)
nodeProp.setValue(propData.value);
else
nodeProp.setDynamicTypeNameAndValue(*typeName, propData.value); nodeProp.setDynamicTypeNameAndValue(*typeName, propData.value);
} }
} }
} }
groupProperty.setDynamicTypeNameAndsetModelNode("QtObject", groupNode);
} }
} }

View File

@@ -12,6 +12,11 @@
#include <optional> #include <optional>
namespace QmlDesigner { namespace QmlDesigner {
enum class DECORATION_CONTEXT {
MCU,
MPU,
COMPONENT_THEME,
};
class QMLDESIGNERCOMPONENTS_EXPORT DSThemeGroup class QMLDESIGNERCOMPONENTS_EXPORT DSThemeGroup
{ {
@@ -50,7 +55,7 @@ public:
void removeTheme(ThemeId theme); void removeTheme(ThemeId theme);
void duplicateValues(ThemeId from, ThemeId to); void duplicateValues(ThemeId from, ThemeId to);
void decorate(ThemeId theme, ModelNode themeNode); void decorate(ThemeId theme, ModelNode themeNode, DECORATION_CONTEXT decorationContext);
private: private:
const GroupType m_type; const GroupType m_type;

View File

@@ -130,27 +130,38 @@ void DSThemeManager::updateProperty(ThemeId id,
dsGroup->updateProperty(id, newName, p); dsGroup->updateProperty(id, newName, p);
} }
void DSThemeManager::decorate(ModelNode rootNode) const void DSThemeManager::decorate(ModelNode rootNode, const QByteArray &nodeType, bool isMCU) const
{ {
if (!m_themes.size()) if (!m_themes.size())
return; return;
auto p = rootNode.bindingProperty("currentTheme"); auto p = rootNode.bindingProperty("currentTheme");
p.setDynamicTypeNameAndExpression("QtObject", QString::fromLatin1(m_themes.begin()->second)); p.setDynamicTypeNameAndExpression(nodeType, QString::fromLatin1(m_themes.begin()->second));
addGroupAliases(rootNode); if (!isMCU)
addGroupAliases(rootNode);
auto model = rootNode.model(); auto model = rootNode.model();
for (auto itr = m_themes.begin(); itr != m_themes.end(); ++itr) { for (auto itr = m_themes.begin(); itr != m_themes.end(); ++itr) {
auto themeNode = model->createModelNode("QtObject"); auto themeNode = model->createModelNode(nodeType);
auto themeProperty = model->rootModelNode().nodeProperty(itr->second); auto themeProperty = model->rootModelNode().nodeProperty(itr->second);
themeProperty.setDynamicTypeNameAndsetModelNode("QtObject", themeNode); themeProperty.setDynamicTypeNameAndsetModelNode(nodeType, themeNode);
// Add property groups // Add property groups
for (auto groupItr = m_groups.begin(); groupItr != m_groups.end(); ++groupItr) for (auto groupItr = m_groups.begin(); groupItr != m_groups.end(); ++groupItr)
groupItr->second->decorate(itr->first, themeNode); groupItr->second->decorate(itr->first, themeNode, isMCU ? DECORATION_CONTEXT::MCU : DECORATION_CONTEXT::MPU);
} }
} }
void DSThemeManager::decorateThemeComponent(ModelNode rootNode) const
{
if (!m_themes.size())
return;
auto itr = m_themes.begin();
for (auto groupItr = m_groups.begin(); groupItr != m_groups.end(); ++groupItr)
groupItr->second->decorate(itr->first, rootNode, DECORATION_CONTEXT::COMPONENT_THEME);
}
DSThemeGroup *DSThemeManager::propertyGroup(GroupType type) DSThemeGroup *DSThemeManager::propertyGroup(GroupType type)
{ {
auto itr = m_groups.find(type); auto itr = m_groups.find(type);

View File

@@ -43,7 +43,8 @@ public:
void updateProperty(ThemeId id, GroupType gType, const ThemeProperty &p); void updateProperty(ThemeId id, GroupType gType, const ThemeProperty &p);
void updateProperty(ThemeId id, GroupType gType, const ThemeProperty &p, const PropertyName &newName); void updateProperty(ThemeId id, GroupType gType, const ThemeProperty &p, const PropertyName &newName);
void decorate(ModelNode rootNode) const; void decorate(ModelNode rootNode, const QByteArray& nodeType, bool isMCU) const;
void decorateThemeComponent(ModelNode rootNode) const;
private: private:
DSThemeGroup *propertyGroup(GroupType type); DSThemeGroup *propertyGroup(GroupType type);