diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp index 93266f344eacc5b50a850be93d6358ef8f131ebe..11963857bdef4bab986d3536ee787f01f5b8799f 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp @@ -583,6 +583,124 @@ void TestCore::testRewriterGroupedProperties() QCOMPARE(textEdit.toPlainText(), expected); } +void TestCore::testRewriterPreserveOrder() +{ + const QLatin1String qmlString1("\n" + "import Qt 4.7\n" + "\n" + "Rectangle {\n" + "width: 640\n" + "height: 480\n" + "\n" + "states: [\n" + "State {\n" + "name: \"State1\"\n" + "}\n" + "]\n" + "\n" + "Rectangle {\n" + "id: rectangle1\n" + "x: 18\n" + "y: 19\n" + "width: 100\n" + "height: 100\n" + "}\n" + "}\n"); + const QLatin1String qmlString2("\n" + "import Qt 4.7\n" + "\n" + "Rectangle {\n" + "width: 640\n" + "height: 480\n" + "\n" + "Rectangle {\n" + "id: rectangle1\n" + "x: 18\n" + "y: 19\n" + "width: 100\n" + "height: 100\n" + "}\n" + "states: [\n" + "State {\n" + "name: \"State1\"\n" + "}\n" + "]\n" + "\n" + "}\n"); + + { + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString2); + NotIndentingTextEditModifier modifier(&textEdit); + + QScopedPointer<Model> model(Model::create("Qt/Text")); + + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&modifier); + model->attachView(testRewriterView.data()); + + QVERIFY(testRewriterView->errors().isEmpty()); + + ModelNode rootModelNode = testRewriterView->rootModelNode(); + QVERIFY(rootModelNode.isValid()); + + RewriterTransaction transaction = testRewriterView->beginRewriterTransaction(); + + ModelNode newModelNode = testRewriterView->createModelNode("Qt/Rectangle", 4, 7); + + newModelNode.setParentProperty(rootModelNode.nodeAbstractProperty("data")); + + newModelNode.setId("rectangle2"); + QCOMPARE(newModelNode.id(), QString("rectangle2")); + + newModelNode.variantProperty("x") = 10; + newModelNode.variantProperty("y") = 10; + newModelNode.variantProperty("width") = 100; + newModelNode.variantProperty("height") = 100; + + transaction.commit(); + + QCOMPARE(newModelNode.id(), QString("rectangle2")); + } + + QSKIP("See BAUHAUS-631", SkipAll); + + { + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString1); + NotIndentingTextEditModifier modifier(&textEdit); + + QScopedPointer<Model> model(Model::create("Qt/Text")); + + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&modifier); + model->attachView(testRewriterView.data()); + + QVERIFY(testRewriterView->errors().isEmpty()); + + ModelNode rootModelNode = testRewriterView->rootModelNode(); + QVERIFY(rootModelNode.isValid()); + + RewriterTransaction transaction = testRewriterView->beginRewriterTransaction(); + + ModelNode newModelNode = testRewriterView->createModelNode("Qt/Rectangle", 4, 7); + + newModelNode.setParentProperty(rootModelNode.nodeAbstractProperty("data")); + + newModelNode.setId("rectangle2"); + QCOMPARE(newModelNode.id(), QString("rectangle2")); + + newModelNode.variantProperty("x") = 10; + newModelNode.variantProperty("y") = 10; + newModelNode.variantProperty("width") = 100; + newModelNode.variantProperty("height") = 100; + + transaction.commit(); + + QCOMPARE(newModelNode.id(), QString("rectangle2")); + } +} + void TestCore::loadSubItems() { QFile file(QString(QTCREATORDIR) + "/tests/auto/qml/qmldesigner/data/fx/topitem.qml"); diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.h b/tests/auto/qml/qmldesigner/coretests/testcore.h index cb1b73660a505b4be6f16a7c8f2a08d486646604..525d555ea7d49db0c3c76066db869e3beb16adba 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.h +++ b/tests/auto/qml/qmldesigner/coretests/testcore.h @@ -120,6 +120,7 @@ private slots: void testRewriterExceptionHandling(); void testRewriterDynamicProperties(); void testRewriterGroupedProperties(); + void testRewriterPreserveOrder(); //