QmlDesigner: Add Connections Shortcuts

Task-number: QDS-7641
Change-Id: I1cb8f10cb675cee7dd48481cb31e4807fc592dc3
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Aleksei German
2022-09-19 18:25:36 +02:00
committed by Thomas Hartmann
parent d47e9772e0
commit 4da6686705
4 changed files with 374 additions and 0 deletions

View File

@@ -304,4 +304,68 @@ void ActionEditor::updateWindowName(const QString &targetName)
}
}
void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
std::function<void(SignalHandlerProperty)> onReject,
QObject * parent)
{
if (!signalHandler.isValid())
return;
ModelNode connectionNode = signalHandler.parentModelNode();
if (!connectionNode.isValid())
return;
if (!connectionNode.bindingProperty("target").isValid())
return;
ModelNode targetNode = connectionNode.bindingProperty("target").resolveToModelNode();
if (!targetNode.isValid())
return;
const QString source = signalHandler.source();
QPointer<ActionEditor> editor = new ActionEditor(parent);
editor->showWidget();
editor->setModelNode(connectionNode);
editor->setConnectionValue(source);
editor->prepareConnections();
editor->updateWindowName(targetNode.validId() + "." + signalHandler.name());
QObject::connect(editor, &ActionEditor::accepted, [=]() {
if (!editor)
return;
if (editor->m_modelNode.isValid()) {
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
"invokeEditorAccepted",
[=]() {
editor->m_modelNode
.signalHandlerProperty(
signalHandler.name())
.setSource(
editor->connectionValue());
});
}
//closing editor widget somewhy triggers rejected() signal. Lets disconect before it affects us:
editor->disconnect();
editor->deleteLater();
});
QObject::connect(editor, &ActionEditor::rejected, [=]() {
if (!editor)
return;
if (onReject) {
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
"invokeEditorOnRejectFunc",
[=]() { onReject(signalHandler); });
}
//closing editor widget somewhy triggers rejected() signal 2nd time. Lets disconect before it affects us:
editor->disconnect();
editor->deleteLater();
});
}
} // QmlDesigner namespace