Clang: Rebuild overview model tree when token data is updated

In release builds overview model tree is built earlier
then the job with token information is completed.

Change-Id: I1a563551e813996001fb97924ac441e2b7d599b9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-03-22 13:05:59 +01:00
parent d66e8b6ea0
commit 99bd0ed2a4
5 changed files with 22 additions and 1 deletions

View File

@@ -267,6 +267,7 @@ void ClangEditorDocumentProcessor::updateTokenInfos(
if (documentRevision != revision()) if (documentRevision != revision())
return; return;
m_tokenInfos = tokenInfos; m_tokenInfos = tokenInfos;
emit tokenInfosUpdated();
} }
static int currentLine(const TextEditor::AssistInterface &assistInterface) static int currentLine(const TextEditor::AssistInterface &assistInterface)

View File

@@ -106,6 +106,9 @@ public:
public: public:
static ClangEditorDocumentProcessor *get(const QString &filePath); static ClangEditorDocumentProcessor *get(const QString &filePath);
signals:
void tokenInfosUpdated();
private: private:
void onParserFinished(); void onParserFinished();
void updateProjectPartAndTranslationUnitForEditor(); void updateProjectPartAndTranslationUnitForEditor();

View File

@@ -206,7 +206,19 @@ bool OverviewModel::rebuild(const QString &filePath)
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(filePath); ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(filePath);
if (!processor) if (!processor)
return false; return false;
if (m_filePath != filePath) {
if (!m_filePath.isEmpty()) {
ClangEditorDocumentProcessor *previousProcessor
= ClangEditorDocumentProcessor::get(m_filePath);
if (previousProcessor) {
disconnect(previousProcessor, &ClangEditorDocumentProcessor::tokenInfosUpdated,
this, &OverviewModel::needsUpdate);
}
}
m_filePath = filePath; m_filePath = filePath;
connect(processor, &ClangEditorDocumentProcessor::tokenInfosUpdated, this,
&OverviewModel::needsUpdate);
}
const TokenContainers &tokenContainers = processor->tokenInfos(); const TokenContainers &tokenContainers = processor->tokenInfos();
auto *root = new TokenTreeItem; auto *root = new TokenTreeItem;

View File

@@ -90,6 +90,9 @@ public:
virtual bool isGenerated(const QModelIndex &) const { return false; } virtual bool isGenerated(const QModelIndex &) const { return false; }
virtual Utils::Link linkFromIndex(const QModelIndex &) const = 0; virtual Utils::Link linkFromIndex(const QModelIndex &) const = 0;
virtual Utils::LineColumn lineColumnFromIndex(const QModelIndex &) const = 0; virtual Utils::LineColumn lineColumnFromIndex(const QModelIndex &) const = 0;
signals:
void needsUpdate();
}; };
} // namespace CppTools } // namespace CppTools

View File

@@ -133,6 +133,8 @@ CppEditorOutline::CppEditorOutline(TextEditor::TextEditorWidget *editorWidget)
m_updateTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs, m_updateTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs,
QLatin1String("CppEditorOutline::m_updateTimer")); QLatin1String("CppEditorOutline::m_updateTimer"));
connect(m_updateTimer, &QTimer::timeout, this, &CppEditorOutline::updateNow); connect(m_updateTimer, &QTimer::timeout, this, &CppEditorOutline::updateNow);
connect(m_model.get(), &CppTools::AbstractOverviewModel::needsUpdate, this,
&CppEditorOutline::updateNow);
m_updateIndexTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs, m_updateIndexTimer = newSingleShotTimer(this, UpdateOutlineIntervalInMs,
QLatin1String("CppEditorOutline::m_updateIndexTimer")); QLatin1String("CppEditorOutline::m_updateIndexTimer"));