forked from qt-creator/qt-creator
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:
@@ -150,13 +150,17 @@ 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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -164,24 +168,33 @@ void DSThemeGroup::decorate(ThemeId theme, ModelNode themeNode)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,11 @@
|
||||
#include <optional>
|
||||
|
||||
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;
|
||||
|
@@ -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));
|
||||
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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user