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,
|
void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
||||||
std::function<void(SignalHandlerProperty)> onReject,
|
std::function<void(SignalHandlerProperty)> removeSignalFunction,
|
||||||
|
bool removeOnReject,
|
||||||
QObject * parent)
|
QObject * parent)
|
||||||
{
|
{
|
||||||
if (!signalHandler.isValid())
|
if (!signalHandler.isValid())
|
||||||
@@ -336,15 +337,23 @@ void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
|||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
if (editor->m_modelNode.isValid()) {
|
if (editor->m_modelNode.isValid()) {
|
||||||
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
|
editor->m_modelNode.view()
|
||||||
"invokeEditorAccepted",
|
->executeInTransaction("ActionEditor::"
|
||||||
[=]() {
|
"invokeEditorAccepted",
|
||||||
editor->m_modelNode
|
[=]() {
|
||||||
.signalHandlerProperty(
|
if (!editor)
|
||||||
signalHandler.name())
|
return;
|
||||||
.setSource(
|
|
||||||
editor->connectionValue());
|
const QString newSource = editor->connectionValue();
|
||||||
});
|
if ((newSource.isNull() || newSource.trimmed().isEmpty())
|
||||||
|
&& removeSignalFunction) {
|
||||||
|
removeSignalFunction(signalHandler);
|
||||||
|
} else {
|
||||||
|
editor->m_modelNode
|
||||||
|
.signalHandlerProperty(signalHandler.name())
|
||||||
|
.setSource(newSource);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//closing editor widget somewhy triggers rejected() signal. Lets disconect before it affects us:
|
//closing editor widget somewhy triggers rejected() signal. Lets disconect before it affects us:
|
||||||
@@ -356,10 +365,10 @@ void ActionEditor::invokeEditor(SignalHandlerProperty signalHandler,
|
|||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (onReject) {
|
if (removeOnReject && removeSignalFunction) {
|
||||||
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
|
editor->m_modelNode.view()->executeInTransaction("ActionEditor::"
|
||||||
"invokeEditorOnRejectFunc",
|
"invokeEditorOnRejectFunc",
|
||||||
[=]() { onReject(signalHandler); });
|
[=]() { removeSignalFunction(signalHandler); });
|
||||||
}
|
}
|
||||||
|
|
||||||
//closing editor widget somewhy triggers rejected() signal 2nd time. Lets disconect before it affects us:
|
//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 = {});
|
Q_INVOKABLE void updateWindowName(const QString &targetName = {});
|
||||||
|
|
||||||
static void invokeEditor(SignalHandlerProperty signalHandler,
|
static void invokeEditor(SignalHandlerProperty signalHandler,
|
||||||
std::function<void(SignalHandlerProperty)> onReject = nullptr,
|
std::function<void(SignalHandlerProperty)> removeSignalFunction = nullptr,
|
||||||
|
bool removeOnReject = false,
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -568,6 +568,8 @@ ModelNode createNewConnection(ModelNode targetNode)
|
|||||||
|
|
||||||
void removeSignal(SignalHandlerProperty signalHandler)
|
void removeSignal(SignalHandlerProperty signalHandler)
|
||||||
{
|
{
|
||||||
|
if (!signalHandler.isValid())
|
||||||
|
return;
|
||||||
auto connectionNode = signalHandler.parentModelNode();
|
auto connectionNode = signalHandler.parentModelNode();
|
||||||
auto connectionSignals = connectionNode.signalProperties();
|
auto connectionSignals = connectionNode.signalProperties();
|
||||||
if (connectionSignals.size() > 1) {
|
if (connectionSignals.size() > 1) {
|
||||||
@@ -681,10 +683,14 @@ public:
|
|||||||
QString(
|
QString(
|
||||||
QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Open Connections Editor")),
|
QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Open Connections Editor")),
|
||||||
[=](const SelectionContext &) {
|
[=](const SelectionContext &) {
|
||||||
signalHandler.parentModelNode().view()->executeInTransaction(
|
signalHandler.parentModelNode()
|
||||||
"ConnectionsModelNodeActionGroup::"
|
.view()
|
||||||
"openConnectionsEditor",
|
->executeInTransaction("ConnectionsModelNodeActionGroup::"
|
||||||
[signalHandler]() { ActionEditor::invokeEditor(signalHandler); });
|
"openConnectionsEditor",
|
||||||
|
[signalHandler]() {
|
||||||
|
ActionEditor::invokeEditor(signalHandler,
|
||||||
|
removeSignal);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
activeSignalHandlerGroup->addAction(openEditorAction);
|
activeSignalHandlerGroup->addAction(openEditorAction);
|
||||||
@@ -747,7 +753,7 @@ public:
|
|||||||
|
|
||||||
newHandler.setSource(
|
newHandler.setSource(
|
||||||
QString("console.log(\"%1.%2\")").arg(currentNode.id(), signalStr));
|
QString("console.log(\"%1.%2\")").arg(currentNode.id(), signalStr));
|
||||||
ActionEditor::invokeEditor(newHandler, removeSignal);
|
ActionEditor::invokeEditor(newHandler, removeSignal, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
newSignal->addAction(openEditorAction);
|
newSignal->addAction(openEditorAction);
|
||||||
|
|||||||
Reference in New Issue
Block a user