From 367cf3247151c65bf98b6f0b9f0fd3ba2d9ddfaf Mon Sep 17 00:00:00 2001 From: thomas_lucky13 Date: Thu, 4 Aug 2022 15:07:07 +0400 Subject: [PATCH] erase vector --- src/domain/UBGraphicsScene.cpp | 50 ++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 4b9350e7..49215348 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1043,13 +1043,15 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) typedef QList POLYGONSLIST; QList intersectedPolygons; + QList intersectedVectorItems; + #pragma omp parallel for for(int i=0; i(collidItems[i]); - if(pi == NULL) - continue; - + UBGraphicsVectorItem *vi = qgraphicsitem_cast(collidItems[i]); + if(pi != NULL) + { QPainterPath itemPainterPath; itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon())); @@ -1072,6 +1074,23 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted()); } } + } else if (vi != NULL) + { + QPainterPath itemPainterPath; + QList linePoints = vi->linePoints(); + for (int i=0; i < linePoints.count(); ++i) + { + itemPainterPath.addEllipse(linePoints[i], 1, 1); + } + if (eraserPath.contains(itemPainterPath) || eraserPath.intersects(itemPainterPath)) + { + #pragma omp critical + { + // Compete remove item + intersectedVectorItems << vi; + } + } + } } for(int i=0; isetTransform(t); } - if (!intersectedItems.empty()) + for (int i=0; isetTransform(t); + } + } + + if (!intersectedItems.empty() || !intersectedVectorItems.empty()) setModified(true); } @@ -1539,7 +1572,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) ? qgraphicsitem_cast(item->parentItem()) : 0; UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); - if (!curDelegate) { + if (!curDelegate && item->type() != UBGraphicsVectorItem::Type) { continue; } @@ -1547,6 +1580,12 @@ void UBGraphicsScene::clearContent(clearCase pCase) bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; bool shouldDelete = false; + if(item->type()==UBGraphicsVectorItem::Type) + { + removedItems << item; + this->removeItem(item); + } else + { switch (static_cast(pCase)) { case clearAnnotations : shouldDelete = isStrokesGroup; @@ -1558,6 +1597,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) shouldDelete = !isGroup && !isBackgroundObject(item); break; } + } if(shouldDelete) { if (itemGroup) {