aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2019-05-15 15:53:40 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2019-05-17 11:25:59 +0000
commit3f423fc13954581cc24357c42145e6faa5a87fa9 (patch)
treef0fe565265184dc13943532880994728803d6102 /tests/auto
parentb38657bcf6956570ab0da6f62cd92767898cb600 (diff)
QmlDesigner: Fix subtle issue with transaction
In an transaction adding a property after reparenting did fail without real reason. If a node does not have a position (yet) we can ingore the operation. Change-Id: I959f1cf50ac6bcacda2a29b37ae69e37158e9acd Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp37
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.h1
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
index 1a4eda3bcc..80658e0a88 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
@@ -1015,6 +1015,43 @@ void tst_TestCore::testRewriterUnicodeChars()
const QLatin1String unicodeChar("\nimport QtQuick 2.1\n\nText {\n text: \"\\u2795\"}\n");
QCOMPARE(textEdit.toPlainText(), unicodeChar);
+
+void tst_TestCore::testRewriterTransactionAddingAfterReparenting()
+{
+ const QLatin1String qmlString("\n"
+ "import QtQuick 2.0\n"
+ "\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());
+
+ {
+ /* Regression test
+ * If a node is not a direct child node of the root item we did get an exception when adding properties
+ * after the reparent */
+
+ RewriterTransaction transaction = testRewriterView->beginRewriterTransaction("TEST");
+ ModelNode rectangle = testRewriterView->createModelNode("QtQuick.Rectangle", 2, 0);
+ rootModelNode.nodeListProperty("data").reparentHere(rectangle);
+ ModelNode rectangle2 = testRewriterView->createModelNode("QtQuick.Rectangle", 2, 0);
+ rectangle.nodeListProperty("data").reparentHere(rectangle2);
+
+ rectangle2.variantProperty("width").setValue(100);
+ }
}
void tst_TestCore::testRewriterForGradientMagic()
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
index 3f1eec576b..92f3b17161 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
@@ -140,6 +140,7 @@ private slots:
void testRewriterImports();
void testRewriterChangeImports();
void testRewriterUnicodeChars();
+ void testRewriterTransactionAddingAfterReparenting();
//
// unit tests QmlModelNodeFacade/QmlModelState