GlslEditor: Move some class definitions to .cpp

Also, de-Q_OBJECT-ify GlslHighlighter and a bit of code cosmetics.

Change-Id: I17469acc950fc77055f68918b1362f01e8a8c8a3
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-12-21 15:59:18 +01:00
parent 32e6f73119
commit cca5f07d35
6 changed files with 64 additions and 73 deletions

View File

@@ -53,8 +53,7 @@
using namespace TextEditor; using namespace TextEditor;
using namespace GLSL; using namespace GLSL;
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
static int versionFor(const QString &source) static int versionFor(const QString &source)
{ {
@@ -356,10 +355,7 @@ std::unique_ptr<AssistInterface> GlslEditorWidget::createAssistInterface(
m_glslDocument); m_glslDocument);
} }
//
// GlslEditorFactory // GlslEditorFactory
//
GlslEditorFactory::GlslEditorFactory() GlslEditorFactory::GlslEditorFactory()
{ {
@@ -373,8 +369,8 @@ GlslEditorFactory::GlslEditorFactory()
setDocumentCreator([]() { return new TextDocument(Constants::C_GLSLEDITOR_ID); }); setDocumentCreator([]() { return new TextDocument(Constants::C_GLSLEDITOR_ID); });
setEditorWidgetCreator([]() { return new GlslEditorWidget; }); setEditorWidgetCreator([]() { return new GlslEditorWidget; });
setIndenterCreator([](QTextDocument *doc) { return new GlslIndenter(doc); }); setIndenterCreator(&createGlslIndenter);
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; }); setSyntaxHighlighterCreator(&createGlslHighlighter);
setCommentDefinition(Utils::CommentDefinition::CppStyle); setCommentDefinition(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(new GlslCompletionAssistProvider); setCompletionAssistProvider(new GlslCompletionAssistProvider);
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
@@ -385,5 +381,4 @@ GlslEditorFactory::GlslEditorFactory()
| TextEditorActionHandler::UnCollapseAll); | TextEditorActionHandler::UnCollapseAll);
} }
} // namespace Internal } // GlslEditor::Internal
} // namespace GlslEditor

View File

@@ -5,8 +5,7 @@
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
int languageVariant(const QString &mimeType); int languageVariant(const QString &mimeType);
@@ -16,5 +15,4 @@ public:
GlslEditorFactory(); GlslEditorFactory();
}; };
} // namespace Internal } // GlslEditor::Internal
} // namespace GlslEditor

View File

@@ -15,13 +15,21 @@ using namespace TextEditor;
const TextStyle GLSLReservedKeyword = C_REMOVED_LINE; const TextStyle GLSLReservedKeyword = C_REMOVED_LINE;
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
GlslHighlighter::GlslHighlighter() class GlslHighlighter final : public TextEditor::SyntaxHighlighter
{ {
public:
GlslHighlighter()
{
setDefaultTextFormatCategories(); 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) void GlslHighlighter::highlightBlock(const QString &text)
{ {
@@ -293,5 +301,10 @@ bool GlslHighlighter::isPPKeyword(QStringView text) const
return false; return false;
} }
} // namespace Internal
} // namespace GlslEditor TextEditor::SyntaxHighlighter *createGlslHighlighter()
{
return new GlslHighlighter;
}
} // GlslEditor::Internal

View File

@@ -5,21 +5,8 @@
#include <texteditor/syntaxhighlighter.h> #include <texteditor/syntaxhighlighter.h>
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
class GlslHighlighter : public TextEditor::SyntaxHighlighter TextEditor::SyntaxHighlighter *createGlslHighlighter();
{
Q_OBJECT
public: } // GlslEditor::Internal
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

View File

@@ -8,18 +8,37 @@
#include <cppeditor/cppcodestylepreferences.h> #include <cppeditor/cppcodestylepreferences.h>
#include <texteditor/tabsettings.h> #include <texteditor/tabsettings.h>
#include <QChar>
#include <QTextDocument> #include <QTextDocument>
#include <QTextBlock> #include <QTextBlock>
#include <QTextCursor> #include <QTextCursor>
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
GlslIndenter::GlslIndenter(QTextDocument *doc) class GlslIndenter final : public TextEditor::TextIndenter
{
public:
explicit GlslIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc) : TextEditor::TextIndenter(doc)
{} {}
GlslIndenter::~GlslIndenter() = default;
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<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) final;
};
bool GlslIndenter::isElectricCharacter(const QChar &ch) const bool GlslIndenter::isElectricCharacter(const QChar &ch) const
{ {
@@ -120,5 +139,9 @@ TextEditor::IndentationForBlock GlslIndenter::indentationForBlocks(
return ret; return ret;
} }
} // namespace Internal TextEditor::TextIndenter *createGlslIndenter(QTextDocument *doc)
} // namespace GlslEditor {
return new GlslIndenter(doc);
}
} // GlslEditor::Internal

View File

@@ -5,33 +5,8 @@
#include <texteditor/textindenter.h> #include <texteditor/textindenter.h>
namespace GlslEditor { namespace GlslEditor::Internal {
namespace Internal {
class GlslIndenter : public TextEditor::TextIndenter TextEditor::TextIndenter *createGlslIndenter(QTextDocument *doc);
{
public:
explicit GlslIndenter(QTextDocument *doc);
~GlslIndenter() override;
bool isElectricCharacter(const QChar &ch) const override; } // namespace GlslEditor::Internal
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<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) override;
};
} // namespace Internal
} // namespace GlslEditor