This import is automatically registered by the engine.
It provides basic language types (Component and QtObject).
Note that the QtQuick import still has these types registered into it,
so this commit doesn't break existing code.
Change-Id: I8ff190f057fc92969020cf8e896da1649ca3069b
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
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);
}
/*!
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()"));
}
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;
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;
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;
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)
void QQmlQtQuick2Module::defineModule()
{
QQuickUtilModule::defineModule();
- QQmlEnginePrivate::defineModule();
+ QQmlEnginePrivate::defineQtQuick2Module();
QQuickItemsModule::defineModule();
qmlRegisterUncreatableType<QQuickApplication>("QtQuick",2,0,"Application", QQuickApplication::tr("Application is an abstract class"));
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)
--- /dev/null
+import QtQml 2.0
+
+QtObject {
+}
--- /dev/null
+import QtQml 3.0
+
+QtObject {
+}
--- /dev/null
+import QtQml 1.0
+
+QtObject {
+}
--- /dev/null
+import QtQml 2.5
+
+QtObject {
+}
--- /dev/null
+import QtQml 2.0
+
+QtObject {
+ property Component c
+}
--- /dev/null
+import QtQml 2.0
+import QtQuick 2.0
+
+QtObject {
+}
--- /dev/null
+import QtQuick 2.0
+import QtQml 2.0
+
+QtObject {
+}
--- /dev/null
+// deliberately no imports
+
+// should fail
+QtObject {
+}
--- /dev/null
+import QtQml 2.0
+
+// Should fail.
+Item {
+}
void outputWarningsToStandardError();
void objectOwnership();
void multipleEngines();
+ void qtqmlModule_data();
+ void qtqmlModule();
public slots:
QObject *createAQObjectForOwnershipTest ()
}
}
+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"