From 562cf9eb4f73cccf74cb5d521b0593a30b90b7f0 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 21 Dec 2023 14:14:31 +0100 Subject: [PATCH] TextEditor: simplify SyntaxHighlighterRunnerPrivate contruction Change-Id: I40e4df9f56b67f550e74c463b2f98a15740eb43b Reviewed-by: Artem Sokolovskii Reviewed-by: Jarek Kobus Reviewed-by: --- .../texteditor/syntaxhighlighterrunner.cpp | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.cpp b/src/plugins/texteditor/syntaxhighlighterrunner.cpp index a22c8dd1a1d..a1241d87e2f 100644 --- a/src/plugins/texteditor/syntaxhighlighterrunner.cpp +++ b/src/plugins/texteditor/syntaxhighlighterrunner.cpp @@ -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 &result); private: - BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator; std::unique_ptr 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,