Skip to content

armgit / krita

Public Imported from GitHub
0

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 the crash when trying to add a shape to a vector layer

Dmitry Kazakovce382c8dc11e
diff --git a/libs/flake/KoShapeController.cpp b/libs/flake/KoShapeController.cpp
index 878572a67d..3e72cfbaad 100644
--- a/libs/flake/KoShapeController.cpp
+++ b/libs/flake/KoShapeController.cpp
@@ -39,7 +39,7 @@ public:
KoCanvasBase *canvas;
KoShapeControllerBase *shapeController;
- KUndo2Command* addShape(KoShape *shape, bool showDialog, KoShapeContainer **parentShape, KUndo2Command *parent) {
+ KUndo2Command* addShape(KoShape *shape, bool showDialog, KoShapeContainer *parentShape, KUndo2Command *parent) {
if (canvas) {
if (showDialog && !shape->shapeId().isEmpty()) {
@@ -87,17 +87,17 @@ public:
return addShapesDirect({shape}, parentShape, parent);
}
- KUndo2Command* addShapesDirect(const QList<KoShape*> shapes, KoShapeContainer **parentShape, KUndo2Command *parent)
+ KUndo2Command* addShapesDirect(const QList<KoShape*> shapes, KoShapeContainer *parentShape, KUndo2Command *parent)
{
KUndo2Command *resultCommand = 0;
- if (!*parentShape) {
+ if (!parentShape) {
resultCommand = new KUndo2Command(parent);
- *parentShape = shapeController->createParentForShapes(shapes, false, resultCommand);
- KUndo2Command *addShapeCommand = new KoShapeCreateCommand(shapeController, shapes, *parentShape, resultCommand);
+ parentShape = shapeController->createParentForShapes(shapes, false, resultCommand);
+ KUndo2Command *addShapeCommand = new KoShapeCreateCommand(shapeController, shapes, parentShape, resultCommand);
resultCommand->setText(addShapeCommand->text());
} else {
- resultCommand = new KoShapeCreateCommand(shapeController, shapes, *parentShape, parent);
+ resultCommand = new KoShapeCreateCommand(shapeController, shapes, parentShape, parent);
}
return resultCommand;
@@ -122,19 +122,19 @@ void KoShapeController::reset()
d->shapeController = 0;
}
-KUndo2Command* KoShapeController::addShape(KoShape *shape, KoShapeContainer **parentShape, KUndo2Command *parent)
+KUndo2Command* KoShapeController::addShape(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent)
{
return d->addShape(shape, true, parentShape, parent);
}
-KUndo2Command* KoShapeController::addShapeDirect(KoShape *shape, KoShapeContainer **parentShape, KUndo2Command *parent)
+KUndo2Command* KoShapeController::addShapeDirect(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent)
{
return d->addShapesDirect({shape}, parentShape, parent);
}
KUndo2Command *KoShapeController::addShapesDirect(const QList<KoShape *> shapes, KoShapeContainer *parentShape, KUndo2Command *parent)
{
- return d->addShapesDirect(shapes, &parentShape, parent);
+ return d->addShapesDirect(shapes, parentShape, parent);
}
KUndo2Command* KoShapeController::removeShape(KoShape *shape, KUndo2Command *parent)
diff --git a/libs/flake/KoShapeController.h b/libs/flake/KoShapeController.h
index 96d88a3b03..d44271e24b 100644
--- a/libs/flake/KoShapeController.h
+++ b/libs/flake/KoShapeController.h
@@ -62,7 +62,7 @@ public:
* @return command which will insert the shape into the document or 0 if the
* insertion was cancelled. The command is not yet executed.
*/
- KUndo2Command* addShape(KoShape *shape, KoShapeContainer **parentShape, KUndo2Command *parent = 0);
+ KUndo2Command* addShape(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent = 0);
/**
* @brief Add a shape to the document, skipping any dialogs or other user interaction.
@@ -73,7 +73,7 @@ public:
*
* @return command which will insert the shape into the document. The command is not yet executed.
*/
- KUndo2Command* addShapeDirect(KoShape *shape, KoShapeContainer **parentShape, KUndo2Command *parent = 0);
+ KUndo2Command* addShapeDirect(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent = 0);
/**
* @brief Add shapes to the document, skipping any dialogs or other user interaction.
diff --git a/libs/flake/tests/TestShapePainting.cpp b/libs/flake/tests/TestShapePainting.cpp
index 5e51eb2ac3..b58adc7405 100644
--- a/libs/flake/tests/TestShapePainting.cpp
+++ b/libs/flake/tests/TestShapePainting.cpp
@@ -268,10 +268,7 @@ void TestShapePainting::testGroupUngroup()
group->setName("group");
KUndo2Command groupingCommand;
-
- KoShapeContainer* parent = shapesFakeLayer.data();
- canvas.shapeController()->addShapeDirect(group, &parent, &groupingCommand);
-
+ canvas.shapeController()->addShapeDirect(group, shapesFakeLayer.data(), &groupingCommand);
new KoShapeGroupCommand(group, groupedShapes, true, &groupingCommand);
groupingCommand.redo();
diff --git a/libs/flake/tools/KoPathTool.cpp b/libs/flake/tools/KoPathTool.cpp
index e5efef92ca..a393c0400a 100644
--- a/libs/flake/tools/KoPathTool.cpp
+++ b/libs/flake/tools/KoPathTool.cpp
@@ -323,7 +323,7 @@ void KoPathTool::convertToPath()
KoShape *outlineShape = shape->textOutline();
KoShapeContainer *parent = shape->parent();
- canvas()->shapeController()->addShapeDirect(outlineShape, &parent, cmd);
+ canvas()->shapeController()->addShapeDirect(outlineShape, parent, cmd);
newSelectedShapes << outlineShape;
}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index f2a737bdd1..251f97716c 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -1808,7 +1808,7 @@ void DefaultTool::selectionBooleanOp(int booleanOp)
newShape->setZIndex(referenceShape->zIndex());
KoShapeContainer *parent = referenceShape->parent();
- canvas()->shapeController()->addShapeDirect(newShape, &parent, cmd);
+ canvas()->shapeController()->addShapeDirect(newShape, parent, cmd);
newSelectedShapes << newShape;
}
diff --git a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
index ba4bbcebef..61208f2319 100644
--- a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
+++ b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
@@ -14,6 +14,7 @@
#include "KoProperties.h"
#include "KoSelection.h"
#include "KoShapeController.h"
+#include "KoShapeControllerBase.h"
#include "KoShapeFactoryBase.h"
#include "KoShapeRegistry.h"
#include "KoToolBase.h"
@@ -155,11 +156,9 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()
KUndo2Command *parentCommand = new KUndo2Command();
new KoKeepShapesSelectedCommand(tool->koSelection()->selectedShapes(), {}, tool->canvas()->selectedShapesProxy(), false, parentCommand);
- KoShapeContainer* parent = nullptr;
- KUndo2Command *cmd = tool->canvas()->shapeController()->addShape(textShape, &parent, parentCommand);
-
- KisShapeLayer *layer = dynamic_cast<KisShapeLayer *>(parent);
+ KoShapeContainer* parent = tool->canvas()->shapeController()->documentBase()->createParentForShapes({textShape}, false, parentCommand);
+ KUndo2Command *cmd = tool->canvas()->shapeController()->addShape(textShape, parent, parentCommand);
parentCommand->setText(cmd->text());
@@ -192,7 +191,17 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()
}
}
- new KoKeepShapesSelectedCommand({}, {textShape}, layer->selectedShapesProxy(), true, parentCommand);
+ {
+ KoSelectedShapesProxy *finalSelectionProxy = tool->canvas()->selectedShapesProxy();
+ if (parent) {
+ KisShapeLayer *layer = dynamic_cast<KisShapeLayer *>(parent);
+ if (layer) {
+ finalSelectionProxy = layer->selectedShapesProxy();
+ }
+ }
+ new KoKeepShapesSelectedCommand({}, {textShape}, finalSelectionProxy, true, parentCommand);
+ }
+
tool->canvas()->snapGuide()->reset();
return parentCommand;
diff --git a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
index 35046733e5..7946373e0f 100644
--- a/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
+++ b/plugins/tools/tool_knife/CutThroughShapeStrategy.cpp
@@ -294,7 +294,7 @@ void CutThroughShapeStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
newSelectedShapes << shape.data();
}
- tool()->canvas()->shapeController()->addShapeDirect(shape.take(), &parent, cmd.data());
+ tool()->canvas()->shapeController()->addShapeDirect(shape.take(), parent, cmd.data());
}
diff --git a/plugins/tools/tool_knife/RemoveGutterStrategy.cpp b/plugins/tools/tool_knife/RemoveGutterStrategy.cpp
index 20ba3b34ce..c37c2b27e8 100644
--- a/plugins/tools/tool_knife/RemoveGutterStrategy.cpp
+++ b/plugins/tools/tool_knife/RemoveGutterStrategy.cpp
@@ -295,7 +295,7 @@ void RemoveGutterStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
KoShapeContainer *parent = referenceShape->parent();
- tool()->canvas()->shapeController()->addShapeDirect(resultShape, &parent, cmd);
+ tool()->canvas()->shapeController()->addShapeDirect(resultShape, parent, cmd);
if (isSelected[shapeOrigIndexes[0]] || isSelected[shapeOrigIndexes[1]]) { // if either is selected
resultSelectedShapes << resultShape;