diff options
14 files changed, 45 insertions, 35 deletions
diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp index f6385d0..741f68a 100644 --- a/examples/declarative/plugins/plugin.cpp +++ b/examples/declarative/plugins/plugin.cpp @@ -144,11 +144,10 @@ class QExampleQmlPlugin : public QDeclarativeExtensionPlugin { Q_OBJECT public: - void initialize(QDeclarativeEngine *engine, const char *uri) + void registerTypes(const char *uri) { - Q_UNUSED(engine); Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample")); - qmlRegisterType<Time>(uri, 1, 0, "Time", "Time"); + qmlRegisterType<Time>(uri, 1, 0, "Time"); } }; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 8abea4e..b4850a9 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1624,7 +1624,16 @@ bool QDeclarativeEngine::importExtension(const QString &fileName, const QString QPluginLoader loader(fileName); if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) { - iface->initialize(this, uri.toUtf8().constData()); + const QByteArray bytes = uri.toUtf8(); + const char *moduleId = bytes.constData(); + + QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this); + if (! d->importedPlugins.contains(fileName)) { + d->importedPlugins.insert(fileName); + iface->registerTypes(moduleId); + } + + iface->initializeEngine(this, moduleId); return true; } @@ -1669,7 +1678,6 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString const QStringList &suffixes, const QString &prefix) { - qWarning() << baseName; foreach (const QString &suffix, suffixes) { QString pluginFileName = prefix; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 2364315..6ef2f93 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -267,6 +267,7 @@ public: QStringList environmentImportPath; + QSet<QString> importedPlugins; QString resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, diff --git a/src/declarative/qml/qdeclarativeextensioninterface.h b/src/declarative/qml/qdeclarativeextensioninterface.h index a8ae064..0fabd6d 100644 --- a/src/declarative/qml/qdeclarativeextensioninterface.h +++ b/src/declarative/qml/qdeclarativeextensioninterface.h @@ -55,7 +55,8 @@ class QDeclarativeEngine; struct Q_DECLARATIVE_EXPORT QDeclarativeExtensionInterface { virtual ~QDeclarativeExtensionInterface() {} - virtual void initialize(QDeclarativeEngine *engine, const char *uri) = 0; + virtual void registerTypes(const char *uri) = 0; + virtual void initializeEngine(QDeclarativeEngine *engine, const char *uri) = 0; }; Q_DECLARE_INTERFACE(QDeclarativeExtensionInterface, "com.trolltech.Qt.QDeclarativeExtensionInterface/1.0") diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp index 6af3a6d..3d44d63 100644 --- a/src/declarative/qml/qdeclarativeextensionplugin.cpp +++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp @@ -63,9 +63,9 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QDeclarativeExtensionPlugin::initialize(QDeclarativeEngine *engine) + \fn void QDeclarativeExtensionPlugin::registerTypes(const char *uri) - Initializes the extension specified in the given \a engine. + Registers the QML types in the given \a uri. */ /*! @@ -84,4 +84,16 @@ QDeclarativeExtensionPlugin::~QDeclarativeExtensionPlugin() { } +/*! + \fn void QDeclarativeExtensionPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri) + + Initializes the extension specified in the given \a engine. +*/ + +void QDeclarativeExtensionPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri) +{ + Q_UNUSED(engine); + Q_UNUSED(uri); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeextensionplugin.h b/src/declarative/qml/qdeclarativeextensionplugin.h index 79df52b..c2ad798 100644 --- a/src/declarative/qml/qdeclarativeextensionplugin.h +++ b/src/declarative/qml/qdeclarativeextensionplugin.h @@ -62,7 +62,8 @@ public: explicit QDeclarativeExtensionPlugin(QObject *parent = 0); ~QDeclarativeExtensionPlugin(); - virtual void initialize(QDeclarativeEngine *engine, const char *uri) = 0; + virtual void registerTypes(const char *uri) = 0; + virtual void initializeEngine(QDeclarativeEngine *engine, const char *uri); }; QT_END_NAMESPACE diff --git a/src/multimedia/qml/multimediadeclarative.cpp b/src/multimedia/qml/multimediadeclarative.cpp index 086250a..7f5298f 100644 --- a/src/multimedia/qml/multimediadeclarative.cpp +++ b/src/multimedia/qml/multimediadeclarative.cpp @@ -55,14 +55,13 @@ namespace QtMultimedia \internal */ -void qRegisterDeclarativeElements(QDeclarativeEngine *engine, const char *uri) +void qRegisterDeclarativeElements(const char *uri) { - Q_UNUSED(engine) Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.multimedia")); - qmlRegisterType<QSoundEffect>("Qt.multimedia", 4, 7, "SoundEffect"); - qmlRegisterType<QDeclarativeAudio>("Qt.multimedia", 4, 7, "Audio"); - qmlRegisterType<QDeclarativeVideo>("Qt.multimedia", 4, 7, "Video"); + qmlRegisterType<QSoundEffect>(uri, 4, 7, "SoundEffect"); + qmlRegisterType<QDeclarativeAudio>(uri, 4, 7, "Audio"); + qmlRegisterType<QDeclarativeVideo>(uri, 4, 7, "Video"); } } diff --git a/src/multimedia/qml/multimediadeclarative.h b/src/multimedia/qml/multimediadeclarative.h index befddb6..29af65a 100644 --- a/src/multimedia/qml/multimediadeclarative.h +++ b/src/multimedia/qml/multimediadeclarative.h @@ -49,11 +49,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Multimedia) -class QDeclarativeEngine; - namespace QtMultimedia { -extern void Q_MULTIMEDIA_EXPORT qRegisterDeclarativeElements(QDeclarativeEngine* engine, const char *uri); +extern void Q_MULTIMEDIA_EXPORT qRegisterDeclarativeElements(const char *uri); } QT_END_NAMESPACE diff --git a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp b/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp index e27dd8d..8becbf3 100644 --- a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp +++ b/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp @@ -49,9 +49,9 @@ class QMultimediaQmlModule : public QDeclarativeExtensionPlugin { Q_OBJECT public: - virtual void initialize(QDeclarativeEngine *engine, const char *uri) + virtual void registerTypes(const char *uri) { - QtMultimedia::qRegisterDeclarativeElements(engine, uri); + QtMultimedia::qRegisterDeclarativeElements(uri); } }; diff --git a/src/plugins/qdeclarativemodules/widgets/widgets.cpp b/src/plugins/qdeclarativemodules/widgets/widgets.cpp index 7229d88..ec21cc4 100644 --- a/src/plugins/qdeclarativemodules/widgets/widgets.cpp +++ b/src/plugins/qdeclarativemodules/widgets/widgets.cpp @@ -114,15 +114,8 @@ class QWidgetsQmlModule : public QDeclarativeExtensionPlugin { Q_OBJECT public: - QStringList keys() const + virtual void registerTypes(const char *uri) { - return QStringList() << QLatin1String("Qt.widgets"); - } - - virtual void initialize(QDeclarativeEngine *engine, const char *uri) - { - Q_UNUSED(engine); - Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); QML_REGISTER_INTERFACE(QGraphicsLayoutItem); diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir b/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir new file mode 100644 index 0000000..0a8b5d4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemoduleplugin/com/nokia/AutoTestQmlPluginType/qmldir @@ -0,0 +1 @@ +plugin plugin diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.cpp b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.cpp index 154693c..fd94cc6 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.cpp +++ b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.cpp @@ -73,15 +73,10 @@ public: qWarning("plugin created"); } - QStringList keys() const - { - return QStringList() << QLatin1String("com.nokia.AutoTestQmlPluginType"); - } - - void initialize(QDeclarativeEngine*, const char *uri) + void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == "com.nokia.AutoTestQmlPluginType"); - QML_REGISTER_TYPE(com.nokia.AutoTestQmlPluginType,1,0,MyPluginType,MyPluginType); + qmlRegisterType<MyPluginType>(uri, 1, 0, "MyPluginType"); } }; diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro index 348080d..035cb7d 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro +++ b/tests/auto/declarative/qdeclarativemoduleplugin/plugin/plugin.pro @@ -2,4 +2,5 @@ TEMPLATE = lib CONFIG += plugin SOURCES = plugin.cpp QT = core declarative -DESTDIR = qdeclarativemodules +DESTDIR = ../com/nokia/AutoTestQmlPluginType + diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro index dd65511..d895ed0 100644 --- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro +++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.pro @@ -1,4 +1,5 @@ load(qttest_p4) SOURCES = tst_qdeclarativemoduleplugin.cpp QT += declarative +CONFIG -= app_bundle DEFINES += SRCDIR=\\\"$$PWD\\\" |