forked from qt-creator/qt-creator
Simplify text format handling in syntax highlighters
Pass the mapping from custom enum to text style in form of a function, which then can use a switch which is checked by compilers, and avoids the need to lookup a different enum somewhere else to find out what the mapping actually is. That mapping is cached to keep performance as before. Also, most highlighters created an enum just for the purpose of mapping to text styles, basically creating duplicated subsets of text style like enums everywhere. Instead provide a default, identity mapping from text styles to text styles. Change-Id: I2ea1ca702b99e36b8742dfda510b1b2753f0a1c2 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -26,10 +26,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "texteditor_global.h"
|
||||
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QTextLayout>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextDocument;
|
||||
class QSyntaxHighlighterPrivate;
|
||||
@@ -70,7 +74,8 @@ public slots:
|
||||
void rehighlightBlock(const QTextBlock &block);
|
||||
|
||||
protected:
|
||||
void setTextFormatCategories(const QVector<TextEditor::TextStyle> &categories);
|
||||
void setDefaultTextFormatCategories();
|
||||
void setTextFormatCategories(int count, std::function<TextStyle(int)> formatMapping);
|
||||
QTextCharFormat formatForCategory(int categoryIndex) const;
|
||||
virtual void highlightBlock(const QString &text) = 0;
|
||||
|
||||
@@ -91,6 +96,7 @@ protected:
|
||||
QTextBlock currentBlock() const;
|
||||
|
||||
private:
|
||||
void setTextFormatCategories(const QVector<std::pair<int, TextStyle>> &categories);
|
||||
void reformatBlocks(int from, int charsRemoved, int charsAdded);
|
||||
void delayedRehighlight();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user