diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2016-09-23 15:46:41 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2016-09-23 14:27:01 +0000 |
commit | d915b22db9a3e66a2faa045251f7df2146dd428e (patch) | |
tree | 726fc40b312c0e86c4a6469f064d7e3b9fcac78c /src | |
parent | 669d04a686418541f83a1936d4b278721ec986fe (diff) |
improve static initializers
Change-Id: I304fdd6627f01fc216c84930da607127c52409d9
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cpphighlighter.cpp | 29 | ||||
-rw-r--r-- | src/plugins/git/githighlighters.cpp | 27 | ||||
-rw-r--r-- | src/plugins/glsleditor/glslhighlighter.cpp | 29 | ||||
-rw-r--r-- | src/plugins/help/searchwidget.cpp | 15 | ||||
-rw-r--r-- | src/plugins/mercurial/mercurialcommitwidget.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/abstractmsvctoolchain.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/settingsaccessor.cpp | 30 | ||||
-rw-r--r-- | src/plugins/qmakeprojectmanager/profilehighlighter.cpp | 4 | ||||
-rw-r--r-- | src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp | 24 | ||||
-rw-r--r-- | src/plugins/qmldesigner/documentwarningwidget.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp | 8 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljshighlighter.cpp | 7 | ||||
-rw-r--r-- | src/plugins/texteditor/generichighlighter/highlighter.cpp | 61 | ||||
-rw-r--r-- | src/plugins/vcsbase/baseannotationhighlighter.cpp | 4 | ||||
-rw-r--r-- | src/plugins/vcsbase/diffandloghighlighter.cpp | 17 |
15 files changed, 119 insertions, 146 deletions
diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index 17fb5e668e..d754b32686 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -42,21 +42,20 @@ using namespace CPlusPlus; CppHighlighter::CppHighlighter(QTextDocument *document) : SyntaxHighlighter(document) { - static QVector<TextStyle> categories; - if (categories.isEmpty()) { - categories << C_NUMBER - << C_STRING - << C_TYPE - << C_KEYWORD - << C_PRIMITIVE_TYPE - << C_OPERATOR - << C_PREPROCESSOR - << C_LABEL - << C_COMMENT - << C_DOXYGEN_COMMENT - << C_DOXYGEN_TAG - << C_VISUAL_WHITESPACE; - } + static const QVector<TextStyle> categories({ + C_NUMBER, + C_STRING, + C_TYPE, + C_KEYWORD, + C_PRIMITIVE_TYPE, + C_OPERATOR, + C_PREPROCESSOR, + C_LABEL, + C_COMMENT, + C_DOXYGEN_COMMENT, + C_DOXYGEN_TAG, + C_VISUAL_WHITESPACE + }); setTextFormatCategories(categories); } diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp index b86efdc6e4..4cbb635137 100644 --- a/src/plugins/git/githighlighters.cpp +++ b/src/plugins/git/githighlighters.cpp @@ -37,9 +37,7 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b"; GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : TextEditor::SyntaxHighlighter(parent) { - static QVector<TextEditor::TextStyle> categories; - if (categories.isEmpty()) - categories << TextEditor::C_COMMENT; + static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT}); setTextFormatCategories(categories); m_keywordPattern.setPattern("^[\\w-]+:"); @@ -98,18 +96,17 @@ GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) : m_hashChar('#'), m_changeNumberPattern(CHANGE_PATTERN) { - static QVector<TextEditor::TextStyle> categories; - if (categories.isEmpty()) { - 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; - } + 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); m_actions << RebaseAction("^(p|pick)\\b", Format_Pick); diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp index 122bb2e7ce..eed647e177 100644 --- a/src/plugins/glsleditor/glslhighlighter.cpp +++ b/src/plugins/glsleditor/glslhighlighter.cpp @@ -39,21 +39,20 @@ namespace Internal { GlslHighlighter::GlslHighlighter() { - static QVector<TextStyle> categories; - if (categories.isEmpty()) { - categories << C_NUMBER - << C_STRING - << C_TYPE - << C_KEYWORD - << C_OPERATOR - << C_PREPROCESSOR - << C_LABEL - << C_COMMENT - << C_DOXYGEN_COMMENT - << C_DOXYGEN_TAG - << C_VISUAL_WHITESPACE - << C_REMOVED_LINE; - } + static const QVector<TextStyle> categories({ + C_NUMBER, + C_STRING, + C_TYPE, + C_KEYWORD, + C_OPERATOR, + C_PREPROCESSOR, + C_LABEL, + C_COMMENT, + C_DOXYGEN_COMMENT, + C_DOXYGEN_TAG, + C_VISUAL_WHITESPACE, + C_REMOVED_LINE + }); setTextFormatCategories(categories); } diff --git a/src/plugins/help/searchwidget.cpp b/src/plugins/help/searchwidget.cpp index c0df8c9bea..1288673a6e 100644 --- a/src/plugins/help/searchwidget.cpp +++ b/src/plugins/help/searchwidget.cpp @@ -157,17 +157,12 @@ void SearchWidget::showEvent(QShowEvent *event) void SearchWidget::search() const { - static QStringList charsToEscapeList; - if (charsToEscapeList.isEmpty()) { - charsToEscapeList << "\\" << "+" - << "-" << "!" << "(" - << ")" << ":" << "^" - << "[" << "]" << "{" - << "}" << "~"; - } + static const QStringList charsToEscapeList({ + "\\", "+", "-", "!", "(", ")", ":", "^", "[", "]", "{", "}", "~" + }); - static QString escapeChar("\\"); - static QRegExp regExp("[\\+\\-\\!\\(\\)\\^\\[\\]\\{\\}~:]"); + static const QString escapeChar("\\"); + static const QRegExp regExp("[\\+\\-\\!\\(\\)\\^\\[\\]\\{\\}~:]"); QList<QHelpSearchQuery> escapedQueries; const QList<QHelpSearchQuery> queries = searchEngine->queryWidget()->query(); diff --git a/src/plugins/mercurial/mercurialcommitwidget.cpp b/src/plugins/mercurial/mercurialcommitwidget.cpp index 7e74d5a4ec..c8d8f262dc 100644 --- a/src/plugins/mercurial/mercurialcommitwidget.cpp +++ b/src/plugins/mercurial/mercurialcommitwidget.cpp @@ -60,9 +60,7 @@ MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) : TextEditor::SyntaxHighlighter(parent), m_keywordPattern(QLatin1String("^\\w+:")) { - static QVector<TextEditor::TextStyle> categories; - if (categories.isEmpty()) - categories << TextEditor::C_COMMENT; + static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT}); setTextFormatCategories(categories); QTC_CHECK(m_keywordPattern.isValid()); diff --git a/src/plugins/projectexplorer/abstractmsvctoolchain.cpp b/src/plugins/projectexplorer/abstractmsvctoolchain.cpp index 1ad836de0a..2710a434e3 100644 --- a/src/plugins/projectexplorer/abstractmsvctoolchain.cpp +++ b/src/plugins/projectexplorer/abstractmsvctoolchain.cpp @@ -280,8 +280,8 @@ bool AbstractMsvcToolChain::generateEnvironmentSettings(Utils::Environment &env, if (cmdPath.isEmpty()) cmdPath = env.searchInPath(QLatin1String("cmd.exe")); // Windows SDK setup scripts require command line switches for environment expansion. - QStringList cmdArguments; - cmdArguments << QLatin1String("/E:ON") << QLatin1String("/V:ON") << QLatin1String("/c"); + QStringList cmdArguments({ + QLatin1String("/E:ON"), QLatin1String("/V:ON"), QLatin1String("/c")}); cmdArguments << QDir::toNativeSeparators(saver.fileName()); if (debug) qDebug() << "readEnvironmentSetting: " << call << cmdPath << cmdArguments.join(' ') diff --git a/src/plugins/projectexplorer/settingsaccessor.cpp b/src/plugins/projectexplorer/settingsaccessor.cpp index 28514964d1..f0c0167a0a 100644 --- a/src/plugins/projectexplorer/settingsaccessor.cpp +++ b/src/plugins/projectexplorer/settingsaccessor.cpp @@ -1868,23 +1868,19 @@ static const char * const varExpandedKeys[] = { // Translate old-style ${} var expansions into new-style %{} ones static QVariant version8VarNodeTransform(const QVariant &var) { - static const char * const vars[] = { - "absoluteFilePath", - "absolutePath", - "baseName", - "canonicalPath", - "canonicalFilePath", - "completeBaseName", - "completeSuffix", - "fileName", - "filePath", - "path", - "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])); + static const QSet<QString> map({ + "CURRENT_DOCUMENT:absoluteFilePath", + "CURRENT_DOCUMENT:absolutePath", + "CURRENT_DOCUMENT:baseName", + "CURRENT_DOCUMENT:canonicalPath", + "CURRENT_DOCUMENT:canonicalFilePath", + "CURRENT_DOCUMENT:completeBaseName", + "CURRENT_DOCUMENT:completeSuffix", + "CURRENT_DOCUMENT:fileName", + "CURRENT_DOCUMENT:filePath", + "CURRENT_DOCUMENT:path", + "CURRENT_DOCUMENT:suffix" + }); QString str = var.toString(); int pos = 0; diff --git a/src/plugins/qmakeprojectmanager/profilehighlighter.cpp b/src/plugins/qmakeprojectmanager/profilehighlighter.cpp index 9a89ed0b44..c93d7af9d7 100644 --- a/src/plugins/qmakeprojectmanager/profilehighlighter.cpp +++ b/src/plugins/qmakeprojectmanager/profilehighlighter.cpp @@ -38,9 +38,7 @@ namespace Internal { ProFileHighlighter::ProFileHighlighter(const Keywords &keywords) : m_keywords(keywords) { - static QVector<TextStyle> categories; - if (categories.isEmpty()) - categories << C_TYPE << C_KEYWORD << C_COMMENT << C_VISUAL_WHITESPACE; + static const QVector<TextStyle> categories({C_TYPE, C_KEYWORD, C_COMMENT, C_VISUAL_WHITESPACE}); setTextFormatCategories(categories); } diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index 5371cedfdd..1b11300be7 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -71,37 +71,33 @@ static inline bool isSupportedAttachedProperties(const QString &propertyName) static inline QStringList supportedVersionsList() { static const QStringList list = { - QStringLiteral("2.0"), QStringLiteral("2.1"), - QStringLiteral("2.2"), QStringLiteral("2.3"), - QStringLiteral("2.4"), QStringLiteral("2.5"), - QStringLiteral("2.6"), QStringLiteral("2.7"), - QStringLiteral("2.8") + "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8" }; return list; } static inline QStringList globalQtEnums() { - static QStringList list = QStringList() << QStringLiteral("Horizontal") << QStringLiteral("Vertical") << QStringLiteral("AlignVCenter") - << QStringLiteral("AlignLeft") << QStringLiteral("LeftToRight") << QStringLiteral("RightToLeft") << QStringLiteral("AlignHCenter") - << QStringLiteral("AlignRight") << QStringLiteral("AlignBottom") << QStringLiteral("AlignBaseline") << QStringLiteral("AlignTop") - << QStringLiteral("BottomLeft") << QStringLiteral("LeftEdge") << QStringLiteral("RightEdge") << QStringLiteral("BottomEdge"); + static const QStringList list = { + "Horizontal", "Vertical", "AlignVCenter", "AlignLeft", "LeftToRight", "RightToLeft", + "AlignHCenter", "AlignRight", "AlignBottom", "AlignBaseline", "AlignTop", "BottomLeft", + "LeftEdge", "RightEdge", "BottomEdge" + }; return list; } static inline QStringList knownEnumScopes() { - static QStringList list = QStringList() << QStringLiteral("TextInput") << QStringLiteral("TextEdit") - << QStringLiteral("Material") << QStringLiteral("Universal") ;; + static const QStringList list = { + "TextInput", "TextEdit", "Material", "Universal" + }; return list; } static inline bool supportedQtQuickVersion(const QString &version) { - static QStringList supportedVersions = supportedVersionsList(); - - return supportedVersions.contains(version); + return supportedVersionsList().contains(version); } static inline QString stripQuotes(const QString &str) diff --git a/src/plugins/qmldesigner/documentwarningwidget.cpp b/src/plugins/qmldesigner/documentwarningwidget.cpp index d816db3264..d3b217844f 100644 --- a/src/plugins/qmldesigner/documentwarningwidget.cpp +++ b/src/plugins/qmldesigner/documentwarningwidget.cpp @@ -142,7 +142,7 @@ void DocumentWarningWidget::refreshContent() QString DocumentWarningWidget::generateNavigateLinks() { - static QString link(QLatin1String("<a href=\"%1\">%2</a>")); + static const QString link("<a href=\"%1\">%2</a>"); QStringList links; if (m_messages.count() > 1) { if (m_currentMessage != 0) diff --git a/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp b/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp index 825c0b37fc..8d3f9d1d59 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp @@ -247,7 +247,7 @@ static void drawCubicSegments(const QList<CubicSegment> &cubicSegments, QPainter 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->drawLine(cubicSegment.firstControlPoint().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 QColor editPointColor(0, 110, 255); - static QColor controlVertexColor(0, 110, 255); - static QColor selectionPointColor(0, 255, 0); + static const QColor editPointColor(0, 110, 255); + static const QColor controlVertexColor(0, 110, 255); + static const QColor selectionPointColor(0, 255, 0); double originX = controlPoint.coordinate().x(); double originY = controlPoint.coordinate().y(); diff --git a/src/plugins/qmljseditor/qmljshighlighter.cpp b/src/plugins/qmljseditor/qmljshighlighter.cpp index f38ab41c76..2a34509ae8 100644 --- a/src/plugins/qmljseditor/qmljshighlighter.cpp +++ b/src/plugins/qmljseditor/qmljshighlighter.cpp @@ -42,10 +42,9 @@ QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent) m_inMultilineComment(false) { m_currentBlockParentheses.reserve(20); - static const QVector<TextStyle> categories{ - C_NUMBER, C_STRING, C_TYPE, - C_KEYWORD, C_FIELD, C_COMMENT, - C_VISUAL_WHITESPACE}; + static const QVector<TextStyle> categories({ + C_NUMBER, C_STRING, C_TYPE, C_KEYWORD, C_FIELD, C_COMMENT, C_VISUAL_WHITESPACE + }); setTextFormatCategories(categories); } diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp index 1cefcfc2a5..877767f4c4 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -85,37 +85,36 @@ Highlighter::Highlighter(QTextDocument *parent) : m_dynamicContextsCounter(0), m_isBroken(false) { - static QVector<TextStyle> categories; - if (categories.isEmpty()) { - categories << C_TEXT // Normal - << C_VISUAL_WHITESPACE // VisualWhitespace - << C_KEYWORD // Keyword - << C_TYPE // DataType - << C_COMMENT // Comment - << C_NUMBER // Decimal - << C_NUMBER // BaseN - << C_NUMBER // Float - << C_STRING // Char - << C_STRING // SpecialChar - << C_STRING // String - << C_WARNING // Alert - << C_TEXT // Information - << C_WARNING // Warning - << C_ERROR // Error - << C_FUNCTION // Function - << C_TEXT // RegionMarker - << C_PREPROCESSOR // BuiltIn - << C_PRIMITIVE_TYPE // Extension - << C_OPERATOR // Operator - << C_LOCAL // Variable - << C_LABEL // Attribute - << C_TEXT // Annotation - << C_COMMENT // CommentVar - << C_PREPROCESSOR // Import - << C_TEXT // Others - << C_LOCAL // Identifier - << C_DOXYGEN_COMMENT; // Documentation - } + static const QVector<TextStyle> categories({ + C_TEXT, // Normal + C_VISUAL_WHITESPACE, // VisualWhitespace + C_KEYWORD, // Keyword + C_TYPE, // DataType + C_COMMENT, // Comment + C_NUMBER, // Decimal + C_NUMBER, // BaseN + C_NUMBER, // Float + C_STRING, // Char + C_STRING, // SpecialChar + C_STRING, // String + C_WARNING, // Alert + C_TEXT, // Information + C_WARNING, // Warning + C_ERROR, // Error + C_FUNCTION, // Function + C_TEXT, // RegionMarker + C_PREPROCESSOR, // BuiltIn + C_PRIMITIVE_TYPE, // Extension + C_OPERATOR, // Operator + C_LOCAL, // Variable + C_LABEL, // Attribute + C_TEXT, // Annotation + C_COMMENT, // CommentVar + C_PREPROCESSOR, // Import + C_TEXT, // Others + C_LOCAL, // Identifier + C_DOXYGEN_COMMENT // Documentation + }); setTextFormatCategories(categories); } diff --git a/src/plugins/vcsbase/baseannotationhighlighter.cpp b/src/plugins/vcsbase/baseannotationhighlighter.cpp index 8636e527e7..389510fb20 100644 --- a/src/plugins/vcsbase/baseannotationhighlighter.cpp +++ b/src/plugins/vcsbase/baseannotationhighlighter.cpp @@ -76,9 +76,7 @@ BaseAnnotationHighlighter::BaseAnnotationHighlighter(const ChangeNumbers &change TextEditor::SyntaxHighlighter(document), d(new BaseAnnotationHighlighterPrivate(this)) { - static QVector<TextEditor::TextStyle> categories; - if (categories.isEmpty()) - categories << TextEditor::C_TEXT; + static const QVector<TextEditor::TextStyle> categories({TextEditor::C_TEXT}); setTextFormatCategories(categories); d->updateOtherFormats(); diff --git a/src/plugins/vcsbase/diffandloghighlighter.cpp b/src/plugins/vcsbase/diffandloghighlighter.cpp index 0bf053f661..f3c5b910e8 100644 --- a/src/plugins/vcsbase/diffandloghighlighter.cpp +++ b/src/plugins/vcsbase/diffandloghighlighter.cpp @@ -155,15 +155,14 @@ DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const Q TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)), d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern)) { - static QVector<TextEditor::TextStyle> categories; - if (categories.isEmpty()) { - categories << TextEditor::C_TEXT - << TextEditor::C_ADDED_LINE - << TextEditor::C_REMOVED_LINE - << TextEditor::C_DIFF_FILE - << TextEditor::C_DIFF_LOCATION - << TextEditor::C_LOG_CHANGE_LINE; - } + static const QVector<TextEditor::TextStyle> categories({ + TextEditor::C_TEXT, + TextEditor::C_ADDED_LINE, + TextEditor::C_REMOVED_LINE, + TextEditor::C_DIFF_FILE, + TextEditor::C_DIFF_LOCATION, + TextEditor::C_LOG_CHANGE_LINE + }); setTextFormatCategories(categories); d->updateOtherFormats(); } |