CppTools: De-noise SemanticHighlighter

Change-Id: Id4655b0d81104468f6fe799744e49e505d3b8748
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-03-08 22:37:27 +02:00
committed by Orgad Shaneh
parent 47295d267f
commit 4191d9ddcd

View File

@@ -35,14 +35,16 @@
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QTextDocument> #include <QTextDocument>
using TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats; using namespace TextEditor;
using TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd;
using SemanticHighlighter::incrementalApplyExtraAdditionalFormats;
using SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd;
static Q_LOGGING_CATEGORY(log, "qtc.cpptools.semantichighlighter") static Q_LOGGING_CATEGORY(log, "qtc.cpptools.semantichighlighter")
namespace CppTools { namespace CppTools {
SemanticHighlighter::SemanticHighlighter(TextEditor::TextDocument *baseTextDocument) SemanticHighlighter::SemanticHighlighter(TextDocument *baseTextDocument)
: QObject(baseTextDocument) : QObject(baseTextDocument)
, m_baseTextDocument(baseTextDocument) , m_baseTextDocument(baseTextDocument)
, m_revision(0) , m_revision(0)
@@ -75,7 +77,7 @@ void SemanticHighlighter::run()
disconnectWatcher(); disconnectWatcher();
m_watcher->cancel(); m_watcher->cancel();
} }
m_watcher.reset(new QFutureWatcher<TextEditor::HighlightingResult>); m_watcher.reset(new QFutureWatcher<HighlightingResult>);
connectWatcher(); connectWatcher();
m_revision = documentRevision(); m_revision = documentRevision();
@@ -91,7 +93,7 @@ void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
qCDebug(log) << "onHighlighterResultAvailable()" << from << to; qCDebug(log) << "onHighlighterResultAvailable()" << from << to;
TextEditor::SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter(); SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
QTC_ASSERT(highlighter, return); QTC_ASSERT(highlighter, return);
incrementalApplyExtraAdditionalFormats(highlighter, m_watcher->future(), from, to, m_formatMap); incrementalApplyExtraAdditionalFormats(highlighter, m_watcher->future(), from, to, m_formatMap);
} }
@@ -100,7 +102,7 @@ void SemanticHighlighter::onHighlighterFinished()
{ {
QTC_ASSERT(m_watcher, return); QTC_ASSERT(m_watcher, return);
if (!m_watcher->isCanceled() && documentRevision() == m_revision) { if (!m_watcher->isCanceled() && documentRevision() == m_revision) {
TextEditor::SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter(); SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
QTC_CHECK(highlighter); QTC_CHECK(highlighter);
if (highlighter) { if (highlighter) {
qCDebug(log) << "onHighlighterFinished() - clearing formats"; qCDebug(log) << "onHighlighterFinished() - clearing formats";
@@ -112,7 +114,7 @@ void SemanticHighlighter::onHighlighterFinished()
void SemanticHighlighter::connectWatcher() void SemanticHighlighter::connectWatcher()
{ {
typedef QFutureWatcher<TextEditor::HighlightingResult> Watcher; typedef QFutureWatcher<HighlightingResult> Watcher;
connect(m_watcher.data(), &Watcher::resultsReadyAt, connect(m_watcher.data(), &Watcher::resultsReadyAt,
this, &SemanticHighlighter::onHighlighterResultAvailable); this, &SemanticHighlighter::onHighlighterResultAvailable);
connect(m_watcher.data(), &Watcher::finished, connect(m_watcher.data(), &Watcher::finished,
@@ -121,7 +123,7 @@ void SemanticHighlighter::connectWatcher()
void SemanticHighlighter::disconnectWatcher() void SemanticHighlighter::disconnectWatcher()
{ {
typedef QFutureWatcher<TextEditor::HighlightingResult> Watcher; typedef QFutureWatcher<HighlightingResult> Watcher;
disconnect(m_watcher.data(), &Watcher::resultsReadyAt, disconnect(m_watcher.data(), &Watcher::resultsReadyAt,
this, &SemanticHighlighter::onHighlighterResultAvailable); this, &SemanticHighlighter::onHighlighterResultAvailable);
disconnect(m_watcher.data(), &Watcher::finished, disconnect(m_watcher.data(), &Watcher::finished,
@@ -137,18 +139,18 @@ void SemanticHighlighter::updateFormatMapFromFontSettings()
{ {
QTC_ASSERT(m_baseTextDocument, return); QTC_ASSERT(m_baseTextDocument, return);
const TextEditor::FontSettings &fs = m_baseTextDocument->fontSettings(); const FontSettings &fs = m_baseTextDocument->fontSettings();
m_formatMap[TypeUse] = fs.toTextCharFormat(TextEditor::C_TYPE); m_formatMap[TypeUse] = fs.toTextCharFormat(C_TYPE);
m_formatMap[LocalUse] = fs.toTextCharFormat(TextEditor::C_LOCAL); m_formatMap[LocalUse] = fs.toTextCharFormat(C_LOCAL);
m_formatMap[FieldUse] = fs.toTextCharFormat(TextEditor::C_FIELD); m_formatMap[FieldUse] = fs.toTextCharFormat(C_FIELD);
m_formatMap[EnumerationUse] = fs.toTextCharFormat(TextEditor::C_ENUMERATION); m_formatMap[EnumerationUse] = fs.toTextCharFormat(C_ENUMERATION);
m_formatMap[VirtualMethodUse] = fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD); m_formatMap[VirtualMethodUse] = fs.toTextCharFormat(C_VIRTUAL_METHOD);
m_formatMap[LabelUse] = fs.toTextCharFormat(TextEditor::C_LABEL); m_formatMap[LabelUse] = fs.toTextCharFormat(C_LABEL);
m_formatMap[MacroUse] = fs.toTextCharFormat(TextEditor::C_PREPROCESSOR); m_formatMap[MacroUse] = fs.toTextCharFormat(C_PREPROCESSOR);
m_formatMap[FunctionUse] = fs.toTextCharFormat(TextEditor::C_FUNCTION); m_formatMap[FunctionUse] = fs.toTextCharFormat(C_FUNCTION);
m_formatMap[PseudoKeywordUse] = fs.toTextCharFormat(TextEditor::C_KEYWORD); m_formatMap[PseudoKeywordUse] = fs.toTextCharFormat(C_KEYWORD);
m_formatMap[StringUse] = fs.toTextCharFormat(TextEditor::C_STRING); m_formatMap[StringUse] = fs.toTextCharFormat(C_STRING);
} }
} // namespace CppTools } // namespace CppTools