aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/git/githighlighters.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-05-05 20:34:29 +0200
committerEike Ziller <eike.ziller@qt.io>2017-05-23 07:47:22 +0000
commitcf57965ebc8ec913a2b2fafe352ddae3f7706b98 (patch)
tree8e793cc8ed288fe1f3156a87613e18a7e6709bf3 /src/plugins/git/githighlighters.cpp
parent762f67f729ea01d21cb23646da69cbce89958789 (diff)
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>
Diffstat (limited to 'src/plugins/git/githighlighters.cpp')
-rw-r--r--src/plugins/git/githighlighters.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp
index f6cea509ec..fbc72dae95 100644
--- a/src/plugins/git/githighlighters.cpp
+++ b/src/plugins/git/githighlighters.cpp
@@ -38,9 +38,7 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
TextEditor::SyntaxHighlighter(parent)
{
- static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT});
-
- setTextFormatCategories(categories);
+ setDefaultTextFormatCategories();
m_keywordPattern.setPattern("^[\\w-]+:");
m_hashChar = '#';
QTC_CHECK(m_keywordPattern.isValid());
@@ -56,7 +54,7 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
setCurrentBlockState(state);
return;
} else if (text.startsWith(m_hashChar)) {
- setFormat(0, text.size(), formatForCategory(Format_Comment));
+ setFormat(0, text.size(), formatForCategory(TextEditor::C_COMMENT));
setCurrentBlockState(state);
return;
} else if (state == None) {
@@ -92,23 +90,34 @@ GitRebaseHighlighter::RebaseAction::RebaseAction(const QString &regexp,
{
}
+static TextEditor::TextStyle styleForFormat(int format)
+{
+ using namespace TextEditor;
+ const auto f = Format(format);
+ switch (f) {
+ case Format_Comment: return C_COMMENT;
+ case Format_Change: return C_DOXYGEN_COMMENT;
+ case Format_Description: return C_STRING;
+ case Format_Pick: return C_KEYWORD;
+ case Format_Reword: return C_FIELD;
+ case Format_Edit: return C_TYPE;
+ case Format_Squash: return C_ENUMERATION;
+ case Format_Fixup: return C_NUMBER;
+ case Format_Exec: return C_LABEL;
+ case Format_Count:
+ QTC_CHECK(false); // should never get here
+ return C_TEXT;
+ }
+ QTC_CHECK(false); // should never get here
+ return C_TEXT;
+}
+
GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent),
m_hashChar('#'),
m_changeNumberPattern(CHANGE_PATTERN)
{
- static const QVector<TextEditor::TextStyle> categories({
- TextEditor::C_COMMENT,
- TextEditor::C_DOXYGEN_COMMENT,
- TextEditor::C_STRING,
- TextEditor::C_KEYWORD,
- TextEditor::C_FIELD,
- TextEditor::C_TYPE,
- TextEditor::C_ENUMERATION,
- TextEditor::C_NUMBER,
- TextEditor::C_LABEL
- });
- setTextFormatCategories(categories);
+ setTextFormatCategories(Format_Count, styleForFormat);
m_actions << RebaseAction("^(p|pick)\\b", Format_Pick);
m_actions << RebaseAction("^(r|reword)\\b", Format_Reword);