TextEditor: avoid creating an highlighter to check a type

check the type after construcing the highlighter instead and save that
information.

Change-Id: I7d942dae4be8471dba90dd266267ff7fa1b6f440
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
David Schulz
2023-12-21 15:01:12 +01:00
parent e1535f5f39
commit a4f9267df1
3 changed files with 18 additions and 8 deletions

View File

@@ -6,6 +6,7 @@
#include "fontsettings.h"
#include "textdocumentlayout.h"
#include "texteditorsettings.h"
#include "highlighter.h"
#include <utils/textutils.h>
@@ -92,13 +93,13 @@ public:
void rehighlight() { m_highlighter->rehighlight(); }
signals:
void resultsReady(const QList<SyntaxHighlighter::Result> &result);
private:
std::unique_ptr<SyntaxHighlighter> m_highlighter;
QTextDocument *m_document = nullptr;
FontSettings m_fontSettings;
signals:
void resultsReady(const QList<SyntaxHighlighter::Result> &result);
};
// ----------------------------- BaseSyntaxHighlighterRunner --------------------------------------
@@ -110,6 +111,8 @@ BaseSyntaxHighlighterRunner::BaseSyntaxHighlighterRunner(
: d(new SyntaxHighlighterRunnerPrivate(creator, document, fontSettings))
, m_document(document)
{
m_useGenericHighlighter = qobject_cast<Highlighter *>(d->m_highlighter.get());
if (document == nullptr)
return;
@@ -176,6 +179,11 @@ void BaseSyntaxHighlighterRunner::changeDocument(int from, int charsRemoved, int
});
}
bool BaseSyntaxHighlighterRunner::useGenericHighlighter() const
{
return m_useGenericHighlighter;
}
void BaseSyntaxHighlighterRunner::setExtraFormats(
const QMap<int, QList<QTextLayout::FormatRange>> &formatMap)
{