Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeCreateCommand.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 "KoShape.h"
10#include "KoShapeContainer.h"
12
13#include <klocalizedstring.h>
14
15#include "kis_assert.h"
16#include <KoShapeLayer.h>
18
19#include <vector>
20#include <memory>
21
22#include <kis_undo_stores.h>
24
25class Q_DECL_HIDDEN KoShapeCreateCommand::Private
26{
27public:
28 Private(KoShapeControllerBase *_document, const QList<KoShape*> &_shapes, KoShapeContainer *_parentShape)
29 : shapesDocument(_document),
30 shapes(_shapes),
31 explicitParentShape(_parentShape)
32 {
33 }
34
38
40 bool firstRedo = true;
41
42};
43
45 : KoShapeCreateCommand(controller, QList<KoShape *>() << shape, parentShape, parent)
46{
47}
48
50 : KoShapeCreateCommand(controller, shapes, parentShape, parent, kundo2_i18np("Create shape", "Create %1 shapes", shapes.size()))
51{
52}
53
55 : KUndo2Command(undoString, parent)
56 , d(new Private(controller, shapes, parentShape))
57{
58}
59
64
66{
68 KIS_SAFE_ASSERT_RECOVER_RETURN(d->explicitParentShape);
69
70 if (d->firstRedo) {
71 Q_FOREACH(KoShape *shape, d->shapes) {
72
73 d->undoStore.addCommand(new KoAddShapeCommand(shape, d->explicitParentShape));
74
75 KoShapeContainer *shapeParent = shape->parent();
77 dynamic_cast<KoShapeLayer*>(shape));
78
79 if (shapeParent) {
80 d->undoStore.addCommand(KoShapeReorderCommand::mergeInShape(shapeParent->shapes(), shape));
81 }
82 }
83 d->firstRedo = false;
84 } else {
85 d->undoStore.redoAll();
86 }
87}
88
90{
91 d->undoStore.undoAll();
93}
virtual void undo()
virtual void redo()
QList< KoShape * > shapes() const
The undo / redo command for creating shapes.
Private(KoShapeControllerBase *_document, const QList< KoShape * > &_shapes, KoShapeContainer *_parentShape)
void undo() override
revert the actions done in redo
KoShapeCreateCommand(KoShapeControllerBase *controller, KoShape *shape, KoShapeContainer *parentShape=0, KUndo2Command *parent=0)
KoShapeContainer * explicitParentShape
void redo() override
redo the command
KisSurrogateUndoStore undoStore
KoShapeControllerBase * shapesDocument
static KoShapeReorderCommand * mergeInShape(QList< KoShape * > shapes, KoShape *newShape, KUndo2Command *parent=0)
mergeInShape adjust zIndex of all the shapes and newShape to avoid collisions between shapes and newS...
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
KUndo2MagicString kundo2_i18np(const char *sing, const char *plur, const A1 &a1)