forked from qt-creator/qt-creator
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:
committed by
Henning Gründl
parent
ff7a0e92e8
commit
557a3c9af7
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user