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()) {
|
if (m_connectonEditor->hasModelIndex()) {
|
||||||
ConnectionModel *connectionModel = qobject_cast<ConnectionModel *>(ui->connectionView->model());
|
ConnectionModel *connectionModel = qobject_cast<ConnectionModel *>(ui->connectionView->model());
|
||||||
if (connectionModel->connectionView()->isWidgetEnabled()
|
if (connectionModel->connectionView()->isWidgetEnabled()
|
||||||
&& (connectionModel->rowCount() > m_connectonEditor->modelIndex().row()))
|
&& (connectionModel->rowCount() > m_connectonEditor->modelIndex().row())) {
|
||||||
{
|
connectionModel->connectionView()
|
||||||
SignalHandlerProperty signalHandler =
|
->executeInTransaction("ConnectionView::setSignal", [this, connectionModel]() {
|
||||||
connectionModel->signalHandlerPropertyForRow(m_connectonEditor->modelIndex().row());
|
SignalHandlerProperty signalHandler
|
||||||
signalHandler.setSource(m_connectonEditor->bindingValue());
|
= connectionModel->signalHandlerPropertyForRow(
|
||||||
|
m_connectonEditor->modelIndex().row());
|
||||||
|
signalHandler.setSource(m_connectonEditor->bindingValue());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
m_connectonEditor->resetModelIndex();
|
m_connectonEditor->resetModelIndex();
|
||||||
}
|
}
|
||||||
@@ -487,20 +490,24 @@ void ConnectionViewWidget::editorForBinding()
|
|||||||
|
|
||||||
if (m_bindingIndex.isValid()) {
|
if (m_bindingIndex.isValid()) {
|
||||||
if (bindingModel->connectionView()->isWidgetEnabled()
|
if (bindingModel->connectionView()->isWidgetEnabled()
|
||||||
&& (bindingModel->rowCount() > m_bindingIndex.row()))
|
&& (bindingModel->rowCount() > m_bindingIndex.row())) {
|
||||||
{
|
bindingModel->connectionView()->executeInTransaction(
|
||||||
BindingProperty property = bindingModel->bindingPropertyForRow(m_bindingIndex.row());
|
"ConnectionView::setBindingProperty", [this, bindingModel, newValue]() {
|
||||||
|
BindingProperty property = bindingModel->bindingPropertyForRow(
|
||||||
|
m_bindingIndex.row());
|
||||||
|
|
||||||
if (property.isValid()) {
|
if (property.isValid()) {
|
||||||
if (property.isBindingProperty()) {
|
if (property.isBindingProperty()) {
|
||||||
if (property.isDynamic()) {
|
if (property.isDynamic()) {
|
||||||
property.setDynamicTypeNameAndExpression(property.dynamicTypeName(), newValue);
|
property
|
||||||
|
.setDynamicTypeNameAndExpression(property.dynamicTypeName(),
|
||||||
|
newValue);
|
||||||
|
} else {
|
||||||
|
property.setExpression(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
property.setExpression(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,29 +530,34 @@ void ConnectionViewWidget::editorForDynamic()
|
|||||||
|
|
||||||
if (m_dynamicIndex.isValid()) {
|
if (m_dynamicIndex.isValid()) {
|
||||||
if (propertiesModel->connectionView()->isWidgetEnabled()
|
if (propertiesModel->connectionView()->isWidgetEnabled()
|
||||||
&& (propertiesModel->rowCount() > m_dynamicIndex.row()))
|
&& (propertiesModel->rowCount() > m_dynamicIndex.row())) {
|
||||||
{
|
propertiesModel->connectionView()->executeInTransaction(
|
||||||
AbstractProperty abProp = propertiesModel->abstractPropertyForRow(m_dynamicIndex.row());
|
"ConnectionView::setBinding", [this, propertiesModel, newValue]() {
|
||||||
|
AbstractProperty abProp = propertiesModel->abstractPropertyForRow(
|
||||||
|
m_dynamicIndex.row());
|
||||||
|
|
||||||
if (abProp.isValid()) {
|
if (abProp.isValid()) {
|
||||||
if (abProp.isBindingProperty()) {
|
if (abProp.isBindingProperty()) {
|
||||||
BindingProperty property = abProp.toBindingProperty();
|
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
|
//if it's a variant property, then we remove it and replace with binding
|
||||||
else if (abProp.isVariantProperty()) {
|
else if (abProp.isVariantProperty()) {
|
||||||
VariantProperty property = abProp.toVariantProperty();
|
VariantProperty property = abProp.toVariantProperty();
|
||||||
PropertyName name = property.name();
|
PropertyName name = property.name();
|
||||||
TypeName type = property.dynamicTypeName();
|
TypeName type = property.dynamicTypeName();
|
||||||
QVariant value = newValue;
|
QVariant value = newValue;
|
||||||
|
|
||||||
BindingProperty newProperty = propertiesModel->replaceVariantWithBinding(name);
|
BindingProperty newProperty = propertiesModel
|
||||||
if (newProperty.isValid()) {
|
->replaceVariantWithBinding(name);
|
||||||
newProperty.setDynamicTypeNameAndExpression(type, newValue);
|
if (newProperty.isValid()) {
|
||||||
|
newProperty.setDynamicTypeNameAndExpression(type, newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user