diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp index 2208c4f5e46a6d06a776c5f6e5c00625f6a946f9..43521af494d7b6b5b74ee5f435c6bc571b6432f8 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp @@ -3278,6 +3278,121 @@ void TestCore::testSubComponentManager() QVERIFY(myButtonMetaInfo.property("border.width", true).isValid()); } +void TestCore::testAnchorsAndRewriting() +{ + const QString qmlString("import Qt 4.7\n" + "Rectangle {\n" + " id: root\n" + " x: 10;\n" + " y: 10;\n" + " Rectangle {\n" + " id: rectangle1\n" + " x: 10;\n" + " y: 10;\n" + " }\n" + " Component {\n" + " id: rectangleComponent\n" + " Rectangle {\n" + " x: 100;\n" + " y: 100;\n" + " }\n" + " }\n" + "}"); + + QSKIP("See BAUHAUS-729", SkipAll); + + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString); + NotIndentingTextEditModifier textModifier(&textEdit); + + QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QVERIFY(model.data()); + + QScopedPointer<TestView> view(new TestView); + model->attachView(view.data()); + + // read in + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&textModifier); + model->attachView(testRewriterView.data()); + + ModelNode rootNode = view->rootModelNode(); + QVERIFY(rootNode.isValid()); + QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + + QmlItemNode rootItemNode = view->rootQmlItemNode(); + QVERIFY(rootItemNode.isValid()); + + QmlItemNode childNode = rootItemNode.allDirectSubModelNodes().first(); + QVERIFY(childNode.isValid()); + + childNode.anchors().setMargin(AnchorLine::Left, 280); + childNode.anchors().setAnchor(AnchorLine::Left, rootItemNode, AnchorLine::Left); + childNode.anchors().setMargin(AnchorLine::Right, 200); + childNode.anchors().setAnchor(AnchorLine::Right, rootItemNode, AnchorLine::Right); + childNode.anchors().setMargin(AnchorLine::Bottom, 50); + childNode.anchors().setAnchor(AnchorLine::Bottom, rootItemNode, AnchorLine::Bottom); + + { + RewriterTransaction transaction = view->beginRewriterTransaction(); + + childNode.anchors().setMargin(AnchorLine::Top, 100); + childNode.anchors().setAnchor(AnchorLine::Top, rootItemNode, AnchorLine::Top); + } +} + +void TestCore::testAnchorsAndRewritingCenter() +{ + const QString qmlString("import Qt 4.7\n" + "Rectangle {\n" + " id: root\n" + " x: 10;\n" + " y: 10;\n" + " Rectangle {\n" + " id: rectangle1\n" + " x: 10;\n" + " y: 10;\n" + " }\n" + " Component {\n" + " id: rectangleComponent\n" + " Rectangle {\n" + " x: 100;\n" + " y: 100;\n" + " }\n" + " }\n" + "}"); + + //QSKIP("See BAUHAUS-729", SkipAll); + + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString); + NotIndentingTextEditModifier textModifier(&textEdit); + + QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QVERIFY(model.data()); + + QScopedPointer<TestView> view(new TestView); + model->attachView(view.data()); + + // read in + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&textModifier); + model->attachView(testRewriterView.data()); + + ModelNode rootNode = view->rootModelNode(); + QVERIFY(rootNode.isValid()); + QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + + QmlItemNode rootItemNode = view->rootQmlItemNode(); + QVERIFY(rootItemNode.isValid()); + + QmlItemNode childNode = rootItemNode.allDirectSubModelNodes().first(); + QVERIFY(childNode.isValid()); + + childNode.anchors().setAnchor(AnchorLine::VerticalCenter, rootItemNode, AnchorLine::VerticalCenter); + childNode.anchors().setAnchor(AnchorLine::HorizontalCenter, rootItemNode, AnchorLine::HorizontalCenter); +} + void TestCore::loadQml() { char qmlString[] = "import Qt 4.7\n" diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.h b/tests/auto/qml/qmldesigner/coretests/testcore.h index 91b4e1e0e5a652e5acd138a268da4c5b0ed61e49..5bfd5e9320cb5787924ae0eb51ab3286be1f66d8 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.h +++ b/tests/auto/qml/qmldesigner/coretests/testcore.h @@ -164,6 +164,8 @@ private slots: void testCopyModelRewriter1(); void testCopyModelRewriter2(); void testSubComponentManager(); + void testAnchorsAndRewriting(); + void testAnchorsAndRewritingCenter(); // // regression tests