QML: Fix crash when opening context menu

The AssistInterface changed to unique_ptr, but the internals of how the
QmlJSEditor looked for quick fixes still wrapped it into a
QSharedPointer, which then deleted the assist interface in addition to
the unique_ptr.

Amends 0e4b0a26d3

Fixes: QTCREATORBUG-28742
Change-Id: If685dbb2c49b09d529d0dcb3677dc90b03a039f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-02-06 15:32:00 +01:00
committed by David Schulz
parent 8512aba9eb
commit 541aafecbb
7 changed files with 40 additions and 45 deletions

View File

@@ -58,24 +58,22 @@ public:
setDescription(Tr::tr("Move Component into Separate File"));
}
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectDefinition *objDef)
: QmlJSQuickFixOperation(interface, 0),
m_idName(idOfObject(objDef)),
m_firstSourceLocation(objDef->firstSourceLocation()),
m_lastSourceLocation(objDef->lastSourceLocation()),
m_initializer(objDef->initializer)
Operation(const Internal::QmlJSQuickFixAssistInterface *interface, UiObjectDefinition *objDef)
: QmlJSQuickFixOperation(interface, 0)
, m_idName(idOfObject(objDef))
, m_firstSourceLocation(objDef->firstSourceLocation())
, m_lastSourceLocation(objDef->lastSourceLocation())
, m_initializer(objDef->initializer)
{
init();
}
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectBinding *objDef)
: QmlJSQuickFixOperation(interface, 0),
m_idName(idOfObject(objDef)),
m_firstSourceLocation(objDef->qualifiedTypeNameId->firstSourceLocation()),
m_lastSourceLocation(objDef->lastSourceLocation()),
m_initializer(objDef->initializer)
Operation(const Internal::QmlJSQuickFixAssistInterface *interface, UiObjectBinding *objDef)
: QmlJSQuickFixOperation(interface, 0)
, m_idName(idOfObject(objDef))
, m_firstSourceLocation(objDef->qualifiedTypeNameId->firstSourceLocation())
, m_lastSourceLocation(objDef->lastSourceLocation())
, m_initializer(objDef->initializer)
{
init();
}
@@ -223,7 +221,7 @@ public:
} // end of anonymous namespace
void matchComponentFromObjectDefQuickFix(const QmlJSQuickFixInterface &interface, QuickFixOperations &result)
void matchComponentFromObjectDefQuickFix(const QmlJSQuickFixAssistInterface *interface, QuickFixOperations &result)
{
const int pos = interface->currentFile()->cursor().position();
@@ -254,8 +252,7 @@ void performComponentFromObjectDef(const QString &fileName, QmlJS::AST::UiObject
QmlJS::ModelManagerInterface::instance()->snapshot());
QmlJSRefactoringFilePtr current = refactoring.file(Utils::FilePath::fromString(fileName));
QmlJSQuickFixInterface interface;
Operation operation(interface, objDef);
Operation operation(nullptr, objDef);
operation.performChanges(current, refactoring);
}