From cf1be672647f9696dbccf7decb4ca9db06c2792a Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 31 May 2019 16:49:04 +0200 Subject: [PATCH] QmlDesigner: Use lambdas for transactions Using lambdas we do not have to repeat the try catch block all over again. This also avoids sublte mistakes when catching the exception. Change-Id: I514fa9b64f43ef08fdc27bf702ec2b173ab1dfd6 Reviewed-by: Tim Jenssen --- .../componentcore/layoutingridlayout.cpp | 11 +- .../componentcore/modelnodeoperations.cpp | 128 +++----- .../components/integration/designdocument.cpp | 41 +-- .../navigator/navigatortreemodel.cpp | 10 +- .../components/navigator/navigatorview.cpp | 10 +- .../propertyeditor/gradientmodel.cpp | 40 ++- .../propertyeditorcontextobject.cpp | 29 +- .../propertyeditor/propertyeditorview.cpp | 34 +-- .../propertyeditor/qmlanchorbindingproxy.cpp | 284 ++++-------------- .../propertyeditor/qmlanchorbindingproxy.h | 2 +- .../designercore/include/abstractview.h | 5 + .../designercore/model/abstractview.cpp | 14 + .../designercore/model/modelmerger.cpp | 34 +-- .../designercore/model/qmlanchors.cpp | 118 ++++---- .../designercore/model/qmlitemnode.cpp | 20 +- .../connectioneditor/backendmodel.cpp | 45 +-- .../connectioneditor/bindingmodel.cpp | 13 +- .../connectioneditor/connectionmodel.cpp | 37 +-- .../dynamicpropertiesmodel.cpp | 41 +-- .../pathtool/pathitem.cpp | 83 +++-- .../timelineeditor/easingcurvedialog.cpp | 15 +- .../timelineeditor/timelineactions.cpp | 43 +-- .../timelineeditor/timelinegraphicsscene.cpp | 23 +- .../timelineeditor/timelinemovetool.cpp | 14 +- .../timelineeditor/timelinepropertyitem.cpp | 10 +- .../timelineeditor/timelinesectionitem.cpp | 15 +- .../timelineeditor/timelinesettingsmodel.cpp | 58 ++-- .../timelineeditor/timelineview.cpp | 33 +- 28 files changed, 391 insertions(+), 819 deletions(-) diff --git a/src/plugins/qmldesigner/components/componentcore/layoutingridlayout.cpp b/src/plugins/qmldesigner/components/componentcore/layoutingridlayout.cpp index 5ec3ea557b3..ba520a1ca33 100644 --- a/src/plugins/qmldesigner/components/componentcore/layoutingridlayout.cpp +++ b/src/plugins/qmldesigner/components/componentcore/layoutingridlayout.cpp @@ -185,17 +185,16 @@ void LayoutInGridLayout::doIt() if (qmlItemNode.hasInstanceParentItem()) { ModelNode layoutNode; - { - RewriterTransaction transaction(m_selectionContext.view(), QByteArrayLiteral("LayoutInGridLayout1")); + + m_selectionContext.view()->executeInTransaction("LayoutInGridLayout1",[this, &layoutNode, layoutType](){ QTC_ASSERT(m_selectionContext.view()->model()->hasNodeMetaInfo(layoutType), return); NodeMetaInfo metaInfo = m_selectionContext.view()->model()->metaInfo(layoutType); layoutNode = m_selectionContext.view()->createModelNode(layoutType, metaInfo.majorVersion(), metaInfo.minorVersion()); reparentTo(layoutNode, m_parentNode); - } + }); - { - RewriterTransaction transaction(m_selectionContext.view(), QByteArrayLiteral("LayoutInGridLayout2")); + m_selectionContext.view()->executeInTransaction("LayoutInGridLayout2", [this, layoutNode](){ fillEmptyCells(); @@ -208,7 +207,7 @@ void LayoutInGridLayout::doIt() reparentToNodeAndRemovePositionForModelNodes(layoutNode, sortedSelectedNodes); setSizeAsPreferredSize(sortedSelectedNodes); setSpanning(layoutNode); - } + }); } } } diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 691c1b6ca51..3c31998576b 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -240,9 +240,7 @@ void changeOrder(const SelectionContext &selectionState, OderAction orderAction) if (!modelNode.parentProperty().isNodeListProperty()) return; - try { - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|raise")); - + selectionState.view()->executeInTransaction("DesignerActionManager|raise",[orderAction, selectionState, modelNode](){ ModelNode modelNode = selectionState.currentSingleSelectedNode(); NodeListProperty parentProperty = modelNode.parentProperty().toNodeListProperty(); const int index = parentProperty.indexOf(modelNode); @@ -255,11 +253,7 @@ void changeOrder(const SelectionContext &selectionState, OderAction orderAction) if (index > 0) parentProperty.slide(index, index - 1); } - - transaction.commit(); - } catch (const RewritingException &e) { //better save then sorry - e.showException(); - } + }); } void raise(const SelectionContext &selectionState) @@ -328,16 +322,13 @@ void resetSize(const SelectionContext &selectionState) if (!selectionState.view()) return; - try { - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|resetSize")); + selectionState.view()->executeInTransaction("DesignerActionManager|resetSize",[selectionState](){ foreach (ModelNode node, selectionState.selectedModelNodes()) { QmlItemNode itemNode(node); itemNode.removeProperty("width"); itemNode.removeProperty("height"); } - } catch (const RewritingException &e) { //better save then sorry - e.showException(); - } + }); } void resetPosition(const SelectionContext &selectionState) @@ -345,17 +336,13 @@ void resetPosition(const SelectionContext &selectionState) if (!selectionState.view()) return; - try { - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|resetPosition")); + selectionState.view()->executeInTransaction("DesignerActionManager|resetPosition",[selectionState](){ foreach (ModelNode node, selectionState.selectedModelNodes()) { QmlItemNode itemNode(node); itemNode.removeProperty("x"); itemNode.removeProperty("y"); } - transaction.commit(); - } catch (const RewritingException &e) { //better save then sorry - e.showException(); - } + }); } void goIntoComponentOperation(const SelectionContext &selectionState) @@ -372,11 +359,12 @@ void resetZ(const SelectionContext &selectionState) if (!selectionState.view()) return; - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|resetZ")); - foreach (ModelNode node, selectionState.selectedModelNodes()) { - QmlItemNode itemNode(node); - itemNode.removeProperty("z"); - } + selectionState.view()->executeInTransaction("DesignerActionManager|resetZ",[selectionState](){ + foreach (ModelNode node, selectionState.selectedModelNodes()) { + QmlItemNode itemNode(node); + itemNode.removeProperty("z"); + } + }); } static inline void backupPropertyAndRemove(const ModelNode &node, const PropertyName &propertyName) @@ -404,9 +392,7 @@ void anchorsFill(const SelectionContext &selectionState) if (!selectionState.view()) return; - try { - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|anchorsFill")); - + selectionState.view()->executeInTransaction("DesignerActionManager|anchorsFill",[selectionState](){ ModelNode modelNode = selectionState.currentSingleSelectedNode(); QmlItemNode node = modelNode; @@ -417,11 +403,7 @@ void anchorsFill(const SelectionContext &selectionState) backupPropertyAndRemove(modelNode, "width"); backupPropertyAndRemove(modelNode, "height"); } - - transaction.commit(); - } catch (const RewritingException &e) { //better save then sorry - e.showException(); - } + }); } void anchorsReset(const SelectionContext &selectionState) @@ -429,19 +411,19 @@ void anchorsReset(const SelectionContext &selectionState) if (!selectionState.view()) return; - RewriterTransaction transaction(selectionState.view(), QByteArrayLiteral("DesignerActionManager|anchorsReset")); + selectionState.view()->executeInTransaction("DesignerActionManager|anchorsReset",[selectionState](){ + ModelNode modelNode = selectionState.currentSingleSelectedNode(); - ModelNode modelNode = selectionState.currentSingleSelectedNode(); - - QmlItemNode node = modelNode; - if (node.isValid()) { - node.anchors().removeAnchors(); - node.anchors().removeMargins(); - restoreProperty(node, "x"); - restoreProperty(node, "y"); - restoreProperty(node, "width"); - restoreProperty(node, "height"); - } + QmlItemNode node = modelNode; + if (node.isValid()) { + node.anchors().removeAnchors(); + node.anchors().removeMargins(); + restoreProperty(node, "x"); + restoreProperty(node, "y"); + restoreProperty(node, "width"); + restoreProperty(node, "height"); + } + }); } using LessThan = std::function; @@ -481,7 +463,7 @@ bool compareByGrid(const ModelNode &node1, const ModelNode &node2) static void layoutHelperFunction(const SelectionContext &selectionContext, const TypeName &layoutType, - LessThan lessThan) + const LessThan &lessThan) { if (!selectionContext.view() || !selectionContext.hasSingleSelectedModelNode() @@ -492,10 +474,8 @@ static void layoutHelperFunction(const SelectionContext &selectionContext, const QmlItemNode qmlItemNode = QmlItemNode(selectionContext.firstSelectedModelNode()); if (qmlItemNode.hasInstanceParentItem()) { - ModelNode layoutNode; - { - RewriterTransaction transaction(selectionContext.view(), QByteArrayLiteral("DesignerActionManager|layoutHelperFunction1")); + selectionContext.view()->executeInTransaction("DesignerActionManager|layoutHelperFunction1",[=, &layoutNode](){ QmlItemNode parentNode = qmlItemNode.instanceParentItem(); @@ -504,10 +484,9 @@ static void layoutHelperFunction(const SelectionContext &selectionContext, layoutNode = selectionContext.view()->createModelNode(layoutType, metaInfo.majorVersion(), metaInfo.minorVersion()); reparentTo(layoutNode, parentNode); - } + }); - { - RewriterTransaction transaction(selectionContext.view(), QByteArrayLiteral("DesignerActionManager|layoutHelperFunction2")); + selectionContext.view()->executeInTransaction("DesignerActionManager|layoutHelperFunction2",[=](){ QList sortedSelectedNodes = selectionContext.selectedModelNodes(); Utils::sort(sortedSelectedNodes, lessThan); @@ -516,7 +495,7 @@ static void layoutHelperFunction(const SelectionContext &selectionContext, LayoutInGridLayout::reparentToNodeAndRemovePositionForModelNodes(layoutNode, sortedSelectedNodes); if (layoutType.contains("Layout")) LayoutInGridLayout::setSizeAsPreferredSize(sortedSelectedNodes); - } + }); } } } @@ -662,16 +641,9 @@ void addSignalHandlerOrGotoImplementation(const SelectionContext &selectionState if (!qmlObjectNode.isRootModelNode()) { isModelNodeRoot = false; - try { - RewriterTransaction transaction = - qmlObjectNode.view()->beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem")); - - QmlObjectNode qmlObjectNode(modelNode); + qmlObjectNode.view()->executeInTransaction("NavigatorTreeModel:exportItem", [&qmlObjectNode](){ qmlObjectNode.ensureAliasExport(); - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); } QString itemId = modelNode.id(); @@ -708,14 +680,10 @@ void addSignalHandlerOrGotoImplementation(const SelectionContext &selectionState if (dialog->signal().isEmpty()) return; - try { - RewriterTransaction transaction = - qmlObjectNode.view()->beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem")); + qmlObjectNode.view()->executeInTransaction("NavigatorTreeModel:exportItem", [=](){ addSignal(typeName, itemId, dialog->signal(), isModelNodeRoot); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); addSignal(typeName, itemId, dialog->signal(), isModelNodeRoot); @@ -751,9 +719,7 @@ void removeLayout(const SelectionContext &selectionContext) if (!parent.isValid()) return; - { - RewriterTransaction transaction(selectionContext.view(), QByteArrayLiteral("DesignerActionManager|removeLayout")); - + selectionContext.view()->executeInTransaction("DesignerActionManager|removeLayout", [selectionContext, &layoutItem, parent](){ foreach (const ModelNode &modelNode, selectionContext.currentSingleSelectedNode().directSubModelNodes()) { if (QmlItemNode::isValidQmlItemNode(modelNode)) { @@ -772,7 +738,7 @@ void removeLayout(const SelectionContext &selectionContext) parent.modelNode().defaultNodeListProperty().reparentHere(modelNode); } layoutItem.destroy(); - } + }); } void removePositioner(const SelectionContext &selectionContext) @@ -826,9 +792,7 @@ void addItemToStackedContainer(const SelectionContext &selectionContext) } } - try { - RewriterTransaction transaction = - view->beginRewriterTransaction(QByteArrayLiteral("DesignerActionManager:addItemToStackedContainer")); + view->executeInTransaction("DesignerActionManager:addItemToStackedContainer", [=](){ NodeMetaInfo itemMetaInfo = view->model()->metaInfo("QtQuick.Item", -1, -1); QTC_ASSERT(itemMetaInfo.isValid(), return); @@ -853,11 +817,7 @@ void addItemToStackedContainer(const SelectionContext &selectionContext) } } - - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); } PropertyName getIndexPropertyName(const ModelNode &modelNode) @@ -969,9 +929,8 @@ void addTabBarToStackedContainer(const SelectionContext &selectionContext) const PropertyName indexPropertyName = getIndexPropertyName(container); QTC_ASSERT(container.metaInfo().hasProperty(indexPropertyName), return); - try { - RewriterTransaction transaction = - view->beginRewriterTransaction(QByteArrayLiteral("DesignerActionManager:addItemToStackedContainer")); + view->executeInTransaction("DesignerActionManager:addItemToStackedContainer", + [view, container, containerItemNode, tabBarMetaInfo, tabButtonMetaInfo, indexPropertyName](){ ModelNode tabBarNode = view->createModelNode("QtQuick.Controls.TabBar", @@ -1003,11 +962,8 @@ void addTabBarToStackedContainer(const SelectionContext &selectionContext) container.removeProperty(indexPropertyName); const QString expression = id + "." + QString::fromLatin1(indexPropertyName); container.bindingProperty(indexPropertyName).setExpression(expression); + }); - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } } bool addImageToProject(const QStringList &fileNames, const QString &defaultDirectory) diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp index a10225cc069..4f23154945d 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp @@ -365,18 +365,13 @@ void DesignDocument::deleteSelected() if (!currentModel()) return; - try { - RewriterTransaction transaction(rewriterView(), QByteArrayLiteral("DesignDocument::deleteSelected")); + rewriterView()->executeInTransaction("DesignDocument::deleteSelected", [this](){ QList toDelete = view()->selectedModelNodes(); foreach (ModelNode node, toDelete) { if (node.isValid() && !node.isRootNode() && QmlObjectNode::isValidQmlObjectNode(node)) QmlObjectNode(node).destroy(); } - - transaction.commit(); - } catch (const RewritingException &e) { - e.showException(); - } + }); } void DesignDocument::copySelected() @@ -465,10 +460,8 @@ void DesignDocument::paste() } } - QList pastedNodeList; - - try { - RewriterTransaction transaction(rewriterView(), QByteArrayLiteral("DesignDocument::paste1")); + rewriterView()->executeInTransaction("DesignDocument::paste1", [this, &view, selectedNodes, targetNode](){ + QList pastedNodeList; int offset = double(qrand()) / RAND_MAX * 20 - 10; @@ -481,14 +474,10 @@ void DesignDocument::paste() } view.setSelectedModelNodes(pastedNodeList); - transaction.commit(); - } catch (const RewritingException &e) { - qWarning() << e.description(); //silent error - } - } else { - try { - RewriterTransaction transaction(rewriterView(), QByteArrayLiteral("DesignDocument::paste2")); + }); + } else { + rewriterView()->executeInTransaction("DesignDocument::paste1", [this, &view, selectedNodes, rootNode](){ currentModel()->attachView(&view); ModelNode pastedNode(view.insertModel(rootNode)); ModelNode targetNode; @@ -500,9 +489,9 @@ void DesignDocument::paste() targetNode = view.rootModelNode(); if (targetNode.hasParentProperty() && - (pastedNode.simplifiedTypeName() == targetNode.simplifiedTypeName()) && - (pastedNode.variantProperty("width").value() == targetNode.variantProperty("width").value()) && - (pastedNode.variantProperty("height").value() == targetNode.variantProperty("height").value())) + (pastedNode.simplifiedTypeName() == targetNode.simplifiedTypeName()) && + (pastedNode.variantProperty("width").value() == targetNode.variantProperty("width").value()) && + (pastedNode.variantProperty("height").value() == targetNode.variantProperty("height").value())) targetNode = targetNode.parentProperty().parentModelNode(); @@ -514,15 +503,9 @@ void DesignDocument::paste() } else { qWarning() << "Cannot reparent to" << targetNode; } - - transaction.commit(); - NodeMetaInfo::clearCache(); - view.setSelectedModelNodes({pastedNode}); - transaction.commit(); - } catch (const RewritingException &e) { - qWarning() << e.description(); //silent error - } + }); + NodeMetaInfo::clearCache(); } } diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp index 126fed8e68f..4ceb51e985e 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp @@ -545,10 +545,9 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i void NavigatorTreeModel::moveNodesInteractive(NodeAbstractProperty &parentProperty, const QList &modelNodes, int targetIndex) { QTC_ASSERT(m_view, return); - try { - const TypeName propertyQmlType = parentProperty.parentModelNode().metaInfo().propertyTypeName(parentProperty.name()); - RewriterTransaction transaction = m_view->beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel::moveNodesInteractive")); + m_view->executeInTransaction("NavigatorTreeModel::moveNodesInteractive",[this, &parentProperty, modelNodes, targetIndex](){ + const TypeName propertyQmlType = parentProperty.parentModelNode().metaInfo().propertyTypeName(parentProperty.name()); foreach (const ModelNode &modelNode, modelNodes) { if (modelNode.isValid() && modelNode != parentProperty.parentModelNode() @@ -565,10 +564,7 @@ void NavigatorTreeModel::moveNodesInteractive(NodeAbstractProperty &parentProper } } } - transaction.commit(); - } catch (const RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); } Qt::DropActions NavigatorTreeModel::supportedDropActions() const diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp index 07434102fce..f43081f14b2 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp @@ -198,16 +198,10 @@ void NavigatorView::handleChangedExport(const ModelNode &modelNode, bool exporte if (rootNode.hasProperty(modelNodeId)) rootNode.removeProperty(modelNodeId); if (exported) { - try { - RewriterTransaction transaction = - beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem")); - + executeInTransaction("NavigatorTreeModel:exportItem", [this, modelNode](){ QmlObjectNode qmlObjectNode(modelNode); qmlObjectNode.ensureAliasExport(); - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); } } diff --git a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp index 471ec2abd4d..d4b1f471848 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/gradientmodel.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include @@ -147,18 +147,16 @@ void GradientModel::addGradient() return; if (!m_itemNode.modelNode().hasNodeProperty(gradientPropertyName().toUtf8())) { - try { + if (m_gradientTypeName != "Gradient") + ensureShapesImport(); + + view()->executeInTransaction("GradientModel::addGradient", [this](){ QColor color = m_itemNode.instanceValue("color").value(); if (!color.isValid()) color = QColor(Qt::white); - if (m_gradientTypeName != "Gradient") - ensureShapesImport(); - - QmlDesigner::RewriterTransaction transaction = view()->beginRewriterTransaction(QByteArrayLiteral("GradientModel::addGradient")); - QmlDesigner::ModelNode gradientNode = createGradientNode(); m_itemNode.modelNode().nodeProperty(gradientPropertyName().toUtf8()).reparentHere(gradientNode); @@ -172,11 +170,7 @@ void GradientModel::addGradient() gradientStopNode.variantProperty("position").setValue(1.0); gradientStopNode.variantProperty("color").setValue(QColor(Qt::black)); gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode); - - } catch (const QmlDesigner::Exception &e) { - e.showException(); - } - + }); } setupModel(); @@ -244,18 +238,18 @@ qreal GradientModel::getPosition(int index) const void GradientModel::removeStop(int index) { if (index < rowCount() - 1 && index != 0) { - QmlDesigner::RewriterTransaction transaction = view()->beginRewriterTransaction(QByteArrayLiteral("GradientModel::removeStop")); - QmlDesigner::ModelNode gradientNode = m_itemNode.modelNode().nodeProperty(gradientPropertyName().toUtf8()).modelNode(); - QmlDesigner::QmlObjectNode stop = gradientNode.nodeListProperty("stops").at(index); - if (stop.isValid()) { - stop.destroy(); - setupModel(); - } + view()->executeInTransaction("GradientModel::removeStop", [this, index](){ + QmlDesigner::ModelNode gradientNode = m_itemNode.modelNode().nodeProperty(gradientPropertyName().toUtf8()).modelNode(); + QmlDesigner::QmlObjectNode stop = gradientNode.nodeListProperty("stops").at(index); + if (stop.isValid()) { + stop.destroy(); + setupModel(); + } + }); } qWarning() << Q_FUNC_INFO << "invalid index"; } - void GradientModel::deleteGradient() { if (!m_itemNode.isValid()) @@ -385,7 +379,11 @@ void GradientModel::ensureShapesImport() { if (!hasShapesImport()) { QmlDesigner::Import timelineImport = QmlDesigner::Import::createLibraryImport("QtQuick.Shapes", "1.0"); - model()->changeImports({timelineImport}, {}); + try { + model()->changeImports({timelineImport}, {}); + } catch (const QmlDesigner::Exception &) { + QTC_ASSERT(false, return); + } } } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index dc8243e1c81..8fdab5a821e 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -152,22 +152,14 @@ void PropertyEditorContextObject::toogleExportAlias() PropertyName modelNodeId = selectedNode.id().toUtf8(); ModelNode rootModelNode = rewriterView->rootModelNode(); - try { - RewriterTransaction transaction = - rewriterView->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorContextObject:toogleExportAlias")); - + rewriterView->executeInTransaction("PropertyEditorContextObject:toogleExportAlias", [&objectNode, &rootModelNode, modelNodeId](){ if (!objectNode.isAliasExported()) objectNode.ensureAliasExport(); else if (rootModelNode.hasProperty(modelNodeId)) rootModelNode.removeProperty(modelNodeId); - - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } + }); } - } void PropertyEditorContextObject::changeTypeName(const QString &typeName) @@ -181,11 +173,8 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName) QTC_ASSERT(!rewriterView->selectedModelNodes().isEmpty(), return); - ModelNode selectedNode = rewriterView->selectedModelNodes().constFirst(); - - try { - RewriterTransaction transaction = - rewriterView->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorContextObject:changeTypeName")); + rewriterView->executeInTransaction("PropertyEditorContextObject:changeTypeName", [this, rewriterView, typeName](){ + ModelNode selectedNode = rewriterView->selectedModelNodes().constFirst(); NodeMetaInfo metaInfo = m_model->metaInfo(typeName.toLatin1()); if (!metaInfo.isValid()) { @@ -193,16 +182,10 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName) return; } if (selectedNode.isRootNode()) - rewriterView->changeRootNodeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion()); + rewriterView->changeRootNodeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion()); else selectedNode.changeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion()); - - transaction.commit(); - } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail - exception.showException(); - } - - + }); } void PropertyEditorContextObject::insertKeyframe(const QString &propertyName) diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp index d0c98c896ff..bb02da3527a 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorview.cpp @@ -235,9 +235,7 @@ void PropertyEditorView::changeExpression(const QString &propertyName) if (!m_selectedNode.isValid()) return; - RewriterTransaction transaction = beginRewriterTransaction(QByteArrayLiteral("PropertyEditorView::changeExpression")); - - try { + executeInTransaction("PropertyEditorView::changeExpression", [this, name](){ PropertyName underscoreName(name); underscoreName.replace('.', '_'); @@ -253,7 +251,6 @@ void PropertyEditorView::changeExpression(const QString &propertyName) if (qmlObjectNode.modelNode().metaInfo().propertyTypeName(name) == "QColor") { if (QColor(value->expression().remove('"')).isValid()) { qmlObjectNode.setVariantProperty(name, QColor(value->expression().remove('"'))); - transaction.commit(); //committing in the try block return; } } else if (qmlObjectNode.modelNode().metaInfo().propertyTypeName(name) == "bool") { @@ -263,7 +260,6 @@ void PropertyEditorView::changeExpression(const QString &propertyName) qmlObjectNode.setVariantProperty(name, true); else qmlObjectNode.setVariantProperty(name, false); - transaction.commit(); //committing in the try block return; } } else if (qmlObjectNode.modelNode().metaInfo().propertyTypeName(name) == "int") { @@ -271,7 +267,6 @@ void PropertyEditorView::changeExpression(const QString &propertyName) int intValue = value->expression().toInt(&ok); if (ok) { qmlObjectNode.setVariantProperty(name, intValue); - transaction.commit(); //committing in the try block return; } } else if (qmlObjectNode.modelNode().metaInfo().propertyTypeName(name) == "qreal") { @@ -279,7 +274,6 @@ void PropertyEditorView::changeExpression(const QString &propertyName) qreal realValue = value->expression().toDouble(&ok); if (ok) { qmlObjectNode.setVariantProperty(name, realValue); - transaction.commit(); //committing in the try block return; } } @@ -291,12 +285,7 @@ void PropertyEditorView::changeExpression(const QString &propertyName) if (qmlObjectNode.expression(name) != value->expression() || !qmlObjectNode.propertyAffectedByCurrentState(name)) qmlObjectNode.setBindingProperty(name, value->expression()); - transaction.commit(); //committing in the try block - } - - catch (const RewritingException &e) { - e.showException(); - } + }); /* end of transaction */ } void PropertyEditorView::exportPopertyAsAlias(const QString &name) @@ -310,9 +299,7 @@ void PropertyEditorView::exportPopertyAsAlias(const QString &name) if (!m_selectedNode.isValid()) return; - RewriterTransaction transaction = beginRewriterTransaction(QByteArrayLiteral("PropertyEditorView::exportPopertyAsAlias")); - - try { + executeInTransaction("PropertyEditorView::exportPopertyAsAlias", [this, name](){ const QString id = m_selectedNode.validId(); QString upperCasePropertyName = name; upperCasePropertyName.replace(0, 1, upperCasePropertyName.at(0).toUpper()); @@ -326,11 +313,7 @@ void PropertyEditorView::exportPopertyAsAlias(const QString &name) return; } rootModelNode().bindingProperty(propertyName).setDynamicTypeNameAndExpression("alias", id + "." + name); - - transaction.commit(); //committing in the try block - } catch (const RewritingException &e) { - e.showException(); - } + }); } void PropertyEditorView::removeAliasExport(const QString &name) @@ -344,9 +327,7 @@ void PropertyEditorView::removeAliasExport(const QString &name) if (!m_selectedNode.isValid()) return; - RewriterTransaction transaction = beginRewriterTransaction(QByteArrayLiteral("PropertyEditorView::exportPopertyAsAlias")); - - try { + executeInTransaction("PropertyEditorView::exportPopertyAsAlias", [this, name](){ const QString id = m_selectedNode.validId(); for (const BindingProperty &property : rootModelNode().bindingProperties()) @@ -354,10 +335,7 @@ void PropertyEditorView::removeAliasExport(const QString &name) rootModelNode().removeProperty(property.name()); break; } - transaction.commit(); //committing in the try block - } catch (const RewritingException &e) { - e.showException(); - } + }); } bool PropertyEditorView::locked() const diff --git a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp index bc6b4376b66..7a38f74f34e 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.cpp @@ -292,9 +292,9 @@ void QmlAnchorBindingProxy::setDefaultRelativeRightTarget() } } -RewriterTransaction QmlAnchorBindingProxy::beginRewriterTransaction(const QByteArray &identifier) +bool QmlAnchorBindingProxy::executeInTransaction(const QByteArray &identifier, const AbstractView::OperationBlock &lambda) { - return m_qmlItemNode.modelNode().view()->beginRewriterTransaction(identifier); + return m_qmlItemNode.modelNode().view()->executeInTransaction(identifier, lambda); } bool QmlAnchorBindingProxy::hasParent() const @@ -361,20 +361,11 @@ void QmlAnchorBindingProxy::setTopTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setTopTarget", [this, newTarget](){ m_topTarget = newTarget; - setDefaultRelativeTopTarget(); - anchorTop(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit topTargetChanged(); } @@ -393,18 +384,12 @@ void QmlAnchorBindingProxy::setBottomTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setBottomTarget", [this, newTarget](){ m_bottomTarget = newTarget; setDefaultRelativeBottomTarget(); anchorBottom(); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit bottomTargetChanged(); } @@ -422,18 +407,11 @@ void QmlAnchorBindingProxy::setLeftTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setLeftTarget", [this, newTarget](){ m_leftTarget = newTarget; setDefaultRelativeLeftTarget(); anchorLeft(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit leftTargetChanged(); } @@ -451,18 +429,11 @@ void QmlAnchorBindingProxy::setRightTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setRightTarget", [this, newTarget](){ m_rightTarget = newTarget; setDefaultRelativeRightTarget(); anchorRight(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit rightTargetChanged(); } @@ -480,17 +451,10 @@ void QmlAnchorBindingProxy::setVerticalTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setVerticalTarget", [this, newTarget](){ m_verticalTarget = newTarget; anchorVertical(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit verticalTargetChanged(); } @@ -508,17 +472,10 @@ void QmlAnchorBindingProxy::setHorizontalTarget(const QString &target) if (!newTarget.isValid()) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalTarget")); - + executeInTransaction("QmlAnchorBindingProxy::setHorizontalTarget", [this, newTarget](){ m_horizontalTarget = newTarget; - anchorHorizontal();\ - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + anchorHorizontal(); + }); emit horizontalTargetChanged(); } @@ -531,18 +488,10 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetTop(QmlAnchorBindingProxy::Re if (target == m_relativeTopTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetTop")); - + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetTop", [this, target](){ m_relativeTopTarget = target; - anchorTop(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetTopChanged(); } @@ -555,19 +504,10 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetBottom(QmlAnchorBindingProxy: if (target == m_relativeBottomTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom")); - + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom", [this, target](){ m_relativeBottomTarget = target; - - anchorBottom(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetBottomChanged(); } @@ -580,18 +520,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetLeft(QmlAnchorBindingProxy::R if (target == m_relativeLeftTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft")); - + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft", [this, target](){ m_relativeLeftTarget = target; - anchorLeft(); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetLeftChanged(); } @@ -604,18 +537,10 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetRight(QmlAnchorBindingProxy:: if (target == m_relativeRightTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetRight")); - + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetRight", [this, target](){ m_relativeRightTarget = target; - anchorRight(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetRightChanged(); @@ -629,18 +554,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetVertical(QmlAnchorBindingProx if (target == m_relativeVerticalTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical")); + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical", [this, target](){ m_relativeVerticalTarget = target; - anchorVertical(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetVerticalChanged(); } @@ -653,18 +571,10 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal(QmlAnchorBindingPr if (target == m_relativeHorizontalTarget) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal")); - + executeInTransaction("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal", [this, target](){ m_relativeHorizontalTarget = target; - anchorHorizontal(); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetHorizontalChanged(); } @@ -709,12 +619,10 @@ int QmlAnchorBindingProxy::indexOfPossibleTargetItem(const QString &targetName) return possibleTargetItems().indexOf(targetName); } -void QmlAnchorBindingProxy::resetLayout() { - - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout")); +void QmlAnchorBindingProxy::resetLayout() +{ + executeInTransaction("QmlAnchorBindingProxy::resetLayout", [this](){ m_qmlItemNode.anchors().removeAnchors(); m_qmlItemNode.anchors().removeMargins(); @@ -722,11 +630,7 @@ void QmlAnchorBindingProxy::resetLayout() { restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "height"); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit topAnchorChanged(); emit bottomAnchorChanged(); @@ -743,10 +647,7 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor) if (bottomAnchored() == anchor) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setBottomAnchor")); - + executeInTransaction("QmlAnchorBindingProxy::setBottomAnchor", [this, anchor](){ if (!anchor) { removeBottomAnchor(); } else { @@ -756,10 +657,7 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor) backupPropertyAndRemove(modelNode(), "height"); } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetBottomChanged(); emit bottomAnchorChanged(); @@ -776,10 +674,8 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor) if (leftAnchored() == anchor) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor")); + executeInTransaction("QmlAnchorBindingProxy::setLeftAnchor", [this, anchor](){ if (!anchor) { removeLeftAnchor(); } else { @@ -791,10 +687,7 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor) backupPropertyAndRemove(modelNode(), "width"); } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetLeftChanged(); emit leftAnchorChanged(); @@ -810,10 +703,7 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor) if (rightAnchored() == anchor) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setRightAnchor")); - + executeInTransaction("QmlAnchorBindingProxy::setRightAnchor", [this, anchor](){ if (!anchor) { removeRightAnchor(); } else { @@ -824,10 +714,7 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor) backupPropertyAndRemove(modelNode(), "width"); } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetRightChanged(); emit rightAnchorChanged(); @@ -1026,10 +913,7 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor) if (topAnchored() == anchor) return; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor")); - + executeInTransaction("QmlAnchorBindingProxy::setTopAnchor", [this, anchor](){ if (!anchor) { removeTopAnchor(); } else { @@ -1040,10 +924,7 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor) if (bottomAnchored()) backupPropertyAndRemove(modelNode(), "height"); } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit relativeAnchorTargetTopChanged(); emit topAnchorChanged(); @@ -1052,70 +933,44 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor) } void QmlAnchorBindingProxy::removeTopAnchor() { - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor")); - + executeInTransaction("QmlAnchorBindingProxy::removeTopAnchor", [this](){ m_qmlItemNode.anchors().removeAnchor(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineTop); restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "height"); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } -void QmlAnchorBindingProxy::removeBottomAnchor() { - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::removeBottomAnchor")); - +void QmlAnchorBindingProxy::removeBottomAnchor() +{ + executeInTransaction("QmlAnchorBindingProxy::removeBottomAnchor", [this](){ m_qmlItemNode.anchors().removeAnchor(AnchorLineBottom); m_qmlItemNode.anchors().removeMargin(AnchorLineBottom); - restoreProperty(modelNode(), "height"); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } -void QmlAnchorBindingProxy::removeLeftAnchor() { - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor")); - +void QmlAnchorBindingProxy::removeLeftAnchor() +{ + executeInTransaction("QmlAnchorBindingProxy::removeLeftAnchor", [this](){ m_qmlItemNode.anchors().removeAnchor(AnchorLineLeft); m_qmlItemNode.anchors().removeMargin(AnchorLineLeft); restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "width"); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } -void QmlAnchorBindingProxy::removeRightAnchor() { - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::removeRightAnchor")); - +void QmlAnchorBindingProxy::removeRightAnchor() +{ + executeInTransaction("QmlAnchorBindingProxy::removeRightAnchor", [this](){ m_qmlItemNode.anchors().removeAnchor(AnchorLineRight); m_qmlItemNode.anchors().removeMargin(AnchorLineRight); restoreProperty(modelNode(), "width"); - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } void QmlAnchorBindingProxy::setVerticalCentered(bool centered) @@ -1128,10 +983,7 @@ void QmlAnchorBindingProxy::setVerticalCentered(bool centered) m_locked = true; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalCentered")); - + executeInTransaction("QmlAnchorBindingProxy::setVerticalCentered", [this, centered](){ if (!centered) { m_qmlItemNode.anchors().removeAnchor(AnchorLineVerticalCenter); m_qmlItemNode.anchors().removeMargin(AnchorLineVerticalCenter); @@ -1141,10 +993,7 @@ void QmlAnchorBindingProxy::setVerticalCentered(bool centered) anchorVertical(); } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); m_locked = false; emit relativeAnchorTargetVerticalChanged(); @@ -1161,10 +1010,7 @@ void QmlAnchorBindingProxy::setHorizontalCentered(bool centered) m_locked = true; - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalCentered")); - + executeInTransaction("QmlAnchorBindingProxy::setHorizontalCentered", [this, centered](){ if (!centered) { m_qmlItemNode.anchors().removeAnchor(AnchorLineHorizontalCenter); m_qmlItemNode.anchors().removeMargin(AnchorLineHorizontalCenter); @@ -1173,11 +1019,7 @@ void QmlAnchorBindingProxy::setHorizontalCentered(bool centered) anchorHorizontal(); } - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); m_locked = false; emit relativeAnchorTargetHorizontalChanged(); @@ -1256,12 +1098,7 @@ bool QmlAnchorBindingProxy::horizontalCentered() void QmlAnchorBindingProxy::fill() { - - try { - RewriterTransaction transaction = beginRewriterTransaction( - QByteArrayLiteral("QmlAnchorBindingProxy::fill")); - - + executeInTransaction("QmlAnchorBindingProxy::fill", [this](){ backupPropertyAndRemove(modelNode(), "x"); backupPropertyAndRemove(modelNode(), "y"); backupPropertyAndRemove(modelNode(), "width"); @@ -1277,10 +1114,7 @@ void QmlAnchorBindingProxy::fill() m_qmlItemNode.anchors().removeMargin(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineBottom); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); emit topAnchorChanged(); emit bottomAnchorChanged(); diff --git a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.h b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.h index cf42ea055ac..0bd562add20 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.h +++ b/src/plugins/qmldesigner/components/propertyeditor/qmlanchorbindingproxy.h @@ -210,7 +210,7 @@ private: void setDefaultRelativeLeftTarget(); void setDefaultRelativeRightTarget(); - RewriterTransaction beginRewriterTransaction(const QByteArray &identifier); + bool executeInTransaction(const QByteArray &identifier, const AbstractView::OperationBlock &lambda); QmlItemNode targetIdToNode(const QString &id) const; QString idForNode(const QmlItemNode &qmlItemNode) const; diff --git a/src/plugins/qmldesigner/designercore/include/abstractview.h b/src/plugins/qmldesigner/designercore/include/abstractview.h index d32a403e5c1..dcbeb5ee74d 100644 --- a/src/plugins/qmldesigner/designercore/include/abstractview.h +++ b/src/plugins/qmldesigner/designercore/include/abstractview.h @@ -39,6 +39,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QStyle; class QToolButton; @@ -263,6 +265,9 @@ public: void activateTimelineRecording(const ModelNode &timeline); void deactivateTimelineRecording(); + using OperationBlock = std::function; + bool executeInTransaction(const QByteArray &identifier, const OperationBlock &lambda); + protected: void setModel(Model * model); void removeModel(); diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index 4e3596001c2..eb7ed16b9ab 100644 --- a/src/plugins/qmldesigner/designercore/model/abstractview.cpp +++ b/src/plugins/qmldesigner/designercore/model/abstractview.cpp @@ -616,6 +616,20 @@ void AbstractView::deactivateTimelineRecording() model()->d->notifyCurrentTimelineChanged(ModelNode()); } +bool AbstractView::executeInTransaction(const QByteArray &identifier, const AbstractView::OperationBlock &lambda) +{ + try { + RewriterTransaction transaction = beginRewriterTransaction(identifier); + lambda(); + transaction.commit(); + } catch (const Exception &e) { + e.showException(); + return false; + } + + return true; +} + QList AbstractView::allModelNodes() const { return toModelNodeList(model()->d->allNodes()); diff --git a/src/plugins/qmldesigner/designercore/model/modelmerger.cpp b/src/plugins/qmldesigner/designercore/model/modelmerger.cpp index 161cf1f9f52..8517f9cb827 100644 --- a/src/plugins/qmldesigner/designercore/model/modelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/modelmerger.cpp @@ -178,29 +178,23 @@ void ModelMerger::replaceModel(const ModelNode &modelNode) view()->model()->changeImports(modelNode.model()->imports(), {}); view()->model()->setFileUrl(modelNode.model()->fileUrl()); - try { - RewriterTransaction transaction(view()->beginRewriterTransaction(QByteArrayLiteral("ModelMerger::replaceModel"))); + view()->executeInTransaction("ModelMerger::replaceModel", [this, modelNode](){ + ModelNode rootNode(view()->rootModelNode()); - ModelNode rootNode(view()->rootModelNode()); + foreach (const PropertyName &propertyName, rootNode.propertyNames()) + rootNode.removeProperty(propertyName); - foreach (const PropertyName &propertyName, rootNode.propertyNames()) - rootNode.removeProperty(propertyName); + QHash idRenamingHash; + setupIdRenamingHash(modelNode, idRenamingHash, view()); - QHash idRenamingHash; - setupIdRenamingHash(modelNode, idRenamingHash, view()); - - syncAuxiliaryProperties(rootNode, modelNode); - syncVariantProperties(rootNode, modelNode); - syncBindingProperties(rootNode, modelNode, idRenamingHash); - syncId(rootNode, modelNode, idRenamingHash); - syncNodeProperties(rootNode, modelNode, idRenamingHash, view()); - syncNodeListProperties(rootNode, modelNode, idRenamingHash, view()); - m_view->changeRootNodeType(modelNode.type(), modelNode.majorVersion(), modelNode.minorVersion()); - - transaction.commit(); - } catch (const RewritingException &e) { - qWarning() << e.description(); //silent error - } + syncAuxiliaryProperties(rootNode, modelNode); + syncVariantProperties(rootNode, modelNode); + syncBindingProperties(rootNode, modelNode, idRenamingHash); + syncId(rootNode, modelNode, idRenamingHash); + syncNodeProperties(rootNode, modelNode, idRenamingHash, view()); + syncNodeListProperties(rootNode, modelNode, idRenamingHash, view()); + m_view->changeRootNodeType(modelNode.type(), modelNode.majorVersion(), modelNode.minorVersion()); + }); } } //namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp index 7b83330a32a..ba821dd788b 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp @@ -161,22 +161,23 @@ void QmlAnchors::setAnchor(AnchorLineType sourceAnchorLine, const QmlItemNode &targetQmlItemNode, AnchorLineType targetAnchorLine) { - RewriterTransaction transaction = qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchors::setAnchor")); - if (qmlItemNode().isInBaseState()) { - if ((qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLineFill)) - || ((qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLineCenter)))) { - removeAnchor(sourceAnchorLine); - } + qmlItemNode().view()->executeInTransaction("QmlAnchors::setAnchor", [this, sourceAnchorLine, targetQmlItemNode, targetAnchorLine](){ + if (qmlItemNode().isInBaseState()) { + if ((qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLineFill)) + || ((qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLineCenter)))) { + removeAnchor(sourceAnchorLine); + } - const PropertyName propertyName = anchorPropertyName(sourceAnchorLine); - ModelNode targetModelNode = targetQmlItemNode.modelNode(); - QString targetExpression = targetModelNode.validId(); - if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode()) - targetExpression = QLatin1String("parent"); - if (sourceAnchorLine != AnchorLineCenter && sourceAnchorLine != AnchorLineFill) - targetExpression = targetExpression + QLatin1Char('.') + QString::fromLatin1(lineTypeToString(targetAnchorLine)); - qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression); - } + const PropertyName propertyName = anchorPropertyName(sourceAnchorLine); + ModelNode targetModelNode = targetQmlItemNode.modelNode(); + QString targetExpression = targetModelNode.validId(); + if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode()) + targetExpression = QLatin1String("parent"); + if (sourceAnchorLine != AnchorLineCenter && sourceAnchorLine != AnchorLineFill) + targetExpression = targetExpression + QLatin1Char('.') + QString::fromLatin1(lineTypeToString(targetAnchorLine)); + qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression); + } + }); } bool detectHorizontalCycle(const ModelNode &node, QList knownNodeList) @@ -315,47 +316,49 @@ AnchorLine QmlAnchors::instanceAnchor(AnchorLineType sourceAnchorLine) const void QmlAnchors::removeAnchor(AnchorLineType sourceAnchorLine) { - RewriterTransaction transaction = qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchors::removeAnchor")); - if (qmlItemNode().isInBaseState()) { - const PropertyName propertyName = anchorPropertyName(sourceAnchorLine); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLineFill)) { - qmlItemNode().modelNode().removeProperty("anchors.fill"); - qmlItemNode().modelNode().bindingProperty("anchors.top").setExpression(QLatin1String("parent.top")); - qmlItemNode().modelNode().bindingProperty("anchors.left").setExpression(QLatin1String("parent.left")); - qmlItemNode().modelNode().bindingProperty("anchors.bottom").setExpression(QLatin1String("parent.bottom")); - qmlItemNode().modelNode().bindingProperty("anchors.right").setExpression(QLatin1String("parent.right")); + qmlItemNode().view()->executeInTransaction("QmlAnchors::removeAnchor", [this, sourceAnchorLine](){ + if (qmlItemNode().isInBaseState()) { + const PropertyName propertyName = anchorPropertyName(sourceAnchorLine); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLineFill)) { + qmlItemNode().modelNode().removeProperty("anchors.fill"); + qmlItemNode().modelNode().bindingProperty("anchors.top").setExpression(QLatin1String("parent.top")); + qmlItemNode().modelNode().bindingProperty("anchors.left").setExpression(QLatin1String("parent.left")); + qmlItemNode().modelNode().bindingProperty("anchors.bottom").setExpression(QLatin1String("parent.bottom")); + qmlItemNode().modelNode().bindingProperty("anchors.right").setExpression(QLatin1String("parent.right")); - } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLineCenter)) { - qmlItemNode().modelNode().removeProperty("anchors.centerIn"); - qmlItemNode().modelNode().bindingProperty("anchors.horizontalCenter").setExpression(QLatin1String("parent.horizontalCenter")); - qmlItemNode().modelNode().bindingProperty("anchors.verticalCenter").setExpression(QLatin1String("parent.verticalCenter")); + } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLineCenter)) { + qmlItemNode().modelNode().removeProperty("anchors.centerIn"); + qmlItemNode().modelNode().bindingProperty("anchors.horizontalCenter").setExpression(QLatin1String("parent.horizontalCenter")); + qmlItemNode().modelNode().bindingProperty("anchors.verticalCenter").setExpression(QLatin1String("parent.verticalCenter")); + } + + qmlItemNode().modelNode().removeProperty(propertyName); } - - qmlItemNode().modelNode().removeProperty(propertyName); - } + }); } void QmlAnchors::removeAnchors() { - RewriterTransaction transaction = qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchors::removeAnchors")); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill")) - qmlItemNode().modelNode().removeProperty("anchors.fill"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn")) - qmlItemNode().modelNode().removeProperty("anchors.centerIn"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.top")) - qmlItemNode().modelNode().removeProperty("anchors.top"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.left")) - qmlItemNode().modelNode().removeProperty("anchors.left"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.right")) - qmlItemNode().modelNode().removeProperty("anchors.right"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.bottom")) - qmlItemNode().modelNode().removeProperty("anchors.bottom"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.horizontalCenter")) - qmlItemNode().modelNode().removeProperty("anchors.horizontalCenter"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.verticalCenter")) - qmlItemNode().modelNode().removeProperty("anchors.verticalCenter"); - if (qmlItemNode().nodeInstance().hasAnchor("anchors.baseline")) - qmlItemNode().modelNode().removeProperty("anchors.baseline"); + qmlItemNode().view()->executeInTransaction("QmlAnchors::removeAnchors", [this](){ + if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill")) + qmlItemNode().modelNode().removeProperty("anchors.fill"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn")) + qmlItemNode().modelNode().removeProperty("anchors.centerIn"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.top")) + qmlItemNode().modelNode().removeProperty("anchors.top"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.left")) + qmlItemNode().modelNode().removeProperty("anchors.left"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.right")) + qmlItemNode().modelNode().removeProperty("anchors.right"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.bottom")) + qmlItemNode().modelNode().removeProperty("anchors.bottom"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.horizontalCenter")) + qmlItemNode().modelNode().removeProperty("anchors.horizontalCenter"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.verticalCenter")) + qmlItemNode().modelNode().removeProperty("anchors.verticalCenter"); + if (qmlItemNode().nodeInstance().hasAnchor("anchors.baseline")) + qmlItemNode().modelNode().removeProperty("anchors.baseline"); + }); } bool QmlAnchors::instanceHasAnchor(AnchorLineType sourceAnchorLine) const @@ -532,13 +535,14 @@ void QmlAnchors::removeMargin(AnchorLineType sourceAnchorLineType) void QmlAnchors::removeMargins() { - RewriterTransaction transaction = qmlItemNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchors::removeMargins")); - removeMargin(AnchorLineLeft); - removeMargin(AnchorLineRight); - removeMargin(AnchorLineTop); - removeMargin(AnchorLineBottom); - removeMargin(AnchorLineHorizontalCenter); - removeMargin(AnchorLineVerticalCenter); + qmlItemNode().view()->executeInTransaction("QmlAnchors::removeMargins", [this](){ + removeMargin(AnchorLineLeft); + removeMargin(AnchorLineRight); + removeMargin(AnchorLineTop); + removeMargin(AnchorLineBottom); + removeMargin(AnchorLineHorizontalCenter); + removeMargin(AnchorLineVerticalCenter); + }); } void QmlAnchors::fill() diff --git a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp index f02ca1ead73..ea40b46e8bf 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlitemnode.cpp @@ -102,9 +102,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary { QmlItemNode newQmlItemNode; - try { - RewriterTransaction transaction = view->beginRewriterTransaction(QByteArrayLiteral("QmlItemNode::createQmlItemNode")); - + view->executeInTransaction("QmlItemNode::createQmlItemNode", [=, &newQmlItemNode, &parentproperty](){ NodeMetaInfo metaInfo = view->model()->metaInfo(itemLibraryEntry.typeName()); int minorVersion = metaInfo.minorVersion(); @@ -139,7 +137,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary parentproperty.reparentHere(newQmlItemNode); if (!newQmlItemNode.isValid()) - return newQmlItemNode; + return; newQmlItemNode.setId(view->generateNewId(itemLibraryEntry.name())); @@ -150,10 +148,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary newQmlItemNode.modelNode().variantProperty(propertyBindingEntry.first).setEnumeration(propertyBindingEntry.second.toUtf8()); Q_ASSERT(newQmlItemNode.isValid()); - } - catch (const RewritingException &e) { - e.showException(); - } + }); Q_ASSERT(newQmlItemNode.isValid()); @@ -174,10 +169,8 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS { QmlItemNode newQmlItemNode; - if (parentproperty.isValid()) { - RewriterTransaction transaction = view->beginRewriterTransaction(QByteArrayLiteral("QmlItemNode::createQmlItemNodeFromImage")); - - if (view->model()->hasNodeMetaInfo("QtQuick.Image")) { + if (parentproperty.isValid() && view->model()->hasNodeMetaInfo("QtQuick.Image")) { + view->executeInTransaction("QmlItemNode::createQmlItemNodeFromImage", [=, &newQmlItemNode, &parentproperty](){ NodeMetaInfo metaInfo = view->model()->metaInfo("QtQuick.Image"); QList > propertyPairList; propertyPairList.append({PropertyName("x"), QVariant(qRound(position.x()))}); @@ -200,8 +193,7 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS newQmlItemNode.modelNode().variantProperty("fillMode").setEnumeration("Image.PreserveAspectFit"); Q_ASSERT(newQmlItemNode.isValid()); - } - Q_ASSERT(newQmlItemNode.isValid()); + }); } return newQmlItemNode; diff --git a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/backendmodel.cpp b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/backendmodel.cpp index f356788a55d..4a004ca5753 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/backendmodel.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/backendmodel.cpp @@ -232,27 +232,24 @@ void BackendModel::addNewBackend() Import import = Import::createLibraryImport(importSplit.constFirst(), importSplit.constLast()); - try { - - /* We cannot add an import and add a node from that import in a single transaction. + /* We cannot add an import and add a node from that import in a single transaction. * We need the import to have the meta info available. */ - if (!model->hasImport(import)) - model->changeImports({import}, {}); + if (!model->hasImport(import)) + model->changeImports({import}, {}); - QString propertyName = m_connectionView->generateNewId(typeName); + QString propertyName = m_connectionView->generateNewId(typeName); - NodeMetaInfo metaInfo = model->metaInfo(typeName.toUtf8()); + NodeMetaInfo metaInfo = model->metaInfo(typeName.toUtf8()); - QTC_ASSERT(metaInfo.isValid(), return); + QTC_ASSERT(metaInfo.isValid(), return); - int minorVersion = metaInfo.minorVersion(); - int majorVersion = metaInfo.majorVersion(); - - /* Add a property for non singleton types. For singletons just adding the import is enough. */ - if (!dialog.isSingleton()) { - RewriterTransaction transaction = m_connectionView->beginRewriterTransaction("BackendModel::addNewBackend"); + /* Add a property for non singleton types. For singletons just adding the import is enough. */ + if (!dialog.isSingleton()) { + m_connectionView->executeInTransaction("BackendModel::addNewBackend", [=, &dialog](){ + int minorVersion = metaInfo.minorVersion(); + int majorVersion = metaInfo.majorVersion(); if (dialog.localDefinition()) { ModelNode newNode = m_connectionView->createModelNode(metaInfo.typeName(), majorVersion, minorVersion); @@ -263,14 +260,9 @@ void BackendModel::addNewBackend() m_connectionView->rootModelNode().bindingProperty( propertyName.toUtf8()).setDynamicTypeNameAndExpression(typeName.toUtf8(), "null"); } - transaction.commit(); - } - - } catch (const Exception &e) { - e.showException(); + }); } } - resetModel(); } @@ -279,11 +271,9 @@ void BackendModel::updatePropertyName(int rowNumber) const PropertyName newName = data(index(rowNumber, 1)).toString().toUtf8(); const PropertyName oldName = data(index(rowNumber, 0), Qt::UserRole + 1).toString().toUtf8(); - ModelNode rootModelNode = m_connectionView->rootModelNode(); - - try { - RewriterTransaction transaction = m_connectionView->beginRewriterTransaction("BackendModel::updatePropertyName"); + m_connectionView->executeInTransaction("BackendModel::updatePropertyName", [this, newName, oldName](){ + ModelNode rootModelNode = m_connectionView->rootModelNode(); if (rootModelNode.property(oldName).isNodeProperty()) { const TypeName typeName = rootModelNode.nodeProperty(oldName).dynamicTypeName(); @@ -306,12 +296,7 @@ void BackendModel::updatePropertyName(int rowNumber) qWarning() << Q_FUNC_INFO << oldName << newName << "failed..."; QTC_ASSERT(false, return); } - - transaction.commit(); - - } catch (const Exception &e) { - e.showException(); - } + }); } void BackendModel::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) diff --git a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp index cd8c92b82c1..2cff12b044d 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp @@ -290,8 +290,6 @@ void BindingModel::addModelNode(const ModelNode &modelNode) void BindingModel::updateExpression(int row) { - BindingProperty bindingProperty = bindingPropertyForRow(row); - const QString sourceNode = data(index(row, SourceModelNodeRow)).toString().trimmed(); const QString sourceProperty = data(index(row, SourcePropertyNameRow)).toString().trimmed(); @@ -302,15 +300,10 @@ void BindingModel::updateExpression(int row) expression = sourceNode + QLatin1String(".") + sourceProperty; } - RewriterTransaction transaction = - connectionView()->beginRewriterTransaction(QByteArrayLiteral("BindingModel::updateExpression")); - try { + connectionView()->executeInTransaction("BindingModel::updateExpression", [this, row, expression](){ + BindingProperty bindingProperty = bindingPropertyForRow(row); bindingProperty.setExpression(expression.trimmed()); - transaction.commit(); //committing in the try block - } catch (Exception &e) { - m_exceptionError = e.description(); - QTimer::singleShot(200, this, &BindingModel::handleException); - } + }); } void BindingModel::updatePropertyName(int rowNumber) diff --git a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/connectionmodel.cpp b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/connectionmodel.cpp index 8cd297890e9..80caf51ce06 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/connectionmodel.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/connectionmodel.cpp @@ -182,26 +182,21 @@ void ConnectionModel::updateSource(int row) void ConnectionModel::updateSignalName(int rowNumber) { SignalHandlerProperty signalHandlerProperty = signalHandlerPropertyForRow(rowNumber); - - const PropertyName newName = data(index(rowNumber, TargetPropertyNameRow)).toString().toUtf8(); - const QString source = signalHandlerProperty.source(); ModelNode connectionNode = signalHandlerProperty.parentModelNode(); + const PropertyName newName = data(index(rowNumber, TargetPropertyNameRow)).toString().toUtf8(); if (!newName.isEmpty()) { - RewriterTransaction transaction = - connectionView()->beginRewriterTransaction(QByteArrayLiteral("ConnectionModel::updateSignalName")); - try { + connectionView()->executeInTransaction("ConnectionModel::updateSignalName", [=, &connectionNode](){ + + const QString source = signalHandlerProperty.source(); + connectionNode.signalHandlerProperty(newName).setSource(source); connectionNode.removeProperty(signalHandlerProperty.name()); - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); QStandardItem* idItem = item(rowNumber, 0); SignalHandlerProperty newSignalHandlerProperty = connectionNode.signalHandlerProperty(newName); updateCustomData(idItem, newSignalHandlerProperty); - } else { qWarning() << "BindingModel::updatePropertyName invalid property name"; } @@ -214,14 +209,9 @@ void ConnectionModel::updateTargetNode(int rowNumber) ModelNode connectionNode = signalHandlerProperty.parentModelNode(); if (!newTarget.isEmpty()) { - RewriterTransaction transaction = - connectionView()->beginRewriterTransaction(QByteArrayLiteral("ConnectionModel::updateTargetNode")); - try { + connectionView()->executeInTransaction("ConnectionModel::updateTargetNode", [= ,&connectionNode](){ connectionNode.bindingProperty("target").setExpression(newTarget); - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); QStandardItem* idItem = item(rowNumber, 0); updateCustomData(idItem, signalHandlerProperty); @@ -256,12 +246,10 @@ void ConnectionModel::addConnection() if (rootModelNode.isValid() && rootModelNode.metaInfo().isValid()) { - NodeMetaInfo nodeMetaInfo = connectionView()->model()->metaInfo("QtQuick.Connections"); + NodeMetaInfo nodeMetaInfo = connectionView()->model()->metaInfo("QtQuick.Connections"); if (nodeMetaInfo.isValid()) { - RewriterTransaction transaction = - connectionView()->beginRewriterTransaction(QByteArrayLiteral("ConnectionModel::addConnection")); - try { + connectionView()->executeInTransaction("ConnectionModel::addConnection", [=](){ ModelNode newNode = connectionView()->createModelNode("QtQuick.Connections", nodeMetaInfo.majorVersion(), nodeMetaInfo.minorVersion()); @@ -276,10 +264,7 @@ void ConnectionModel::addConnection() } else { newNode.bindingProperty("target").setExpression(QLatin1String("parent")); } - transaction.commit(); - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); } } } diff --git a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/dynamicpropertiesmodel.cpp b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/dynamicpropertiesmodel.cpp index 8d4186a5b54..0a08e5c8839 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/dynamicpropertiesmodel.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/connectioneditor/dynamicpropertiesmodel.cpp @@ -464,19 +464,16 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber) BindingProperty bindingProperty = bindingPropertyForRow(rowNumber); - if (bindingProperty.isBindingProperty()) { - const QString expression = bindingProperty.expression(); - const PropertyName dynamicPropertyType = bindingProperty.dynamicTypeName(); - ModelNode targetNode = bindingProperty.parentModelNode(); + ModelNode targetNode = bindingProperty.parentModelNode(); + + if (bindingProperty.isBindingProperty()) { + connectionView()->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [bindingProperty, newName, &targetNode](){ + const QString expression = bindingProperty.expression(); + const PropertyName dynamicPropertyType = bindingProperty.dynamicTypeName(); - RewriterTransaction transaction = connectionView()->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updatePropertyName")); - try { targetNode.bindingProperty(newName).setDynamicTypeNameAndExpression(dynamicPropertyType, expression); targetNode.removeProperty(bindingProperty.name()); - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); updateCustomData(rowNumber, targetNode.bindingProperty(newName)); return; @@ -489,14 +486,10 @@ void DynamicPropertiesModel::updatePropertyName(int rowNumber) const PropertyName dynamicPropertyType = variantProperty.dynamicTypeName(); ModelNode targetNode = variantProperty.parentModelNode(); - RewriterTransaction transaction = connectionView()->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updatePropertyName")); - try { + connectionView()->executeInTransaction("DynamicPropertiesModel::updatePropertyName", [=](){ targetNode.variantProperty(newName).setDynamicTypeNameAndValue(dynamicPropertyType, value); targetNode.removeProperty(variantProperty.name()); - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); updateCustomData(rowNumber, targetNode.variantProperty(newName)); } @@ -519,14 +512,10 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber) const PropertyName propertyName = bindingProperty.name(); ModelNode targetNode = bindingProperty.parentModelNode(); - RewriterTransaction transaction = connectionView()->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updatePropertyType")); - try { + connectionView()->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ targetNode.removeProperty(bindingProperty.name()); targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(newType, expression); - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); updateCustomData(rowNumber, targetNode.bindingProperty(propertyName)); return; @@ -539,18 +528,14 @@ void DynamicPropertiesModel::updatePropertyType(int rowNumber) ModelNode targetNode = variantProperty.parentModelNode(); const PropertyName propertyName = variantProperty.name(); - RewriterTransaction transaction = connectionView()->beginRewriterTransaction(QByteArrayLiteral("DynamicPropertiesModel::updatePropertyType")); - try { + connectionView()->executeInTransaction("DynamicPropertiesModel::updatePropertyType", [=](){ targetNode.removeProperty(variantProperty.name()); if (newType == "alias") { //alias properties have to be bindings targetNode.bindingProperty(propertyName).setDynamicTypeNameAndExpression(newType, QLatin1String("none.none")); } else { targetNode.variantProperty(propertyName).setDynamicTypeNameAndValue(newType, convertVariantForTypeName(value, newType)); } - transaction.commit(); //committing in the try block - } catch (Exception &e) { //better save then sorry - QMessageBox::warning(nullptr, tr("Error"), e.description()); - } + }); updateCustomData(rowNumber, targetNode.variantProperty(propertyName)); diff --git a/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp b/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp index ad5437f34e9..76fe6f0b90f 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/pathtool/pathitem.cpp @@ -133,46 +133,7 @@ void PathItem::writePathToProperty() ModelNode pathNode = pathModelNode(formEditorItem()); - RewriterTransaction rewriterTransaction = pathNode.view()->beginRewriterTransaction(QByteArrayLiteral("PathItem::writePathToProperty")); - - QList pathSegmentNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); - - foreach (ModelNode pathSegment, pathSegmentNodes) - pathSegment.destroy(); - - if (!m_cubicSegments.isEmpty()) { - pathNode.variantProperty("startX").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().x()); - pathNode.variantProperty("startY").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().y()); - - foreach (const CubicSegment &cubicSegment, m_cubicSegments) { - writePathAttributes(pathNode, cubicSegment.attributes()); - writePathPercent(pathNode, cubicSegment.percent()); - - if (cubicSegment.canBeConvertedToLine()) - writeLinePath(pathNode, cubicSegment); - else if (cubicSegment.canBeConvertedToQuad()) - writeQuadPath(pathNode, cubicSegment); - else - writeCubicPath(pathNode, cubicSegment); - } - - writePathAttributes(pathNode, m_lastAttributes); - writePathPercent(pathNode, m_lastPercent); - } - - rewriterTransaction.commit(); -} - -void PathItem::writePathAsCubicSegmentsOnly() -{ - try { - PathUpdateDisabler pathUpdateDisabler(this); - - ModelNode pathNode = pathModelNode(formEditorItem()); - - RewriterTransaction rewriterTransaction = - pathNode.view()->beginRewriterTransaction(QByteArrayLiteral("PathItem::writePathAsCubicSegmentsOnly")); - + pathNode.view()->executeInTransaction("PathItem::writePathToProperty", [this, &pathNode](){ QList pathSegmentNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); foreach (ModelNode pathSegment, pathSegmentNodes) @@ -182,21 +143,51 @@ void PathItem::writePathAsCubicSegmentsOnly() pathNode.variantProperty("startX").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().x()); pathNode.variantProperty("startY").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().y()); - foreach (const CubicSegment &cubicSegment, m_cubicSegments) { writePathAttributes(pathNode, cubicSegment.attributes()); writePathPercent(pathNode, cubicSegment.percent()); - writeCubicPath(pathNode, cubicSegment); + + if (cubicSegment.canBeConvertedToLine()) + writeLinePath(pathNode, cubicSegment); + else if (cubicSegment.canBeConvertedToQuad()) + writeQuadPath(pathNode, cubicSegment); + else + writeCubicPath(pathNode, cubicSegment); } writePathAttributes(pathNode, m_lastAttributes); writePathPercent(pathNode, m_lastPercent); } + }); +} - rewriterTransaction.commit(); - } catch (const RewritingException &e) { - e.showException(); - } +void PathItem::writePathAsCubicSegmentsOnly() +{ + PathUpdateDisabler pathUpdateDisabler(this); + + ModelNode pathNode = pathModelNode(formEditorItem()); + pathNode.view()->executeInTransaction("PathItem::writePathAsCubicSegmentsOnly", [this, &pathNode](){ + + QList pathSegmentNodes = pathNode.nodeListProperty("pathElements").toModelNodeList(); + + foreach (ModelNode pathSegment, pathSegmentNodes) + pathSegment.destroy(); + + if (!m_cubicSegments.isEmpty()) { + pathNode.variantProperty("startX").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().x()); + pathNode.variantProperty("startY").setValue(m_cubicSegments.constFirst().firstControlPoint().coordinate().y()); + + + foreach (const CubicSegment &cubicSegment, m_cubicSegments) { + writePathAttributes(pathNode, cubicSegment.attributes()); + writePathPercent(pathNode, cubicSegment.percent()); + writeCubicPath(pathNode, cubicSegment); + } + + writePathAttributes(pathNode, m_lastAttributes); + writePathPercent(pathNode, m_lastPercent); + } + }); } void PathItem::setFormEditorItem(FormEditorItem *formEditorItem) diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/easingcurvedialog.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/easingcurvedialog.cpp index 844be8e12fa..a069dc187b6 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/easingcurvedialog.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/easingcurvedialog.cpp @@ -202,22 +202,13 @@ bool EasingCurveDialog::apply() msgBox.exec(); return false; } + AbstractView *view = m_frames.first().view(); - try { - AbstractView *view = m_frames.first().view(); - RewriterTransaction transaction(view->beginRewriterTransaction("EasingCurveDialog::apply")); - + return view->executeInTransaction("EasingCurveDialog::apply", [this, view](){ auto expression = m_splineEditor->easingCurve().toString(); for (const auto &frame : m_frames) frame.bindingProperty("easing.bezierCurve").setExpression(expression); - - transaction.commit(); - return true; - } catch (const RewritingException &e) { - e.showException(); - } - - return false; + }); } void EasingCurveDialog::textChanged() diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineactions.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineactions.cpp index 419e9294a2c..4751765874b 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineactions.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineactions.cpp @@ -48,28 +48,18 @@ TimelineActions::TimelineActions() = default; void TimelineActions::deleteAllKeyframesForTarget(const ModelNode &targetNode, const QmlTimeline &timeline) { - try { - RewriterTransaction transaction(targetNode.view()->beginRewriterTransaction( - "TimelineActions::deleteAllKeyframesForTarget")); - + targetNode.view()->executeInTransaction("TimelineActions::deleteAllKeyframesForTarget", [=](){ if (timeline.isValid()) { for (auto frames : timeline.keyframeGroupsForTarget(targetNode)) frames.destroy(); } - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } void TimelineActions::insertAllKeyframesForTarget(const ModelNode &targetNode, const QmlTimeline &timeline) { - try { - RewriterTransaction transaction(targetNode.view()->beginRewriterTransaction( - "TimelineGraphicsScene::insertAllKeyframesForTarget")); - + targetNode.view()->executeInTransaction("TimelineActions::insertAllKeyframesForTarget", [=](){ auto object = QmlObjectNode(targetNode); if (timeline.isValid() && object.isValid()) { for (auto frames : timeline.keyframeGroupsForTarget(targetNode)) { @@ -78,10 +68,7 @@ void TimelineActions::insertAllKeyframesForTarget(const ModelNode &targetNode, } } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } void TimelineActions::copyAllKeyframesForTarget(const ModelNode &targetNode, @@ -117,11 +104,10 @@ void TimelineActions::pasteKeyframesToTarget(const ModelNode &targetNode, pasteModel->detachView(&view); - try { - targetNode.view()->model()->attachView(&view); + view.executeInTransaction("TimelineActions::pasteKeyframesToTarget", [=, &view](){ - RewriterTransaction transaction( - view.beginRewriterTransaction("TimelineActions::pasteKeyframesToTarget")); + + targetNode.view()->model()->attachView(&view); ModelNode nonConstTargetNode = targetNode; nonConstTargetNode.validId(); @@ -144,11 +130,7 @@ void TimelineActions::pasteKeyframesToTarget(const ModelNode &targetNode, timeline.modelNode().defaultNodeListProperty().reparentHere(newNode); } } - - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } } @@ -296,9 +278,7 @@ void TimelineActions::pasteKeyframes(AbstractView *timelineView, const QmlTimeli ModelNode rootNode = view.rootModelNode(); - try { - RewriterTransaction transaction( - timelineView->beginRewriterTransaction("TimelineActions::pasteKeyframes")); + timelineView->executeInTransaction("TimelineActions::pasteKeyframes", [=](){ if (isKeyframe(rootNode)) pasteKeyframe(currentTime, rootNode, timelineView, timeline); else @@ -308,10 +288,7 @@ void TimelineActions::pasteKeyframes(AbstractView *timelineView, const QmlTimeli timelineView, timeline); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } bool TimelineActions::clipboardContainsKeyframes() diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinegraphicsscene.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinegraphicsscene.cpp index eb09492397b..99cc4867101 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinegraphicsscene.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinegraphicsscene.cpp @@ -663,26 +663,16 @@ void TimelineGraphicsScene::deleteKeyframeGroup(const ModelNode &group) if (!QmlTimelineKeyframeGroup::isValidQmlTimelineKeyframeGroup(group)) return; - ModelNode nonConst = group; - - try { - RewriterTransaction transaction(timelineView()->beginRewriterTransaction( - "TimelineGraphicsScene::handleKeyframeGroupDeletion")); - + timelineView()->executeInTransaction("TimelineGraphicsScene::handleKeyframeGroupDeletion", [group](){ + ModelNode nonConst = group; nonConst.destroy(); + }); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } } void TimelineGraphicsScene::deleteKeyframes(const QList &frames) { - try { - RewriterTransaction transaction(timelineView()->beginRewriterTransaction( - "TimelineGraphicsScene::handleKeyframeDeletion")); - + timelineView()->executeInTransaction("TimelineGraphicsScene::handleKeyframeDeletion", [frames](){ for (auto keyframe : frames) { if (keyframe.isValid()) { ModelNode frame = keyframe; @@ -692,10 +682,7 @@ void TimelineGraphicsScene::deleteKeyframes(const QList &frames) parent.destroy(); } } - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } void TimelineGraphicsScene::activateLayout() diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinemovetool.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinemovetool.cpp index 49d35b781b9..0384d7c0a31 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinemovetool.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinemovetool.cpp @@ -136,15 +136,12 @@ void TimelineMoveTool::mouseReleaseEvent(TimelineMovableAbstractItem *item, } } - try { - RewriterTransaction transaction(scene()->timelineView()->beginRewriterTransaction( - "TimelineMoveTool::mouseReleaseEvent")); - + scene()->timelineView()->executeInTransaction("TimelineMoveTool::mouseReleaseEvent", [this, current](){ current->commitPosition(mapToItem(current, current->rect().center())); if (current->asTimelineKeyframeItem()) { double frame = std::round( - current->mapFromSceneToFrame(current->rect().center().x())); + current->mapFromSceneToFrame(current->rect().center().x())); scene()->statusBarMessageChanged(QObject::tr("Frame %1").arg(frame)); @@ -152,12 +149,7 @@ void TimelineMoveTool::mouseReleaseEvent(TimelineMovableAbstractItem *item, if (keyframe != current) keyframe->commitPosition(mapToItem(current, keyframe->rect().center())); } - - transaction.commit(); - - } catch (const Exception &e) { - e.showException(); - } + }); } } diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinepropertyitem.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinepropertyitem.cpp index d0b89dfef4d..beeca23183b 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinepropertyitem.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinepropertyitem.cpp @@ -534,15 +534,9 @@ void TimelineKeyframeItem::commitPosition(const QPointF &point) blockUpdates(); - try { - RewriterTransaction transaction( - m_frame.view()->beginRewriterTransaction("TimelineKeyframeItem::commitPosition")); - + m_frame.view()->executeInTransaction("TimelineKeyframeItem::commitPosition", [this, frame](){ m_frame.variantProperty("frame").setValue(frame); - transaction.commit(); - } catch (const RewritingException &e) { - e.showException(); - } + }); enableUpdates(); } diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesectionitem.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesectionitem.cpp index 32012dd145c..7bd784a7dd8 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesectionitem.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesectionitem.cpp @@ -821,20 +821,15 @@ void TimelineBarItem::commitPosition(const QPointF & /*point*/) { if (sectionItem()->view()) { if (m_handle != Location::Undefined) { - qreal scaleFactor = rect().width() / m_oldRect.width(); + sectionItem()->view()->executeInTransaction("TimelineBarItem::commitPosition", [this](){ + qreal scaleFactor = rect().width() / m_oldRect.width(); - qreal moved = (rect().topLeft().x() - m_oldRect.topLeft().x()) / rulerScaling(); - qreal supposedFirstFrame = qRound(sectionItem()->firstFrame() + moved); + qreal moved = (rect().topLeft().x() - m_oldRect.topLeft().x()) / rulerScaling(); + qreal supposedFirstFrame = qRound(sectionItem()->firstFrame() + moved); - try { - RewriterTransaction transaction(sectionItem()->view()->beginRewriterTransaction( - "TimelineBarItem::commitPosition")); sectionItem()->scaleAllFrames(scaleFactor); sectionItem()->moveAllFrames(supposedFirstFrame - sectionItem()->firstFrame()); - transaction.commit(); - } catch (const RewritingException &e) { - e.showException(); - } + }); } } diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesettingsmodel.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesettingsmodel.cpp index 47426d97551..f75d1299839 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesettingsmodel.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelinesettingsmodel.cpp @@ -266,15 +266,13 @@ ModelNode TimelineSettingsModel::animationForTimelineAndState(const QmlTimeline void TimelineSettingsModel::updateTimeline(int row) { - QmlModelState modelState(stateForRow(row)); - QmlTimeline timeline(timelineForRow(row)); - ModelNode animation(animationForRow(row)); - QmlTimeline oldTimeline = timelineView()->timelineForState(modelState); - RewriterTransaction transaction = timelineView()->beginRewriterTransaction( - QByteArrayLiteral("TimelineSettingsModel::updateTimeline")); + timelineView()->executeInTransaction("TimelineSettingsModel::updateTimeline", [this, row](){ + QmlModelState modelState(stateForRow(row)); + QmlTimeline timeline(timelineForRow(row)); + ModelNode animation(animationForRow(row)); + QmlTimeline oldTimeline = timelineView()->timelineForState(modelState); - try { if (modelState.isBaseState()) { if (oldTimeline.isValid()) oldTimeline.modelNode().variantProperty("enabled").setValue(false); @@ -301,27 +299,20 @@ void TimelineSettingsModel::updateTimeline(int row) propertyChanges.modelNode().variantProperty("enabled").setValue(true); } } - - } catch (Exception &e) { - m_exceptionError = e.description(); - QTimer::singleShot(200, this, &TimelineSettingsModel::handleException); - } + }); resetRow(row); } void TimelineSettingsModel::updateAnimation(int row) { - QmlModelState modelState(stateForRow(row)); - QmlTimeline timeline(timelineForRow(row)); - ModelNode animation(animationForRow(row)); - QmlTimeline oldTimeline = timelineView()->timelineForState(modelState); - ModelNode oldAnimation = animationForTimelineAndState(oldTimeline, modelState); + timelineView()->executeInTransaction("TimelineSettingsModel::updateAnimation", [this, row](){ + QmlModelState modelState(stateForRow(row)); + QmlTimeline timeline(timelineForRow(row)); + ModelNode animation(animationForRow(row)); + QmlTimeline oldTimeline = timelineView()->timelineForState(modelState); + ModelNode oldAnimation = animationForTimelineAndState(oldTimeline, modelState); - RewriterTransaction transaction = timelineView()->beginRewriterTransaction( - QByteArrayLiteral("TimelineSettingsModel::updateAnimation")); - - try { if (modelState.isBaseState()) { if (oldAnimation.isValid()) oldAnimation.variantProperty("running").setValue(false); @@ -353,27 +344,20 @@ void TimelineSettingsModel::updateAnimation(int row) propertyChanges.modelNode().variantProperty("running").setValue(true); } } - } catch (Exception &e) { - m_exceptionError = e.description(); - QTimer::singleShot(200, this, &TimelineSettingsModel::handleException); - } - + }); resetRow(row); } void TimelineSettingsModel::updateFixedFrameRow(int row) { - QmlModelState modelState(stateForRow(row)); - QmlTimeline timeline(timelineForRow(row)); + timelineView()->executeInTransaction("TimelineSettingsModel::updateFixedFrameRow", [this, row](){ + QmlModelState modelState(stateForRow(row)); + QmlTimeline timeline(timelineForRow(row)); - ModelNode animation = animationForTimelineAndState(timeline, modelState); + ModelNode animation = animationForTimelineAndState(timeline, modelState); - RewriterTransaction transaction = timelineView()->beginRewriterTransaction( - QByteArrayLiteral("TimelineSettingsModel::updateFixedFrameRow")); + int fixedFrame = fixedFrameForRow(row); - int fixedFrame = fixedFrameForRow(row); - - try { if (modelState.isBaseState()) { if (animation.isValid()) animation.variantProperty("running").setValue(false); @@ -390,10 +374,8 @@ void TimelineSettingsModel::updateFixedFrameRow(int row) if (propertyChanges.isValid()) propertyChanges.modelNode().variantProperty("currentFrame").setValue(fixedFrame); } - } catch (Exception &e) { - m_exceptionError = e.description(); - QTimer::singleShot(200, this, &TimelineSettingsModel::handleException); - } + + }); resetRow(row); } diff --git a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineview.cpp b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineview.cpp index 653ed27ba75..f39a17db2ff 100644 --- a/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineview.cpp +++ b/src/plugins/qmldesigner/qmldesignerextension/timelineeditor/timelineview.cpp @@ -264,9 +264,7 @@ const QmlTimeline TimelineView::addNewTimeline() ModelNode timelineNode; - try { - RewriterTransaction transaction(beginRewriterTransaction("TimelineView::addNewTimeline")); - + executeInTransaction("TimelineView::addNewTimeline", [=, &timelineNode](){ bool hasTimelines = getTimelines().isEmpty(); timelineNode = createModelNode(timelineType, @@ -279,10 +277,7 @@ const QmlTimeline TimelineView::addNewTimeline() timelineNode.variantProperty("enabled").setValue(hasTimelines); rootModelNode().defaultNodeListProperty().reparentHere(timelineNode); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); return QmlTimeline(timelineNode); } @@ -300,10 +295,8 @@ ModelNode TimelineView::addAnimation(QmlTimeline timeline) QTC_ASSERT(metaInfo.isValid(), return ModelNode()); ModelNode animationNode; - try { - RewriterTransaction transaction( - beginRewriterTransaction("TimelineSettingsDialog::addAnimation")); + executeInTransaction("TimelineView::addAnimation", [=, &animationNode](){ animationNode = createModelNode(animationType, metaInfo.majorVersion(), metaInfo.minorVersion()); @@ -321,10 +314,7 @@ ModelNode TimelineView::addAnimation(QmlTimeline timeline) if (timeline.modelNode().hasProperty("currentFrame")) timeline.modelNode().removeProperty("currentFrame"); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); return animationNode; } @@ -390,28 +380,23 @@ void TimelineView::insertKeyframe(const ModelNode &target, const PropertyName &p QmlTimeline timeline = widget()->graphicsScene()->currentTimeline(); ModelNode targetNode = target; if (timeline.isValid() && targetNode.isValid() - && QmlObjectNode::isValidQmlObjectNode(targetNode)) { - try { - RewriterTransaction transaction( - beginRewriterTransaction("TimelineView::insertKeyframe")); + && QmlObjectNode::isValidQmlObjectNode(targetNode)) { + executeInTransaction("TimelineView::insertKeyframe", [=, &timeline, &targetNode](){ targetNode.validId(); QmlTimelineKeyframeGroup timelineFrames( - timeline.keyframeGroup(targetNode, propertyName)); + timeline.keyframeGroup(targetNode, propertyName)); QTC_ASSERT(timelineFrames.isValid(), return ); const qreal frame - = timeline.modelNode().auxiliaryData("currentFrame@NodeInstance").toReal(); + = timeline.modelNode().auxiliaryData("currentFrame@NodeInstance").toReal(); const QVariant value = QmlObjectNode(targetNode).instanceValue(propertyName); timelineFrames.setValue(value, frame); - transaction.commit(); - } catch (const Exception &e) { - e.showException(); - } + }); } }