From 57d31b8ebc1b8c18ae01ab7f65e11269aca8aa5b Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Sun, 11 Nov 2018 00:24:20 +0100 Subject: GlslEditor: Modernize modernize-use-auto modernize-use-equals-default modernize-use-nullptr modernize-use-override modernize-use-using Change-Id: Ic83ce33890ef2d4916997671af6163228135b7b0 Reviewed-by: Orgad Shaneh --- src/plugins/glsleditor/glslcompletionassist.cpp | 32 ++++++++----------------- src/plugins/glsleditor/glslcompletionassist.h | 14 +++++------ src/plugins/glsleditor/glsleditor.cpp | 7 +++--- src/plugins/glsleditor/glslhighlighter.cpp | 2 +- src/plugins/glsleditor/glslhighlighter.h | 2 +- src/plugins/glsleditor/glslindenter.cpp | 6 +---- src/plugins/glsleditor/glslindenter.h | 27 ++++++++++----------- 7 files changed, 35 insertions(+), 55 deletions(-) (limited to 'src/plugins/glsleditor') diff --git a/src/plugins/glsleditor/glslcompletionassist.cpp b/src/plugins/glsleditor/glslcompletionassist.cpp index 4fb33ac17e..39ac8b9832 100644 --- a/src/plugins/glsleditor/glslcompletionassist.cpp +++ b/src/plugins/glsleditor/glslcompletionassist.cpp @@ -60,13 +60,6 @@ using namespace TextEditor; namespace GlslEditor { namespace Internal { -Document::Document() - : _engine(0) - , _ast(0) - , _globalScope(0) -{ -} - Document::~Document() { delete _globalScope; @@ -211,7 +204,7 @@ bool GlslCompletionAssistProvider::isActivationCharSequence(const QString &seque struct FunctionItem { - FunctionItem() {} + FunctionItem() = default; explicit FunctionItem(const GLSL::Function *function); QString prettyPrint(int currentArgument) const; QString returnValue; @@ -279,7 +272,7 @@ int GlslFunctionHintProposalModel::activeArgument(const QString &prefix) const const QByteArray &str = prefix.toLatin1(); int argnr = 0; int parcount = 0; - GLSL::Lexer lexer(0, str.constData(), str.length()); + GLSL::Lexer lexer(nullptr, str.constData(), str.length()); GLSL::Token tk; QList tokens; do { @@ -308,16 +301,11 @@ int GlslFunctionHintProposalModel::activeArgument(const QString &prefix) const // ----------------------------- // GLSLCompletionAssistProcessor // ----------------------------- -GlslCompletionAssistProcessor::GlslCompletionAssistProcessor() - : m_startPosition(0) -{} - -GlslCompletionAssistProcessor::~GlslCompletionAssistProcessor() -{} +GlslCompletionAssistProcessor::~GlslCompletionAssistProcessor() = default; static AssistProposalItem *createCompletionItem(const QString &text, const QIcon &icon, int order = 0) { - AssistProposalItem *item = new AssistProposalItem; + auto item = new AssistProposalItem; item->setText(text); item->setIcon(icon); item->setOrder(order); @@ -329,7 +317,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i m_interface.reset(static_cast(interface)); if (interface->reason() == IdleEditor && !acceptsIdleEditor()) - return 0; + return nullptr; int pos = m_interface->position() - 1; QChar ch = m_interface->characterAt(pos); @@ -351,7 +339,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i tc.setPosition(pos); const int start = expressionUnderCursor.startOfFunctionCall(tc); if (start == -1) - return 0; + return nullptr; if (m_interface->characterAt(start) == QLatin1Char('(')) { pos = start; @@ -448,7 +436,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i "qt_MultiTexCoord0", "qt_MultiTexCoord1", "qt_MultiTexCoord2", - 0 + nullptr }; static const char * const uniformNames[] = { "qt_ModelViewProjectionMatrix", @@ -460,7 +448,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i "qt_Texture2", "qt_Color", "qt_Opacity", - 0 + nullptr }; for (int index = 0; attributeNames[index]; ++index) m_completions << createCompletionItem(QString::fromLatin1(attributeNames[index]), glslIcon(IconTypeAttribute)); @@ -542,8 +530,8 @@ bool GlslCompletionAssistProcessor::acceptsIdleEditor() const const QString word = m_interface->textAt(pos, cursorPosition - pos); if (word.length() > 2 && checkStartOfIdentifier(word)) { - for (int i = 0; i < word.length(); ++i) { - if (! isIdentifierChar(word.at(i))) + for (auto character : word) { + if (!isIdentifierChar(character)) return false; } return true; diff --git a/src/plugins/glsleditor/glslcompletionassist.h b/src/plugins/glsleditor/glslcompletionassist.h index d09537fec1..90a09c108a 100644 --- a/src/plugins/glsleditor/glslcompletionassist.h +++ b/src/plugins/glsleditor/glslcompletionassist.h @@ -51,9 +51,8 @@ namespace Internal { class Document { public: - typedef QSharedPointer Ptr; + using Ptr = QSharedPointer; - Document(); ~Document(); GLSL::Engine *engine() const { return _engine; } @@ -69,9 +68,9 @@ private: GLSL::Scope *scope; }; - GLSL::Engine *_engine; - GLSL::TranslationUnitAST *_ast; - GLSL::Scope *_globalScope; + GLSL::Engine *_engine = nullptr; + GLSL::TranslationUnitAST *_ast = nullptr; + GLSL::Scope *_globalScope = nullptr; QList _cursors; friend class GlslEditorWidget; @@ -93,8 +92,7 @@ public: class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor { public: - GlslCompletionAssistProcessor(); - ~GlslCompletionAssistProcessor(); + ~GlslCompletionAssistProcessor() override; TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override; @@ -102,7 +100,7 @@ private: TextEditor::IAssistProposal *createHintProposal(const QVector &symbols); bool acceptsIdleEditor() const; - int m_startPosition; + int m_startPosition = 0; QScopedPointer m_interface; }; diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 8280c9713e..33a4dafa47 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -125,14 +125,13 @@ private: QString wordUnderCursor() const; QTimer m_updateDocumentTimer; - QComboBox *m_outlineCombo; + QComboBox *m_outlineCombo = nullptr; Document::Ptr m_glslDocument; }; GlslEditorWidget::GlslEditorWidget() { setAutoCompleter(new GlslCompleter); - m_outlineCombo = 0; m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer.setSingleShot(true); @@ -147,7 +146,7 @@ GlslEditorWidget::GlslEditorWidget() // ### m_outlineCombo->setModel(m_outlineModel); - QTreeView *treeView = new QTreeView; + auto treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); @@ -203,7 +202,7 @@ void GlslEditorWidget::updateDocumentNow() doc->_engine = new Engine(); Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant); TranslationUnitAST *ast = parser.parse(); - if (ast != 0 || extraSelections(CodeWarningsSelection).isEmpty()) { + if (ast || extraSelections(CodeWarningsSelection).isEmpty()) { Semantic sem; Scope *globalScope = new Namespace(); doc->_globalScope = globalScope; diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp index 1faf60d2c0..417525dac6 100644 --- a/src/plugins/glsleditor/glslhighlighter.cpp +++ b/src/plugins/glsleditor/glslhighlighter.cpp @@ -56,7 +56,7 @@ void GlslHighlighter::highlightBlock(const QString &text) int braceDepth = initialBraceDepth; const QByteArray data = text.toLatin1(); - GLSL::Lexer lex(/*engine=*/ 0, data.constData(), data.size()); + GLSL::Lexer lex(/*engine=*/ nullptr, data.constData(), data.size()); lex.setState(state); lex.setScanKeywords(false); lex.setScanComments(true); diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h index 0a8215c0f5..2b29818aca 100644 --- a/src/plugins/glsleditor/glslhighlighter.h +++ b/src/plugins/glsleditor/glslhighlighter.h @@ -38,7 +38,7 @@ public: GlslHighlighter(); protected: - void highlightBlock(const QString &text); + void highlightBlock(const QString &text) override; void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); bool isPPKeyword(const QStringRef &text) const; }; diff --git a/src/plugins/glsleditor/glslindenter.cpp b/src/plugins/glsleditor/glslindenter.cpp index a743d815f9..b2c533f1e2 100644 --- a/src/plugins/glsleditor/glslindenter.cpp +++ b/src/plugins/glsleditor/glslindenter.cpp @@ -38,11 +38,7 @@ namespace GlslEditor { namespace Internal { -GlslIndenter::GlslIndenter() -{} - -GlslIndenter::~GlslIndenter() -{} +GlslIndenter::~GlslIndenter() = default; bool GlslIndenter::isElectricCharacter(const QChar &ch) const { diff --git a/src/plugins/glsleditor/glslindenter.h b/src/plugins/glsleditor/glslindenter.h index b5b55ccd13..75495f8303 100644 --- a/src/plugins/glsleditor/glslindenter.h +++ b/src/plugins/glsleditor/glslindenter.h @@ -33,20 +33,19 @@ namespace Internal { class GlslIndenter : public TextEditor::Indenter { public: - GlslIndenter(); - virtual ~GlslIndenter(); - - virtual bool isElectricCharacter(const QChar &ch) const override; - virtual void indentBlock(QTextDocument *doc, - const QTextBlock &block, - const QChar &typedChar, - const TextEditor::TabSettings &tabSettings) override; - - virtual void indent(QTextDocument *doc, - const QTextCursor &cursor, - const QChar &typedChar, - const TextEditor::TabSettings &tabSettings, - bool autoTriggered = true) override; + ~GlslIndenter() override; + + bool isElectricCharacter(const QChar &ch) const override; + void indentBlock(QTextDocument *doc, + const QTextBlock &block, + const QChar &typedChar, + const TextEditor::TabSettings &tabSettings) override; + + void indent(QTextDocument *doc, + const QTextCursor &cursor, + const QChar &typedChar, + const TextEditor::TabSettings &tabSettings, + bool autoTriggered = true) override; int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override; TextEditor::IndentationForBlock indentationForBlocks(const QVector &blocks, -- cgit v1.2.3