Android: Move JavaIndenter class definition to .cpp

Change-Id: I0634062c22abfe592afb1be62616eaf05882519d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-12-21 17:38:52 +01:00
parent 1610bb8ff4
commit 78a708f0fe
3 changed files with 32 additions and 34 deletions

View File

@@ -24,7 +24,7 @@ static TextEditor::TextDocument *createJavaDocument()
auto doc = new TextEditor::TextDocument;
doc->setId(Constants::JAVA_EDITOR_ID);
doc->setMimeType(Utils::Constants::JAVA_MIMETYPE);
doc->setIndenter(new JavaIndenter(doc->document()));
doc->setIndenter(createJavaIndenter(doc->document()));
return doc;
}

View File

@@ -2,27 +2,34 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "javaindenter.h"
#include <texteditor/tabsettings.h>
#include <QTextDocument>
using namespace Android;
using namespace Android::Internal;
namespace Android::Internal {
JavaIndenter::JavaIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
{}
JavaIndenter::~JavaIndenter() = default;
bool JavaIndenter::isElectricCharacter(const QChar &ch) const
class JavaIndenter final : public TextEditor::TextIndenter
{
if (ch == QLatin1Char('{')
|| ch == QLatin1Char('}')) {
return true;
public:
explicit JavaIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
{}
bool isElectricCharacter(const QChar &ch) const final
{
return ch == QLatin1Char('{') || ch == QLatin1Char('}');
}
return false;
}
void indentBlock(const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) final;
int indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) final;
};
void JavaIndenter::indentBlock(const QTextBlock &block,
const QChar &typedChar,
@@ -58,3 +65,10 @@ int JavaIndenter::indentFor(const QTextBlock &block,
return qMax(0, indent + adjust);
}
TextEditor::TextIndenter *createJavaIndenter(QTextDocument *doc)
{
return new JavaIndenter(doc);
}
} // Android::Internal

View File

@@ -5,24 +5,8 @@
#include <texteditor/textindenter.h>
namespace Android {
namespace Internal {
class JavaIndenter : public TextEditor::TextIndenter
{
public:
explicit JavaIndenter(QTextDocument *doc);
~JavaIndenter() override;
namespace Android::Internal {
bool isElectricCharacter(const QChar &ch) const override;
TextEditor::TextIndenter *createJavaIndenter(QTextDocument *doc);
void indentBlock(const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) override;
int indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor = -1) override;
};
} // namespace Internal
} // namespace Android
} // Android::Internal