Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeDeleteCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
3 * SPDX-FileCopyrightText: 2006 Jan Hambrecht <jaham@gmx.net>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9#include "KoShapeContainer.h"
11
12#include <klocalizedstring.h>
13
14class Q_DECL_HIDDEN KoShapeDeleteCommand::Private
15{
16public:
18 : controller(c),
19 deleteShapes(false) {
20 }
21
23 if (! deleteShapes)
24 return;
25
26 Q_FOREACH (KoShape *shape, shapes)
27 delete shape;
28 }
29
34};
35
37 : KUndo2Command(parent),
38 d(new Private(controller))
39{
40 d->shapes.append(shape);
41 d->oldParents.append(shape->parent());
42
43 setText(kundo2_i18nc("Delete one shape", "Delete shape"));
44}
45
47 KUndo2Command *parent)
48 : KUndo2Command(parent),
49 d(new Private(controller))
50{
51 d->shapes = shapes;
52 Q_FOREACH (KoShape *shape, d->shapes) {
53 d->oldParents.append(shape->parent());
54 }
55
56 setText(kundo2_i18np("Delete shape", "Delete shapes", shapes.count()));
57}
58
63
65{
67 if (! d->controller)
68 return;
69
70 for (int i = 0; i < d->shapes.count(); i++) {
71 if (d->oldParents.at(i)) {
72 d->oldParents.at(i)->removeShape(d->shapes[i]);
73 }
74 }
75 d->deleteShapes = true;
76}
77
79{
81 if (! d->controller)
82 return;
83
84 for (int i = 0; i < d->shapes.count(); i++) {
85 if (d->oldParents.at(i)) {
86 d->oldParents.at(i)->addShape(d->shapes[i]);
87 }
88 }
89 d->deleteShapes = false;
90}
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
The undo / redo command for deleting shapes.
bool deleteShapes
shows if shapes should be deleted when deleting the command
KoShapeControllerBase * controller
the shape controller to use for removing/readding
Private(KoShapeControllerBase *c)
KoShapeDeleteCommand(KoShapeControllerBase *controller, KoShape *shape, KUndo2Command *parent=0)
QList< KoShape * > shapes
the list of shapes to delete
void undo() override
revert the actions done in redo
void redo() override
redo the command
QList< KoShapeContainer * > oldParents
the old parents of the shapes
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
KUndo2MagicString kundo2_i18nc(const char *ctxt, const char *text)
KUndo2MagicString kundo2_i18np(const char *sing, const char *plur, const A1 &a1)