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;
|
bool visibleInLibrary() const;
|
||||||
QString forceNonDefaultProperty() const;
|
QString forceNonDefaultProperty() const;
|
||||||
QPair<QString, QVariant> setParentProperty() const;
|
QPair<QString, QVariant> setParentProperty() const;
|
||||||
|
QString bindParentToProperty() const;
|
||||||
|
|
||||||
QHash<QString, QString> hints() const;
|
QHash<QString, QString> hints() const;
|
||||||
static NodeHints fromModelNode(const ModelNode &modelNode);
|
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()));
|
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
|
QHash<QString, QString> NodeHints::hints() const
|
||||||
{
|
{
|
||||||
return m_hints;
|
return m_hints;
|
||||||
|
@@ -301,7 +301,7 @@ QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
|
|||||||
for (const auto &property : itemLibraryEntry.properties()) {
|
for (const auto &property : itemLibraryEntry.properties()) {
|
||||||
if (property.type() == "binding") {
|
if (property.type() == "binding") {
|
||||||
propertyBindingList.append(PropertyBindingEntry(property.name(), property.value().toString()));
|
propertyBindingList.append(PropertyBindingEntry(property.name(), property.value().toString()));
|
||||||
} else if (property.type() == "enum") {
|
} else if (property.type() == "enum") {
|
||||||
propertyEnumList.append(PropertyBindingEntry(property.name(), property.value().toString()));
|
propertyEnumList.append(PropertyBindingEntry(property.name(), property.value().toString()));
|
||||||
} else if (property.value().toString() == QString::fromLatin1(imagePlaceHolder)) {
|
} else if (property.value().toString() == QString::fromLatin1(imagePlaceHolder)) {
|
||||||
propertyPairList.append({property.name(), imagePlaceHolderPath(view->model()) });
|
propertyPairList.append({property.name(), imagePlaceHolderPath(view->model()) });
|
||||||
@@ -361,6 +361,15 @@ QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
|
|||||||
parent.variantProperty(property).setValue(value);
|
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;
|
return newQmlObjectNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user