From e307bc250676f22b753e5b4ee9014929e55686f6 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 9 Jun 2010 14:27:30 +0200 Subject: QmlJS: Store plugin metatypes in LibraryInfo. Rework type loading. --- src/plugins/qmljseditor/qmljsmodelmanager.cpp | 66 ++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'src/plugins/qmljseditor/qmljsmodelmanager.cpp') diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.cpp b/src/plugins/qmljseditor/qmljsmodelmanager.cpp index a418d023c9..a7db326466 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.cpp +++ b/src/plugins/qmljseditor/qmljsmodelmanager.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include @@ -85,7 +86,7 @@ void ModelManager::loadQmlTypeDescriptions() QDir::Files, QDir::Name); - const QStringList errors = Interpreter::CppQmlTypesLoader::instance()->load(xmlFiles); + const QStringList errors = Interpreter::CppQmlTypesLoader::load(xmlFiles); foreach (const QString &error, errors) qWarning() << qPrintable(error); } @@ -195,7 +196,7 @@ void ModelManager::onLibraryInfoUpdated(const QString &path, const LibraryInfo & QMutexLocker locker(&m_mutex); if (!_snapshot.libraryInfo(path).isValid()) - QmlJS::Interpreter::CppQmlTypesLoader::instance()->loadPluginTypes(path); + loadQmlPluginTypes(path); _snapshot.insertLibraryInfo(path, info); } @@ -435,3 +436,64 @@ static QStringList environmentImportPaths() return paths; } + +void ModelManager::loadQmlPluginTypes(const QString &pluginPath) +{ + static QString qmldumpPath; + if (qmldumpPath.isNull()) { + QDir qmldumpExecutable(QCoreApplication::applicationDirPath()); +#ifndef Q_OS_WIN + qmldumpPath = qmldumpExecutable.absoluteFilePath(QLatin1String("qmldump")); +#else + qmldumpPath = qmldumpExecutable.absoluteFilePath(QLatin1String("qmldump.exe")); +#endif + QFileInfo qmldumpFileInfo(qmldumpPath); + if (!qmldumpFileInfo.exists()) { + qWarning() << "ModelManager::loadQmlPluginTypes: qmldump executable does not exist at" << qmldumpPath; + qmldumpPath.clear(); + } else if (!qmldumpFileInfo.isFile()) { + qWarning() << "ModelManager::loadQmlPluginTypes: " << qmldumpPath << " is not a file"; + qmldumpPath.clear(); + } + + } + if (qmldumpPath.isEmpty()) + return; + + QProcess *process = new QProcess(this); + connect(process, SIGNAL(finished(int)), SLOT(qmlPluginTypeDumpDone(int))); + process->start(qmldumpPath, QStringList(pluginPath)); + m_runningQmldumps.insert(process, pluginPath); +} + +void ModelManager::qmlPluginTypeDumpDone(int exitCode) +{ + QProcess *process = qobject_cast(sender()); + if (!process) + return; + process->deleteLater(); + if (exitCode != 0) + return; + + const QByteArray output = process->readAllStandardOutput(); + QMap newObjects; + const QString error = Interpreter::CppQmlTypesLoader::parseQmlTypeXml(output, &newObjects); + if (!error.isEmpty()) + return; + + // convert from QList to QList + QList objectsList; + QMapIterator it(newObjects); + while (it.hasNext()) { + it.next(); + objectsList.append(it.value()); + } + + const QString libraryPath = m_runningQmldumps.take(process); + + QMutexLocker locker(&m_mutex); + + LibraryInfo libraryInfo = _snapshot.libraryInfo(libraryPath); + libraryInfo.setMetaObjects(objectsList); + _snapshot.insertLibraryInfo(libraryPath, libraryInfo); +} -- cgit v1.2.1