CMakeProjectManager: Move CMakeIndenter class definition to .cpp

Leaner internal interface.

Change-Id: I297c74e667891efbeab0edabbfc82fb058501aa2
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
hjk
2023-12-21 15:43:19 +01:00
parent bdeded45a9
commit cf4f221065
3 changed files with 24 additions and 16 deletions

View File

@@ -515,7 +515,7 @@ CMakeEditorFactory::CMakeEditorFactory()
setEditorCreator([] { return new CMakeEditor; });
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
setDocumentCreator(createCMakeDocument);
setIndenterCreator([](QTextDocument *doc) { return new CMakeIndenter(doc); });
setIndenterCreator(createCMakeIndenter);
setUseGenericHighlighter(true);
setCommentDefinition(Utils::CommentDefinition::HashStyle);
setCodeFoldingSupported(true);

View File

@@ -5,9 +5,20 @@
namespace CMakeProjectManager::Internal {
CMakeIndenter::CMakeIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
{}
class CMakeIndenter final : public TextEditor::TextIndenter
{
public:
explicit CMakeIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
{}
bool isElectricCharacter(const QChar &ch) const final;
int indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) final;
};
bool CMakeIndenter::isElectricCharacter(const QChar &ch) const
{
@@ -44,6 +55,7 @@ static bool lineContainsFunction(const QString &line, const QString &function)
}
return false;
}
static bool lineStartsBlock(const QString &line)
{
return lineContainsFunction(line, QStringLiteral("function")) ||
@@ -55,6 +67,7 @@ static bool lineStartsBlock(const QString &line)
lineContainsFunction(line, QStringLiteral("else")) ||
lineContainsFunction(line, QStringLiteral("block"));
}
static bool lineEndsBlock(const QString &line)
{
return lineContainsFunction(line, QStringLiteral("endfunction")) ||
@@ -66,6 +79,7 @@ static bool lineEndsBlock(const QString &line)
lineContainsFunction(line, QStringLiteral("else")) ||
lineContainsFunction(line, QStringLiteral("endblock"));
}
static bool lineIsEmpty(const QString &line)
{
for (const QChar &c : line) {
@@ -112,4 +126,9 @@ int CMakeIndenter::indentFor(const QTextBlock &block,
return qMax(0, indentation);
}
TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc)
{
return new CMakeIndenter(doc);
}
} // CMakeProjectManager::Internal

View File

@@ -3,21 +3,10 @@
#pragma once
#include "cmake_global.h"
#include <texteditor/textindenter.h>
namespace CMakeProjectManager::Internal {
class CMAKE_EXPORT CMakeIndenter : public TextEditor::TextIndenter
{
public:
explicit CMakeIndenter(QTextDocument *doc);
bool isElectricCharacter(const QChar &ch) const override;
int indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) override;
};
TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc);
} // CMakeProjectManager::Internal