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 <orgads@gmail.com>
This commit is contained in:
Alessandro Portale
2018-11-11 00:24:20 +01:00
parent 01d19b4f70
commit 57d31b8ebc
7 changed files with 33 additions and 53 deletions

View File

@@ -60,13 +60,6 @@ using namespace TextEditor;
namespace GlslEditor { namespace GlslEditor {
namespace Internal { namespace Internal {
Document::Document()
: _engine(0)
, _ast(0)
, _globalScope(0)
{
}
Document::~Document() Document::~Document()
{ {
delete _globalScope; delete _globalScope;
@@ -211,7 +204,7 @@ bool GlslCompletionAssistProvider::isActivationCharSequence(const QString &seque
struct FunctionItem struct FunctionItem
{ {
FunctionItem() {} FunctionItem() = default;
explicit FunctionItem(const GLSL::Function *function); explicit FunctionItem(const GLSL::Function *function);
QString prettyPrint(int currentArgument) const; QString prettyPrint(int currentArgument) const;
QString returnValue; QString returnValue;
@@ -279,7 +272,7 @@ int GlslFunctionHintProposalModel::activeArgument(const QString &prefix) const
const QByteArray &str = prefix.toLatin1(); const QByteArray &str = prefix.toLatin1();
int argnr = 0; int argnr = 0;
int parcount = 0; int parcount = 0;
GLSL::Lexer lexer(0, str.constData(), str.length()); GLSL::Lexer lexer(nullptr, str.constData(), str.length());
GLSL::Token tk; GLSL::Token tk;
QList<GLSL::Token> tokens; QList<GLSL::Token> tokens;
do { do {
@@ -308,16 +301,11 @@ int GlslFunctionHintProposalModel::activeArgument(const QString &prefix) const
// ----------------------------- // -----------------------------
// GLSLCompletionAssistProcessor // GLSLCompletionAssistProcessor
// ----------------------------- // -----------------------------
GlslCompletionAssistProcessor::GlslCompletionAssistProcessor() GlslCompletionAssistProcessor::~GlslCompletionAssistProcessor() = default;
: m_startPosition(0)
{}
GlslCompletionAssistProcessor::~GlslCompletionAssistProcessor()
{}
static AssistProposalItem *createCompletionItem(const QString &text, const QIcon &icon, int order = 0) static AssistProposalItem *createCompletionItem(const QString &text, const QIcon &icon, int order = 0)
{ {
AssistProposalItem *item = new AssistProposalItem; auto item = new AssistProposalItem;
item->setText(text); item->setText(text);
item->setIcon(icon); item->setIcon(icon);
item->setOrder(order); item->setOrder(order);
@@ -329,7 +317,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i
m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface)); m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface));
if (interface->reason() == IdleEditor && !acceptsIdleEditor()) if (interface->reason() == IdleEditor && !acceptsIdleEditor())
return 0; return nullptr;
int pos = m_interface->position() - 1; int pos = m_interface->position() - 1;
QChar ch = m_interface->characterAt(pos); QChar ch = m_interface->characterAt(pos);
@@ -351,7 +339,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i
tc.setPosition(pos); tc.setPosition(pos);
const int start = expressionUnderCursor.startOfFunctionCall(tc); const int start = expressionUnderCursor.startOfFunctionCall(tc);
if (start == -1) if (start == -1)
return 0; return nullptr;
if (m_interface->characterAt(start) == QLatin1Char('(')) { if (m_interface->characterAt(start) == QLatin1Char('(')) {
pos = start; pos = start;
@@ -448,7 +436,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i
"qt_MultiTexCoord0", "qt_MultiTexCoord0",
"qt_MultiTexCoord1", "qt_MultiTexCoord1",
"qt_MultiTexCoord2", "qt_MultiTexCoord2",
0 nullptr
}; };
static const char * const uniformNames[] = { static const char * const uniformNames[] = {
"qt_ModelViewProjectionMatrix", "qt_ModelViewProjectionMatrix",
@@ -460,7 +448,7 @@ IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *i
"qt_Texture2", "qt_Texture2",
"qt_Color", "qt_Color",
"qt_Opacity", "qt_Opacity",
0 nullptr
}; };
for (int index = 0; attributeNames[index]; ++index) for (int index = 0; attributeNames[index]; ++index)
m_completions << createCompletionItem(QString::fromLatin1(attributeNames[index]), glslIcon(IconTypeAttribute)); 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); const QString word = m_interface->textAt(pos, cursorPosition - pos);
if (word.length() > 2 && checkStartOfIdentifier(word)) { if (word.length() > 2 && checkStartOfIdentifier(word)) {
for (int i = 0; i < word.length(); ++i) { for (auto character : word) {
if (! isIdentifierChar(word.at(i))) if (!isIdentifierChar(character))
return false; return false;
} }
return true; return true;

View File

@@ -51,9 +51,8 @@ namespace Internal {
class Document class Document
{ {
public: public:
typedef QSharedPointer<Document> Ptr; using Ptr = QSharedPointer<Document>;
Document();
~Document(); ~Document();
GLSL::Engine *engine() const { return _engine; } GLSL::Engine *engine() const { return _engine; }
@@ -69,9 +68,9 @@ private:
GLSL::Scope *scope; GLSL::Scope *scope;
}; };
GLSL::Engine *_engine; GLSL::Engine *_engine = nullptr;
GLSL::TranslationUnitAST *_ast; GLSL::TranslationUnitAST *_ast = nullptr;
GLSL::Scope *_globalScope; GLSL::Scope *_globalScope = nullptr;
QList<Range> _cursors; QList<Range> _cursors;
friend class GlslEditorWidget; friend class GlslEditorWidget;
@@ -93,8 +92,7 @@ public:
class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor
{ {
public: public:
GlslCompletionAssistProcessor(); ~GlslCompletionAssistProcessor() override;
~GlslCompletionAssistProcessor();
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override; TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
@@ -102,7 +100,7 @@ private:
TextEditor::IAssistProposal *createHintProposal(const QVector<GLSL::Function *> &symbols); TextEditor::IAssistProposal *createHintProposal(const QVector<GLSL::Function *> &symbols);
bool acceptsIdleEditor() const; bool acceptsIdleEditor() const;
int m_startPosition; int m_startPosition = 0;
QScopedPointer<const GlslCompletionAssistInterface> m_interface; QScopedPointer<const GlslCompletionAssistInterface> m_interface;
}; };

View File

@@ -125,14 +125,13 @@ private:
QString wordUnderCursor() const; QString wordUnderCursor() const;
QTimer m_updateDocumentTimer; QTimer m_updateDocumentTimer;
QComboBox *m_outlineCombo; QComboBox *m_outlineCombo = nullptr;
Document::Ptr m_glslDocument; Document::Ptr m_glslDocument;
}; };
GlslEditorWidget::GlslEditorWidget() GlslEditorWidget::GlslEditorWidget()
{ {
setAutoCompleter(new GlslCompleter); setAutoCompleter(new GlslCompleter);
m_outlineCombo = 0;
m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer.setSingleShot(true); m_updateDocumentTimer.setSingleShot(true);
@@ -147,7 +146,7 @@ GlslEditorWidget::GlslEditorWidget()
// ### m_outlineCombo->setModel(m_outlineModel); // ### m_outlineCombo->setModel(m_outlineModel);
QTreeView *treeView = new QTreeView; auto treeView = new QTreeView;
treeView->header()->hide(); treeView->header()->hide();
treeView->setItemsExpandable(false); treeView->setItemsExpandable(false);
treeView->setRootIsDecorated(false); treeView->setRootIsDecorated(false);
@@ -203,7 +202,7 @@ void GlslEditorWidget::updateDocumentNow()
doc->_engine = new Engine(); doc->_engine = new Engine();
Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant); Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
TranslationUnitAST *ast = parser.parse(); TranslationUnitAST *ast = parser.parse();
if (ast != 0 || extraSelections(CodeWarningsSelection).isEmpty()) { if (ast || extraSelections(CodeWarningsSelection).isEmpty()) {
Semantic sem; Semantic sem;
Scope *globalScope = new Namespace(); Scope *globalScope = new Namespace();
doc->_globalScope = globalScope; doc->_globalScope = globalScope;

View File

@@ -56,7 +56,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
int braceDepth = initialBraceDepth; int braceDepth = initialBraceDepth;
const QByteArray data = text.toLatin1(); 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.setState(state);
lex.setScanKeywords(false); lex.setScanKeywords(false);
lex.setScanComments(true); lex.setScanComments(true);

View File

@@ -38,7 +38,7 @@ public:
GlslHighlighter(); GlslHighlighter();
protected: protected:
void highlightBlock(const QString &text); void highlightBlock(const QString &text) override;
void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format);
bool isPPKeyword(const QStringRef &text) const; bool isPPKeyword(const QStringRef &text) const;
}; };

View File

@@ -38,11 +38,7 @@
namespace GlslEditor { namespace GlslEditor {
namespace Internal { namespace Internal {
GlslIndenter::GlslIndenter() GlslIndenter::~GlslIndenter() = default;
{}
GlslIndenter::~GlslIndenter()
{}
bool GlslIndenter::isElectricCharacter(const QChar &ch) const bool GlslIndenter::isElectricCharacter(const QChar &ch) const
{ {

View File

@@ -33,20 +33,19 @@ namespace Internal {
class GlslIndenter : public TextEditor::Indenter class GlslIndenter : public TextEditor::Indenter
{ {
public: public:
GlslIndenter(); ~GlslIndenter() override;
virtual ~GlslIndenter();
virtual bool isElectricCharacter(const QChar &ch) const override; bool isElectricCharacter(const QChar &ch) const override;
virtual void indentBlock(QTextDocument *doc, void indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
const TextEditor::TabSettings &tabSettings) override; const TextEditor::TabSettings &tabSettings) override;
virtual void indent(QTextDocument *doc, void indent(QTextDocument *doc,
const QTextCursor &cursor, const QTextCursor &cursor,
const QChar &typedChar, const QChar &typedChar,
const TextEditor::TabSettings &tabSettings, const TextEditor::TabSettings &tabSettings,
bool autoTriggered = true) override; bool autoTriggered = true) override;
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override; int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks, TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,