diff options
author | David Schulz <david.schulz@qt.io> | 2023-05-16 14:57:37 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2023-05-25 07:01:35 +0000 |
commit | f235a72554693414d39ae1d59dc42d13b7deca2a (patch) | |
tree | 892151e0b0ce5157c138bce123c863477c5a0045 /src | |
parent | 31090ded156173e17a6be2772f4f098de60787a6 (diff) |
TextEditor: add tests for semantic highlighter
Change-Id: Id64c933f01c0dbc0e077656b6f4260b93e124311
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.cpp | 16 | ||||
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.h | 5 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index de72c7b0db6..6d2616193ef 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -23,8 +23,12 @@ class SyntaxHighlighterPrivate Q_DECLARE_PUBLIC(SyntaxHighlighter) public: SyntaxHighlighterPrivate() + : SyntaxHighlighterPrivate(TextEditorSettings::fontSettings()) + { } + + SyntaxHighlighterPrivate(const FontSettings &fontSettings) { - updateFormats(TextEditorSettings::fontSettings()); + updateFormats(fontSettings); } QPointer<QTextDocument> doc; @@ -76,6 +80,16 @@ void SyntaxHighlighter::delayedRehighlight() rehighlight(); } +#ifdef WITH_TESTS +SyntaxHighlighter::SyntaxHighlighter(QTextDocument *parent, const FontSettings &fontsettings) + : QObject(parent), d_ptr(new SyntaxHighlighterPrivate(fontsettings)) +{ + d_ptr->q_ptr = this; + if (parent) + setDocument(parent); +} +#endif + void SyntaxHighlighterPrivate::applyFormatChanges(int from, int charsRemoved, int charsAdded) { bool formatsChanged = false; diff --git a/src/plugins/texteditor/syntaxhighlighter.h b/src/plugins/texteditor/syntaxhighlighter.h index 7a1822e4667..1b66e2ff56a 100644 --- a/src/plugins/texteditor/syntaxhighlighter.h +++ b/src/plugins/texteditor/syntaxhighlighter.h @@ -91,6 +91,11 @@ private: void delayedRehighlight(); QScopedPointer<SyntaxHighlighterPrivate> d_ptr; + +#ifdef WITH_TESTS + friend class tst_highlighter; + SyntaxHighlighter(QTextDocument *parent, const FontSettings &fontsettings); +#endif }; } // namespace TextEditor |