From 06a5dcafdd7172335ed0cee5365915d8e9a72c41 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Wed, 24 Oct 2012 16:50:08 +0300 Subject: [PATCH] Implemented undo stack for eraser. Implemented undo stack for moved unselected items. --- src/board/UBBoardView.cpp | 10 ++++++ src/domain/UBGraphicsItemUndoCommand.cpp | 12 +++++++ src/domain/UBGraphicsScene.cpp | 41 ++++++++++++------------ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index cfc93094..0ff3c8e1 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -733,7 +733,13 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) else { if (movingItem) + { + UBGraphicsItem *graphicsItem = dynamic_cast(movingItem); + if (graphicsItem) + graphicsItem->Delegate()->startUndoStep(); + movingItem->clearFocus(); + } if (suspendedMousePressEvent) { @@ -1115,6 +1121,10 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) return; } + UBGraphicsItem *graphicsItem = dynamic_cast(movingItem); + if (graphicsItem) + graphicsItem->Delegate()->commitUndoStep(); + bool bReleaseIsNeed = true; if (movingItem != determineItemToPress(scene()->itemAt(this->mapToScene(event->posF().toPoint())))) { diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index be716a5e..5cba966c 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -25,6 +25,7 @@ #include "core/memcheck.h" #include "domain/UBGraphicsGroupContainerItem.h" +#include "domain/UBGraphicsPolygonItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, const QSet& pAddedItems, const GroupDataTable &groupsMap) @@ -107,6 +108,13 @@ void UBGraphicsItemUndoCommand::undo() else mScene->addItem(item); + if (UBGraphicsPolygonItem::Type == item->type()) + { + UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast(item); + if (polygonItem) + polygonItem->strokesGroup()->addToGroup(polygonItem); + } + UBApplication::boardController->freezeW3CWidget(item, false); } } @@ -206,6 +214,10 @@ void UBGraphicsItemUndoCommand::redo() mScene->setAsBackgroundObject(item); else mScene->addItem(item); + + UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast(item); + if (polygonItem) + polygonItem->strokesGroup()->addToGroup(polygonItem); } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 31dc0b96..91d04307 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -629,9 +629,9 @@ bool UBGraphicsScene::inputDeviceRelease() if (mCurrentStroke && mCurrentStroke->polygons().empty()){ delete mCurrentStroke; - mCurrentStroke = NULL; } + mCurrentStroke = NULL; return accepted; } @@ -794,7 +794,7 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) { #pragma omp critical { - // Compele remove item + // Compete remove item intersectedItems << pi; intersectedPolygons << QList(); } @@ -813,30 +813,29 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) for(int i=0; i QPainterPath::toFillPolygons(), + // so each intersectedPolygonItem has one or couple of QPolygons who should be removed from it. for(int j = 0; j < intersectedPolygons[i].size(); j++) { - QPolygonF p = intersectedPolygons[i][j]; - if (j==0) - pi->setPolygon(intersectedPolygons[i][j]); - else - { - UBGraphicsPolygonItem* polygonItem = new UBGraphicsPolygonItem(intersectedPolygons[i][j], pi->parentItem()); - pi->copyItemParameters(polygonItem); - - polygonItem->setStroke(pi->stroke()); - polygonItem->setStrokesGroup(pi->strokesGroup()); - pi->strokesGroup()->addToGroup(polygonItem); - } + // create small polygon from couple of polygons to replace particular erased polygon + UBGraphicsPolygonItem* polygonItem = new UBGraphicsPolygonItem(intersectedPolygons[i][j], intersectedPolygonItem->parentItem()); + + intersectedPolygonItem->copyItemParameters(polygonItem); + polygonItem->setStroke(intersectedPolygonItem->stroke()); + polygonItem->setStrokesGroup(intersectedPolygonItem->strokesGroup()); + intersectedPolygonItem->strokesGroup()->addToGroup(polygonItem); + mAddedItems << polygonItem; } } + + //remove full polygon item for replace it by couple of polygons who creates the same stroke without a part which intersects with eraser + mRemovedItems << intersectedPolygonItem; + removeItem(intersectedPolygonItem); } if (!intersectedItems.empty())