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 GLSL;
namespace GlslEditor {
namespace Internal {
namespace GlslEditor::Internal {
static int versionFor(const QString &source)
{
@@ -356,10 +355,7 @@ std::unique_ptr<AssistInterface> 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

View File

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

View File

@@ -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
{
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

View File

@@ -5,21 +5,8 @@
#include <texteditor/syntaxhighlighter.h>
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

View File

@@ -8,18 +8,37 @@
#include <cppeditor/cppcodestylepreferences.h>
#include <texteditor/tabsettings.h>
#include <QChar>
#include <QTextDocument>
#include <QTextBlock>
#include <QTextCursor>
namespace GlslEditor {
namespace Internal {
namespace GlslEditor::Internal {
GlslIndenter::GlslIndenter(QTextDocument *doc)
class GlslIndenter final : public TextEditor::TextIndenter
{
public:
explicit GlslIndenter(QTextDocument *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
{
@@ -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

View File

@@ -5,33 +5,8 @@
#include <texteditor/textindenter.h>
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<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) override;
};
} // namespace Internal
} // namespace GlslEditor
} // namespace GlslEditor::Internal