From 3a3a936916d3989d362b683f19785e1a70fa5e26 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sat, 11 Mar 2017 16:11:10 -0500 Subject: [PATCH] Fix undo/redo messing up item transforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This code was lifted from Open-Sankoré 2.10. This fixes an issue where erasing part of a stroke that had been moved or rotated, then clicking "undo" then "redo" would place part of the stroke in the wrong place. --- src/domain/UBGraphicsItemUndoCommand.cpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index ee23a7bb..aae00f2b 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -98,7 +98,28 @@ void UBGraphicsItemUndoCommand::undo() UBApplication::boardController->freezeW3CWidget(item, true); item->setSelected(false); + + QTransform t; + bool bApplyTransform = false; + UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast(item); + if (polygonItem){ + if (polygonItem->strokesGroup() + && polygonItem->strokesGroup()->parentItem() + && UBGraphicsGroupContainerItem::Type == polygonItem->strokesGroup()->parentItem()->type()) + { + bApplyTransform = true; + t = polygonItem->sceneTransform(); + } + else if (polygonItem->strokesGroup()) + polygonItem->resetTransform(); + + polygonItem->strokesGroup()->removeFromGroup(polygonItem); + } mScene->removeItem(item); + + if (bApplyTransform) + polygonItem->setTransform(t); + } QSetIterator itRemoved(mRemovedItems); @@ -207,7 +228,29 @@ void UBGraphicsItemUndoCommand::redo() { QGraphicsItem* item = itRemoved.next(); item->setSelected(false); + + QTransform t; + bool bApplyTransform = false; + UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast(item); + + if (polygonItem){ + if(polygonItem->strokesGroup() + && polygonItem->strokesGroup()->parentItem() + && UBGraphicsGroupContainerItem::Type == polygonItem->strokesGroup()->parentItem()->type()) + { + bApplyTransform = true; + t = polygonItem->sceneTransform(); + } + else if (polygonItem->strokesGroup()) + polygonItem->resetTransform(); + + polygonItem->strokesGroup()->removeFromGroup(polygonItem); + } mScene->removeItem(item); + + if (bApplyTransform) + item->setTransform(t); + UBApplication::boardController->freezeW3CWidget(item, true); }