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

Command to break a subpath at points. More...

#include <KoPathBreakAtPointCommand.h>

+ Inheritance diagram for KoPathBreakAtPointCommand:

Public Member Functions

 KoPathBreakAtPointCommand (const QList< KoPathPointData > &pointDataList, KUndo2Command *parent=0)
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoPathBreakAtPointCommand () 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 ()
 

Private Attributes

QList< KoPathPointIndexm_closedIndex
 
bool m_deletePoints
 
QList< KoPathPointDatam_pointDataList
 
QList< KoPathPoint * > m_points
 

Detailed Description

Command to break a subpath at points.

Definition at line 18 of file KoPathBreakAtPointCommand.h.

Constructor & Destructor Documentation

◆ KoPathBreakAtPointCommand()

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

Command to break a subpath at points.

The paths are broken at the given points. New points will be inserted after the given points and then the paths will be split after the given points.

Parameters
pointDataListList of point data where the path should be split.
parentthe parent command used for macro commands

Definition at line 21 of file KoPathBreakAtPointCommand.cpp.

22 : KUndo2Command(parent)
23 , m_deletePoints(true)
24{
25 QList<KoPathPointData> sortedPointDataList(pointDataList);
26 std::sort(sortedPointDataList.begin(), sortedPointDataList.end());
27 setText(kundo2_i18n("Break subpath at points"));
28
29 QList<KoPathPointData>::const_iterator it(sortedPointDataList.constBegin());
30 for (; it != sortedPointDataList.constEnd(); ++it) {
31 KoPathShape * pathShape = it->pathShape;
32 KoPathPoint * point = pathShape->pointByIndex(it->pointIndex);
33 if(! point)
34 continue;
35
36 // check if subpath is closed and the point is start or end point of the subpath
37 if(! pathShape->isClosedSubpath(it->pointIndex.first)) {
38 if(it->pointIndex.second == 0
39 || it->pointIndex.second == pathShape->subpathPointCount(it->pointIndex.first)) {
40 continue;
41 }
42 }
43
44 m_pointDataList.append(*it);
45 m_points.push_back(new KoPathPoint(*point));
46 m_closedIndex.push_back(KoPathPointIndex(-1, 0));
47 }
48
49 KoPathPointData last(0, KoPathPointIndex(-1, -1));
50 for (int i = m_pointDataList.size() - 1; i >= 0; --i) {
51 const KoPathPointData &current = m_pointDataList.at(i);
52
53 if (last.pathShape != current.pathShape || last.pointIndex.first != current.pointIndex.first) {
54 last = current;
55 if (current.pathShape->isClosedSubpath(current.pointIndex.first)) {
56 // the break will happen before the inserted point so we have to increment by 1
57 m_closedIndex[i] = current.pointIndex;
58 ++m_closedIndex[i].second;
59 }
60 }
61 }
62}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
QList< KoPathPointData > m_pointDataList
QList< KoPathPointIndex > m_closedIndex
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
A KoPathPoint represents a point in a path.
The position of a path point within a path shape.
Definition KoPathShape.h:63
int subpathPointCount(int subpathIndex) const
Returns the number of points in a subpath.
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathShape::isClosedSubpath(), kundo2_i18n(), m_closedIndex, m_pointDataList, m_points, KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KUndo2Command::setText(), and KoPathShape::subpathPointCount().

◆ ~KoPathBreakAtPointCommand()

KoPathBreakAtPointCommand::~KoPathBreakAtPointCommand ( )
override

Definition at line 64 of file KoPathBreakAtPointCommand.cpp.

65{
66 if (m_deletePoints) {
67 qDeleteAll(m_points);
68 }
69}

References m_deletePoints, and m_points.

Member Function Documentation

◆ redo()

void KoPathBreakAtPointCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 71 of file KoPathBreakAtPointCommand.cpp.

72{
74 KoPathPointData last(0, KoPathPointIndex(-1, -1));
75
76 // offset, needed when path was opened
77 int offset = 0;
78 for (int i = m_pointDataList.size() - 1; i >= 0; --i) {
79 const KoPathPointData & pd = m_pointDataList.at(i);
80 KoPathShape * pathShape = pd.pathShape;
81
82 KoPathPointIndex pointIndex = pd.pointIndex;
83 if (last.pathShape != pathShape || last.pointIndex.first != pointIndex.first) {
84 offset = 0;
85 }
86
87 pointIndex.second = pointIndex.second + offset + 1;
88 pathShape->insertPoint(m_points[i], pointIndex);
89
90 if (m_closedIndex.at(i).first != -1) {
91 m_closedIndex[i] = pathShape->openSubpath(m_closedIndex.at(i));
92 offset = m_closedIndex.at(i).second;
93 } else {
94 KoPathPointIndex breakIndex = pd.pointIndex;
95 breakIndex.second += offset;
96 pathShape->breakAfter(breakIndex);
97 m_closedIndex[i].second = offset;
98 }
99
100 if (last.pathShape != pathShape) {
101 if (last.pathShape) {
102 last.pathShape->update();
103 }
104 last = pd;
105 }
106 }
107 if (last.pathShape) {
108 last.pathShape->update();
109 }
110
111 m_deletePoints = false;
112}
virtual void redo()
bool breakAfter(const KoPathPointIndex &pointIndex)
Breaks the path after the point index.
KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex)
Opens a closed subpath.
bool insertPoint(KoPathPoint *point, const KoPathPointIndex &pointIndex)
Inserts a new point into the given subpath at the specified position.
void update() const override
reimplemented

References KoPathShape::breakAfter(), KoPathShape::insertPoint(), m_closedIndex, m_deletePoints, m_pointDataList, m_points, KoPathShape::openSubpath(), KoPathPointData::pathShape, KoPathPointData::pointIndex, KUndo2Command::redo(), and KoShapeContainer::update().

◆ undo()

void KoPathBreakAtPointCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 114 of file KoPathBreakAtPointCommand.cpp.

115{
117 KoPathShape * lastPathShape = 0;
118
119 QMap<KoPathShape *, QList<KoPathPointIndex>> pointsMap;
120
121 for (int i = 0; i < m_pointDataList.size(); ++i) {
122 const KoPathPointData & pd = m_pointDataList.at(i);
123 KoPathShape * pathShape = pd.pathShape;
124 KoPathPointIndex pointIndex = pd.pointIndex;
125 ++pointIndex.second;
126 if (m_closedIndex.at(i).first != -1) {
127 m_closedIndex[i] = pathShape->closeSubpath(m_closedIndex.at(i));
128 } else {
129 pointIndex.second = pointIndex.second + m_closedIndex.at(i).second;
130 pathShape->join(pd.pointIndex.first);
131 }
132
133 m_points[i] = pathShape->removePoint(pointIndex);
134
135 pointsMap[pathShape].append(pd.pointIndex);
136
137 if (lastPathShape != pathShape) {
138 if (lastPathShape) {
139 lastPathShape->update();
140 }
141 lastPathShape = pathShape;
142 }
143 }
144 if (lastPathShape) {
145 lastPathShape->update();
146 }
147
148 for (auto it = pointsMap.constBegin(); it != pointsMap.constEnd(); ++it) {
149 it.key()->recommendPointSelectionChange(it.value());
150 }
151
152 m_deletePoints = true;
153}
virtual void undo()
bool join(int subpathIndex)
Joins the given subpath with the following one.
KoPathPointIndex closeSubpath(const KoPathPointIndex &pointIndex)
Close a open subpath.
KoPathPoint * removePoint(const KoPathPointIndex &pointIndex)
Removes a point from the path.

References KoPathShape::closeSubpath(), KoPathShape::join(), m_closedIndex, m_deletePoints, m_pointDataList, m_points, KoPathPointData::pathShape, KoPathPointData::pointIndex, KoPathShape::removePoint(), KUndo2Command::undo(), and KoShapeContainer::update().

Member Data Documentation

◆ m_closedIndex

QList<KoPathPointIndex> KoPathBreakAtPointCommand::m_closedIndex
private

Definition at line 43 of file KoPathBreakAtPointCommand.h.

◆ m_deletePoints

bool KoPathBreakAtPointCommand::m_deletePoints
private

Definition at line 44 of file KoPathBreakAtPointCommand.h.

◆ m_pointDataList

QList<KoPathPointData> KoPathBreakAtPointCommand::m_pointDataList
private

Definition at line 39 of file KoPathBreakAtPointCommand.h.

◆ m_points

QList<KoPathPoint*> KoPathBreakAtPointCommand::m_points
private

Definition at line 40 of file KoPathBreakAtPointCommand.h.


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