summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2022-07-13 12:07:58 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2022-07-13 15:33:07 +0000
commitaeea22257c32ac06c71a9183c5964372fd7d01eb (patch)
tree0685133d14187823abd07673a7cf0c58f3ba69b4 /tests
parentc505d6a72e80114521f23105738f814585e36356 (diff)
downloadqt-creator-aeea22257c32ac06c71a9183c5964372fd7d01eb.tar.gz
QmlDesigner: Add support for Behaviours
A Behavior will be added as a normal ModelNode to the default property, but we store the property name in behaviorPropertyName. The value of behaviorPropertyName cannot be changed after the ModelNode was created, since I do not see any use case and it keeps things simple. Change-Id: I69ba1d4d706432cfbbd35b001238f623e6e0b4fd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp97
-rw-r--r--tests/auto/qml/qmldesigner/coretests/tst_testcore.h1
2 files changed, 98 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
index ef77342719..4813ac96f2 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp
@@ -1248,6 +1248,103 @@ void tst_TestCore::testRewriterReparentToNewNode()
QCOMPARE(testRewriterView->allModelNodes().count(), 8);
}
+void tst_TestCore::testRewriterBehaivours()
+{
+ const QLatin1String qmlString("\n"
+ "import QtQuick 2.0\n"
+ "\n"
+ "Item {\n"
+ " Item {}\n"
+ " Item {}\n"
+ " Behavior on width {\n"
+ " NumberAnimation { duration: 1000 }\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());
+
+ const QList<ModelNode> children = rootModelNode.directSubModelNodes();
+
+ QCOMPARE(children.count(), 4);
+
+ ModelNode behavior;
+ for (const ModelNode &child : children) {
+ if (child.type() == "QtQuick.Behavior")
+ behavior = child;
+ }
+
+ QVERIFY(behavior.isValid());
+ QVERIFY(!behavior.behaviorPropertyName().isEmpty());
+ QCOMPARE(behavior.behaviorPropertyName(), "width");
+
+ QVERIFY(!behavior.directSubModelNodes().isEmpty());
+
+ ModelNode animation = behavior.directSubModelNodes().first();
+
+ QVERIFY(animation.isValid());
+
+ NodeMetaInfo metaInfo = behavior.metaInfo();
+
+ QVERIFY(metaInfo.isValid());
+
+ ModelNode newBehavior = testRewriterView->createModelNode("QtQuick.Behavior",
+ metaInfo.majorVersion(),
+ metaInfo.minorVersion(),
+ {},
+ {},
+ {},
+ ModelNode::NodeWithoutSource,
+ "height");
+
+ rootModelNode.defaultNodeListProperty().reparentHere(newBehavior);
+
+ QCOMPARE(newBehavior.behaviorPropertyName(), "height");
+
+ metaInfo = animation.metaInfo();
+ QVERIFY(metaInfo.isValid());
+ ModelNode newAnimation = testRewriterView->createModelNode(metaInfo.typeName(),
+ metaInfo.majorVersion(),
+ metaInfo.minorVersion());
+
+ newBehavior.defaultNodeListProperty().reparentHere(newAnimation);
+
+ newAnimation.variantProperty("duration").setValue(500);
+
+ const QLatin1String expextedQmlCode(
+ "\nimport QtQuick 2.0\n\n"
+ "Item {\n Item {}\n Item {}\n"
+ " Behavior on width {\n "
+ " NumberAnimation { duration: 1000 }\n"
+ " }\n"
+ " Item {}\n\n"
+ " Behavior on height {\n"
+ " NumberAnimation {\n"
+ " duration: 500\n"
+ " }\n }\n}\n");
+
+
+ QCOMPARE(textEdit.toPlainText(), expextedQmlCode);
+
+ newBehavior.destroy();
+
+ QVERIFY(!newBehavior.isValid());
+}
+
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 5248763fef..d55bb2a196 100644
--- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
+++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h
@@ -145,6 +145,7 @@ private slots:
void testRewriterUnicodeChars();
void testRewriterTransactionAddingAfterReparenting();
void testRewriterReparentToNewNode();
+ void testRewriterBehaivours();
//
// unit tests QmlModelNodeFacade/QmlModelState