forked from qt-creator/qt-creator
TextEditor: simplify SyntaxHighlighterRunner interface
Change-Id: I6c8d51d8dccc91514c89267eac2cea66c87a871a Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -27,16 +27,11 @@ class SyntaxHighlighterRunnerPrivate : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SyntaxHighlighterRunnerPrivate(SyntaxHighlighterRunner::SyntaxHighlighterCreator creator,
|
SyntaxHighlighterRunnerPrivate(SyntaxHighlighter *highlighter,
|
||||||
QTextDocument *document,
|
QTextDocument *document,
|
||||||
bool async,
|
bool async)
|
||||||
const QString &mimeType,
|
: m_highlighter(highlighter)
|
||||||
FontSettings fontSettings)
|
|
||||||
{
|
{
|
||||||
m_highlighter = creator();
|
|
||||||
m_highlighter->setFontSettings(fontSettings);
|
|
||||||
m_highlighter->setMimeType(mimeType);
|
|
||||||
|
|
||||||
if (async) {
|
if (async) {
|
||||||
m_document = new QTextDocument(this);
|
m_document = new QTextDocument(this);
|
||||||
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
||||||
@@ -111,12 +106,10 @@ signals:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SyntaxHighlighterRunner::SyntaxHighlighterRunner(SyntaxHighlighterCreator creator,
|
SyntaxHighlighterRunner::SyntaxHighlighterRunner(SyntaxHighlighter *highlighter,
|
||||||
QTextDocument *document,
|
QTextDocument *document,
|
||||||
bool async,
|
bool async)
|
||||||
const QString &mimeType,
|
: d(new SyntaxHighlighterRunnerPrivate(highlighter, document, async))
|
||||||
const TextEditor::FontSettings &fontSettings)
|
|
||||||
: d(new SyntaxHighlighterRunnerPrivate(creator, document, async, mimeType, fontSettings))
|
|
||||||
, m_document(document)
|
, m_document(document)
|
||||||
{
|
{
|
||||||
m_useGenericHighlighter = qobject_cast<Highlighter *>(d->m_highlighter);
|
m_useGenericHighlighter = qobject_cast<Highlighter *>(d->m_highlighter);
|
||||||
|
@@ -24,12 +24,7 @@ class TEXTEDITOR_EXPORT SyntaxHighlighterRunner : public QObject
|
|||||||
public:
|
public:
|
||||||
using SyntaxHighlighterCreator = std::function<SyntaxHighlighter *()>;
|
using SyntaxHighlighterCreator = std::function<SyntaxHighlighter *()>;
|
||||||
|
|
||||||
SyntaxHighlighterRunner(
|
SyntaxHighlighterRunner(SyntaxHighlighter *highlighter, QTextDocument *document, bool async);
|
||||||
SyntaxHighlighterCreator creator,
|
|
||||||
QTextDocument *document,
|
|
||||||
bool async,
|
|
||||||
const QString &mimeType,
|
|
||||||
const TextEditor::FontSettings &fontSettings = TextEditorSettings::fontSettings());
|
|
||||||
virtual ~SyntaxHighlighterRunner();
|
virtual ~SyntaxHighlighterRunner();
|
||||||
|
|
||||||
void setExtraFormats(const QMap<int, QList<QTextLayout::FormatRange>> &formats);
|
void setExtraFormats(const QMap<int, QList<QTextLayout::FormatRange>> &formats);
|
||||||
|
@@ -921,10 +921,12 @@ void TextDocument::resetSyntaxHighlighter(const std::function<SyntaxHighlighter
|
|||||||
= qtcEnvironmentVariable("QTC_USE_THREADED_HIGHLIGHTER", "TRUE").toUpper()
|
= qtcEnvironmentVariable("QTC_USE_THREADED_HIGHLIGHTER", "TRUE").toUpper()
|
||||||
== QLatin1String("TRUE");
|
== QLatin1String("TRUE");
|
||||||
|
|
||||||
d->m_highlighterRunner = new SyntaxHighlighterRunner(creator,
|
SyntaxHighlighter *highlighter = creator();
|
||||||
|
highlighter->setFontSettings(TextEditorSettings::fontSettings());
|
||||||
|
highlighter->setMimeType(mimeType());
|
||||||
|
d->m_highlighterRunner = new SyntaxHighlighterRunner(highlighter,
|
||||||
document(),
|
document(),
|
||||||
threaded && envValue,
|
threaded && envValue);
|
||||||
mimeType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDocument::cleanWhitespace(const QTextCursor &cursor)
|
void TextDocument::cleanWhitespace(const QTextCursor &cursor)
|
||||||
|
@@ -58,9 +58,8 @@ Last)";
|
|||||||
|
|
||||||
doc = new QTextDocument();
|
doc = new QTextDocument();
|
||||||
doc->setPlainText(text);
|
doc->setPlainText(text);
|
||||||
|
auto highlighter = new SyntaxHighlighter(doc, fontsettings);
|
||||||
highlighterRunner = new SyntaxHighlighterRunner(
|
highlighterRunner = new SyntaxHighlighterRunner(highlighter, doc, false);
|
||||||
[this] { return new SyntaxHighlighter(doc, fontsettings); }, doc, false, {}, fontsettings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const HighlightingResults &highlightingResults()
|
static const HighlightingResults &highlightingResults()
|
||||||
|
Reference in New Issue
Block a user