forked from qt-creator/qt-creator
DesignerCore: Make stylesheet merger transfer custom properties
Do not ignore root level properties and add them to the final model (ignore the state changes properties though). Task-number: QDS-13688 Change-Id: Icbd544e0c1cb866d7bec19fe305950bb6a384247 Reviewed-by: Przemyslaw Lewandowski <przemyslaw.lewandowski@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
bca1d47c98
commit
e9f76460ab
@@ -328,8 +328,20 @@ void StylesheetMerger::adjustNodeIndex(ModelNode &node)
|
|||||||
parentListProperty.slide(currentIndex, info.parentIndex);
|
parentListProperty.slide(currentIndex, info.parentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StylesheetMerger::applyStyleProperties(ModelNode &templateNode, const ModelNode &styleNode)
|
void StylesheetMerger::applyStyleProperties(ModelNode &templateNode,
|
||||||
|
const ModelNode &styleNode,
|
||||||
|
bool isRootNode)
|
||||||
{
|
{
|
||||||
|
// using isRootNode allows transferring custom properties that may have been added in Qt Bridge
|
||||||
|
auto addProperty = [&templateNode, isRootNode](const VariantProperty &variantProperty) {
|
||||||
|
if (isRootNode)
|
||||||
|
templateNode.variantProperty(variantProperty.name())
|
||||||
|
.setDynamicTypeNameAndValue(variantProperty.dynamicTypeName(),
|
||||||
|
variantProperty.value());
|
||||||
|
else
|
||||||
|
templateNode.variantProperty(variantProperty.name()).setValue(variantProperty.value());
|
||||||
|
};
|
||||||
|
|
||||||
const QRegularExpression regEx("[a-z]", QRegularExpression::CaseInsensitiveOption);
|
const QRegularExpression regEx("[a-z]", QRegularExpression::CaseInsensitiveOption);
|
||||||
for (const VariantProperty &variantProperty : styleNode.variantProperties()) {
|
for (const VariantProperty &variantProperty : styleNode.variantProperties()) {
|
||||||
if (templateNode.hasBindingProperty(variantProperty.name())) {
|
if (templateNode.hasBindingProperty(variantProperty.name())) {
|
||||||
@@ -337,16 +349,20 @@ void StylesheetMerger::applyStyleProperties(ModelNode &templateNode, const Model
|
|||||||
// replace it with the corresponding variant property.
|
// replace it with the corresponding variant property.
|
||||||
if (!templateNode.bindingProperty(variantProperty.name()).expression().contains(regEx)) {
|
if (!templateNode.bindingProperty(variantProperty.name()).expression().contains(regEx)) {
|
||||||
templateNode.removeProperty(variantProperty.name());
|
templateNode.removeProperty(variantProperty.name());
|
||||||
templateNode.variantProperty(variantProperty.name()).setValue(variantProperty.value());
|
addProperty(variantProperty);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (variantProperty.holdsEnumeration()) {
|
if (variantProperty.holdsEnumeration())
|
||||||
templateNode.variantProperty(variantProperty.name()).setEnumeration(variantProperty.enumeration().toEnumerationName());
|
templateNode.variantProperty(variantProperty.name())
|
||||||
} else {
|
.setEnumeration(variantProperty.enumeration().toEnumerationName());
|
||||||
templateNode.variantProperty(variantProperty.name()).setValue(variantProperty.value());
|
else
|
||||||
}
|
addProperty(variantProperty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isRootNode)
|
||||||
|
return;
|
||||||
|
|
||||||
syncBindingProperties(templateNode, styleNode);
|
syncBindingProperties(templateNode, styleNode);
|
||||||
syncNodeProperties(templateNode, styleNode, true);
|
syncNodeProperties(templateNode, styleNode, true);
|
||||||
syncNodeListProperties(templateNode, styleNode, true);
|
syncNodeListProperties(templateNode, styleNode, true);
|
||||||
@@ -473,6 +489,9 @@ void StylesheetMerger::merge()
|
|||||||
// build a hash of generated replacement ids
|
// build a hash of generated replacement ids
|
||||||
setupIdRenamingHash();
|
setupIdRenamingHash();
|
||||||
|
|
||||||
|
// transfer custom root properties
|
||||||
|
applyStyleProperties(templateRootNode, styleRootNode, true);
|
||||||
|
|
||||||
//in case we are replacing the root node, just do that and exit
|
//in case we are replacing the root node, just do that and exit
|
||||||
if (m_styleView->hasId(templateRootNode.id())) {
|
if (m_styleView->hasId(templateRootNode.id())) {
|
||||||
replaceRootNode(templateRootNode);
|
replaceRootNode(templateRootNode);
|
||||||
|
@@ -40,7 +40,9 @@ private:
|
|||||||
bool idExistsInBothModels(const QString& id);
|
bool idExistsInBothModels(const QString& id);
|
||||||
void replaceNode(ModelNode&, ModelNode&);
|
void replaceNode(ModelNode&, ModelNode&);
|
||||||
void replaceRootNode(ModelNode& templateRootNode);
|
void replaceRootNode(ModelNode& templateRootNode);
|
||||||
void applyStyleProperties(ModelNode &templateNode, const ModelNode &styleNode);
|
void applyStyleProperties(ModelNode &templateNode,
|
||||||
|
const ModelNode &styleNode,
|
||||||
|
bool isRootNode = false);
|
||||||
void adjustNodeIndex(ModelNode &node);
|
void adjustNodeIndex(ModelNode &node);
|
||||||
void setupIdRenamingHash();
|
void setupIdRenamingHash();
|
||||||
ModelNode createReplacementNode(const ModelNode &styleNode, ModelNode &modelNode);
|
ModelNode createReplacementNode(const ModelNode &styleNode, ModelNode &modelNode);
|
||||||
|
Reference in New Issue
Block a user