forked from qt-creator/qt-creator
QmlDesigner: Improve connection editor stability
Task-number: QDS-8039 Change-Id: Ie200eb080b82558925582a7720e40fc39e93ec63 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -305,7 +305,8 @@ void ActionEditor::updateWindowName(const QString &targetName)
|
||||
}
|
||||
|
||||
void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
||||
std::function<void(SignalHandlerProperty)> onReject,
|
||||
std::function<void(SignalHandlerProperty)> removeSignalFunction,
|
||||
bool removeOnReject,
|
||||
QObject * parent)
|
||||
{
|
||||
if (!signalHandler.isValid())
|
||||
@@ -336,14 +337,22 @@ void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
||||
if (!editor)
|
||||
return;
|
||||
if (editor->m_modelNode.isValid()) {
|
||||
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
|
||||
editor->m_modelNode.view()
|
||||
->executeInTransaction("ActionEditor::"
|
||||
"invokeEditorAccepted",
|
||||
[=]() {
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
const QString newSource = editor->connectionValue();
|
||||
if ((newSource.isNull() || newSource.trimmed().isEmpty())
|
||||
&& removeSignalFunction) {
|
||||
removeSignalFunction(signalHandler);
|
||||
} else {
|
||||
editor->m_modelNode
|
||||
.signalHandlerProperty(
|
||||
signalHandler.name())
|
||||
.setSource(
|
||||
editor->connectionValue());
|
||||
.signalHandlerProperty(signalHandler.name())
|
||||
.setSource(newSource);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -356,10 +365,10 @@ void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
if (onReject) {
|
||||
if (removeOnReject && removeSignalFunction) {
|
||||
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
|
||||
"invokeEditorOnRejectFunc",
|
||||
[=]() { onReject(signalHandler); });
|
||||
[=]() { removeSignalFunction(signalHandler); });
|
||||
}
|
||||
|
||||
//closing editor widget somewhy triggers rejected() signal 2nd time. Lets disconect before it affects us:
|
||||
|
||||
@@ -68,7 +68,8 @@ public:
|
||||
Q_INVOKABLE void updateWindowName(const QString &targetName = {});
|
||||
|
||||
static void invokeEditor(SignalHandlerProperty signalHandler,
|
||||
std::function<void(SignalHandlerProperty)> onReject = nullptr,
|
||||
std::function<void(SignalHandlerProperty)> removeSignalFunction = nullptr,
|
||||
bool removeOnReject = false,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
@@ -568,6 +568,8 @@ ModelNode createNewConnection(ModelNode targetNode)
|
||||
|
||||
void removeSignal(SignalHandlerProperty signalHandler)
|
||||
{
|
||||
if (!signalHandler.isValid())
|
||||
return;
|
||||
auto connectionNode = signalHandler.parentModelNode();
|
||||
auto connectionSignals = connectionNode.signalProperties();
|
||||
if (connectionSignals.size() > 1) {
|
||||
@@ -681,10 +683,14 @@ public:
|
||||
QString(
|
||||
QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Open Connections Editor")),
|
||||
[=](const SelectionContext &) {
|
||||
signalHandler.parentModelNode().view()->executeInTransaction(
|
||||
"ConnectionsModelNodeActionGroup::"
|
||||
signalHandler.parentModelNode()
|
||||
.view()
|
||||
->executeInTransaction("ConnectionsModelNodeActionGroup::"
|
||||
"openConnectionsEditor",
|
||||
[signalHandler]() { ActionEditor::invokeEditor(signalHandler); });
|
||||
[signalHandler]() {
|
||||
ActionEditor::invokeEditor(signalHandler,
|
||||
removeSignal);
|
||||
});
|
||||
});
|
||||
|
||||
activeSignalHandlerGroup->addAction(openEditorAction);
|
||||
@@ -747,7 +753,7 @@ public:
|
||||
|
||||
newHandler.setSource(
|
||||
QString("console.log(\"%1.%2\")").arg(currentNode.id(), signalStr));
|
||||
ActionEditor::invokeEditor(newHandler, removeSignal);
|
||||
ActionEditor::invokeEditor(newHandler, removeSignal, true);
|
||||
});
|
||||
});
|
||||
newSignal->addAction(openEditorAction);
|
||||
|
||||
Reference in New Issue
Block a user