diff options
author | Eike Ziller <eike.ziller@digia.com> | 2013-06-27 14:24:57 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2013-06-27 14:24:57 +0200 |
commit | c9128b7fdd59f8482fcd5e8bc5e0d481ad5e86d1 (patch) | |
tree | 421eb840b83dc79a2fd958eb4af25c88d0dce97f /src/plugins/cpptools/cpptoolsplugin.cpp | |
parent | 9055eea11f86fce9157970088af0832cff17e1df (diff) | |
parent | 6c8f87556a2c7acdddca750e078b568ba082acf3 (diff) | |
download | qt-creator-c9128b7fdd59f8482fcd5e8bc5e0d481ad5e86d1.tar.gz |
Merge remote-tracking branch 'origin/2.8'
Conflicts:
qtcreator.pri
qtcreator.qbs
Change-Id: I1aa7506519e0f461f33921ca20ce1b51adb5783f
Diffstat (limited to 'src/plugins/cpptools/cpptoolsplugin.cpp')
-rw-r--r-- | src/plugins/cpptools/cpptoolsplugin.cpp | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 93b2a80482..7f2bdbd24c 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -237,6 +237,35 @@ static int commonStringLength(const QString &s1, const QString &s2) return length; } +static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo, + const QStringList &candidateFileNames, + const ProjectExplorer::Project *project) +{ + QString bestFileName; + int compareValue = 0; + const QString filePath = fileInfo.filePath(); + foreach (const QString &candidateFileName, candidateFileNames) { + const QStringList projectFiles = findFilesInProject(candidateFileName, project); + // Find the file having the most common path with fileName + foreach (const QString &projectFile, projectFiles) { + int value = commonStringLength(filePath, projectFile); + if (value > compareValue) { + compareValue = value; + bestFileName = projectFile; + } + } + } + if (!bestFileName.isEmpty()) { + const QFileInfo candidateFi(bestFileName); + QTC_ASSERT(candidateFi.isFile(), return QString()); + m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath(); + m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath(); + return candidateFi.absoluteFilePath(); + } + + return QString(); +} + } // namespace Internal QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) @@ -287,29 +316,26 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader) } } - // Find files in the project - ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject(); - if (project) { - QString bestFileName; - int compareValue = 0; - foreach (const QString &candidateFileName, candidateFileNames) { - const QStringList projectFiles = findFilesInProject(candidateFileName, project); - // Find the file having the most common path with fileName - foreach (const QString &projectFile, projectFiles) { - int value = commonStringLength(fileName, projectFile); - if (value > compareValue) { - compareValue = value; - bestFileName = projectFile; - } - } - } - if (!bestFileName.isEmpty()) { - const QFileInfo candidateFi(bestFileName); - QTC_ASSERT(candidateFi.isFile(), return QString()); - m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath(); - m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath(); - return candidateFi.absoluteFilePath(); - } + // Find files in the current project + ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject(); + if (currentProject) { + const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, + currentProject); + if (!path.isEmpty()) + return path; + } + + // Find files in other projects + CppModelManager *modelManager = CppModelManager::instance(); + QList<CppModelManagerInterface::ProjectInfo> projectInfos = modelManager->projectInfos(); + foreach (const CppModelManagerInterface::ProjectInfo &projectInfo, projectInfos) { + const ProjectExplorer::Project *project = projectInfo.project().data(); + if (project == currentProject) + continue; // We have already checked the current project. + + const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, project); + if (!path.isEmpty()) + return path; } return QString(); |