summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppmodelmanager.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-19 15:46:40 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2017-01-26 07:52:54 +0000
commit741596481900347ef4c69d80efdffe710e79ff6b (patch)
treec7c9471da1abe791de994d8256fcf2b53d03dbbe /src/plugins/cpptools/cppmodelmanager.cpp
parentbddfe21961f59ee471b302da9bc7a5c7ee4f561d (diff)
downloadqt-creator-741596481900347ef4c69d80efdffe710e79ff6b.tar.gz
CppTools: Fix choosing project part after project open
As long as there are project parts for a source file, always determine the best project part, instead of trying to stick to the previous one. This ensures the best project part at all times and simplifies the code. Change-Id: I25ea3eb43a5a3e6d93688d4b8965f596dc9ae22b Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppmodelmanager.cpp')
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 330501d3b3..0d9a3e6722 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -793,7 +793,7 @@ void CppModelManager::watchForCanceledProjectIndexer(QFuture<void> future,
watcher->setFuture(future);
}
-void CppModelManager::updateCppEditorDocuments(bool hasActiveProjectChanged) const
+void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const
{
// Refresh visible documents
QSet<Core::IDocument *> visibleCppEditorDocuments;
@@ -802,7 +802,7 @@ void CppModelManager::updateCppEditorDocuments(bool hasActiveProjectChanged) con
const QString filePath = document->filePath().toString();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
visibleCppEditorDocuments.insert(document);
- theCppEditorDocument->processor()->run(hasActiveProjectChanged);
+ theCppEditorDocument->processor()->run(projectsUpdated);
}
}
}
@@ -814,9 +814,9 @@ void CppModelManager::updateCppEditorDocuments(bool hasActiveProjectChanged) con
foreach (Core::IDocument *document, invisibleCppEditorDocuments) {
const QString filePath = document->filePath().toString();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
- const CppEditorDocumentHandle::RefreshReason refreshReason = hasActiveProjectChanged
- ? CppEditorDocumentHandle::ActiveProjectChange
- : CppEditorDocumentHandle::Usual;
+ const CppEditorDocumentHandle::RefreshReason refreshReason = projectsUpdated
+ ? CppEditorDocumentHandle::ProjectUpdate
+ : CppEditorDocumentHandle::Other;
theCppEditorDocument->setRefreshReason(refreshReason);
}
}
@@ -905,7 +905,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
// However, on e.g. a session restore first the editor documents are created and then the
// project updates come in. That is, there are no reasonable dependency tables based on
// resolved includes that we could rely on.
- updateCppEditorDocuments();
+ updateCppEditorDocuments(/*projectsUpdated = */ true);
// Trigger reindexing
QFuture<void> indexerFuture = updateSourceFiles(filesToReindex, ForcedProgressNotification);
@@ -1044,9 +1044,18 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
delayedGC();
}
-void CppModelManager::onActiveProjectChanged(ProjectExplorer::Project *)
+void CppModelManager::onActiveProjectChanged(ProjectExplorer::Project *project)
{
- updateCppEditorDocuments(true);
+ if (!project)
+ return; // Last project closed.
+
+ {
+ QMutexLocker locker(&d->m_projectMutex);
+ if (!d->m_projectToProjectsInfo.contains(project))
+ return; // Not yet known to us.
+ }
+
+ updateCppEditorDocuments();
}
void CppModelManager::onSourceFilesRefreshed() const
@@ -1067,10 +1076,9 @@ void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor)
const CppEditorDocumentHandle::RefreshReason refreshReason
= theCppEditorDocument->refreshReason();
if (refreshReason != CppEditorDocumentHandle::None) {
+ const bool projectsChanged = refreshReason == CppEditorDocumentHandle::ProjectUpdate;
theCppEditorDocument->setRefreshReason(CppEditorDocumentHandle::None);
- const bool hasActiveProjectChanged
- = refreshReason == CppEditorDocumentHandle::ActiveProjectChange;
- theCppEditorDocument->processor()->run(hasActiveProjectChanged);
+ theCppEditorDocument->processor()->run(projectsChanged);
}
}
}