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:
David Schulz
2023-12-21 14:14:31 +01:00
parent 3a53648209
commit 562cf9eb4f

View File

@@ -20,11 +20,21 @@ class SyntaxHighlighterRunnerPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: 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->setFontSettings(m_fontSettings);
m_highlighter->setDocument(m_document); m_highlighter->setDocument(m_document);
m_highlighter->setParent(m_document);
connect(m_highlighter.get(), connect(m_highlighter.get(),
&SyntaxHighlighter::resultsReady, &SyntaxHighlighter::resultsReady,
@@ -32,26 +42,6 @@ public:
&SyntaxHighlighterRunnerPrivate::resultsReady); &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, void cloneDocument(int from,
int charsRemoved, int charsRemoved,
const QString textAdded, const QString textAdded,
@@ -106,7 +96,6 @@ signals:
void resultsReady(const QList<SyntaxHighlighter::Result> &result); void resultsReady(const QList<SyntaxHighlighter::Result> &result);
private: private:
BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator;
std::unique_ptr<SyntaxHighlighter> m_highlighter; std::unique_ptr<SyntaxHighlighter> m_highlighter;
QTextDocument *m_document = nullptr; QTextDocument *m_document = nullptr;
FontSettings m_fontSettings; FontSettings m_fontSettings;
@@ -260,8 +249,6 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
connect(&m_thread, &QThread::finished, d.get(), [this] { d.release()->deleteLater(); }); connect(&m_thread, &QThread::finished, d.get(), [this] { d.release()->deleteLater(); });
m_thread.start(); m_thread.start();
QMetaObject::invokeMethod(d.get(), &SyntaxHighlighterRunnerPrivate::create);
m_document = document; m_document = document;
connect(d.get(), connect(d.get(),
&SyntaxHighlighterRunnerPrivate::resultsReady, &SyntaxHighlighterRunnerPrivate::resultsReady,