forked from qt-creator/qt-creator
QmlDesigner: Use executeInTransaction in ConnectionView
This ensures proper error handling and makes the operation atomic on the undo stack. Change-Id: I73c11721f3abf9d8d9c4c26b20919c98cc807af3 Reviewed-by: Aleksei German <aleksei.german@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -460,11 +460,14 @@ void ConnectionViewWidget::editorForConnection()
|
||||
if (m_connectonEditor->hasModelIndex()) {
|
||||
ConnectionModel *connectionModel = qobject_cast<ConnectionModel *>(ui->connectionView->model());
|
||||
if (connectionModel->connectionView()->isWidgetEnabled()
|
||||
&& (connectionModel->rowCount() > m_connectonEditor->modelIndex().row()))
|
||||
{
|
||||
SignalHandlerProperty signalHandler =
|
||||
connectionModel->signalHandlerPropertyForRow(m_connectonEditor->modelIndex().row());
|
||||
&& (connectionModel->rowCount() > m_connectonEditor->modelIndex().row())) {
|
||||
connectionModel->connectionView()
|
||||
->executeInTransaction("ConnectionView::setSignal", [this, connectionModel]() {
|
||||
SignalHandlerProperty signalHandler
|
||||
= connectionModel->signalHandlerPropertyForRow(
|
||||
m_connectonEditor->modelIndex().row());
|
||||
signalHandler.setSource(m_connectonEditor->bindingValue());
|
||||
});
|
||||
}
|
||||
m_connectonEditor->resetModelIndex();
|
||||
}
|
||||
@@ -487,20 +490,24 @@ void ConnectionViewWidget::editorForBinding()
|
||||
|
||||
if (m_bindingIndex.isValid()) {
|
||||
if (bindingModel->connectionView()->isWidgetEnabled()
|
||||
&& (bindingModel->rowCount() > m_bindingIndex.row()))
|
||||
{
|
||||
BindingProperty property = bindingModel->bindingPropertyForRow(m_bindingIndex.row());
|
||||
&& (bindingModel->rowCount() > m_bindingIndex.row())) {
|
||||
bindingModel->connectionView()->executeInTransaction(
|
||||
"ConnectionView::setBindingProperty", [this, bindingModel, newValue]() {
|
||||
BindingProperty property = bindingModel->bindingPropertyForRow(
|
||||
m_bindingIndex.row());
|
||||
|
||||
if (property.isValid()) {
|
||||
if (property.isBindingProperty()) {
|
||||
if (property.isDynamic()) {
|
||||
property.setDynamicTypeNameAndExpression(property.dynamicTypeName(), newValue);
|
||||
}
|
||||
else {
|
||||
property
|
||||
.setDynamicTypeNameAndExpression(property.dynamicTypeName(),
|
||||
newValue);
|
||||
} else {
|
||||
property.setExpression(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,14 +530,17 @@ void ConnectionViewWidget::editorForDynamic()
|
||||
|
||||
if (m_dynamicIndex.isValid()) {
|
||||
if (propertiesModel->connectionView()->isWidgetEnabled()
|
||||
&& (propertiesModel->rowCount() > m_dynamicIndex.row()))
|
||||
{
|
||||
AbstractProperty abProp = propertiesModel->abstractPropertyForRow(m_dynamicIndex.row());
|
||||
&& (propertiesModel->rowCount() > m_dynamicIndex.row())) {
|
||||
propertiesModel->connectionView()->executeInTransaction(
|
||||
"ConnectionView::setBinding", [this, propertiesModel, newValue]() {
|
||||
AbstractProperty abProp = propertiesModel->abstractPropertyForRow(
|
||||
m_dynamicIndex.row());
|
||||
|
||||
if (abProp.isValid()) {
|
||||
if (abProp.isBindingProperty()) {
|
||||
BindingProperty property = abProp.toBindingProperty();
|
||||
property.setDynamicTypeNameAndExpression(property.dynamicTypeName(), newValue);
|
||||
property.setDynamicTypeNameAndExpression(property.dynamicTypeName(),
|
||||
newValue);
|
||||
}
|
||||
|
||||
//if it's a variant property, then we remove it and replace with binding
|
||||
@@ -540,12 +550,14 @@ void ConnectionViewWidget::editorForDynamic()
|
||||
TypeName type = property.dynamicTypeName();
|
||||
QVariant value = newValue;
|
||||
|
||||
BindingProperty newProperty = propertiesModel->replaceVariantWithBinding(name);
|
||||
BindingProperty newProperty = propertiesModel
|
||||
->replaceVariantWithBinding(name);
|
||||
if (newProperty.isValid()) {
|
||||
newProperty.setDynamicTypeNameAndExpression(type, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user