Commit a97e2f53 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed testcase.

parent 4e50dfe3
......@@ -30,6 +30,7 @@
#include <QtCore/QDebug>
#include "nodeabstractproperty.h"
#include "nodelistproperty.h"
#include "rewriteaction.h"
using namespace QmlDesigner;
......@@ -93,6 +94,16 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos
<< m_valueText << ") **"
<< info();
}
} else if (m_property.isNodeListProperty() && m_property.toNodeListProperty().toModelNodeList().size() > 1) {
result = refactoring.addToArrayMemberList(nodeLocation, m_property.name(), m_valueText);
if (!result) {
qDebug() << "*** AddPropertyRewriteAction::execute failed in addToArrayMemberList("
<< nodeLocation << ','
<< m_property.name() << ','
<< m_valueText << ") **"
<< info();
}
} else {
result = refactoring.addProperty(nodeLocation, m_property.name(), m_valueText, m_propertyType);
......@@ -100,7 +111,8 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos
qDebug() << "*** AddPropertyRewriteAction::execute failed in addProperty("
<< nodeLocation << ','
<< m_property.name() << ','
<< m_valueText << ", ScriptBinding) **"
<< m_valueText << ","
<< qPrintable(toString(m_propertyType)) << ") **"
<< info();
}
}
......
......@@ -367,7 +367,12 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
const QString astPropertyName = flatten(array->qualifiedId);
if (isValidPropertyForNode(modelNode, astPropertyName)) {
AbstractProperty modelProperty = modelNode.property(astPropertyName);
syncArrayProperty(modelProperty, array, context, differenceHandler);
QList<UiObjectMember *> arrayMembers;
for (UiArrayMemberList *iter = array->members; iter; iter = iter->next)
if (UiObjectMember *member = iter->member)
arrayMembers.append(member);
syncArrayProperty(modelProperty, arrayMembers, context, differenceHandler);
modelPropertyNames.remove(astPropertyName);
} else {
qWarning() << "Skipping invalid array property" << astPropertyName
......@@ -383,8 +388,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
if (isValidPropertyForNode(modelNode, astPropertyName)) {
AbstractProperty modelProperty = modelNode.property(astPropertyName);
if (modelProperty.metaInfo().isListProperty()) {
NodeListProperty listProperty = modelProperty.toNodeListProperty();
syncNodeListProperty(listProperty, QList<QmlJS::AST::UiObjectMember*>() << member, context, differenceHandler);
syncArrayProperty(modelProperty, QList<QmlJS::AST::UiObjectMember*>() << member, context, differenceHandler);
} else {
syncNodeProperty(modelProperty, binding, context, differenceHandler);
}
......@@ -538,15 +542,10 @@ void TextToModelMerger::syncExpressionProperty(AbstractProperty &modelProperty,
}
void TextToModelMerger::syncArrayProperty(AbstractProperty &modelProperty,
UiArrayBinding *array,
const QList<UiObjectMember *> &arrayMembers,
ReadingContext *context,
DifferenceHandler &differenceHandler)
{
QList<UiObjectMember *> arrayMembers;
for (UiArrayMemberList *iter = array->members; iter; iter = iter->next)
if (UiObjectMember *member = iter->member)
arrayMembers.append(member);
if (modelProperty.isNodeListProperty()) {
NodeListProperty nodeListProperty = modelProperty.toNodeListProperty();
syncNodeListProperty(nodeListProperty, arrayMembers, context, differenceHandler);
......
......@@ -78,7 +78,7 @@ public:
const QString &javascript,
DifferenceHandler &differenceHandler);
void syncArrayProperty(AbstractProperty &modelProperty,
QmlJS::AST::UiArrayBinding *array,
const QList<QmlJS::AST::UiObjectMember *> &arrayMembers,
ReadingContext *context,
DifferenceHandler &differenceHandler);
void syncVariantProperty(AbstractProperty &modelProperty,
......
......@@ -2441,6 +2441,7 @@ void TestCore::testRewriterForArrayMagic()
ModelNode rootNode = view->rootModelNode();
QVERIFY(rootNode.isValid());
QCOMPARE(rootNode.type(), QString("Qt/Rectangle"));
QVERIFY(rootNode.property(QLatin1String("states")).isNodeListProperty());
QmlItemNode rootItem(rootNode);
QVERIFY(rootItem.isValid());
......
Supports Markdown
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