QmlDesigner: Improve ownership of text editor

Handling raw pointer can easily lead to mistakes. So it's better to
remove unique pointer. In this case a deleteLater pointer is added.

The pointer has not be tested for null  because of:

23.11.1.2.2 unique_ptr destructor [unique.ptr.single.dtor]

2 Effects: If get() == nullptr there are no effects. Otherwise
get_deleter()(get()).

Change-Id: I97eeb86b7316fc93fbed89707644ab7dde7f89f6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2023-04-13 00:40:03 +02:00
parent 49c85bbf70
commit 86e2426ac6
4 changed files with 48 additions and 20 deletions

View File

@@ -27,10 +27,11 @@
#include <texteditor/texteditorconstants.h>
#include <qmljseditor/qmljseditordocument.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsreformatter.h>
#include <utils/changeset.h>
#include <utils/qtcassert.h>
#include <utils/uniqueobjectptr.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsreformatter.h>
#include <QDebug>
#include <QPair>
@@ -78,15 +79,16 @@ void TextEditorView::modelAttached(Model *model)
AbstractView::modelAttached(model);
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(
QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate());
auto textEditor = Utils::UniqueObjectLatePtr<TextEditor::BaseTextEditor>(
static_cast<TextEditor::BaseTextEditor *>(
QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate()));
// Set the context of the text editor, but we add another special context to override shortcuts.
Core::Context context = textEditor->context();
context.prepend(TEXTEDITOR_CONTEXT_ID);
m_textEditorContext->setContext(context);
m_widget->setTextEditor(textEditor);
m_widget->setTextEditor(std::move(textEditor));
}
void TextEditorView::modelAboutToBeDetached(Model *model)