forked from qt-creator/qt-creator
SyntaxHighlighter: Remove using global fontSettings
Currently, default font settings are set inside the highlighter runner after creating a highlighter. It prevents to call TextEditorSettings::fontSettings() from non-main threads. Change-Id: I0c806f0f586c67749cb2964bebdf2bf3c58a5302 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -26,7 +26,6 @@ namespace Internal {
|
|||||||
HaskellHighlighter::HaskellHighlighter()
|
HaskellHighlighter::HaskellHighlighter()
|
||||||
{
|
{
|
||||||
setDefaultTextFormatCategories();
|
setDefaultTextFormatCategories();
|
||||||
updateFormats(TextEditorSettings::fontSettings());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HaskellHighlighter::highlightBlock(const QString &text)
|
void HaskellHighlighter::highlightBlock(const QString &text)
|
||||||
|
@@ -27,9 +27,7 @@ class SyntaxHighlighterPrivate
|
|||||||
SyntaxHighlighter *q_ptr = nullptr;
|
SyntaxHighlighter *q_ptr = nullptr;
|
||||||
Q_DECLARE_PUBLIC(SyntaxHighlighter)
|
Q_DECLARE_PUBLIC(SyntaxHighlighter)
|
||||||
public:
|
public:
|
||||||
SyntaxHighlighterPrivate()
|
SyntaxHighlighterPrivate() = default;
|
||||||
: SyntaxHighlighterPrivate(TextEditorSettings::fontSettings())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
SyntaxHighlighterPrivate(const FontSettings &fontSettings)
|
SyntaxHighlighterPrivate(const FontSettings &fontSettings)
|
||||||
{
|
{
|
||||||
@@ -881,7 +879,7 @@ void SyntaxHighlighter::setTextFormatCategories(const QList<std::pair<int, TextS
|
|||||||
d->formatCategories = categories;
|
d->formatCategories = categories;
|
||||||
const int maxCategory = Utils::maxElementOr(categories, {-1, C_TEXT}).first;
|
const int maxCategory = Utils::maxElementOr(categories, {-1, C_TEXT}).first;
|
||||||
d->formats = QList<QTextCharFormat>(maxCategory + 1);
|
d->formats = QList<QTextCharFormat>(maxCategory + 1);
|
||||||
d->updateFormats(TextEditorSettings::fontSettings());
|
d->updateFormats(d->fontSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const
|
QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const
|
||||||
@@ -925,4 +923,3 @@ void SyntaxHighlighterPrivate::updateFormats(const FontSettings &fontSettings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "fontsettings.h"
|
#include "fontsettings.h"
|
||||||
#include "textdocumentlayout.h"
|
#include "textdocumentlayout.h"
|
||||||
|
#include "texteditorsettings.h"
|
||||||
|
|
||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
@@ -19,13 +20,20 @@ class SyntaxHighlighterRunnerPrivate : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
void createHighlighter()
|
||||||
|
{
|
||||||
|
m_highlighter.reset(m_creator());
|
||||||
|
m_highlighter->setFontSettings(m_fontSettings);
|
||||||
|
m_highlighter->setDocument(m_document);
|
||||||
|
}
|
||||||
|
|
||||||
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
||||||
QTextDocument *document)
|
QTextDocument *document)
|
||||||
: m_creator(creator)
|
: m_creator(creator)
|
||||||
|
, m_document(document)
|
||||||
{
|
{
|
||||||
m_highlighter.reset(m_creator());
|
m_highlighter.reset(m_creator());
|
||||||
m_highlighter->setDocument(document);
|
createHighlighter();
|
||||||
m_document = document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void create()
|
void create()
|
||||||
@@ -36,8 +44,7 @@ public:
|
|||||||
m_document = new QTextDocument(this);
|
m_document = new QTextDocument(this);
|
||||||
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
||||||
|
|
||||||
m_highlighter.reset(m_creator());
|
createHighlighter();
|
||||||
m_highlighter->setDocument(m_document);
|
|
||||||
|
|
||||||
connect(m_highlighter.get(),
|
connect(m_highlighter.get(),
|
||||||
&SyntaxHighlighter::resultsReady,
|
&SyntaxHighlighter::resultsReady,
|
||||||
@@ -102,6 +109,7 @@ private:
|
|||||||
BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator;
|
BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator;
|
||||||
std::unique_ptr<SyntaxHighlighter> m_highlighter;
|
std::unique_ptr<SyntaxHighlighter> m_highlighter;
|
||||||
QTextDocument *m_document = nullptr;
|
QTextDocument *m_document = nullptr;
|
||||||
|
const FontSettings m_fontSettings = TextEditorSettings::fontSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------- BaseSyntaxHighlighterRunner --------------------------------------
|
// ----------------------------- BaseSyntaxHighlighterRunner --------------------------------------
|
||||||
|
Reference in New Issue
Block a user