diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 8da47733d69..4e738f29f80 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -53,8 +53,7 @@ using namespace TextEditor; using namespace GLSL; -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { static int versionFor(const QString &source) { @@ -356,10 +355,7 @@ std::unique_ptr GlslEditorWidget::createAssistInterface( m_glslDocument); } - -// // GlslEditorFactory -// GlslEditorFactory::GlslEditorFactory() { @@ -373,8 +369,8 @@ GlslEditorFactory::GlslEditorFactory() setDocumentCreator([]() { return new TextDocument(Constants::C_GLSLEDITOR_ID); }); setEditorWidgetCreator([]() { return new GlslEditorWidget; }); - setIndenterCreator([](QTextDocument *doc) { return new GlslIndenter(doc); }); - setSyntaxHighlighterCreator([]() { return new GlslHighlighter; }); + setIndenterCreator(&createGlslIndenter); + setSyntaxHighlighterCreator(&createGlslHighlighter); setCommentDefinition(Utils::CommentDefinition::CppStyle); setCompletionAssistProvider(new GlslCompletionAssistProvider); setParenthesesMatchingEnabled(true); @@ -385,5 +381,4 @@ GlslEditorFactory::GlslEditorFactory() | TextEditorActionHandler::UnCollapseAll); } -} // namespace Internal -} // namespace GlslEditor +} // GlslEditor::Internal diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index 417a9a7791a..b8d9afb6e44 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -5,8 +5,7 @@ #include -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { int languageVariant(const QString &mimeType); @@ -16,5 +15,4 @@ public: GlslEditorFactory(); }; -} // namespace Internal -} // namespace GlslEditor +} // GlslEditor::Internal diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp index 70452deefcd..3c6028e0dc3 100644 --- a/src/plugins/glsleditor/glslhighlighter.cpp +++ b/src/plugins/glsleditor/glslhighlighter.cpp @@ -15,13 +15,21 @@ using namespace TextEditor; const TextStyle GLSLReservedKeyword = C_REMOVED_LINE; -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { -GlslHighlighter::GlslHighlighter() +class GlslHighlighter final : public TextEditor::SyntaxHighlighter { - setDefaultTextFormatCategories(); -} +public: + GlslHighlighter() + { + setDefaultTextFormatCategories(); + } + +private: + void highlightBlock(const QString &text) final; + void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); + bool isPPKeyword(QStringView text) const; +}; void GlslHighlighter::highlightBlock(const QString &text) { @@ -293,5 +301,10 @@ bool GlslHighlighter::isPPKeyword(QStringView text) const return false; } -} // namespace Internal -} // namespace GlslEditor + +TextEditor::SyntaxHighlighter *createGlslHighlighter() +{ + return new GlslHighlighter; +} + +} // GlslEditor::Internal diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h index 3fb250c31e0..56079496596 100644 --- a/src/plugins/glsleditor/glslhighlighter.h +++ b/src/plugins/glsleditor/glslhighlighter.h @@ -5,21 +5,8 @@ #include -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { -class GlslHighlighter : public TextEditor::SyntaxHighlighter -{ - Q_OBJECT +TextEditor::SyntaxHighlighter *createGlslHighlighter(); -public: - GlslHighlighter(); - -protected: - void highlightBlock(const QString &text) override; - void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); - bool isPPKeyword(QStringView text) const; -}; - -} // namespace Internal -} // namespace GlslEditor +} // GlslEditor::Internal diff --git a/src/plugins/glsleditor/glslindenter.cpp b/src/plugins/glsleditor/glslindenter.cpp index 7a8dcbbb289..8a14112327d 100644 --- a/src/plugins/glsleditor/glslindenter.cpp +++ b/src/plugins/glsleditor/glslindenter.cpp @@ -8,18 +8,37 @@ #include #include -#include #include #include #include -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { -GlslIndenter::GlslIndenter(QTextDocument *doc) - : TextEditor::TextIndenter(doc) -{} -GlslIndenter::~GlslIndenter() = default; +class GlslIndenter final : public TextEditor::TextIndenter +{ +public: + explicit GlslIndenter(QTextDocument *doc) + : TextEditor::TextIndenter(doc) + {} + + bool isElectricCharacter(const QChar &ch) const final; + void indentBlock(const QTextBlock &block, + const QChar &typedChar, + const TextEditor::TabSettings &tabSettings, + int cursorPositionInEditor = -1) final; + + void indent(const QTextCursor &cursor, + const QChar &typedChar, + const TextEditor::TabSettings &tabSettings, + int cursorPositionInEditor = -1) final; + + int indentFor(const QTextBlock &block, + const TextEditor::TabSettings &tabSettings, + int cursorPositionInEditor = -1) final; + TextEditor::IndentationForBlock indentationForBlocks(const QVector &blocks, + const TextEditor::TabSettings &tabSettings, + int cursorPositionInEditor = -1) final; +}; bool GlslIndenter::isElectricCharacter(const QChar &ch) const { @@ -120,5 +139,9 @@ TextEditor::IndentationForBlock GlslIndenter::indentationForBlocks( return ret; } -} // namespace Internal -} // namespace GlslEditor +TextEditor::TextIndenter *createGlslIndenter(QTextDocument *doc) +{ + return new GlslIndenter(doc); +} + +} // GlslEditor::Internal diff --git a/src/plugins/glsleditor/glslindenter.h b/src/plugins/glsleditor/glslindenter.h index da0040fdcb8..f1cbeef0d45 100644 --- a/src/plugins/glsleditor/glslindenter.h +++ b/src/plugins/glsleditor/glslindenter.h @@ -5,33 +5,8 @@ #include -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { -class GlslIndenter : public TextEditor::TextIndenter -{ -public: - explicit GlslIndenter(QTextDocument *doc); - ~GlslIndenter() override; +TextEditor::TextIndenter *createGlslIndenter(QTextDocument *doc); - bool isElectricCharacter(const QChar &ch) const override; - void indentBlock(const QTextBlock &block, - const QChar &typedChar, - const TextEditor::TabSettings &tabSettings, - int cursorPositionInEditor = -1) override; - - void indent(const QTextCursor &cursor, - const QChar &typedChar, - const TextEditor::TabSettings &tabSettings, - int cursorPositionInEditor = -1) override; - - int indentFor(const QTextBlock &block, - const TextEditor::TabSettings &tabSettings, - int cursorPositionInEditor = -1) override; - TextEditor::IndentationForBlock indentationForBlocks(const QVector &blocks, - const TextEditor::TabSettings &tabSettings, - int cursorPositionInEditor = -1) override; -}; - -} // namespace Internal -} // namespace GlslEditor +} // namespace GlslEditor::Internal