From 8b19847c1121b9ca8f93259b0b6c7d2067a0d91e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 31 Aug 2012 12:18:50 +0300 Subject: [PATCH] Fixed deletion removed groups. Code was cleaned. Corrections in removing strokes. --- src/board/UBBoardController.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 4 ---- src/domain/UBGraphicsPolygonItem.cpp | 4 ++-- src/domain/UBGraphicsScene.cpp | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 891591d7..3c56d617 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1495,7 +1495,7 @@ void UBBoardController::ClearUndoStack() while (itRemoved.hasNext()) { QGraphicsItem* item = itRemoved.next(); - if( !uniqueItems.contains(item) && (item->parentItem() && UBGraphicsGroupContainerItem::Type != item->parentItem()->type())) + if( !uniqueItems.contains(item) && !(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type())) uniqueItems.insert(item); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 1c63d004..b3e9dec8 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -219,10 +219,6 @@ void UBGraphicsGroupContainerItem::destroy() { UBCoreGraphicsScene *groupScene = corescene(); - if (groupScene) { - // groupScene->addItemToDeletion(this); - } - foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); item->setFlag(QGraphicsItem::ItemIsSelectable, true); diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 8e0e6f85..b21f2760 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -67,8 +67,8 @@ void UBGraphicsPolygonItem::clearStroke() if (mStroke!=NULL) { mStroke->remove(this); - //if (mStroke->polygons().empty()) - // delete mStroke; + if (mStroke->polygons().empty()) + delete mStroke; mStroke = NULL; } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f5463574..a982a2d1 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -305,7 +305,10 @@ UBGraphicsScene::~UBGraphicsScene() { if (mCurrentStroke) if (mCurrentStroke->polygons().empty()) + { delete mCurrentStroke; + mCurrentStroke = NULL; + } if (mZLayerController) delete mZLayerController; @@ -433,6 +436,11 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre } } + if (mCurrentStroke && mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + mCurrentStroke = NULL; + } + return accepted; } @@ -474,6 +482,10 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon); mAddedItems.remove(mpLastPolygon); mCurrentStroke->remove(mpLastPolygon); + if (mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + mCurrentStroke = NULL; + } removeItem(mpLastPolygon); mPreviousPolygonItems.removeAll(mpLastPolygon); } @@ -2285,6 +2297,11 @@ void UBGraphicsScene::setToolCursor(int tool) { deselectAllItems(); } + + if (mCurrentStroke && mCurrentStroke->polygons().empty()){ + delete mCurrentStroke; + } + mCurrentStroke = NULL; } void UBGraphicsScene::initStroke(){