From 2f301bc45b4ae06a7678812b1a3d5ec6755b76f8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bremer Date: Mon, 18 Apr 2016 13:06:41 +0200 Subject: [PATCH] CMake: Update qmljs codemodel With this patch it is possible to specify QML_IMPORT_PATH in CMake projects and QtCreator will scan those paths. One only has to make sure that the variable which is set in the CMakeLists.txt is also added to the CMakeCache.txt Task-number: QTCREATORBUG-11328 Change-Id: I11c7694806664d3203d855983e7db4a89fac267d Reviewed-by: Thomas Hartmann Reviewed-by: Tobias Hunger --- src/libs/qmljs/qmljslink.cpp | 3 +- .../cmakebuildconfiguration.h | 2 +- .../cmakeprojectmanager/cmakeproject.cpp | 36 +++++++++++++++++++ .../cmakeprojectmanager/cmakeproject.h | 1 + .../cmakeprojectmanager_dependencies.pri | 1 + 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index f46b228547b..1d9b633370a 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -437,7 +437,8 @@ Import LinkPrivate::importNonFile(Document::Ptr doc, const ImportInfo &importInf "For qmake projects, use the QML_IMPORT_PATH variable to add import paths.\n" "For Qbs projects, declare and set a qmlImportPaths property in your product " "to add import paths.\n" - "For qmlproject projects, use the importPaths property to add import paths.").arg( + "For qmlproject projects, use the importPaths property to add import paths.\n" + "For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.\n").arg( importPaths.join(QLatin1Char('\n')))); } diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h index 01a69102402..3ad06afa939 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h @@ -106,7 +106,7 @@ private: BuildDirManager *m_buildDirManager = nullptr; friend class CMakeBuildSettingsWidget; - friend class CMakeProject; + friend class CMakeProjectManager::CMakeProject; }; class CMakeBuildConfigurationFactory : public ProjectExplorer::IBuildConfigurationFactory diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index b7dcd0eaa69..4d5a44ae3c2 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -264,12 +265,47 @@ void CMakeProject::parseCMakeOutput() pinfo.finish(); m_codeModelFuture = modelmanager->updateProjectInfo(pinfo); + updateQmlJSCodeModel(); + emit displayNameChanged(); emit fileListChanged(); emit cmakeBc->emitBuildTypeChanged(); } +void CMakeProject::updateQmlJSCodeModel() +{ + QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance(); + QTC_ASSERT(modelManager, return); + + if (!activeTarget() || !activeTarget()->activeBuildConfiguration()) + return; + + QmlJS::ModelManagerInterface::ProjectInfo projectInfo = + modelManager->defaultProjectInfoForProject(this); + + projectInfo.importPaths.clear(); + + QString cmakeImports; + CMakeBuildConfiguration *bc = qobject_cast(activeTarget()->activeBuildConfiguration()); + if (!bc) + return; + + const QList &cm = bc->completeCMakeConfiguration(); + foreach (const ConfigModel::DataItem &di, cm) { + if (di.key.contains(QStringLiteral("QML_IMPORT_PATH"))) { + cmakeImports = di.value; + break; + } + } + + foreach (const QString &cmakeImport, cmakeImports.split(QLatin1Char(';'))) { + projectInfo.importPaths.maybeInsert(FileName::fromString(cmakeImport),QmlJS::Dialect::Qml); + } + + modelManager->updateProjectInfo(projectInfo, this); +} + bool CMakeProject::needsConfiguration() const { return targets().isEmpty(); diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index f6616ef9d8c..38126f5f9aa 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -124,6 +124,7 @@ private: void handleActiveBuildConfigurationChanged(); void handleParsingStarted(); void parseCMakeOutput(); + void updateQmlJSCodeModel(); void buildTree(Internal::CMakeProjectNode *rootNode, QList list); void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList &list) const; diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri b/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri index 41e9b7e0301..89094c8ad5c 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri @@ -1,6 +1,7 @@ QTC_PLUGIN_NAME = CMakeProjectManager QTC_LIB_DEPENDS += \ extensionsystem \ + qmljs \ utils QTC_PLUGIN_DEPENDS += \ coreplugin \