diff --git a/src/plugins/qmldesigner/components/designsystem/dsthemegroup.cpp b/src/plugins/qmldesigner/components/designsystem/dsthemegroup.cpp index aa2b5c78a23..4a26fef5ec9 100644 --- a/src/plugins/qmldesigner/components/designsystem/dsthemegroup.cpp +++ b/src/plugins/qmldesigner/components/designsystem/dsthemegroup.cpp @@ -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)) return; // No props for this theme in this group. - const auto groupName = GroupId(m_type); + ModelNode *targetNode = &themeNode; const auto typeName = groupTypeName(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; + if (decorationContext == DECORATION_CONTEXT::MPU) { + // Create a group node + 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) { auto &[propName, values] = *itr; auto themeValue = values.find(theme); if (themeValue != values.end()) { auto &propData = themeValue->second; if (propData.isBinding) { - auto bindingProp = groupNode.bindingProperty(propName); + auto bindingProp = targetNode->bindingProperty(propName); if (bindingProp) - bindingProp.setDynamicTypeNameAndExpression(*typeName, propData.value.toString()); + bindingProp.setDynamicTypeNameAndExpression(*typeName, + propData.value.toString()); } else { - auto nodeProp = groupNode.variantProperty(propName); - if (nodeProp) + auto nodeProp = targetNode->variantProperty(propName); + if (!nodeProp) + continue; + + if (decorationContext == DECORATION_CONTEXT::MCU) + nodeProp.setValue(propData.value); + else nodeProp.setDynamicTypeNameAndValue(*typeName, propData.value); } } } - groupProperty.setDynamicTypeNameAndsetModelNode("QtObject", groupNode); } } diff --git a/src/plugins/qmldesigner/components/designsystem/dsthemegroup.h b/src/plugins/qmldesigner/components/designsystem/dsthemegroup.h index 9b795115ab1..b76e2f3d504 100644 --- a/src/plugins/qmldesigner/components/designsystem/dsthemegroup.h +++ b/src/plugins/qmldesigner/components/designsystem/dsthemegroup.h @@ -12,6 +12,11 @@ #include namespace QmlDesigner { +enum class DECORATION_CONTEXT { + MCU, + MPU, + COMPONENT_THEME, +}; class QMLDESIGNERCOMPONENTS_EXPORT DSThemeGroup { @@ -50,7 +55,7 @@ public: void removeTheme(ThemeId theme); void duplicateValues(ThemeId from, ThemeId to); - void decorate(ThemeId theme, ModelNode themeNode); + void decorate(ThemeId theme, ModelNode themeNode, DECORATION_CONTEXT decorationContext); private: const GroupType m_type; diff --git a/src/plugins/qmldesigner/components/designsystem/dsthememanager.cpp b/src/plugins/qmldesigner/components/designsystem/dsthememanager.cpp index 652c0080cd3..8e6513392d4 100644 --- a/src/plugins/qmldesigner/components/designsystem/dsthememanager.cpp +++ b/src/plugins/qmldesigner/components/designsystem/dsthememanager.cpp @@ -130,27 +130,38 @@ void DSThemeManager::updateProperty(ThemeId id, 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()) return; auto p = rootNode.bindingProperty("currentTheme"); - p.setDynamicTypeNameAndExpression("QtObject", QString::fromLatin1(m_themes.begin()->second)); - addGroupAliases(rootNode); - + p.setDynamicTypeNameAndExpression(nodeType, QString::fromLatin1(m_themes.begin()->second)); + if (!isMCU) + addGroupAliases(rootNode); auto model = rootNode.model(); + 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); - themeProperty.setDynamicTypeNameAndsetModelNode("QtObject", themeNode); + themeProperty.setDynamicTypeNameAndsetModelNode(nodeType, themeNode); // Add property groups 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) { auto itr = m_groups.find(type); diff --git a/src/plugins/qmldesigner/components/designsystem/dsthememanager.h b/src/plugins/qmldesigner/components/designsystem/dsthememanager.h index a28bf232c1c..e3ac9e2e4c9 100644 --- a/src/plugins/qmldesigner/components/designsystem/dsthememanager.h +++ b/src/plugins/qmldesigner/components/designsystem/dsthememanager.h @@ -43,7 +43,8 @@ public: void updateProperty(ThemeId id, GroupType gType, const ThemeProperty &p); 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: DSThemeGroup *propertyGroup(GroupType type);