diff options
author | Robin Burchell <robin+qt@viroteck.net> | 2012-08-31 11:24:42 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-04 09:27:45 (GMT) |
commit | b5e6ca71283f0f68b7ba6d9fe9663650751ad43e (patch) | |
tree | 4a8c80646e34e299c3d740488231bbcd9cf3355f /src | |
parent | d252cc7896200d6c82c345453fcb4d4fc3b42834 (diff) | |
download | Qt-b5e6ca71283f0f68b7ba6d9fe9663650751ad43e.zip Qt-b5e6ca71283f0f68b7ba6d9fe9663650751ad43e.tar.gz Qt-b5e6ca71283f0f68b7ba6d9fe9663650751ad43e.tar.bz2 |
Register Qt 4.7 import on-demand, instead of at startup.
This is a slightly less awkward approach (keeps backwards-compatibility) while
speeding up startup for applications that don't use the old import path.
Also prints a warning to let developers know they should migrate their code when
possible. Completely disabling the Qt 4.7 import is still possible by setting
QT_NO_IMPORT_QT47_QML.
This takes around 10-15ms off a very simple "hello world" on my macbook.
(backport of qtquick1/2a3e9eb0ba00acf30b9cc40f7e2e4347726fb6b4)
Change-Id: I6960e7c28bb4f153d793802b978c1944977e8ed4
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp | 11 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitemsmodule_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 19 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativemetatype.cpp | 20 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativevaluetype.cpp | 10 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativevaluetype_p.h | 1 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeutilmodule.cpp | 11 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativeutilmodule_p.h | 3 |
9 files changed, 58 insertions, 19 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 0f7c1bb..7ea24d7 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -96,6 +96,9 @@ static QDeclarativePrivate::AutoParentResult qgraphicsobject_autoParent(QObject void QDeclarativeItemModule::defineModule() { + if (QApplication::type() == QApplication::Tty) + return; + QDeclarativePrivate::RegisterAutoParent autoparent = { 0, &qgraphicsobject_autoParent }; QDeclarativePrivate::qmlregister(QDeclarativePrivate::AutoParentRegistration, &autoparent); #ifdef QT_NO_MOVIE @@ -199,8 +202,13 @@ void QDeclarativeItemModule::defineModule() qmlRegisterRevision<QDeclarativeImplicitSizePaintedItem,0>("QtQuick",1,0); qmlRegisterRevision<QDeclarativeImplicitSizePaintedItem,1>("QtQuick",1,1); qmlRegisterUncreatableType<QDeclarativeLayoutMirroringAttached>("QtQuick",1,1,"LayoutMirroring", QDeclarativeLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties")); +} + +void QDeclarativeItemModule::defineModuleCompat() +{ + if (QApplication::type() == QApplication::Tty) + return; -#ifndef QT_NO_IMPORT_QT47_QML #ifdef QT_NO_MOVIE qmlRegisterTypeNotAvailable("Qt",4,7,"AnimatedImage", qApp->translate("QDeclarativeAnimatedImage","Qt was built without support for QMovie")); @@ -257,5 +265,4 @@ void QDeclarativeItemModule::defineModule() qmlRegisterUncreatableType<QDeclarativeKeyNavigationAttached>("Qt",4,7,"KeyNavigation",QDeclarativeKeyNavigationAttached::tr("KeyNavigation is only available via attached properties")); qmlRegisterUncreatableType<QDeclarativeKeysAttached>("Qt",4,7,"Keys",QDeclarativeKeysAttached::tr("Keys is only available via attached properties")); -#endif } diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule_p.h b/src/declarative/graphicsitems/qdeclarativeitemsmodule_p.h index 49aac3c..af18180 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule_p.h @@ -54,6 +54,7 @@ class QDeclarativeItemModule { public: static void defineModule(); + static void defineModuleCompat(); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 343b299..3ada9f4 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -189,13 +189,14 @@ void QDeclarativeEnginePrivate::defineModule() qmlRegisterType<QObject>("QtQuick",1,0,"QtObject"); qmlRegisterType<QDeclarativeWorkerScript>("QtQuick",1,0,"WorkerScript"); -#ifndef QT_NO_IMPORT_QT47_QML + qmlRegisterType<QDeclarativeBinding>(); +} + +void QDeclarativeEnginePrivate::defineModuleCompat() +{ qmlRegisterType<QDeclarativeComponent>("Qt",4,7,"Component"); qmlRegisterType<QObject>("Qt",4,7,"QtObject"); qmlRegisterType<QDeclarativeWorkerScript>("Qt",4,7,"WorkerScript"); -#endif - - qmlRegisterType<QDeclarativeBinding>(); } /*! @@ -357,13 +358,9 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) if (!qt_QmlQtModule_registered) { qt_QmlQtModule_registered = true; QDeclarativeEnginePrivate::defineModule(); - - const QApplication::Type appType = QApplication::type(); - if (appType != QApplication::Tty) { - QDeclarativeItemModule::defineModule(); - QDeclarativeValueTypeFactory::registerValueTypes(); - } - QDeclarativeUtilModule::defineModule(appType); + QDeclarativeItemModule::defineModule(); + QDeclarativeValueTypeFactory::registerValueTypes(); + QDeclarativeUtilModule::defineModule(); } globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine); } diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 42e8a96..cc1d552 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -324,6 +324,7 @@ public: static QString urlToLocalFileOrQrc(const QUrl& url); static void defineModule(); + static void defineModuleCompat(); static bool qml_debugging_enabled; }; diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 745e87c..3517b7c 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -45,6 +45,9 @@ #include "private/qdeclarativeproxymetaobject_p.h" #include "private/qdeclarativecustomparser_p.h" #include "private/qdeclarativeguard_p.h" +#include "private/qdeclarativeengine_p.h" +#include "private/qdeclarativeitemsmodule_p.h" +#include "private/qdeclarativeutilmodule_p.h" #include <QtCore/qdebug.h> #include <QtCore/qstringlist.h> @@ -690,6 +693,23 @@ int QDeclarativePrivate::qmlregister(RegistrationType type, void *data) */ bool QDeclarativeMetaType::isModule(const QByteArray &module, int versionMajor, int versionMinor) { +#ifndef QT_NO_IMPORT_QT47_QML + // "import Qt 4.7" should have died off, but unfortunately, it was in a + // major release. We don't register 4.7 types by default, as it's a + // performance penalty. Instead, register them on-demand. + if (strcmp(module.constData(), "Qt") == 0 && versionMajor == 4 && versionMinor == 7) { + static bool qt47Registered = false; + if (!qt47Registered) { + qWarning() << Q_FUNC_INFO << "Qt 4.7 import detected; please note that Qt 4.7 is directly reusable as QtQuick 1.x with no code changes. Continuing, but startup time will be slower."; + qt47Registered = true; + QDeclarativeEnginePrivate::defineModuleCompat(); + QDeclarativeItemModule::defineModuleCompat(); + QDeclarativeValueTypeFactory::registerValueTypesCompat(); + QDeclarativeUtilModule::defineModuleCompat(); + } + } +#endif + QDeclarativeMetaTypeData *data = metaTypeData(); QDeclarativeMetaTypeData::ModuleInfoHash::Iterator it = data->modules.find(module); return it != data->modules.end() diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index 77c5ede..9d8648c 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -44,6 +44,7 @@ #include "private/qdeclarativemetatype_p.h" #include "private/qfont_p.h" +#include <QtGui/qapplication.h> #include <QtCore/qdebug.h> QT_BEGIN_NAMESPACE @@ -101,10 +102,15 @@ void QDeclarativeValueTypeFactory::registerValueTypes() { qmlRegisterValueTypeEnums<QDeclarativeEasingValueType>("QtQuick",1,0,"Easing"); qmlRegisterValueTypeEnums<QDeclarativeFontValueType>("QtQuick",1,0,"Font"); -#ifndef QT_NO_IMPORT_QT47_QML +} + +void QDeclarativeValueTypeFactory::registerValueTypesCompat() +{ + if (QApplication::type() == QApplication::Tty) + return; + qmlRegisterValueTypeEnums<QDeclarativeEasingValueType>("Qt",4,7,"Easing"); qmlRegisterValueTypeEnums<QDeclarativeFontValueType>("Qt",4,7,"Font"); -#endif } QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index 79561d2..1b03adc 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -90,6 +90,7 @@ public: static QDeclarativeValueType *valueType(int); static void registerValueTypes(); + static void registerValueTypesCompat(); QDeclarativeValueType *operator[](int idx) const { if (idx < 0 || idx >= (int)QVariant::UserType) return 0; diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 4402730..29ddd26 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -74,9 +74,9 @@ #include "private/qdeclarativexmllistmodel_p.h" #endif -void QDeclarativeUtilModule::defineModule(QApplication::Type appType) +void QDeclarativeUtilModule::defineModule() { - if (appType != QApplication::Tty) { + if (QApplication::type() != QApplication::Tty) { qmlRegisterUncreatableType<QDeclarativeApplication>("QtQuick",1,1,"Application", QDeclarativeApplication::tr("Application is an abstract class")); qmlRegisterType<QDeclarativeAnchorAnimation>("QtQuick",1,0,"AnchorAnimation"); @@ -127,9 +127,12 @@ void QDeclarativeUtilModule::defineModule(QApplication::Type appType) qmlRegisterCustomType<QDeclarativeConnections>("QtQuick",1,0,"Connections", new QDeclarativeConnectionsParser); qmlRegisterCustomType<QDeclarativePropertyChanges>("QtQuick",1,0,"PropertyChanges", new QDeclarativePropertyChangesParser); qmlRegisterCustomType<QDeclarativeListModel>("QtQuick",1,0,"ListModel", new QDeclarativeListModelParser); +} +void QDeclarativeUtilModule::defineModuleCompat() +{ #ifndef QT_NO_IMPORT_QT47_QML - if (appType != QApplication::Tty) { + if (QApplication::type() != QApplication::Tty) { qmlRegisterType<QDeclarativeAnchorAnimation>("Qt",4,7,"AnchorAnimation"); qmlRegisterType<QDeclarativeAnchorChanges>("Qt",4,7,"AnchorChanges"); qmlRegisterType<QDeclarativeBehavior>("Qt",4,7,"Behavior"); @@ -162,6 +165,7 @@ void QDeclarativeUtilModule::defineModule(QApplication::Type appType) qmlRegisterType<QDeclarativeState>("Qt",4,7,"State"); qmlRegisterType<QDeclarativeStateChangeScript>("Qt",4,7,"StateChangeScript"); qmlRegisterType<QDeclarativeListElement>("Qt",4,7,"ListElement"); + #ifdef QT_NO_XMLPATTERNS qmlRegisterTypeNotAvailable("Qt",4,7,"XmlListModel", qApp->translate("QDeclarativeXmlListModel","Qt was built without support for xmlpatterns")); @@ -176,3 +180,4 @@ void QDeclarativeUtilModule::defineModule(QApplication::Type appType) qmlRegisterCustomType<QDeclarativeListModel>("Qt", 4,7, "ListModel", new QDeclarativeListModelParser); #endif } + diff --git a/src/declarative/util/qdeclarativeutilmodule_p.h b/src/declarative/util/qdeclarativeutilmodule_p.h index dbd2619..15b7d41 100644 --- a/src/declarative/util/qdeclarativeutilmodule_p.h +++ b/src/declarative/util/qdeclarativeutilmodule_p.h @@ -54,7 +54,8 @@ QT_MODULE(Declarative) class QDeclarativeUtilModule { public: - static void defineModule(QApplication::Type appType); + static void defineModule(); + static void defineModuleCompat(); }; QT_END_NAMESPACE |