diff options
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 29 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetype.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetype_p.h | 3 | ||||
-rw-r--r-- | src/quick/qtquick2.cpp | 2 | ||||
-rw-r--r-- | src/quick/util/qquickvaluetypes.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.1.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.2.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.3.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.4.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.5.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.6.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.7.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.8.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/data/qtqmlModule.9.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 75 |
16 files changed, 147 insertions, 26 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index ca1ac84046..3017c7336c 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -104,7 +104,8 @@ QT_BEGIN_NAMESPACE void qmlRegisterBaseTypes(const char *uri, int versionMajor, int versionMinor) { QQmlEnginePrivate::registerBaseTypes(uri, versionMajor, versionMinor); - QQmlValueTypeFactory::registerBaseTypes(uri, versionMajor, versionMinor); + QQmlEnginePrivate::registerQtQuick2Types(uri, versionMajor, versionMinor); + QQmlValueTypeFactory::registerValueTypes(uri, versionMajor, versionMinor); } /*! @@ -165,19 +166,30 @@ void qmlRegisterBaseTypes(const char *uri, int versionMajor, int versionMinor) bool QQmlEnginePrivate::qml_debugging_enabled = false; +// these types are part of the QML language void QQmlEnginePrivate::registerBaseTypes(const char *uri, int versionMajor, int versionMinor) { qmlRegisterType<QQmlComponent>(uri,versionMajor,versionMinor,"Component"); qmlRegisterType<QObject>(uri,versionMajor,versionMinor,"QtObject"); - qmlRegisterType<QQuickListElement>(uri, versionMajor, versionMinor,"ListElement"); - qmlRegisterCustomType<QQuickListModel>(uri, versionMajor, versionMinor,"ListModel", new QQuickListModelParser); - qmlRegisterType<QQuickWorkerScript>(uri,versionMajor,versionMinor,"WorkerScript"); } -void QQmlEnginePrivate::defineModule() + +// These QtQuick types' implementation resides in the QtQml module +void QQmlEnginePrivate::registerQtQuick2Types(const char *uri, int versionMajor, int versionMinor) { - registerBaseTypes("QtQuick", 2, 0); - qmlRegisterUncreatableType<QQmlLocale>("QtQuick",2,0,"Locale",QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); + qmlRegisterType<QQuickListElement>(uri, versionMajor, versionMinor, "ListElement"); + qmlRegisterCustomType<QQuickListModel>(uri, versionMajor, versionMinor, "ListModel", new QQuickListModelParser); + qmlRegisterType<QQuickWorkerScript>(uri, versionMajor, versionMinor, "WorkerScript"); +} + +void QQmlEnginePrivate::defineQtQuick2Module() +{ + // register the base types into the QtQuick namespace + registerBaseTypes("QtQuick",2,0); + + // register the QtQuick2 types which are implemented in the QtQml module. + registerQtQuick2Types("QtQuick",2,0); + qmlRegisterUncreatableType<QQmlLocale>("QtQuick", 2, 0, "Locale", QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); } @@ -602,7 +614,8 @@ void QQmlEnginePrivate::init() static bool firstTime = true; if (firstTime) { - qmlRegisterType<QQmlComponent>("QML", 1, 0, "Component"); + qmlRegisterType<QQmlComponent>("QML", 1, 0, "Component"); // required for the Compiler. + registerBaseTypes("QtQml", 2, 0); // import which provides language building blocks. QQmlData::init(); firstTime = false; diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index f74ded8159..b90d597be6 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -267,7 +267,8 @@ public: inline static QQmlEngine *get(QQmlEnginePrivate *p); static void registerBaseTypes(const char *uri, int versionMajor, int versionMinor); - static void defineModule(); + static void registerQtQuick2Types(const char *uri, int versionMajor, int versionMinor); + static void defineQtQuick2Module(); static bool qml_debugging_enabled; diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp index b96c2f65a4..c0759a31b4 100644 --- a/src/qml/qml/qqmlvaluetype.cpp +++ b/src/qml/qml/qqmlvaluetype.cpp @@ -72,16 +72,11 @@ bool QQmlValueTypeFactory::isValueType(int idx) return false; } -void QQmlValueTypeFactory::registerBaseTypes(const char *uri, int versionMajor, int versionMinor) +void QQmlValueTypeFactory::registerValueTypes(const char *uri, int versionMajor, int versionMinor) { qmlRegisterValueTypeEnums<QQmlEasingValueType>(uri, versionMajor, versionMinor, "Easing"); } -void QQmlValueTypeFactory::registerValueTypes() -{ - registerBaseTypes("QtQuick", 2, 0); -} - QQmlValueType *QQmlValueTypeFactory::valueType(int t) { QQmlValueType *rv = 0; diff --git a/src/qml/qml/qqmlvaluetype_p.h b/src/qml/qml/qqmlvaluetype_p.h index 776847af6f..f704da2c8e 100644 --- a/src/qml/qml/qqmlvaluetype_p.h +++ b/src/qml/qml/qqmlvaluetype_p.h @@ -145,8 +145,7 @@ public: static bool isValueType(int); static QQmlValueType *valueType(int); - static void registerBaseTypes(const char *uri, int versionMajor, int versionMinor); - static void registerValueTypes(); + static void registerValueTypes(const char *uri, int versionMajor, int versionMinor); QQmlValueType *operator[](int idx) const { if (idx >= (int)QVariant::UserType) diff --git a/src/quick/qtquick2.cpp b/src/quick/qtquick2.cpp index ed1fa0da6d..ae2d245dd9 100644 --- a/src/quick/qtquick2.cpp +++ b/src/quick/qtquick2.cpp @@ -173,7 +173,7 @@ void QQmlQtQuick2DebugStatesDelegate::resetBindingForInvalidProperty(QObject *ob void QQmlQtQuick2Module::defineModule() { QQuickUtilModule::defineModule(); - QQmlEnginePrivate::defineModule(); + QQmlEnginePrivate::defineQtQuick2Module(); QQuickItemsModule::defineModule(); qmlRegisterUncreatableType<QQuickApplication>("QtQuick",2,0,"Application", QQuickApplication::tr("Application is an abstract class")); diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp index 179f840acd..e3da2658b4 100644 --- a/src/quick/util/qquickvaluetypes.cpp +++ b/src/quick/util/qquickvaluetypes.cpp @@ -49,14 +49,11 @@ QT_BEGIN_NAMESPACE namespace QQuickValueTypes { - -void registerValueTypes() -{ - QQmlValueTypeFactory::registerValueTypes(); - - qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font"); -} - + void registerValueTypes() + { + QQmlValueTypeFactory::registerValueTypes("QtQuick", 2, 0); + qmlRegisterValueTypeEnums<QQuickFontValueType>("QtQuick", 2, 0, "Font"); + } } QQuickColorValueType::QQuickColorValueType(QObject *parent) diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.1.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.1.qml new file mode 100644 index 0000000000..e879577e10 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.1.qml @@ -0,0 +1,4 @@ +import QtQml 2.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.2.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.2.qml new file mode 100644 index 0000000000..6cbe96b1ee --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.2.qml @@ -0,0 +1,4 @@ +import QtQml 3.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.3.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.3.qml new file mode 100644 index 0000000000..1160c2827c --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.3.qml @@ -0,0 +1,4 @@ +import QtQml 1.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.4.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.4.qml new file mode 100644 index 0000000000..9b9b7922da --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.4.qml @@ -0,0 +1,4 @@ +import QtQml 2.5 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.5.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.5.qml new file mode 100644 index 0000000000..7a4fe5ed24 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.5.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property Component c +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.6.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.6.qml new file mode 100644 index 0000000000..e8cc22fd5b --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.6.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 +import QtQuick 2.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.7.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.7.qml new file mode 100644 index 0000000000..619489b22e --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.7.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 +import QtQml 2.0 + +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.8.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.8.qml new file mode 100644 index 0000000000..59bf31662c --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.8.qml @@ -0,0 +1,5 @@ +// deliberately no imports + +// should fail +QtObject { +} diff --git a/tests/auto/qml/qqmlengine/data/qtqmlModule.9.qml b/tests/auto/qml/qqmlengine/data/qtqmlModule.9.qml new file mode 100644 index 0000000000..cbf90b9dd1 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/qtqmlModule.9.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +// Should fail. +Item { +} diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 85c32d8118..c9d3e27afe 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -75,6 +75,8 @@ private slots: void outputWarningsToStandardError(); void objectOwnership(); void multipleEngines(); + void qtqmlModule_data(); + void qtqmlModule(); public slots: QObject *createAQObjectForOwnershipTest () @@ -565,6 +567,79 @@ void tst_qqmlengine::multipleEngines() } } +void tst_qqmlengine::qtqmlModule_data() +{ + QTest::addColumn<QUrl>("testFile"); + QTest::addColumn<QString>("expectedError"); + QTest::addColumn<QStringList>("expectedWarnings"); + + QTest::newRow("import QtQml of correct version (2.0)") + << testFileUrl("qtqmlModule.1.qml") + << QString() + << QStringList(); + + QTest::newRow("import QtQml of incorrect version (3.0)") + << testFileUrl("qtqmlModule.2.qml") + << QString(testFileUrl("qtqmlModule.2.qml").toString() + QLatin1String(":1 module \"QtQml\" version 3.0 is not installed\n")) + << QStringList(); + + QTest::newRow("import QtQml of incorrect version (1.0)") + << testFileUrl("qtqmlModule.3.qml") + << QString(testFileUrl("qtqmlModule.3.qml").toString() + QLatin1String(":1 module \"QtQml\" version 1.0 is not installed\n")) + << QStringList(); + + QTest::newRow("import QtQml of incorrect version (2.5)") + << testFileUrl("qtqmlModule.4.qml") + << QString(testFileUrl("qtqmlModule.4.qml").toString() + QLatin1String(":1 module \"QtQml\" version 2.5 is not installed\n")) + << QStringList(); + + QTest::newRow("QtQml 2.0 module provides Component and QtObject") + << testFileUrl("qtqmlModule.5.qml") + << QString() + << QStringList(); + + QTest::newRow("can import QtQml then QtQuick") + << testFileUrl("qtqmlModule.6.qml") + << QString() + << QStringList(); + + QTest::newRow("can import QtQuick then QtQml") + << testFileUrl("qtqmlModule.7.qml") + << QString() + << QStringList(); + + QTest::newRow("no import results in no QtObject availability") + << testFileUrl("qtqmlModule.8.qml") + << QString(testFileUrl("qtqmlModule.8.qml").toString() + QLatin1String(":4 QtObject is not a type\n")) + << QStringList(); + + QTest::newRow("importing QtQml only results in no Item availability") + << testFileUrl("qtqmlModule.9.qml") + << QString(testFileUrl("qtqmlModule.9.qml").toString() + QLatin1String(":4 Item is not a type\n")) + << QStringList(); +} + +// Test that the engine registers the QtQml module +void tst_qqmlengine::qtqmlModule() +{ + QFETCH(QUrl, testFile); + QFETCH(QString, expectedError); + QFETCH(QStringList, expectedWarnings); + + foreach (const QString &w, expectedWarnings) + QTest::ignoreMessage(QtWarningMsg, qPrintable(w)); + + QQmlEngine e; + QQmlComponent c(&e, testFile); + if (expectedError.isEmpty()) { + QObject *o = c.create(); + QVERIFY(o); + delete o; + } else { + QCOMPARE(c.errorString(), expectedError); + } +} + QTEST_MAIN(tst_qqmlengine) #include "tst_qqmlengine.moc" |