forked from qt-creator/qt-creator
QmlDesigner: Fix attached property handling
* Add margins to the list of attached properties * Add handling of margins change Change-Id: I4630169ce07a4903360962b7c8d9fb6d4c01df13 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Henning Gründl
parent
e0f32375a6
commit
15bf546ff9
@@ -133,7 +133,11 @@ void PropertyEditorQmlBackend::setupPropertyEditorValue(const PropertyName &name
|
|||||||
|
|
||||||
QVariant properDefaultLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &propertyName)
|
QVariant properDefaultLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &propertyName)
|
||||||
{
|
{
|
||||||
QVariant value = qmlObjectNode.modelValue(propertyName);
|
const QVariant value = qmlObjectNode.modelValue("Layout." + propertyName);
|
||||||
|
QVariant marginsValue = qmlObjectNode.modelValue("Layout.margins");
|
||||||
|
|
||||||
|
if (!marginsValue.isValid())
|
||||||
|
marginsValue.setValue(0.0);
|
||||||
|
|
||||||
if (value.isValid())
|
if (value.isValid())
|
||||||
return value;
|
return value;
|
||||||
@@ -153,11 +157,10 @@ QVariant properDefaultLayoutAttachedProperties(const QmlObjectNode &qmlObjectNod
|
|||||||
if ("columnSpan" == propertyName || "rowSpan" == propertyName)
|
if ("columnSpan" == propertyName || "rowSpan" == propertyName)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if ("topMargin" == propertyName || "bottomMargin" == propertyName)
|
if ("topMargin" == propertyName || "bottomMargin" == propertyName ||
|
||||||
return 0;
|
"leftMargin" == propertyName || "rightMargin" == propertyName ||
|
||||||
|
"margins" == propertyName)
|
||||||
if ("leftMargin" == propertyName || "rightMargin" == propertyName)
|
return marginsValue;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@@ -169,9 +172,9 @@ void PropertyEditorQmlBackend::setupLayoutAttachedProperties(const QmlObjectNode
|
|||||||
static const PropertyNameList propertyNames =
|
static const PropertyNameList propertyNames =
|
||||||
{"alignment", "column", "columnSpan", "fillHeight", "fillWidth", "maximumHeight", "maximumWidth",
|
{"alignment", "column", "columnSpan", "fillHeight", "fillWidth", "maximumHeight", "maximumWidth",
|
||||||
"minimumHeight", "minimumWidth", "preferredHeight", "preferredWidth", "row", "rowSpan",
|
"minimumHeight", "minimumWidth", "preferredHeight", "preferredWidth", "row", "rowSpan",
|
||||||
"topMargin", "bottomMargin", "leftMargin", "rightMargin"};
|
"topMargin", "bottomMargin", "leftMargin", "rightMargin", "margins"};
|
||||||
|
|
||||||
foreach (const PropertyName &propertyName, propertyNames) {
|
for (const PropertyName &propertyName : propertyNames) {
|
||||||
createPropertyEditorValue(qmlObjectNode, "Layout." + propertyName, properDefaultLayoutAttachedProperties(qmlObjectNode, propertyName), propertyEditor);
|
createPropertyEditorValue(qmlObjectNode, "Layout." + propertyName, properDefaultLayoutAttachedProperties(qmlObjectNode, propertyName), propertyEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -629,7 +632,15 @@ void PropertyEditorQmlBackend::setValueforLayoutAttachedProperties(const QmlObje
|
|||||||
{
|
{
|
||||||
PropertyName propertyName = name;
|
PropertyName propertyName = name;
|
||||||
propertyName.replace("Layout.", "");
|
propertyName.replace("Layout.", "");
|
||||||
setValue(qmlObjectNode, name, properDefaultLayoutAttachedProperties(qmlObjectNode, propertyName));
|
setValue(qmlObjectNode, name, properDefaultLayoutAttachedProperties(qmlObjectNode, propertyName));
|
||||||
|
|
||||||
|
if (propertyName == "margins") {
|
||||||
|
const QVariant marginsValue = properDefaultLayoutAttachedProperties(qmlObjectNode, "margins");
|
||||||
|
setValue(qmlObjectNode, "Layout.topMargin", marginsValue);
|
||||||
|
setValue(qmlObjectNode, "Layout.bottomMargin", marginsValue);
|
||||||
|
setValue(qmlObjectNode, "Layout.leftMargin", marginsValue);
|
||||||
|
setValue(qmlObjectNode, "Layout.rightMargin", marginsValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl PropertyEditorQmlBackend::getQmlUrlForMetaInfo(const NodeMetaInfo &metaInfo, TypeName &className)
|
QUrl PropertyEditorQmlBackend::getQmlUrlForMetaInfo(const NodeMetaInfo &metaInfo, TypeName &className)
|
||||||
|
|||||||
@@ -591,9 +591,18 @@ void PropertyEditorView::propertiesRemoved(const QList<AbstractProperty>& proper
|
|||||||
if (node == m_selectedNode || QmlObjectNode(m_selectedNode).propertyChangeForCurrentState() == node) {
|
if (node == m_selectedNode || QmlObjectNode(m_selectedNode).propertyChangeForCurrentState() == node) {
|
||||||
setValue(m_selectedNode, property.name(), QmlObjectNode(m_selectedNode).instanceValue(property.name()));
|
setValue(m_selectedNode, property.name(), QmlObjectNode(m_selectedNode).instanceValue(property.name()));
|
||||||
|
|
||||||
if (propertyIsAttachedLayoutProperty(property.name()))
|
if (propertyIsAttachedLayoutProperty(property.name())) {
|
||||||
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, property.name());
|
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, property.name());
|
||||||
|
|
||||||
|
if (property.name() == "Layout.margins") {
|
||||||
|
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, "Layout.topMargin");
|
||||||
|
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, "Layout.bottomMargin");
|
||||||
|
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, "Layout.leftMargin");
|
||||||
|
m_qmlBackEndForCurrentType->setValueforLayoutAttachedProperties(m_selectedNode, "Layout.rightMargin");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ("width" == property.name() || "height" == property.name()) {
|
if ("width" == property.name() || "height" == property.name()) {
|
||||||
const QmlItemNode qmlItemNode = m_selectedNode;
|
const QmlItemNode qmlItemNode = m_selectedNode;
|
||||||
if (qmlItemNode.isValid() && qmlItemNode.isInLayout())
|
if (qmlItemNode.isValid() && qmlItemNode.isInLayout())
|
||||||
|
|||||||
Reference in New Issue
Block a user