QmlDesigner: Add support for auxiliary data in property editor

This patch exposed certain auxiliary data to the property editor.
Currently the list is hard coded.

Change-Id: I599ace622f061ffd6063950fc143ff22c963e775
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2020-01-29 14:05:40 +01:00
parent e9a26ae420
commit 8f614d04a4
4 changed files with 111 additions and 8 deletions

View File

@@ -131,7 +131,40 @@ void PropertyEditorQmlBackend::setupPropertyEditorValue(const PropertyName &name
}
QVariant properDefaultLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &propertyName)
PropertyName auxNamePostFix(const PropertyName &propertyName)
{
return propertyName + "__AUX";
}
QVariant properDefaultAuxiliaryProperties(const QmlObjectNode &qmlObjectNode,
const PropertyName &propertyName)
{
const ModelNode node = qmlObjectNode.modelNode();
const PropertyName auxName = propertyName;
if (node.hasAuxiliaryData(auxName))
return node.auxiliaryData(auxName);
if (propertyName == "color")
return QColor(Qt::red);
if (propertyName == "fillColor")
return QColor(Qt::transparent);
else if (propertyName == "width")
return 4;
else if (propertyName == "dash")
return false;
else if (propertyName == "inOffset")
return 0;
else if (propertyName == "outOffset")
return 0;
else if (propertyName == "break")
return 50;
return {};
}
QVariant properDefaultLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode,
const PropertyName &propertyName)
{
const QVariant value = qmlObjectNode.modelValue("Layout." + propertyName);
QVariant marginsValue = qmlObjectNode.modelValue("Layout.margins");
@@ -180,6 +213,29 @@ void PropertyEditorQmlBackend::setupLayoutAttachedProperties(const QmlObjectNode
}
}
void PropertyEditorQmlBackend::setupAuxiliaryProperties(const QmlObjectNode &qmlObjectNode,
PropertyEditorView *propertyEditor)
{
const QmlItemNode itemNode(qmlObjectNode);
PropertyNameList propertyNames;
if (itemNode.isFlowTransition()) {
propertyNames.append({"color", "width", "inOffset", "outOffset", "dash", "break"});
} else if (itemNode.isFlowItem()) {
propertyNames.append({"color", "width", "inOffset", "outOffset"});
} else if (itemNode.isFlowActionArea()) {
propertyNames.append({"color", "width", "fillColor", "outOffset", "dash"});
}
for (const PropertyName &propertyName : propertyNames) {
createPropertyEditorValue(qmlObjectNode, auxNamePostFix(propertyName),
properDefaultAuxiliaryProperties(qmlObjectNode, propertyName), propertyEditor);
}
}
void PropertyEditorQmlBackend::createPropertyEditorValue(const QmlObjectNode &qmlObjectNode,
const PropertyName &name,
const QVariant &value,
@@ -222,14 +278,8 @@ void PropertyEditorQmlBackend::setValue(const QmlObjectNode & qmlObjectNode, con
PropertyName propertyName = name;
propertyName.replace('.', '_');
auto propertyValue = qobject_cast<PropertyEditorValue*>(variantToQObject(m_backendValuesPropertyMap.value(QString::fromUtf8(propertyName))));
if (propertyValue) {
if (propertyValue)
propertyValue->setValue(value);
if (!qmlObjectNode.hasBindingProperty(name))
propertyValue->setExpression(value.toString());
else
propertyValue->setExpression(qmlObjectNode.expression(name));
}
}
QQmlContext *PropertyEditorQmlBackend::context() {
@@ -281,6 +331,7 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
createPropertyEditorValue(qmlObjectNode, propertyName, qmlObjectNode.instanceValue(propertyName), propertyEditor);
setupLayoutAttachedProperties(qmlObjectNode, propertyEditor);
setupAuxiliaryProperties(qmlObjectNode, propertyEditor);
// model node
m_backendModelNode.setup(qmlObjectNode.modelNode());
@@ -643,6 +694,12 @@ void PropertyEditorQmlBackend::setValueforLayoutAttachedProperties(const QmlObje
}
}
void PropertyEditorQmlBackend::setValueforAuxiliaryProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &name)
{
const PropertyName propertyName = auxNamePostFix(name);
setValue(qmlObjectNode, propertyName, qmlObjectNode.modelNode().auxiliaryData(name));
}
QUrl PropertyEditorQmlBackend::getQmlUrlForMetaInfo(const NodeMetaInfo &metaInfo, TypeName &className)
{
if (metaInfo.isValid()) {

View File

@@ -79,8 +79,10 @@ public:
void emitSelectionChanged();
void setValueforLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &name);
void setValueforAuxiliaryProperties(const QmlObjectNode &qmlObjectNode, const PropertyName &name);
void setupLayoutAttachedProperties(const QmlObjectNode &qmlObjectNode, PropertyEditorView *propertyEditor);
void setupAuxiliaryProperties(const QmlObjectNode &qmlObjectNode, PropertyEditorView *propertyEditor);
static NodeMetaInfo findCommonAncestor(const ModelNode &node);

View File

@@ -177,6 +177,11 @@ void PropertyEditorView::changeValue(const QString &name)
if (value ==nullptr)
return;
if (propertyName.endsWith( "__AUX")) {
commitAuxValueToModel(propertyName, value->value());
return;
}
QmlObjectNode qmlObjectNode(m_selectedNode);
QVariant castedValue;
@@ -512,6 +517,30 @@ void PropertyEditorView::commitVariantValueToModel(const PropertyName &propertyN
m_locked = false;
}
void PropertyEditorView::commitAuxValueToModel(const PropertyName &propertyName, const QVariant &value)
{
m_locked = true;
PropertyName name = propertyName;
name.chop(5);
try {
if (value.isValid()) {
for (const ModelNode &node : m_selectedNode.view()->selectedModelNodes()) {
node.setAuxiliaryData(name, value);
}
} else {
for (const ModelNode &node : m_selectedNode.view()->selectedModelNodes()) {
node.removeAuxiliaryData(name);
}
}
}
catch (const Exception &e) {
e.showException();
}
m_locked = false;
}
void PropertyEditorView::removePropertyFromModel(const PropertyName &propertyName)
{
m_locked = true;
@@ -660,6 +689,19 @@ void PropertyEditorView::bindingPropertiesChanged(const QList<BindingProperty>&
}
}
void PropertyEditorView::auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &)
{
if (noValidSelection())
return;
if (!node.isSelected())
return;
m_qmlBackEndForCurrentType->setValueforAuxiliaryProperties(m_selectedNode, name);
}
void PropertyEditorView::instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangedHash)
{
if (noValidSelection())

View File

@@ -69,6 +69,7 @@ public:
void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange) override;
void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange) override;
void auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &data) override;
void instanceInformationsChanged(const QMultiHash<ModelNode, InformationName> &informationChangedHash) override;
@@ -112,6 +113,7 @@ private: //functions
void setupQmlBackend();
void commitVariantValueToModel(const PropertyName &propertyName, const QVariant &value);
void commitAuxValueToModel(const PropertyName &propertyName, const QVariant &value);
void removePropertyFromModel(const PropertyName &propertyName);
bool noValidSelection() const;