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 <Thomas.Hartmann@theqtcompany.com>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Wolfgang Bremer
2016-04-18 13:06:41 +02:00
parent c90a356be6
commit 2f301bc45b
5 changed files with 41 additions and 2 deletions

View File

@@ -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'))));
}

View File

@@ -106,7 +106,7 @@ private:
BuildDirManager *m_buildDirManager = nullptr;
friend class CMakeBuildSettingsWidget;
friend class CMakeProject;
friend class CMakeProjectManager::CMakeProject;
};
class CMakeBuildConfigurationFactory : public ProjectExplorer::IBuildConfigurationFactory

View File

@@ -57,6 +57,7 @@
#include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h>
#include <cpptools/projectpartbuilder.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -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<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!bc)
return;
const QList<ConfigModel::DataItem> &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();

View File

@@ -124,6 +124,7 @@ private:
void handleActiveBuildConfigurationChanged();
void handleParsingStarted();
void parseCMakeOutput();
void updateQmlJSCodeModel();
void buildTree(Internal::CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list) const;

View File

@@ -1,6 +1,7 @@
QTC_PLUGIN_NAME = CMakeProjectManager
QTC_LIB_DEPENDS += \
extensionsystem \
qmljs \
utils
QTC_PLUGIN_DEPENDS += \
coreplugin \