improve static initializers

Change-Id: I304fdd6627f01fc216c84930da607127c52409d9
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tim Jenssen
2016-09-23 15:46:41 +02:00
parent 669d04a686
commit d915b22db9
15 changed files with 119 additions and 146 deletions

View File

@@ -42,21 +42,20 @@ using namespace CPlusPlus;
CppHighlighter::CppHighlighter(QTextDocument *document) : CppHighlighter::CppHighlighter(QTextDocument *document) :
SyntaxHighlighter(document) SyntaxHighlighter(document)
{ {
static QVector<TextStyle> categories; static const QVector<TextStyle> categories({
if (categories.isEmpty()) { C_NUMBER,
categories << C_NUMBER C_STRING,
<< C_STRING C_TYPE,
<< C_TYPE C_KEYWORD,
<< C_KEYWORD C_PRIMITIVE_TYPE,
<< C_PRIMITIVE_TYPE C_OPERATOR,
<< C_OPERATOR C_PREPROCESSOR,
<< C_PREPROCESSOR C_LABEL,
<< C_LABEL C_COMMENT,
<< C_COMMENT C_DOXYGEN_COMMENT,
<< C_DOXYGEN_COMMENT C_DOXYGEN_TAG,
<< C_DOXYGEN_TAG C_VISUAL_WHITESPACE
<< C_VISUAL_WHITESPACE; });
}
setTextFormatCategories(categories); setTextFormatCategories(categories);
} }

View File

@@ -37,9 +37,7 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
TextEditor::SyntaxHighlighter(parent) TextEditor::SyntaxHighlighter(parent)
{ {
static QVector<TextEditor::TextStyle> categories; static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT});
if (categories.isEmpty())
categories << TextEditor::C_COMMENT;
setTextFormatCategories(categories); setTextFormatCategories(categories);
m_keywordPattern.setPattern("^[\\w-]+:"); m_keywordPattern.setPattern("^[\\w-]+:");
@@ -98,18 +96,17 @@ GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
m_hashChar('#'), m_hashChar('#'),
m_changeNumberPattern(CHANGE_PATTERN) m_changeNumberPattern(CHANGE_PATTERN)
{ {
static QVector<TextEditor::TextStyle> categories; static const QVector<TextEditor::TextStyle> categories({
if (categories.isEmpty()) { TextEditor::C_COMMENT,
categories << TextEditor::C_COMMENT TextEditor::C_DOXYGEN_COMMENT,
<< TextEditor::C_DOXYGEN_COMMENT TextEditor::C_STRING,
<< TextEditor::C_STRING TextEditor::C_KEYWORD,
<< TextEditor::C_KEYWORD TextEditor::C_FIELD,
<< TextEditor::C_FIELD TextEditor::C_TYPE,
<< TextEditor::C_TYPE TextEditor::C_ENUMERATION,
<< TextEditor::C_ENUMERATION TextEditor::C_NUMBER,
<< TextEditor::C_NUMBER TextEditor::C_LABEL
<< TextEditor::C_LABEL; });
}
setTextFormatCategories(categories); setTextFormatCategories(categories);
m_actions << RebaseAction("^(p|pick)\\b", Format_Pick); m_actions << RebaseAction("^(p|pick)\\b", Format_Pick);

View File

@@ -39,21 +39,20 @@ namespace Internal {
GlslHighlighter::GlslHighlighter() GlslHighlighter::GlslHighlighter()
{ {
static QVector<TextStyle> categories; static const QVector<TextStyle> categories({
if (categories.isEmpty()) { C_NUMBER,
categories << C_NUMBER C_STRING,
<< C_STRING C_TYPE,
<< C_TYPE C_KEYWORD,
<< C_KEYWORD C_OPERATOR,
<< C_OPERATOR C_PREPROCESSOR,
<< C_PREPROCESSOR C_LABEL,
<< C_LABEL C_COMMENT,
<< C_COMMENT C_DOXYGEN_COMMENT,
<< C_DOXYGEN_COMMENT C_DOXYGEN_TAG,
<< C_DOXYGEN_TAG C_VISUAL_WHITESPACE,
<< C_VISUAL_WHITESPACE C_REMOVED_LINE
<< C_REMOVED_LINE; });
}
setTextFormatCategories(categories); setTextFormatCategories(categories);
} }

View File

@@ -157,17 +157,12 @@ void SearchWidget::showEvent(QShowEvent *event)
void SearchWidget::search() const void SearchWidget::search() const
{ {
static QStringList charsToEscapeList; static const QStringList charsToEscapeList({
if (charsToEscapeList.isEmpty()) { "\\", "+", "-", "!", "(", ")", ":", "^", "[", "]", "{", "}", "~"
charsToEscapeList << "\\" << "+" });
<< "-" << "!" << "("
<< ")" << ":" << "^"
<< "[" << "]" << "{"
<< "}" << "~";
}
static QString escapeChar("\\"); static const QString escapeChar("\\");
static QRegExp regExp("[\\+\\-\\!\\(\\)\\^\\[\\]\\{\\}~:]"); static const QRegExp regExp("[\\+\\-\\!\\(\\)\\^\\[\\]\\{\\}~:]");
QList<QHelpSearchQuery> escapedQueries; QList<QHelpSearchQuery> escapedQueries;
const QList<QHelpSearchQuery> queries = searchEngine->queryWidget()->query(); const QList<QHelpSearchQuery> queries = searchEngine->queryWidget()->query();

View File

@@ -60,9 +60,7 @@ MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
TextEditor::SyntaxHighlighter(parent), TextEditor::SyntaxHighlighter(parent),
m_keywordPattern(QLatin1String("^\\w+:")) m_keywordPattern(QLatin1String("^\\w+:"))
{ {
static QVector<TextEditor::TextStyle> categories; static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT});
if (categories.isEmpty())
categories << TextEditor::C_COMMENT;
setTextFormatCategories(categories); setTextFormatCategories(categories);
QTC_CHECK(m_keywordPattern.isValid()); QTC_CHECK(m_keywordPattern.isValid());

View File

@@ -280,8 +280,8 @@ bool AbstractMsvcToolChain::generateEnvironmentSettings(Utils::Environment &env,
if (cmdPath.isEmpty()) if (cmdPath.isEmpty())
cmdPath = env.searchInPath(QLatin1String("cmd.exe")); cmdPath = env.searchInPath(QLatin1String("cmd.exe"));
// Windows SDK setup scripts require command line switches for environment expansion. // Windows SDK setup scripts require command line switches for environment expansion.
QStringList cmdArguments; QStringList cmdArguments({
cmdArguments << QLatin1String("/E:ON") << QLatin1String("/V:ON") << QLatin1String("/c"); QLatin1String("/E:ON"), QLatin1String("/V:ON"), QLatin1String("/c")});
cmdArguments << QDir::toNativeSeparators(saver.fileName()); cmdArguments << QDir::toNativeSeparators(saver.fileName());
if (debug) if (debug)
qDebug() << "readEnvironmentSetting: " << call << cmdPath << cmdArguments.join(' ') qDebug() << "readEnvironmentSetting: " << call << cmdPath << cmdArguments.join(' ')

View File

@@ -1868,23 +1868,19 @@ static const char * const varExpandedKeys[] = {
// Translate old-style ${} var expansions into new-style %{} ones // Translate old-style ${} var expansions into new-style %{} ones
static QVariant version8VarNodeTransform(const QVariant &var) static QVariant version8VarNodeTransform(const QVariant &var)
{ {
static const char * const vars[] = { static const QSet<QString> map({
"absoluteFilePath", "CURRENT_DOCUMENT:absoluteFilePath",
"absolutePath", "CURRENT_DOCUMENT:absolutePath",
"baseName", "CURRENT_DOCUMENT:baseName",
"canonicalPath", "CURRENT_DOCUMENT:canonicalPath",
"canonicalFilePath", "CURRENT_DOCUMENT:canonicalFilePath",
"completeBaseName", "CURRENT_DOCUMENT:completeBaseName",
"completeSuffix", "CURRENT_DOCUMENT:completeSuffix",
"fileName", "CURRENT_DOCUMENT:fileName",
"filePath", "CURRENT_DOCUMENT:filePath",
"path", "CURRENT_DOCUMENT:path",
"suffix" "CURRENT_DOCUMENT:suffix"
}; });
static QSet<QString> map;
if (map.isEmpty())
for (unsigned i = 0; i < sizeof(vars)/sizeof(vars[0]); ++i)
map.insert(QLatin1String("CURRENT_DOCUMENT:") + QLatin1String(vars[i]));
QString str = var.toString(); QString str = var.toString();
int pos = 0; int pos = 0;

View File

@@ -38,9 +38,7 @@ namespace Internal {
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords) ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
: m_keywords(keywords) : m_keywords(keywords)
{ {
static QVector<TextStyle> categories; static const QVector<TextStyle> categories({C_TYPE, C_KEYWORD, C_COMMENT, C_VISUAL_WHITESPACE});
if (categories.isEmpty())
categories << C_TYPE << C_KEYWORD << C_COMMENT << C_VISUAL_WHITESPACE;
setTextFormatCategories(categories); setTextFormatCategories(categories);
} }

View File

@@ -71,37 +71,33 @@ static inline bool isSupportedAttachedProperties(const QString &propertyName)
static inline QStringList supportedVersionsList() static inline QStringList supportedVersionsList()
{ {
static const QStringList list = { static const QStringList list = {
QStringLiteral("2.0"), QStringLiteral("2.1"), "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8"
QStringLiteral("2.2"), QStringLiteral("2.3"),
QStringLiteral("2.4"), QStringLiteral("2.5"),
QStringLiteral("2.6"), QStringLiteral("2.7"),
QStringLiteral("2.8")
}; };
return list; return list;
} }
static inline QStringList globalQtEnums() static inline QStringList globalQtEnums()
{ {
static QStringList list = QStringList() << QStringLiteral("Horizontal") << QStringLiteral("Vertical") << QStringLiteral("AlignVCenter") static const QStringList list = {
<< QStringLiteral("AlignLeft") << QStringLiteral("LeftToRight") << QStringLiteral("RightToLeft") << QStringLiteral("AlignHCenter") "Horizontal", "Vertical", "AlignVCenter", "AlignLeft", "LeftToRight", "RightToLeft",
<< QStringLiteral("AlignRight") << QStringLiteral("AlignBottom") << QStringLiteral("AlignBaseline") << QStringLiteral("AlignTop") "AlignHCenter", "AlignRight", "AlignBottom", "AlignBaseline", "AlignTop", "BottomLeft",
<< QStringLiteral("BottomLeft") << QStringLiteral("LeftEdge") << QStringLiteral("RightEdge") << QStringLiteral("BottomEdge"); "LeftEdge", "RightEdge", "BottomEdge"
};
return list; return list;
} }
static inline QStringList knownEnumScopes() static inline QStringList knownEnumScopes()
{ {
static QStringList list = QStringList() << QStringLiteral("TextInput") << QStringLiteral("TextEdit") static const QStringList list = {
<< QStringLiteral("Material") << QStringLiteral("Universal") ;; "TextInput", "TextEdit", "Material", "Universal"
};
return list; return list;
} }
static inline bool supportedQtQuickVersion(const QString &version) static inline bool supportedQtQuickVersion(const QString &version)
{ {
static QStringList supportedVersions = supportedVersionsList(); return supportedVersionsList().contains(version);
return supportedVersions.contains(version);
} }
static inline QString stripQuotes(const QString &str) static inline QString stripQuotes(const QString &str)

View File

@@ -142,7 +142,7 @@ void DocumentWarningWidget::refreshContent()
QString DocumentWarningWidget::generateNavigateLinks() QString DocumentWarningWidget::generateNavigateLinks()
{ {
static QString link(QLatin1String("<a href=\"%1\">%2</a>")); static const QString link("<a href=\"%1\">%2</a>");
QStringList links; QStringList links;
if (m_messages.count() > 1) { if (m_messages.count() > 1) {
if (m_currentMessage != 0) if (m_currentMessage != 0)

View File

@@ -247,7 +247,7 @@ static void drawCubicSegments(const QList<CubicSegment> &cubicSegments, QPainter
static void drawControlLine(const CubicSegment &cubicSegment, QPainter *painter) static void drawControlLine(const CubicSegment &cubicSegment, QPainter *painter)
{ {
static QPen solidPen(QColor(104, 183, 214), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); static const QPen solidPen(QColor(104, 183, 214), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
painter->setPen(solidPen); painter->setPen(solidPen);
painter->drawLine(cubicSegment.firstControlPoint().coordinate(), painter->drawLine(cubicSegment.firstControlPoint().coordinate(),
cubicSegment.secondControlPoint().coordinate()); cubicSegment.secondControlPoint().coordinate());
@@ -281,9 +281,9 @@ static QRectF controlPointShape(-2, -2, 5, 5);
static void drawControlPoint(const ControlPoint &controlPoint, const QList<ControlPoint> &selectionPoints, QPainter *painter) static void drawControlPoint(const ControlPoint &controlPoint, const QList<ControlPoint> &selectionPoints, QPainter *painter)
{ {
static QColor editPointColor(0, 110, 255); static const QColor editPointColor(0, 110, 255);
static QColor controlVertexColor(0, 110, 255); static const QColor controlVertexColor(0, 110, 255);
static QColor selectionPointColor(0, 255, 0); static const QColor selectionPointColor(0, 255, 0);
double originX = controlPoint.coordinate().x(); double originX = controlPoint.coordinate().x();
double originY = controlPoint.coordinate().y(); double originY = controlPoint.coordinate().y();

View File

@@ -42,10 +42,9 @@ QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent)
m_inMultilineComment(false) m_inMultilineComment(false)
{ {
m_currentBlockParentheses.reserve(20); m_currentBlockParentheses.reserve(20);
static const QVector<TextStyle> categories{ static const QVector<TextStyle> categories({
C_NUMBER, C_STRING, C_TYPE, C_NUMBER, C_STRING, C_TYPE, C_KEYWORD, C_FIELD, C_COMMENT, C_VISUAL_WHITESPACE
C_KEYWORD, C_FIELD, C_COMMENT, });
C_VISUAL_WHITESPACE};
setTextFormatCategories(categories); setTextFormatCategories(categories);
} }

View File

@@ -85,37 +85,36 @@ Highlighter::Highlighter(QTextDocument *parent) :
m_dynamicContextsCounter(0), m_dynamicContextsCounter(0),
m_isBroken(false) m_isBroken(false)
{ {
static QVector<TextStyle> categories; static const QVector<TextStyle> categories({
if (categories.isEmpty()) { C_TEXT, // Normal
categories << C_TEXT // Normal C_VISUAL_WHITESPACE, // VisualWhitespace
<< C_VISUAL_WHITESPACE // VisualWhitespace C_KEYWORD, // Keyword
<< C_KEYWORD // Keyword C_TYPE, // DataType
<< C_TYPE // DataType C_COMMENT, // Comment
<< C_COMMENT // Comment C_NUMBER, // Decimal
<< C_NUMBER // Decimal C_NUMBER, // BaseN
<< C_NUMBER // BaseN C_NUMBER, // Float
<< C_NUMBER // Float C_STRING, // Char
<< C_STRING // Char C_STRING, // SpecialChar
<< C_STRING // SpecialChar C_STRING, // String
<< C_STRING // String C_WARNING, // Alert
<< C_WARNING // Alert C_TEXT, // Information
<< C_TEXT // Information C_WARNING, // Warning
<< C_WARNING // Warning C_ERROR, // Error
<< C_ERROR // Error C_FUNCTION, // Function
<< C_FUNCTION // Function C_TEXT, // RegionMarker
<< C_TEXT // RegionMarker C_PREPROCESSOR, // BuiltIn
<< C_PREPROCESSOR // BuiltIn C_PRIMITIVE_TYPE, // Extension
<< C_PRIMITIVE_TYPE // Extension C_OPERATOR, // Operator
<< C_OPERATOR // Operator C_LOCAL, // Variable
<< C_LOCAL // Variable C_LABEL, // Attribute
<< C_LABEL // Attribute C_TEXT, // Annotation
<< C_TEXT // Annotation C_COMMENT, // CommentVar
<< C_COMMENT // CommentVar C_PREPROCESSOR, // Import
<< C_PREPROCESSOR // Import C_TEXT, // Others
<< C_TEXT // Others C_LOCAL, // Identifier
<< C_LOCAL // Identifier C_DOXYGEN_COMMENT // Documentation
<< C_DOXYGEN_COMMENT; // Documentation });
}
setTextFormatCategories(categories); setTextFormatCategories(categories);
} }

View File

@@ -76,9 +76,7 @@ BaseAnnotationHighlighter::BaseAnnotationHighlighter(const ChangeNumbers &change
TextEditor::SyntaxHighlighter(document), TextEditor::SyntaxHighlighter(document),
d(new BaseAnnotationHighlighterPrivate(this)) d(new BaseAnnotationHighlighterPrivate(this))
{ {
static QVector<TextEditor::TextStyle> categories; static const QVector<TextEditor::TextStyle> categories({TextEditor::C_TEXT});
if (categories.isEmpty())
categories << TextEditor::C_TEXT;
setTextFormatCategories(categories); setTextFormatCategories(categories);
d->updateOtherFormats(); d->updateOtherFormats();

View File

@@ -155,15 +155,14 @@ DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const Q
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)), TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern)) d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern))
{ {
static QVector<TextEditor::TextStyle> categories; static const QVector<TextEditor::TextStyle> categories({
if (categories.isEmpty()) { TextEditor::C_TEXT,
categories << TextEditor::C_TEXT TextEditor::C_ADDED_LINE,
<< TextEditor::C_ADDED_LINE TextEditor::C_REMOVED_LINE,
<< TextEditor::C_REMOVED_LINE TextEditor::C_DIFF_FILE,
<< TextEditor::C_DIFF_FILE TextEditor::C_DIFF_LOCATION,
<< TextEditor::C_DIFF_LOCATION TextEditor::C_LOG_CHANGE_LINE
<< TextEditor::C_LOG_CHANGE_LINE; });
}
setTextFormatCategories(categories); setTextFormatCategories(categories);
d->updateOtherFormats(); d->updateOtherFormats();
} }