Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix empty paths and slowness in Knife Tool
Agata Cacko32aa0ba55a39
diff --git a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp b/plugins/tools/tool_knife/CutThroughShapeStrategy.cppindex 6992aa881b..ed879d7cb6 100644--- a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp+++ b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp@@ -164,31 +164,31 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)for (int i = 0; i < srcOutlines.size(); i++) {QPainterPath leftPath = srcOutlines[i] & left;QPainterPath rightPath = srcOutlines[i] & right;+ bool nonEmptyShapeExists = false;- // there is a bug in Qt, sometimes it leaves the resulting- // outline open, so just close it explicitly.+ QList<QPainterPath> paths;+ paths << leftPath << rightPath;- leftPath.closeSubpath();- rightPath.closeSubpath();-- leftPath = booleanWorkaroundTransform.inverted().map(leftPath);- rightPath = booleanWorkaroundTransform.inverted().map(rightPath);-- //qCritical() << "Path 1 = " << leftPath << leftPath.length();- //qCritical() << "Path 2 = " << rightPath << rightPath.length();+ KoShape* referenceShape = m_selectedShapes[i];+ Q_FOREACH(QPainterPath path, paths) {+ if (path.isEmpty()) {+ continue;+ }- KoPathShape* leftShape = KoPathShape::createShapeFromPainterPath(leftPath);- KoPathShape* rightShape = KoPathShape::createShapeFromPainterPath(rightPath);+ // comment copied from another place:+ // there is a bug in Qt, sometimes it leaves the resulting+ // outline open, so just close it explicitly.+ path.closeSubpath();+ // this is needed because Qt linearize curves; this allows for a+ // "sane" linearization instead of a very blocky appearance+ path = booleanWorkaroundTransform.inverted().map(path);+ KoPathShape* shape = KoPathShape::createShapeFromPainterPath(path);- if (!leftPath.isEmpty() || !rightPath.isEmpty()) {- shapesToRemove << m_selectedShapes[i];- }+ if (shape->boundingRect().isEmpty()) {+ continue;+ }- QList<KoPathShape*> shapes;- shapes << leftShape << rightShape;- KoShape* referenceShape = m_selectedShapes[i];- Q_FOREACH(KoShape* shape, shapes) {shape->setBackground(referenceShape->background());shape->setStroke(referenceShape->stroke());shape->setZIndex(referenceShape->zIndex());@@ -197,9 +197,14 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)tool()->canvas()->shapeController()->addShapeDirect(shape, parent, cmd);newSelectedShapes << shape;+ nonEmptyShapeExists = true;}+ if (nonEmptyShapeExists) {+ shapesToRemove << m_selectedShapes[i];+ }+}tool()->canvas()->shapeController()->removeShapes(shapesToRemove, cmd);@@ -210,12 +215,6 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)------}void CutThroughShapeStrategy::paint(QPainter &painter, const KoViewConverter &converter)