forked from qt-creator/qt-creator
TextEditor: simplify SyntaxHighlighterRunnerPrivate contruction
Change-Id: I40e4df9f56b67f550e74c463b2f98a15740eb43b Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -20,11 +20,21 @@ class SyntaxHighlighterRunnerPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void createHighlighter()
|
||||
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
||||
QTextDocument *document,
|
||||
FontSettings fontSettings)
|
||||
: m_document(document)
|
||||
, m_fontSettings(fontSettings)
|
||||
{
|
||||
m_highlighter.reset(m_creator());
|
||||
if (!m_document) {
|
||||
m_document = new QTextDocument(this);
|
||||
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
||||
}
|
||||
|
||||
m_highlighter.reset(creator());
|
||||
m_highlighter->setFontSettings(m_fontSettings);
|
||||
m_highlighter->setDocument(m_document);
|
||||
m_highlighter->setParent(m_document);
|
||||
|
||||
connect(m_highlighter.get(),
|
||||
&SyntaxHighlighter::resultsReady,
|
||||
@@ -32,26 +42,6 @@ public:
|
||||
&SyntaxHighlighterRunnerPrivate::resultsReady);
|
||||
}
|
||||
|
||||
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
||||
QTextDocument *document, FontSettings fontSettings)
|
||||
: m_creator(creator)
|
||||
, m_document(document)
|
||||
, m_fontSettings(fontSettings)
|
||||
{
|
||||
createHighlighter();
|
||||
}
|
||||
|
||||
void create()
|
||||
{
|
||||
if (m_document != nullptr)
|
||||
return;
|
||||
|
||||
m_document = new QTextDocument(this);
|
||||
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
||||
|
||||
createHighlighter();
|
||||
}
|
||||
|
||||
void cloneDocument(int from,
|
||||
int charsRemoved,
|
||||
const QString textAdded,
|
||||
@@ -106,7 +96,6 @@ signals:
|
||||
void resultsReady(const QList<SyntaxHighlighter::Result> &result);
|
||||
|
||||
private:
|
||||
BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator;
|
||||
std::unique_ptr<SyntaxHighlighter> m_highlighter;
|
||||
QTextDocument *m_document = nullptr;
|
||||
FontSettings m_fontSettings;
|
||||
@@ -260,8 +249,6 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
|
||||
connect(&m_thread, &QThread::finished, d.get(), [this] { d.release()->deleteLater(); });
|
||||
m_thread.start();
|
||||
|
||||
QMetaObject::invokeMethod(d.get(), &SyntaxHighlighterRunnerPrivate::create);
|
||||
|
||||
m_document = document;
|
||||
connect(d.get(),
|
||||
&SyntaxHighlighterRunnerPrivate::resultsReady,
|
||||
|
||||
Reference in New Issue
Block a user