From b149ee8dbbb9017f59e08895d0b2bafd8df14506 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Mon, 26 Apr 2010 16:21:40 +0200 Subject: [PATCH] Fixed invalid order when inserting new objects. Done-with: ckamm Task-number: BAUHAUS-631 --- .../core/filemanager/qmlrewriter.cpp | 22 +++++++++++-------- .../qml/qmldesigner/coretests/testcore.cpp | 2 -- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/plugins/qmldesigner/core/filemanager/qmlrewriter.cpp b/src/plugins/qmldesigner/core/filemanager/qmlrewriter.cpp index e148c80cca5..83a304e9315 100644 --- a/src/plugins/qmldesigner/core/filemanager/qmlrewriter.cpp +++ b/src/plugins/qmldesigner/core/filemanager/qmlrewriter.cpp @@ -276,29 +276,33 @@ void QMLRewriter::includeLeadingEmptyLine(int &start) const UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QStringList &propertyOrder) { const int objectDefinitionInsertionPoint = propertyOrder.indexOf(QString::null); - UiObjectMemberList *previous = 0; + + UiObjectMemberList *lastObjectDef = 0; + UiObjectMemberList *lastNonObjectDef = 0; + for (UiObjectMemberList *iter = members; iter; iter = iter->next) { UiObjectMember *member = iter->member; int idx = -1; - if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) + if (cast<UiObjectDefinition*>(member)) + lastObjectDef = iter; + else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) idx = propertyOrder.indexOf(flatten(arrayBinding->qualifiedId)); else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) idx = propertyOrder.indexOf(flatten(objectBinding->qualifiedId)); - else if (cast<UiObjectDefinition*>(member)) - idx = propertyOrder.indexOf(QString::null); else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) idx = propertyOrder.indexOf(flatten(scriptBinding->qualifiedId)); else if (cast<UiPublicMember*>(member)) idx = propertyOrder.indexOf(QLatin1String("property")); - if (idx > objectDefinitionInsertionPoint) - return iter; - - previous = iter; + if (idx < objectDefinitionInsertionPoint) + lastNonObjectDef = iter; } - return previous; + if (lastObjectDef) + return lastObjectDef; + else + return lastNonObjectDef; } UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QString &propertyName, const QStringList &propertyOrder) diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp index f42069fc794..e7da2755c5c 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp @@ -663,8 +663,6 @@ void TestCore::testRewriterPreserveOrder() QCOMPARE(newModelNode.id(), QString("rectangle2")); } - QSKIP("See BAUHAUS-631", SkipAll); - { QPlainTextEdit textEdit; textEdit.setPlainText(qmlString1); -- GitLab