ClangFormat: Don't leak editor

Amends e1f7469afb

Change-Id: I862bca5a57d818e8b813d557fa7c3a4e3690dcd2
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2024-03-12 10:52:19 +01:00
parent d5750f8cb7
commit 31e97d5069

View File

@@ -101,7 +101,7 @@ private:
QWidget *m_editorWidget = nullptr; QWidget *m_editorWidget = nullptr;
QScrollArea *m_editorScrollArea = nullptr; QScrollArea *m_editorScrollArea = nullptr;
TextEditor::SnippetEditorWidget *m_preview = nullptr; TextEditor::SnippetEditorWidget *m_preview = nullptr;
Core::IEditor *m_editor = nullptr; std::unique_ptr<Core::IEditor> m_editor;
std::unique_ptr<ClangFormatFile> m_config; std::unique_ptr<ClangFormatFile> m_config;
@@ -156,8 +156,7 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
updatePreview(); updatePreview();
} }
void ClangFormatConfigWidget::slotCodeStyleChanged( void ClangFormatConfigWidget::slotCodeStyleChanged(TextEditor::ICodeStylePreferences *codeStyle)
TextEditor::ICodeStylePreferences *codeStyle)
{ {
if (!codeStyle) if (!codeStyle)
return; return;
@@ -177,7 +176,7 @@ void ClangFormatConfigWidget::initEditor(TextEditor::ICodeStylePreferences *code
Core::EditorFactories factories = Core::IEditorFactory::preferredEditorTypes( Core::EditorFactories factories = Core::IEditorFactory::preferredEditorTypes(
m_config->filePath()); m_config->filePath());
Core::IEditorFactory *factory = factories.takeFirst(); Core::IEditorFactory *factory = factories.takeFirst();
m_editor = factory->createEditor(); m_editor.reset(factory->createEditor());
QString errorString; QString errorString;
m_editor->document()->open(&errorString, m_config->filePath(), m_config->filePath()); m_editor->document()->open(&errorString, m_config->filePath(), m_config->filePath());
@@ -186,7 +185,7 @@ void ClangFormatConfigWidget::initEditor(TextEditor::ICodeStylePreferences *code
invokeMethodForLanguageClientManager("documentOpened", invokeMethodForLanguageClientManager("documentOpened",
Q_ARG(Core::IDocument *, m_editor->document())); Q_ARG(Core::IDocument *, m_editor->document()));
invokeMethodForLanguageClientManager("editorOpened", invokeMethodForLanguageClientManager("editorOpened",
Q_ARG(Core::IEditor *, m_editor)); Q_ARG(Core::IEditor *, m_editor.get()));
m_editorWidget = m_editor->widget(); m_editorWidget = m_editor->widget();
m_editorWidget->setEnabled(!codeStyle->isReadOnly() && !codeStyle->isTemporarilyReadOnly() m_editorWidget->setEnabled(!codeStyle->isReadOnly() && !codeStyle->isTemporarilyReadOnly()
@@ -221,7 +220,7 @@ void ClangFormatConfigWidget::initEditor(TextEditor::ICodeStylePreferences *code
QShortcut *completionSC = new QShortcut(QKeySequence("Ctrl+Space"), this); QShortcut *completionSC = new QShortcut(QKeySequence("Ctrl+Space"), this);
connect(completionSC, &QShortcut::activated, this, [this] { connect(completionSC, &QShortcut::activated, this, [this] {
if (auto *editor = qobject_cast<TextEditor::BaseTextEditor *>(m_editor)) if (auto *editor = qobject_cast<TextEditor::BaseTextEditor *>(m_editor.get()))
editor->editorWidget()->invokeAssist(TextEditor::Completion); editor->editorWidget()->invokeAssist(TextEditor::Completion);
}); });