diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 2ff810ffb1bf0e40841dc497bbc3d2185f4c351a..c076773821eeb8ec596f91094ca510d657b8e201 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -33,6 +33,7 @@ #include "qmljsdocument.h" #include "qmljsbind.h" #include "qmljsscopebuilder.h" +#include "qmljsmodelmanagerinterface.h" #include <QtCore/QFileInfo> #include <QtCore/QDir> @@ -302,14 +303,22 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A if (!dir.cd(packagePath)) continue; - const LibraryInfo libraryInfo = _snapshot.libraryInfo(dir.path()); + const QString &libraryPath = dir.path(); + const LibraryInfo libraryInfo = _snapshot.libraryInfo(libraryPath); if (!libraryInfo.isValid()) continue; importFound = true; - if (!libraryInfo.plugins().isEmpty()) - engine()->cppQmlTypes().load(engine(), libraryInfo.metaObjects()); + if (!libraryInfo.plugins().isEmpty()) { + if (libraryInfo.metaObjects().isEmpty()) { + ModelManagerInterface *modelManager = ModelManagerInterface::instance(); + if (modelManager) + modelManager->loadPluginTypes(libraryPath, importPath, Bind::toString(import->importUri, QLatin1Char('.'))); + } else { + engine()->cppQmlTypes().load(engine(), libraryInfo.metaObjects()); + } + } QSet<QString> importedTypes; foreach (const QmlDirParser::Component &component, libraryInfo.components()) { diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 7cd4e9bc47dbaaef30af0fab8c42aa168d8c1fb7..896878bceb7e94117ebe35a3fdf4847f1db309e8 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -94,6 +94,8 @@ public: virtual QStringList importPaths() const = 0; + virtual void loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri) = 0; + signals: void documentUpdated(QmlJS::Document::Ptr doc); void documentChangedOnDisk(QmlJS::Document::Ptr doc); diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.cpp b/src/plugins/qmljseditor/qmljsmodelmanager.cpp index 836ce34a15fedb8207280fa3a3d4331f9179c028..6bbe8a0b7f2d95563ce5ffc044b939cf9d62d4d5 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.cpp +++ b/src/plugins/qmljseditor/qmljsmodelmanager.cpp @@ -228,9 +228,6 @@ void ModelManager::onLibraryInfoUpdated(const QString &path, const LibraryInfo & { QMutexLocker locker(&m_mutex); - if (!_snapshot.libraryInfo(path).isValid()) - loadQmlPluginTypes(path); - _snapshot.insertLibraryInfo(path, info); } @@ -453,8 +450,20 @@ static QStringList environmentImportPaths() return paths; } -void ModelManager::loadQmlPluginTypes(const QString &pluginPath) +void ModelManager::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri) +{ + // make sure loading is always triggered in ModelManager's thread + metaObject()->invokeMethod(this, "onLoadPluginTypes", + Q_ARG(QString, libraryPath), + Q_ARG(QString, importPath), + Q_ARG(QString, importUri)); +} + +void ModelManager::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri) { + if (m_runningQmldumps.values().contains(libraryPath)) + return; + static QString qmldumpPath; if (qmldumpPath.isNull()) { QDir qmldumpExecutable(QCoreApplication::applicationDirPath()); @@ -482,8 +491,11 @@ void ModelManager::loadQmlPluginTypes(const QString &pluginPath) QProcess *process = new QProcess(this); connect(process, SIGNAL(finished(int)), SLOT(qmlPluginTypeDumpDone(int))); - process->start(qmldumpPath, QStringList(pluginPath)); - m_runningQmldumps.insert(process, pluginPath); + QStringList args; + args << importPath; + args << importUri; + process->start(qmldumpPath, args); + m_runningQmldumps.insert(process, libraryPath); } void ModelManager::updateImportPaths() diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.h b/src/plugins/qmljseditor/qmljsmodelmanager.h index 41d93fbf781b1ccd8629dbc1f88f485483208cd9..7b5ca21242a8cb1c15f2c47f45540a41add2b13d 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.h +++ b/src/plugins/qmljseditor/qmljsmodelmanager.h @@ -69,6 +69,8 @@ public: virtual QStringList importPaths() const; + virtual void loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri); + Q_SIGNALS: void projectPathChanged(const QString &projectPath); void libraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info); @@ -77,6 +79,7 @@ private Q_SLOTS: // this should be executed in the GUI thread. void onDocumentUpdated(QmlJS::Document::Ptr doc); void onLibraryInfoUpdated(const QString &path, const QmlJS::LibraryInfo &info); + void onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri); void qmlPluginTypeDumpDone(int exitCode); protected: @@ -98,7 +101,6 @@ protected: bool emitDocChangedOnDisk); void loadQmlTypeDescriptions(); - void loadQmlPluginTypes(const QString &pluginPath); void updateImportPaths(); diff --git a/src/tools/qml/qmldump/main.cpp b/src/tools/qml/qmldump/main.cpp index 99c70553a2ad04a0be0fcc29f1a24e21ff828da9..24678d5030a98845203813956a3679dc93b1a7ef 100644 --- a/src/tools/qml/qmldump/main.cpp +++ b/src/tools/qml/qmldump/main.cpp @@ -243,19 +243,16 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - if (argc != 1 && argc != 2) { - qWarning() << "Usage: qmldump [path/to/plugin/directory]"; + if (argc != 1 && argc != 3) { + qWarning() << "Usage: qmldump [plugin/import/path plugin.uri]"; return 1; } QString pluginImportName; QString pluginImportPath; - if (argc == 2) { - QFileInfo pluginPath(argv[1]); - if (pluginPath.exists() && pluginPath.isDir()) { - pluginImportPath = pluginPath.absolutePath(); - pluginImportName = pluginPath.fileName(); - } + if (argc == 3) { + pluginImportPath = QString(argv[1]); + pluginImportName = QString(argv[2]); } QDeclarativeView view; @@ -265,12 +262,14 @@ int main(int argc, char *argv[]) QByteArray importCode; importCode += "import Qt 4.7;\n"; - importCode += "import Qt.labs.particles 4.7;\n"; - importCode += "import Qt.labs.gestures 4.7;\n"; - importCode += "import Qt.labs.folderlistmodel 4.7;\n"; - importCode += "import QtWebKit 1.0;\n"; - if (!pluginImportName.isEmpty()) + if (pluginImportName.isEmpty()) { + importCode += "import Qt.labs.particles 4.7;\n"; + importCode += "import Qt.labs.gestures 4.7;\n"; + importCode += "import Qt.labs.folderlistmodel 4.7;\n"; + importCode += "import QtWebKit 1.0;\n"; + } else { importCode += QString("import %0 1.0;\n").arg(pluginImportName).toAscii(); + } { QByteArray code = importCode;