summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppprojectpartchooser.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-12 18:01:12 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-16 10:17:50 +0000
commite4e65726614fa4e3ee02f25db755d959850441ea (patch)
treea76a4aab899eb313f25f0da8a1f3e89ede71b67b /src/plugins/cpptools/cppprojectpartchooser.cpp
parent4416eecc024e155438c7ed6399182dbff143bd0d (diff)
downloadqt-creator-e4e65726614fa4e3ee02f25db755d959850441ea.tar.gz
CppTools: Allow interpreting ambiguous headers as C headers
...instead of C++ headers. For the Clang Code Model this results in using "-x c-header" instead of "-x c++-header". This introduces a new option in Options > C++ > "Code Model" to configure this. Change-Id: I8a0ce8fa6155f5ef58743ebc7f1d0b500fbf6599 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppprojectpartchooser.cpp')
-rw-r--r--src/plugins/cpptools/cppprojectpartchooser.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/plugins/cpptools/cppprojectpartchooser.cpp b/src/plugins/cpptools/cppprojectpartchooser.cpp
index 19c40c5fe0..5f7d3de137 100644
--- a/src/plugins/cpptools/cppprojectpartchooser.cpp
+++ b/src/plugins/cpptools/cppprojectpartchooser.cpp
@@ -31,25 +31,39 @@
namespace CppTools {
namespace Internal {
-static int priority(const ProjectPart &projectPart, const ProjectExplorer::Project *activeProject)
+static bool isPreferredLanguage(const ProjectPart &projectPart, Language preference)
+{
+ const bool isCProjectPart = projectPart.languageVersion <= ProjectPart::LatestCVersion;
+ return (preference == Language::C && isCProjectPart)
+ || (preference == Language::Cxx && !isCProjectPart);
+}
+
+static int priority(const ProjectPart &projectPart,
+ const ProjectExplorer::Project *activeProject,
+ Language languagePreference)
{
int thePriority = 0;
if (projectPart.project == activeProject)
- thePriority += 10;
+ thePriority += 100;
if (projectPart.selectedForBuilding)
+ thePriority += 10;
+
+ if (isPreferredLanguage(projectPart, languagePreference))
thePriority += 1;
return thePriority;
}
static ProjectPart::Ptr chooseFromMultiple(const QList<ProjectPart::Ptr> &projectParts,
- const ProjectExplorer::Project *activeProject)
+ const ProjectExplorer::Project *activeProject,
+ Language languagePreference)
{
QList<ProjectPart::Ptr> projectPartsPrioritized = projectParts;
- const auto lessThan = [activeProject] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
- return priority(*p1, activeProject) > priority(*p2, activeProject);
+ const auto lessThan = [&] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
+ return priority(*p1, activeProject, languagePreference)
+ > priority(*p2, activeProject, languagePreference);
};
std::stable_sort(projectPartsPrioritized.begin(), projectPartsPrioritized.end(), lessThan);
@@ -61,6 +75,7 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
const ProjectPart::Ptr &manuallySetProjectPart,
bool stickToPreviousProjectPart,
const ProjectExplorer::Project *activeProject,
+ Language languagePreference,
bool projectHasChanged) const
{
QTC_CHECK(m_projectPartsForFile);
@@ -85,10 +100,10 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
// Fall-back step 2: Use fall-back part from the model manager:
projectPart = m_fallbackProjectPart();
else
- projectPart = chooseFromMultiple(projectParts, activeProject);
+ projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
} else {
if (projectHasChanged || !projectParts.contains(projectPart))
- projectPart = chooseFromMultiple(projectParts, activeProject);
+ projectPart = chooseFromMultiple(projectParts, activeProject, languagePreference);
}
return projectPart;