From 0379f4394d0eba92ae795ad00b49893ba1af5bea Mon Sep 17 00:00:00 2001 From: Didier Clerc Date: Mon, 29 Jul 2013 14:21:13 +0900 Subject: [PATCH] Fixed an issue with backspace on group items --- src/domain/UBGraphicsScene.cpp | 57 ++++++++++++++++++++++++++++++---- src/domain/UBGraphicsScene.h | 1 + 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index dc008a6b..fca39c3a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -2324,6 +2324,11 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) if (keyEvent->matches(QKeySequence::Delete)) #endif { + QVector ubItemsToRemove; + QVector itemToRemove; + + bool bRemoveOk = true; + foreach(QGraphicsItem* item, si) { switch (item->type()) @@ -2333,28 +2338,52 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) UBGraphicsW3CWidgetItem *wc3_widget = dynamic_cast(item); if (0 != wc3_widget) if (!wc3_widget->hasFocus()) - wc3_widget->remove(); + ubItemsToRemove << wc3_widget; break; } case UBGraphicsTextItem::Type: { UBGraphicsTextItem *text_item = dynamic_cast(item); - if (0 != text_item) - if (!text_item->hasFocus()) - text_item->remove(); + if (0 != text_item){ + if (!text_item->hasFocus()) + ubItemsToRemove << text_item; + else + bRemoveOk = false; + } break; } + case UBGraphicsGroupContainerItem::Type: + { + UBGraphicsGroupContainerItem* group_item = dynamic_cast(item); + if(NULL != group_item){ + if(!hasTextItemWithFocus(group_item)) + ubItemsToRemove << group_item; + else + bRemoveOk = false; + } + break; + } + default: { UBGraphicsItem *ubgi = dynamic_cast(item); if (0 != ubgi) - ubgi->remove(); + ubItemsToRemove << ubgi; else - UBCoreGraphicsScene::removeItem(item); + itemToRemove << item; } } } + + if(bRemoveOk){ + foreach(UBGraphicsItem* pUBItem, ubItemsToRemove){ + pUBItem->remove(); + } + foreach(QGraphicsItem* pItem, itemToRemove){ + UBCoreGraphicsScene::removeItem(pItem); + } + } } keyEvent->accept(); @@ -2363,6 +2392,22 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) QGraphicsScene::keyReleaseEvent(keyEvent); } +bool UBGraphicsScene::hasTextItemWithFocus(UBGraphicsGroupContainerItem *item){ + bool bHasFocus = false; + + foreach(QGraphicsItem* pItem, item->childItems()){ + UBGraphicsTextItem *text_item = dynamic_cast(pItem); + if (NULL != text_item){ + if(text_item->hasFocus()){ + bHasFocus = true; + break; + } + } + } + + return bHasFocus; +} + void UBGraphicsScene::setDocumentUpdated() { if (document()) diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 3d437bda..19db8218 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -374,6 +374,7 @@ public slots: void setDocumentUpdated(); void createEraiser(); void createPointer(); + bool hasTextItemWithFocus(UBGraphicsGroupContainerItem* item); QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mPointer;