QmlDesigner: Add new node hint

Add a new node hint called "bindParentToProperty" which enables the
metainfo file to specify an automatic binding of a nodes parent id to an
arbitrary property.

Change-Id: Ib16955df608cdca5732882afc1f5ba0891283ca5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Henning Gruendl
2022-02-04 15:31:26 +01:00
committed by Henning Gründl
parent ff7a0e92e8
commit 557a3c9af7
3 changed files with 21 additions and 1 deletions

View File

@@ -72,6 +72,7 @@ public:
bool visibleInLibrary() const;
QString forceNonDefaultProperty() const;
QPair<QString, QVariant> setParentProperty() const;
QString bindParentToProperty() const;
QHash<QString, QString> hints() const;
static NodeHints fromModelNode(const ModelNode &modelNode);

View File

@@ -295,6 +295,16 @@ QPair<QString, QVariant> NodeHints::setParentProperty() const
return qMakePair(list.first().trimmed(), parseValue(list.last().trimmed()));
}
QString NodeHints::bindParentToProperty() const
{
const QString expression = m_hints.value("bindParentToProperty");
if (expression.isEmpty())
return {};
return Internal::evaluateExpression(expression, modelNode(), ModelNode()).toString();
}
QHash<QString, QString> NodeHints::hints() const
{
return m_hints;

View File

@@ -361,6 +361,15 @@ QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
parent.variantProperty(property).setValue(value);
}
if (!hints.bindParentToProperty().isEmpty() && parentProperty.isValid()) {
const PropertyName property = hints.bindParentToProperty().toUtf8();
ModelNode parent = parentProperty.parentModelNode();
const NodeMetaInfo metaInfo = newQmlObjectNode.modelNode().metaInfo();
if (metaInfo.hasProperty(property))
newQmlObjectNode.setBindingProperty(property, parent.validId());
}
return newQmlObjectNode;
}