Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPathPointRemoveCommand Class Reference

The undo / redo command for removing path points. More...

#include <KoPathPointRemoveCommand.h>

+ Inheritance diagram for KoPathPointRemoveCommand:

Public Member Functions

 KoPathPointRemoveCommand (const QList< KoPathPointData > &pointDataList, KUndo2Command *parent=0)
 Command to remove a points from path shapes.
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoPathPointRemoveCommand () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual int id () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual bool mergeWith (const KUndo2Command *other)
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Static Public Member Functions

static KUndo2CommandcreateCommand (const QList< KoPathPointData > &pointDataList, KoShapeController *shapeController, KUndo2Command *parent=0)
 Create command for removing points from path shapes.
 

Private Attributes

KoPathPointRemoveCommandPrivated
 

Detailed Description

The undo / redo command for removing path points.

Definition at line 20 of file KoPathPointRemoveCommand.h.

Constructor & Destructor Documentation

◆ KoPathPointRemoveCommand()

KoPathPointRemoveCommand::KoPathPointRemoveCommand ( const QList< KoPathPointData > & pointDataList,
KUndo2Command * parent = 0 )
explicit

Command to remove a points from path shapes.

Don't use this directly use createCommand instead.

Parameters
pointDataListList of point data to remove.
parentthe parent command used for macro commands

Definition at line 106 of file KoPathPointRemoveCommand.cpp.

108 : KUndo2Command(parent),
110{
111 QList<KoPathPointData>::const_iterator it(pointDataList.begin());
112 for (; it != pointDataList.end(); ++it) {
113 KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
114 if (point) {
115 d->pointDataList.append(*it);
116 d->points.append(0);
117 }
118 }
119 std::sort(d->pointDataList.begin(), d->pointDataList.end());
120 setText(kundo2_i18n("Remove points"));
121}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
KoPathPointRemoveCommandPrivate * d
A KoPathPoint represents a point in a path.
KUndo2MagicString kundo2_i18n(const char *text)

References d, kundo2_i18n(), KoPathPointRemoveCommandPrivate::pointDataList, KoPathPointRemoveCommandPrivate::points, and KUndo2Command::setText().

◆ ~KoPathPointRemoveCommand()

KoPathPointRemoveCommand::~KoPathPointRemoveCommand ( )
override

Definition at line 123 of file KoPathPointRemoveCommand.cpp.

124{
125 delete d;
126}

References d.

Member Function Documentation

◆ createCommand()

KUndo2Command * KoPathPointRemoveCommand::createCommand ( const QList< KoPathPointData > & pointDataList,
KoShapeController * shapeController,
KUndo2Command * parent = 0 )
static

Create command for removing points from path shapes.

This will create the command for removing points from path shapes. If all points from a path shape are deleted it will delete the path shape. If all points from a subpath are deleted it will delete the subpath.

Parameters
pointDataListList of point data to remove
shapeControllershape controller in charge
parentthe parent command used for macro commands

Definition at line 27 of file KoPathPointRemoveCommand.cpp.

31{
32 /*
33 * We want to decide if we have to:
34 * 1. delete only some points of a path or
35 * 2. delete one or more complete subpath or
36 * 3. delete a complete path
37 */
38
39 QList<KoPathPointData> sortedPointData(pointDataList);
40 std::sort(sortedPointData.begin(), sortedPointData.end());
41
42 KoPathPointData last(0, KoPathPointIndex(-1, -1));
43 // add last at the end so that the point date before last will also be put in
44 // the right places.
45 sortedPointData.append(last);
46
47 QList<KoPathPointData> pointsOfSubpath; // points of current subpath
48 QList<KoPathPointData> subpathsOfPath; // subpaths of current path
49 QList<KoPathPointData> pointsToDelete; // single points to delete
50 QList<KoPathPointData> subpathToDelete; // single subpaths to delete
51 QList<KoShape*> shapesToDelete; // single paths to delete
52
53 last = sortedPointData.first();
54
55 QList<KoPathPointData>::const_iterator it(sortedPointData.constBegin());
56 for (; it != sortedPointData.constEnd(); ++it) {
57 // check if we have come to the next subpath of the same or another path
58 if (last.pathShape != it->pathShape || last.pointIndex.first != it->pointIndex.first) {
59 // check if all points of the last subpath should be deleted
60 if (last.pathShape->subpathPointCount(last.pointIndex.first) == pointsOfSubpath.size()) {
61 // all points of subpath to be deleted -> mark subpath as to be deleted
62 subpathsOfPath.append(pointsOfSubpath.first());
63 } else {
64 // not all points of subpath to be deleted -> add them to the delete point list
65 pointsToDelete += pointsOfSubpath;
66 }
67 // clear the suboath point list
68 pointsOfSubpath.clear();
69 }
70
71 // check if we have come to the next shape
72 if (last.pathShape != it->pathShape) {
73 // check if all subpath of the shape should be deleted
74 if (last.pathShape->subpathCount() == subpathsOfPath.size()) {
75 // all subpaths of path to be deleted -> add shape to delete shape list
76 shapesToDelete.append(last.pathShape);
77 } else {
78 // not all subpaths of path to be deleted -> add them to delete subpath list
79 subpathToDelete += subpathsOfPath;
80 }
81 subpathsOfPath.clear();
82 }
83 if (! it->pathShape)
84 continue;
85 // keep reference to last point
86 last = *it;
87 // add this point to the current subpath point list
88 pointsOfSubpath.append(*it);
89 }
90
91 KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Remove points"), parent);
92
93 if (pointsToDelete.size() > 0) {
94 new KoPathPointRemoveCommand(pointsToDelete, cmd);
95 }
96 Q_FOREACH (const KoPathPointData & pd, subpathToDelete) {
97 new KoSubpathRemoveCommand(pd.pathShape, pd.pointIndex.first, cmd);
98 }
99 if (shapesToDelete.size() > 0) {
100 shapeController->removeShapes(shapesToDelete, cmd);
101 }
102
103 return cmd;
104}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
KoPathPointRemoveCommand(const QList< KoPathPointData > &pointDataList, KUndo2Command *parent=0)
Command to remove a points from path shapes.
KUndo2Command * removeShapes(const QList< KoShape * > &shapes, KUndo2Command *parent=0)
The undo / redo command for removing a subpath.

References KoPathPointRemoveCommand(), kundo2_i18n(), KUndo2Command::KUndo2Command(), KoPathPointData::pathShape, KoPathPointData::pointIndex, KoShapeController::removeShapes(), KoPathShape::subpathCount(), and KoPathShape::subpathPointCount().

◆ redo()

void KoPathPointRemoveCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 128 of file KoPathPointRemoveCommand.cpp.

129{
131 KoPathShape * lastPathShape = 0;
132 int updateBefore = d->pointDataList.size();
133 for (int i = d->pointDataList.size() - 1; i >= 0; --i) {
134 const KoPathPointData &pd = d->pointDataList.at(i);
135 pd.pathShape->update();
137
138 if (lastPathShape != pd.pathShape) {
139 if (lastPathShape) {
140 QPointF offset = lastPathShape->normalize();
141
142 QTransform matrix;
143 matrix.translate(-offset.x(), -offset.y());
144 for (int j = i + 1; j < updateBefore; ++j) {
145 d->points.at(j)->map(matrix);
146 }
147 lastPathShape->update();
148 updateBefore = i + 1;
149 }
150 lastPathShape = pd.pathShape;
151 }
152 }
153
154 if (lastPathShape) {
155 QPointF offset = lastPathShape->normalize();
156
157 QTransform matrix;
158 matrix.translate(-offset.x(), -offset.y());
159 for (int j = 0; j < updateBefore; ++j) {
160 d->points.at(j)->map(matrix);
161 }
162 lastPathShape->update();
163 }
164
165 d->deletePoints = true;
166}
virtual void redo()
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual QPointF normalize()
Normalizes the path data.
KoPathPoint * removePoint(const KoPathPointIndex &pointIndex)
Removes a point from the path.
void update() const override
reimplemented

References d, KoPathPointRemoveCommandPrivate::deletePoints, KoPathShape::normalize(), KoPathPointData::pathShape, KoPathPointRemoveCommandPrivate::pointDataList, KoPathPointData::pointIndex, KoPathPointRemoveCommandPrivate::points, KUndo2Command::redo(), KoPathShape::removePoint(), and KoShapeContainer::update().

◆ undo()

void KoPathPointRemoveCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 168 of file KoPathPointRemoveCommand.cpp.

169{
171 KoPathShape * lastPathShape = 0;
172
173 QMap<KoPathShape *, QList<KoPathPointIndex>> pointsMap;
174
175 for (int i = 0; i < d->pointDataList.size(); ++i) {
176 const KoPathPointData &pd = d->pointDataList.at(i);
177 if (lastPathShape && lastPathShape != pd.pathShape) {
178 lastPathShape->normalize();
179 lastPathShape->update();
180 }
182 lastPathShape = pd.pathShape;
183
184 pointsMap[pd.pathShape].append(pd.pointIndex);
185 }
186
187 if (lastPathShape) {
188 lastPathShape->normalize();
189 lastPathShape->update();
190 }
191
192 for (auto it = pointsMap.constBegin(); it != pointsMap.constEnd(); ++it) {
193 it.key()->recommendPointSelectionChange(it.value());
194 }
195
196 d->deletePoints = false;
197}
virtual void undo()
bool insertPoint(KoPathPoint *point, const KoPathPointIndex &pointIndex)
Inserts a new point into the given subpath at the specified position.

References d, KoPathPointRemoveCommandPrivate::deletePoints, KoPathShape::insertPoint(), KoPathShape::normalize(), KoPathPointData::pathShape, KoPathPointRemoveCommandPrivate::pointDataList, KoPathPointData::pointIndex, KoPathPointRemoveCommandPrivate::points, KUndo2Command::undo(), and KoShapeContainer::update().

Member Data Documentation

◆ d

KoPathPointRemoveCommandPrivate* KoPathPointRemoveCommand::d
private

Definition at line 53 of file KoPathPointRemoveCommand.h.


The documentation for this class was generated from the following files: