Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeStrokeCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
4 * SPDX-FileCopyrightText: 2006-2008 Jan Hambrecht <jaham@gmx.net>
5 * SPDX-FileCopyrightText: 2012 Inge Wallin <inge@lysator.liu.se>
6 *
7 * SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9
11#include "KoShape.h"
12#include "KoShapeStrokeModel.h"
14
15#include <klocalizedstring.h>
16
17#include "kis_command_ids.h"
18
19
20class Q_DECL_HIDDEN KoShapeStrokeCommand::Private
21{
22public:
25 {
26 }
27
29 {
30 oldStrokes.append(oldStroke);
31 }
32
34 {
35 newStrokes.append(newStroke);
36 }
37
41};
42
44 : KUndo2Command(parent)
45 , d(new Private())
46{
47 d->shapes = shapes;
48
49 // save old strokes
50 Q_FOREACH (KoShape *shape, d->shapes) {
51 d->addOldStroke(shape->stroke());
52 d->addNewStroke(stroke);
53 }
54
55 setText(kundo2_i18n("Set stroke"));
56}
57
59 const QList<KoShapeStrokeModelSP> &strokes,
60 KUndo2Command *parent)
61 : KUndo2Command(parent)
62 , d(new Private())
63{
64 Q_ASSERT(shapes.count() == strokes.count());
65
66 d->shapes = shapes;
67
68 // save old strokes
69 Q_FOREACH (KoShape *shape, shapes)
70 d->addOldStroke(shape->stroke());
71 foreach (KoShapeStrokeModelSP stroke, strokes)
72 d->addNewStroke(stroke);
73
74 setText(kundo2_i18n("Set stroke"));
75}
76
78 : KUndo2Command(parent)
79 , d(new Private())
80{
81 d->shapes.append(shape);
82 d->addNewStroke(stroke);
83 d->addOldStroke(shape->stroke());
84
85 setText(kundo2_i18n("Set stroke"));
86}
87
92
94{
96
97 KoShapeBulkActionLock lock(d->shapes);
98
99 QList<KoShapeStrokeModelSP>::iterator strokeIt = d->newStrokes.begin();
100 Q_FOREACH (KoShape *shape, d->shapes) {
101 shape->setStroke(*strokeIt);
102 ++strokeIt;
103 }
104
106}
107
109{
111
112 KoShapeBulkActionLock lock(d->shapes);
113
114 QList<KoShapeStrokeModelSP>::iterator strokeIt = d->oldStrokes.begin();
115 Q_FOREACH (KoShape *shape, d->shapes) {
116 shape->setStroke(*strokeIt);
117 ++strokeIt;
118 }
119
121}
122
127
129{
130 const KoShapeStrokeCommand *other = dynamic_cast<const KoShapeStrokeCommand*>(command);
131
132 if (!other ||
133 other->d->shapes != d->shapes) {
134
135 return false;
136 }
137
138 d->newStrokes = other->d->newStrokes;
139 return true;
140}
virtual void undo()
void setText(const KUndo2MagicString &text)
virtual void redo()
static void bulkShapesUpdate(const UpdatesList &updates)
The undo / redo command for setting the shape stroke.
QList< KoShapeStrokeModelSP > newStrokes
the new strokes to set
void undo() override
revert the actions done in redo
void addOldStroke(KoShapeStrokeModelSP oldStroke)
void redo() override
redo the command
QList< KoShape * > shapes
the shapes to set stroke for
void addNewStroke(KoShapeStrokeModelSP newStroke)
KoShapeStrokeCommand(const QList< KoShape * > &shapes, KoShapeStrokeModelSP stroke, KUndo2Command *parent=0)
QList< KoShapeStrokeModelSP > oldStrokes
the old strokes, one for each shape
bool mergeWith(const KUndo2Command *command) override
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:890
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:904
KUndo2MagicString kundo2_i18n(const char *text)