ClangFormat: Dont create a style factory to only use the indenter

Change-Id: I2bfe7c7a68341a4a11439067581f5704b1388164
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
hjk
2023-12-21 14:42:29 +01:00
parent 37c9b41273
commit 2945dc379f
6 changed files with 20 additions and 6 deletions

View File

@@ -9,6 +9,7 @@
#include <cppeditor/cppcodestylepreferences.h>
#include <cppeditor/cppcodestylepreferencesfactory.h>
#include <cppeditor/cppqtstyleindenter.h>
#include <cppeditor/cpptoolssettings.h>
#include <extensionsystem/pluginmanager.h>
@@ -122,7 +123,7 @@ bool ClangFormatIndenter::formatWhileTyping() const
ClangFormatForwardingIndenter::ClangFormatForwardingIndenter(QTextDocument *doc)
: TextEditor::Indenter(doc)
, m_clangFormatIndenter(std::make_unique<ClangFormatIndenter>(doc))
, m_cppIndenter(CppEditor::CppCodeStylePreferencesFactory().createIndenter(doc))
, m_cppIndenter(CppEditor::createCppQtStyleIndenter(doc))
{}
ClangFormatForwardingIndenter::~ClangFormatForwardingIndenter() = default;

View File

@@ -97,7 +97,7 @@ TextEditor::CodeStyleEditorWidget *CppCodeStylePreferencesFactory::createEditor(
TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter(QTextDocument *doc) const
{
return new Internal::CppQtStyleIndenter(doc);
return createCppQtStyleIndenter(doc);
}
QString CppCodeStylePreferencesFactory::snippetProviderGroupId() const

View File

@@ -8,6 +8,7 @@
#include <texteditor/icodestylepreferencesfactory.h>
namespace CppEditor {
class CppCodeStyleWidget;
class CPPEDITOR_EXPORT CppCodeStylePreferencesFactory : public TextEditor::ICodeStylePreferencesFactory

View File

@@ -12,7 +12,8 @@
#include <QTextBlock>
#include <QTextCursor>
namespace CppEditor::Internal {
namespace CppEditor {
namespace Internal {
CppQtStyleIndenter::CppQtStyleIndenter(QTextDocument *doc)
: TextEditor::TextIndenter(doc)
@@ -189,4 +190,11 @@ TextEditor::IndentationForBlock CppQtStyleIndenter::indentationForBlocks(
return ret;
}
} // namespace CppEditor::Internal
} // namespace Internal
TextEditor::Indenter *createCppQtStyleIndenter(QTextDocument *doc)
{
return new Internal::CppQtStyleIndenter(doc);
}
} // namespace CppEditor

View File

@@ -3,6 +3,8 @@
#pragma once
#include "cppeditor_global.h"
#include <texteditor/textindenter.h>
namespace TextEditor { class ICodeStylePreferences; }
@@ -46,4 +48,7 @@ private:
};
} // namespace Internal
CPPEDITOR_EXPORT TextEditor::Indenter *createCppQtStyleIndenter(QTextDocument *doc);
} // namespace CppEditor

View File

@@ -855,8 +855,7 @@ namespace Internal {
void decorateCppEditor(TextEditor::TextEditorWidget *editor)
{
editor->textDocument()->resetSyntaxHighlighter([] { return new CppHighlighter(); });
editor->textDocument()->setIndenter(
new CppQtStyleIndenter(editor->textDocument()->document()));
editor->textDocument()->setIndenter(createCppQtStyleIndenter(editor->textDocument()->document()));
editor->setAutoCompleter(new CppAutoCompleter);
}