summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2022-06-22 14:32:02 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2022-06-22 13:56:38 +0000
commit092a1fc6a3b9668df3028b071d871f6f43f1e156 (patch)
treecd07ad74e8841a58e89c15551a8c0ed1892e118b /tests
parent2cb45cbb6b12048a1e7e02877a56d63a09e708ed (diff)
downloadqt-creator-092a1fc6a3b9668df3028b071d871f6f43f1e156.tar.gz
QmlDesigner: Support reparenting to new nodes in transactions
When we reparent to a new node that was created during the same transaction, then this node has no position. In this case we have to delete the reparented nodes and they will be created as part of the creation of the new node, since they are children. Change-Id: Icd1d02f29f529fc0f00809f7ecebf3eabfdc9a5c Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp73
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.h1
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
index 26b8ddcf8e..f6708d2c8f 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
@@ -1152,6 +1152,79 @@ void tst_TestCore::testRewriterTransactionAddingAfterReparenting()
}
}
+void tst_TestCore::testRewriterReparentToNewNode()
+{
+ const QLatin1String qmlString("\n"
+ "import QtQuick 2.0\n"
+ "\n"
+ "Item {\n"
+ " Item {}\n"
+ " Item {}\n"
+ " Item {}\n"
+ " Item {}\n"
+ "}\n");
+
+ QPlainTextEdit textEdit;
+ textEdit.setPlainText(qmlString);
+ NotIndentingTextEditModifier modifier(&textEdit);
+
+ QScopedPointer<Model> model(Model::create("QtQuick.Rectangle"));
+
+ QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView(0, RewriterView::Amend));
+ testRewriterView->setTextModifier(&modifier);
+ model->attachView(testRewriterView.data());
+
+ QVERIFY(testRewriterView->errors().isEmpty());
+
+ ModelNode rootModelNode = testRewriterView->rootModelNode();
+ QVERIFY(rootModelNode.isValid());
+
+ const QList<ModelNode> children = rootModelNode.directSubModelNodes();
+
+ ModelNode rectangle = testRewriterView->createModelNode("QtQuick.Rectangle", 2, 0);
+ rootModelNode.nodeListProperty("data").reparentHere(rectangle);
+
+ rectangle.setIdWithoutRefactoring("newParent");
+
+ QVERIFY(rectangle.isValid());
+
+ for (const ModelNode &child : children)
+ rectangle.nodeListProperty("data").reparentHere(child);
+
+ {
+ RewriterTransaction transaction = testRewriterView->beginRewriterTransaction("TEST");
+ ModelNode rectangle = testRewriterView->createModelNode("QtQuick.Rectangle", 2, 0);
+ rootModelNode.nodeListProperty("data").reparentHere(rectangle);
+
+ rectangle.setIdWithoutRefactoring("newParent2");
+
+ for (const ModelNode &child : children)
+ rectangle.nodeListProperty("data").reparentHere(child);
+ }
+
+ QCOMPARE(testRewriterView->allModelNodes().count(), 7);
+
+ const QLatin1String expectedOutcome("\nimport QtQuick 2.0\n\n"
+ "Item {\n\n"
+ " Rectangle {\n"
+ " id: newParent\n"
+ " }\n\n"
+ " Rectangle {\n"
+ " id: newParent2\n"
+ " Item {\n"
+ " }\n\n"
+ " Item {\n"
+ " }\n\n"
+ " Item {\n"
+ " }\n\n"
+ " Item {\n"
+ " }\n"
+ " }\n}\n");
+
+
+ QCOMPARE(textEdit.toPlainText(), expectedOutcome);
+}
+
void tst_TestCore::testRewriterForGradientMagic()
{
const QLatin1String qmlString("\n"
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
index 9a8aeb6450..5248763fef 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
@@ -144,6 +144,7 @@ private slots:
void testRewriterChangeImports();
void testRewriterUnicodeChars();
void testRewriterTransactionAddingAfterReparenting();
+ void testRewriterReparentToNewNode();
//
// unit tests QmlModelNodeFacade/QmlModelState