diff --git a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp index b2289095986..b3083ebe541 100644 --- a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include @@ -209,55 +209,7 @@ void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc) void QmlProfilerDetailsRewriter::populateFileFinder(const ProjectExplorer::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 projects = ProjectExplorer::SessionManager::projects(); - if (!startupProject && !projects.isEmpty()) - startupProject = projects.first(); - - 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 deduct a - // target from that. - if (!target && startupProject) - target = startupProject->activeTarget(); - - // ... and find the sysroot if we have any target at all. - QString activeSysroot; - QStringList additionalSearchDirectories; - if (target) { - if (const ProjectExplorer::Kit *kit = target->kit()) { - if (ProjectExplorer::SysRootKitInformation::hasSysRoot(kit)) - activeSysroot = ProjectExplorer::SysRootKitInformation::sysRoot(kit).toString(); - if (QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(kit)) - additionalSearchDirectories.append(qtVersion->qmlPath().toString()); - } - } - - // Finally, do populate m_projectFinder - m_projectFinder.setProjectDirectory(projectDirectory); - m_projectFinder.setProjectFiles(sourceFiles); - m_projectFinder.setSysroot(activeSysroot); - m_projectFinder.setAdditionalSearchDirectories(additionalSearchDirectories); + QtSupport::BaseQtVersion::populateQmlFileFinder(&m_projectFinder, target); m_filesCache.clear(); } diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index 03ef46e5b55..8a8e00c6c7f 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include #include #include @@ -47,6 +50,7 @@ #include #include #include +#include #include #include @@ -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 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); diff --git a/src/plugins/qtsupport/baseqtversion.h b/src/plugins/qtsupport/baseqtversion.h index 0970f31b0dd..da5e6480cd6 100644 --- a/src/plugins/qtsupport/baseqtversion.h +++ b/src/plugins/qtsupport/baseqtversion.h @@ -36,7 +36,10 @@ #include #include -namespace Utils { class Environment; } +namespace Utils { +class Environment; +class FileInProjectFinder; +} namespace Core { class Id; } namespace ProjectExplorer { @@ -44,6 +47,7 @@ class IOutputParser; class Kit; class ToolChain; class HeaderPath; +class Target; class Task; } // namespace ProjectExplorer @@ -227,6 +231,9 @@ public: Utils::MacroExpander *macroExpander() const; // owned by the Qt version + static void populateQmlFileFinder(Utils::FileInProjectFinder *finder, + const ProjectExplorer::Target *target); + protected: BaseQtVersion(); BaseQtVersion(const Utils::FileName &path, bool isAutodetected = false, const QString &autodetectionSource = QString());