Commit 4c2d2f24 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.Rewriter: Support bindings in dynamic property definitions

e.g. property int myHeight: height + 42
parent 95bec644
......@@ -744,7 +744,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
const QVariant variantValue = convertDynamicPropertyValueToVariant(astValue, astType);
syncVariantProperty(modelProperty, variantValue, astType, differenceHandler);
} else {
syncExpressionProperty(modelProperty, astValue, differenceHandler);
syncExpressionProperty(modelProperty, astValue, astType, differenceHandler);
}
modelPropertyNames.remove(astName);
} else {
......@@ -836,12 +836,12 @@ QString TextToModelMerger::syncScriptBinding(ModelNode &modelNode,
const QVariant enumValue = context->convertToEnum(script->statement, prefix, script->qualifiedId);
if (enumValue.isValid()) { // It is a qualified enum:
AbstractProperty modelProperty = modelNode.property(astPropertyName);
syncVariantProperty(modelProperty, enumValue, QString(), differenceHandler);
syncVariantProperty(modelProperty, enumValue, QString(), differenceHandler); // TODO: parse type
return astPropertyName;
} else { // Not an enum, so:
if (modelNode.type() == QLatin1String("Qt/PropertyChanges") || context->lookupProperty(prefix, script->qualifiedId)) {
AbstractProperty modelProperty = modelNode.property(astPropertyName);
syncExpressionProperty(modelProperty, astValue, differenceHandler);
syncExpressionProperty(modelProperty, astValue, QString(), differenceHandler); // TODO: parse type
return astPropertyName;
} else {
qWarning() << "Skipping invalid expression property" << astPropertyName
......@@ -900,15 +900,18 @@ void TextToModelMerger::syncNodeProperty(AbstractProperty &modelProperty,
void TextToModelMerger::syncExpressionProperty(AbstractProperty &modelProperty,
const QString &javascript,
const QString &astType,
DifferenceHandler &differenceHandler)
{
if (modelProperty.isBindingProperty()) {
BindingProperty bindingProperty = modelProperty.toBindingProperty();
if (bindingProperty.expression() != javascript) {
differenceHandler.bindingExpressionsDiffer(bindingProperty, javascript);
if (bindingProperty.expression() != javascript
|| !astType.isEmpty() != bindingProperty.isDynamic()
|| astType != bindingProperty.dynamicTypeName()) {
differenceHandler.bindingExpressionsDiffer(bindingProperty, javascript, astType);
}
} else {
differenceHandler.shouldBeBindingProperty(modelProperty, javascript);
differenceHandler.shouldBeBindingProperty(modelProperty, javascript, astType);
}
}
......@@ -1025,14 +1028,17 @@ void ModelValidator::importAbsentInQMl(const Import &import)
}
void ModelValidator::bindingExpressionsDiffer(BindingProperty &modelProperty,
const QString &javascript)
const QString &javascript,
const QString &astType)
{
Q_ASSERT(modelProperty.expression() == javascript);
Q_ASSERT(modelProperty.dynamicTypeName() == astType);
Q_ASSERT(0);
}
void ModelValidator::shouldBeBindingProperty(AbstractProperty &modelProperty,
const QString &/*javascript*/)
const QString &/*javascript*/,
const QString &/*astType*/)
{
Q_ASSERT(modelProperty.isBindingProperty());
Q_ASSERT(0);
......@@ -1125,17 +1131,27 @@ void ModelAmender::importAbsentInQMl(const Import &import)
}
void ModelAmender::bindingExpressionsDiffer(BindingProperty &modelProperty,
const QString &javascript)
const QString &javascript,
const QString &astType)
{
modelProperty.toBindingProperty().setExpression(javascript);
if (astType.isEmpty()) {
modelProperty.setExpression(javascript);
} else {
modelProperty.setDynamicTypeNameAndExpression(astType, javascript);
}
}
void ModelAmender::shouldBeBindingProperty(AbstractProperty &modelProperty,
const QString &javascript)
const QString &javascript,
const QString &astType)
{
ModelNode theNode = modelProperty.parentModelNode();
BindingProperty newModelProperty = theNode.bindingProperty(modelProperty.name());
newModelProperty.setExpression(javascript);
if (astType.isEmpty()) {
newModelProperty.setExpression(javascript);
} else {
newModelProperty.setDynamicTypeNameAndExpression(astType, javascript);
}
}
void ModelAmender::shouldBeNodeListProperty(AbstractProperty &modelProperty,
......
......@@ -84,6 +84,7 @@ public:
DifferenceHandler &differenceHandler);
void syncExpressionProperty(AbstractProperty &modelProperty,
const QString &javascript,
const QString &astType,
DifferenceHandler &differenceHandler);
void syncArrayProperty(AbstractProperty &modelProperty,
const QList<QmlJS::AST::UiObjectMember *> &arrayMembers,
......@@ -135,9 +136,11 @@ public:
virtual void modelMissesImport(const Import &import) = 0;
virtual void importAbsentInQMl(const Import &import) = 0;
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty,
const QString &javascript) = 0;
const QString &javascript,
const QString &astType) = 0;
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty,
const QString &javascript) = 0;
const QString &javascript,
const QString &astType) = 0;
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty,
const QList<QmlJS::AST::UiObjectMember *> arrayMembers,
ReadingContext *context) = 0;
......@@ -179,9 +182,11 @@ public:
virtual void modelMissesImport(const Import &import);
virtual void importAbsentInQMl(const Import &import);
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty,
const QString &javascript);
const QString &javascript,
const QString &astType);
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty,
const QString &javascript);
const QString &javascript,
const QString &astType);
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty,
const QList<QmlJS::AST::UiObjectMember *> arrayMembers,
ReadingContext *context);
......@@ -220,9 +225,11 @@ public:
virtual void modelMissesImport(const Import &import);
virtual void importAbsentInQMl(const Import &import);
virtual void bindingExpressionsDiffer(BindingProperty &modelProperty,
const QString &javascript);
const QString &javascript,
const QString &astType);
virtual void shouldBeBindingProperty(AbstractProperty &modelProperty,
const QString &javascript);
const QString &javascript,
const QString &astType);
virtual void shouldBeNodeListProperty(AbstractProperty &modelProperty,
const QList<QmlJS::AST::UiObjectMember *> arrayMembers,
ReadingContext *context);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment