diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-09-27 17:02:13 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-10-04 10:49:40 +0000 |
commit | 7749a47e621ceb5ef89f78508cda79a153156ece (patch) | |
tree | 0c1f7258ee7590b4509ae240fd312f714efef5bf /src/plugins/qtsupport/baseqtversion.cpp | |
parent | 0693db35795da7a1a8e777c5ce4a0df97ce34382 (diff) |
QtSupport: Move populateFileFinder to BaseQtVersion
This populates a file finder so that it is best able to find QML files,
prioritizing the given project/target. Some of it would also apply to a
non QML file finder, but as we don't use FileInProjectFinder for other
file types we keep the code here, for now.
Change-Id: I14e2ac63e699afe27d2f3af8ca3d57dfe732da8c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/qtsupport/baseqtversion.cpp')
-rw-r--r-- | src/plugins/qtsupport/baseqtversion.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index 03ef46e5b5..8a8e00c6c7 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -37,6 +37,9 @@ #include <projectexplorer/toolchain.h> #include <projectexplorer/projectexplorer.h> #include <projectexplorer/headerpath.h> +#include <projectexplorer/project.h> +#include <projectexplorer/session.h> +#include <projectexplorer/target.h> #include <qtsupport/qtkitinformation.h> #include <qtsupport/qtsupportconstants.h> @@ -47,6 +50,7 @@ #include <utils/runextensions.h> #include <utils/synchronousprocess.h> #include <utils/winutils.h> +#include <utils/fileinprojectfinder.h> #include <QDir> #include <QUrl> @@ -1318,6 +1322,53 @@ MacroExpander *BaseQtVersion::macroExpander() const return &m_expander; } +void BaseQtVersion::populateQmlFileFinder(FileInProjectFinder *finder, const Target *target) +{ + // If target given, then use the project associated with that ... + const ProjectExplorer::Project *startupProject = target ? target->project() : nullptr; + + // ... else try the session manager's global startup project ... + if (!startupProject) + startupProject = ProjectExplorer::SessionManager::startupProject(); + + // ... and if that is null, use the first project available. + const QList<ProjectExplorer::Project *> projects = ProjectExplorer::SessionManager::projects(); + QTC_CHECK(projects.isEmpty() || startupProject); + + QString projectDirectory; + QStringList sourceFiles; + + // Sort files from startupProject to the front of the list ... + if (startupProject) { + projectDirectory = startupProject->projectDirectory().toString(); + sourceFiles.append(startupProject->files(ProjectExplorer::Project::SourceFiles)); + } + + // ... then add all the other projects' files. + for (const ProjectExplorer::Project *project : projects) { + if (project != startupProject) + sourceFiles.append(project->files(ProjectExplorer::Project::SourceFiles)); + } + + // If no target was given, but we've found a startupProject, then try to deduce a + // target from that. + if (!target && startupProject) + target = startupProject->activeTarget(); + + // ... and find the sysroot and qml directory if we have any target at all. + const ProjectExplorer::Kit *kit = target ? target->kit() : nullptr; + QString activeSysroot = ProjectExplorer::SysRootKitInformation::sysRoot(kit).toString(); + const QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(kit); + QStringList additionalSearchDirectories = qtVersion + ? QStringList(qtVersion->qmlPath().toString()) : QStringList(); + + // Finally, do populate m_projectFinder + finder->setProjectDirectory(projectDirectory); + finder->setProjectFiles(sourceFiles); + finder->setSysroot(activeSysroot); + finder->setAdditionalSearchDirectories(additionalSearchDirectories); +} + void BaseQtVersion::addToEnvironment(const Kit *k, Environment &env) const { Q_UNUSED(k); |