introduce *.ui.qml file types as new forms file type
authorTim Jenssen <tim.jenssen@digia.com>
Fri, 29 Aug 2014 11:09:53 +0000 (13:09 +0200)
committerTim Jenssen <tim.jenssen@digia.com>
Fri, 29 Aug 2014 11:15:49 +0000 (13:15 +0200)
Change-Id: I1f07b6c1ab8afac7ee7ad05e988fe313ba904705
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
src/qml/qml/qqmlimport.cpp
tests/auto/qml/qqmlimport/FormFromQmlDir/TestForm.ui.qml [new file with mode: 0644]
tests/auto/qml/qqmlimport/FormFromQmlDir/qmldir [new file with mode: 0644]
tests/auto/qml/qqmlimport/data/FormFromDir/TestForm.ui.qml [new file with mode: 0644]
tests/auto/qml/qqmlimport/data/TestForm.ui.qml [new file with mode: 0644]
tests/auto/qml/qqmlimport/data/openTestFormFromDir.qml [new file with mode: 0644]
tests/auto/qml/qqmlimport/data/openTestFormFromQmlDir.qml [new file with mode: 0644]
tests/auto/qml/qqmlimport/tst_qqmlimport.cpp

index 141cd4a..df4006d 100644 (file)
@@ -665,6 +665,13 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
             exists = QQmlFile::bundleFileExists(qmlUrl, typeLoader->engine());
         } else {
             exists = !typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(qmlUrl)).isEmpty();
+            if (!exists) {
+                QString formUrl = url + QString::fromRawData(type.constData(), type.length()) + QStringLiteral(".ui.qml");
+                if (!typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(formUrl)).isEmpty()) {
+                    exists = true;
+                    qmlUrl = formUrl;
+                }
+            }
             if (!exists)
                 exists = QQmlMetaType::findCachedCompilationUnit(QUrl(qmlUrl));
         }
diff --git a/tests/auto/qml/qqmlimport/FormFromQmlDir/TestForm.ui.qml b/tests/auto/qml/qqmlimport/FormFromQmlDir/TestForm.ui.qml
new file mode 100644 (file)
index 0000000..837835f
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+    property bool success: true
+}
diff --git a/tests/auto/qml/qqmlimport/FormFromQmlDir/qmldir b/tests/auto/qml/qqmlimport/FormFromQmlDir/qmldir
new file mode 100644 (file)
index 0000000..95dfedc
--- /dev/null
@@ -0,0 +1,2 @@
+module FormFromQmlDir
+TestForm 1.0 TestForm.ui.qml
diff --git a/tests/auto/qml/qqmlimport/data/FormFromDir/TestForm.ui.qml b/tests/auto/qml/qqmlimport/data/FormFromDir/TestForm.ui.qml
new file mode 100644 (file)
index 0000000..837835f
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+    property bool success: true
+}
diff --git a/tests/auto/qml/qqmlimport/data/TestForm.ui.qml b/tests/auto/qml/qqmlimport/data/TestForm.ui.qml
new file mode 100644 (file)
index 0000000..837835f
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+    property bool success: true
+}
diff --git a/tests/auto/qml/qqmlimport/data/openTestFormFromDir.qml b/tests/auto/qml/qqmlimport/data/openTestFormFromDir.qml
new file mode 100644 (file)
index 0000000..a1d7396
--- /dev/null
@@ -0,0 +1,4 @@
+import "FormFromDir"
+
+TestForm {
+}
diff --git a/tests/auto/qml/qqmlimport/data/openTestFormFromQmlDir.qml b/tests/auto/qml/qqmlimport/data/openTestFormFromQmlDir.qml
new file mode 100644 (file)
index 0000000..aea8d0f
--- /dev/null
@@ -0,0 +1,4 @@
+import FormFromQmlDir 1.0
+
+TestForm {
+}
index bd29b8f..33a6c6f 100644 (file)
@@ -52,6 +52,7 @@ class tst_QQmlImport : public QQmlDataTest
 
 private slots:
     void testDesignerSupported();
+    void uiFormatLoading();
     void cleanup();
 };
 
@@ -95,6 +96,45 @@ void tst_QQmlImport::testDesignerSupported()
     delete window;
 }
 
+void tst_QQmlImport::uiFormatLoading()
+{
+    int size = 0;
+
+    QQmlApplicationEngine *test = new QQmlApplicationEngine(testFileUrl("TestForm.ui.qml"));
+    test->addImportPath(QT_TESTCASE_BUILDDIR);
+    QCOMPARE(test->rootObjects().size(), ++size);
+    QVERIFY(test->rootObjects()[size -1]);
+    QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+    QSignalSpy objectCreated(test, SIGNAL(objectCreated(QObject*,QUrl)));
+    test->load(testFileUrl("TestForm.ui.qml"));
+    QCOMPARE(objectCreated.count(), size);//one less than rootObjects().size() because we missed the first one
+    QCOMPARE(test->rootObjects().size(), ++size);
+    QVERIFY(test->rootObjects()[size -1]);
+    QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+    QByteArray testQml("import QtQml 2.0; QtObject{property bool success: true; property TestForm t: TestForm{}}");
+    test->loadData(testQml, testFileUrl("dynamicTestForm.ui.qml"));
+    QCOMPARE(objectCreated.count(), size);
+    QCOMPARE(test->rootObjects().size(), ++size);
+    QVERIFY(test->rootObjects()[size -1]);
+    QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+    test->load(testFileUrl("openTestFormFromDir.qml"));
+    QCOMPARE(objectCreated.count(), size);
+    QCOMPARE(test->rootObjects().size(), ++size);
+    QVERIFY(test->rootObjects()[size -1]);
+    QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+    test->load(testFileUrl("openTestFormFromQmlDir.qml"));
+    QCOMPARE(objectCreated.count(), size);
+    QCOMPARE(test->rootObjects().size(), ++size);
+    QVERIFY(test->rootObjects()[size -1]);
+    QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+    delete test;
+}
+
 QTEST_MAIN(tst_QQmlImport)
 
 #include "tst_qqmlimport.moc"