Fix undo/redo messing up item transforms

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.
preferencesAboutTextFull
Craig Watson 8 years ago
parent 7346bb8182
commit 3a3a936916
  1. 43
      src/domain/UBGraphicsItemUndoCommand.cpp

@ -98,7 +98,28 @@ void UBGraphicsItemUndoCommand::undo()
UBApplication::boardController->freezeW3CWidget(item, true); UBApplication::boardController->freezeW3CWidget(item, true);
item->setSelected(false); item->setSelected(false);
QTransform t;
bool bApplyTransform = false;
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(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); mScene->removeItem(item);
if (bApplyTransform)
polygonItem->setTransform(t);
} }
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems); QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
@ -207,7 +228,29 @@ void UBGraphicsItemUndoCommand::redo()
{ {
QGraphicsItem* item = itRemoved.next(); QGraphicsItem* item = itRemoved.next();
item->setSelected(false); item->setSelected(false);
QTransform t;
bool bApplyTransform = false;
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(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); mScene->removeItem(item);
if (bApplyTransform)
item->setTransform(t);
UBApplication::boardController->freezeW3CWidget(item, true); UBApplication::boardController->freezeW3CWidget(item, true);
} }

Loading…
Cancel
Save