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 110 of file KoPathPointRemoveCommand.cpp.

112 : KUndo2Command(parent),
114{
115 QList<KoPathPointData>::const_iterator it(pointDataList.begin());
116 for (; it != pointDataList.end(); ++it) {
117 KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
118 if (point) {
119 d->pointDataList.append(*it);
120 d->points.append(0);
121 }
122 }
123 std::sort(d->pointDataList.begin(), d->pointDataList.end());
124 setText(kundo2_i18n("Remove points"));
125}
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 127 of file KoPathPointRemoveCommand.cpp.

128{
129 delete d;
130}

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
97 //Reverse sort the subpath list to account for shifting indices of the subpaths
98 std::sort(subpathToDelete.begin(), subpathToDelete.end(), std::greater<>{});
99
100 Q_FOREACH (const KoPathPointData & pd, subpathToDelete) {
101 new KoSubpathRemoveCommand(pd.pathShape, pd.pointIndex.first, cmd);
102 }
103 if (shapesToDelete.size() > 0) {
104 shapeController->removeShapes(shapesToDelete, cmd);
105 }
106
107 return cmd;
108}
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 132 of file KoPathPointRemoveCommand.cpp.

133{
135 KoPathShape * lastPathShape = 0;
136 int updateBefore = d->pointDataList.size();
137 for (int i = d->pointDataList.size() - 1; i >= 0; --i) {
138 const KoPathPointData &pd = d->pointDataList.at(i);
139 pd.pathShape->update();
141
142 if (lastPathShape != pd.pathShape) {
143 if (lastPathShape) {
144 QPointF offset = lastPathShape->normalize();
145
146 QTransform matrix;
147 matrix.translate(-offset.x(), -offset.y());
148 for (int j = i + 1; j < updateBefore; ++j) {
149 d->points.at(j)->map(matrix);
150 }
151 lastPathShape->update();
152 updateBefore = i + 1;
153 }
154 lastPathShape = pd.pathShape;
155 }
156 }
157
158 if (lastPathShape) {
159 QPointF offset = lastPathShape->normalize();
160
161 QTransform matrix;
162 matrix.translate(-offset.x(), -offset.y());
163 for (int j = 0; j < updateBefore; ++j) {
164 d->points.at(j)->map(matrix);
165 }
166 lastPathShape->update();
167 }
168
169 d->deletePoints = true;
170}
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.
virtual void update() const
Definition KoShape.cpp:529

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

◆ undo()

void KoPathPointRemoveCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 172 of file KoPathPointRemoveCommand.cpp.

173{
175 KoPathShape * lastPathShape = 0;
176
177 QMap<KoPathShape *, QList<KoPathPointIndex>> pointsMap;
178
179 for (int i = 0; i < d->pointDataList.size(); ++i) {
180 const KoPathPointData &pd = d->pointDataList.at(i);
181 if (lastPathShape && lastPathShape != pd.pathShape) {
182 lastPathShape->normalize();
183 lastPathShape->update();
184 }
186 lastPathShape = pd.pathShape;
187
188 pointsMap[pd.pathShape].append(pd.pointIndex);
189 }
190
191 if (lastPathShape) {
192 lastPathShape->normalize();
193 lastPathShape->update();
194 }
195
196 for (auto it = pointsMap.constBegin(); it != pointsMap.constEnd(); ++it) {
197 it.key()->recommendPointSelectionChange(it.value());
198 }
199
200 d->deletePoints = false;
201}
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 KoShape::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: