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

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

#include <KoPathPointInsertCommand.h>

+ Inheritance diagram for KoPathPointInsertCommand:

Public Member Functions

QList< KoPathPoint * > insertedPoints () const
 Returns list of inserted points.
 
 KoPathPointInsertCommand (const QList< KoPathPointData > &pointDataList, qreal insertPosition, KUndo2Command *parent=0)
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoPathPointInsertCommand () 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

KoPathPointInsertCommandPrivate *const d
 

Detailed Description

The undo / redo command for inserting path points.

Definition at line 20 of file KoPathPointInsertCommand.h.

Constructor & Destructor Documentation

◆ KoPathPointInsertCommand()

KoPathPointInsertCommand::KoPathPointInsertCommand ( const QList< KoPathPointData > & pointDataList,
qreal insertPosition,
KUndo2Command * parent = 0 )

Command to insert path points.

This splits the segments at the given position by inserting new points. The De Casteljau algorithm is used for calculating the position of the new points.

Parameters
pointDataListdescribing the segments to split
insertPositionthe position to insert at [0..1]
parentthe parent command used for macro commands

Definition at line 29 of file KoPathPointInsertCommand.cpp.

30 : KUndo2Command(parent),
32{
33 if (insertPosition < 0)
34 insertPosition = 0;
35 if (insertPosition > 1)
36 insertPosition = 1;
37
38 //TODO the list needs to be sorted
39
40 QList<KoPathPointData>::const_iterator it(pointDataList.begin());
41 for (; it != pointDataList.end(); ++it) {
42 KoPathShape * pathShape = it->pathShape;
43
44 KoPathSegment segment = pathShape->segmentByIndex(it->pointIndex);
45
46 // should not happen but to be sure
47 if (! segment.isValid())
48 continue;
49
50 d->pointDataList.append(*it);
51
52 QPair<KoPathSegment, KoPathSegment> splitSegments = segment.splitAt(insertPosition);
53
54 KoPathPoint * split1 = splitSegments.first.second();
55 KoPathPoint * split2 = splitSegments.second.first();
56 KoPathPoint * splitPoint = new KoPathPoint(pathShape, split1->point());
57 if(split1->activeControlPoint1())
58 splitPoint->setControlPoint1(split1->controlPoint1());
59 if(split2->activeControlPoint2())
60 splitPoint->setControlPoint2(split2->controlPoint2());
61
62 d->points.append(splitPoint);
63 QPointF cp1 = splitSegments.first.first()->controlPoint2();
64 QPointF cp2 = splitSegments.second.second()->controlPoint1();
65 d->controlPoints.append(QPair<QPointF, QPointF>(cp1, cp2));
66 }
67 setText(kundo2_i18n("Insert points"));
68}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
QList< QPair< QPointF, QPointF > > controlPoints
KoPathPointInsertCommandPrivate *const d
A KoPathPoint represents a point in a path.
void setControlPoint1(const QPointF &point)
Set the control point 1.
QPointF point
void setControlPoint2(const QPointF &point)
Set the control point 2.
QPointF controlPoint1
bool activeControlPoint1
bool activeControlPoint2
QPointF controlPoint2
A KoPathSegment consist of two neighboring KoPathPoints.
QPair< KoPathSegment, KoPathSegment > splitAt(qreal t) const
Splits segment at given position returning the two resulting segments.
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathSegment segmentByIndex(const KoPathPointIndex &pointIndex) const
Returns the segment specified by a path point index.
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, KoPathPointInsertCommandPrivate::controlPoints, d, KoPathSegment::isValid(), kundo2_i18n(), KoPathPoint::point, KoPathPointInsertCommandPrivate::pointDataList, KoPathPointInsertCommandPrivate::points, KoPathShape::segmentByIndex(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), KUndo2Command::setText(), and KoPathSegment::splitAt().

◆ ~KoPathPointInsertCommand()

KoPathPointInsertCommand::~KoPathPointInsertCommand ( )
override

Definition at line 70 of file KoPathPointInsertCommand.cpp.

71{
72 delete d;
73}

References d.

Member Function Documentation

◆ insertedPoints()

QList< KoPathPoint * > KoPathPointInsertCommand::insertedPoints ( ) const

Returns list of inserted points.

Definition at line 150 of file KoPathPointInsertCommand.cpp.

151{
152 return d->points;
153}

References d, and KoPathPointInsertCommandPrivate::points.

◆ redo()

void KoPathPointInsertCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 75 of file KoPathPointInsertCommand.cpp.

76{
78 for (int i = d->pointDataList.size() - 1; i >= 0; --i) {
79 KoPathPointData pointData = d->pointDataList.at(i);
80 KoPathShape * pathShape = pointData.pathShape;
81
82 KoPathSegment segment = pathShape->segmentByIndex(pointData.pointIndex);
83
84 ++pointData.pointIndex.second;
85
86 if (segment.first()->activeControlPoint2()) {
87 QPointF controlPoint2 = segment.first()->controlPoint2();
88 std::swap(controlPoint2, d->controlPoints[i].first);
89 segment.first()->setControlPoint2(controlPoint2);
90 }
91
92 if (segment.second()->activeControlPoint1()) {
93 QPointF controlPoint1 = segment.second()->controlPoint1();
94 std::swap(controlPoint1, d->controlPoints[i].second);
95 segment.second()->setControlPoint1(controlPoint1);
96 }
97
98 pathShape->insertPoint(d->points.at(i), pointData.pointIndex);
99 pathShape->recommendPointSelectionChange({pointData.pointIndex});
100 pathShape->update();
101 }
102 d->deletePoints = false;
103}
virtual void redo()
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
KoPathPoint * first
KoPathPoint * second
void recommendPointSelectionChange(const QList< KoPathPointIndex > &newSelection)
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 KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, KoPathPointInsertCommandPrivate::controlPoints, d, KoPathPointInsertCommandPrivate::deletePoints, KoPathSegment::first, KoPathShape::insertPoint(), KoPathPointData::pathShape, KoPathPointInsertCommandPrivate::pointDataList, KoPathPointData::pointIndex, KoPathPointInsertCommandPrivate::points, KoPathShape::recommendPointSelectionChange(), KUndo2Command::redo(), KoPathSegment::second, KoPathShape::segmentByIndex(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), and KoShapeContainer::update().

◆ undo()

void KoPathPointInsertCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 105 of file KoPathPointInsertCommand.cpp.

106{
108 for (int i = 0; i < d->pointDataList.size(); ++i) {
109 const KoPathPointData &pdBefore = d->pointDataList.at(i);
110 KoPathShape * pathShape = pdBefore.pathShape;
111 KoPathPointIndex piAfter = pdBefore.pointIndex;
112 ++piAfter.second;
113
114 KoPathPoint * before = pathShape->pointByIndex(pdBefore.pointIndex);
115
116 d->points[i] = pathShape->removePoint(piAfter);
117
118 if (d->points[i]->properties() & KoPathPoint::CloseSubpath) {
119 piAfter.second = 0;
120 }
121
122 KoPathPoint * after = pathShape->pointByIndex(piAfter);
123
124 if (before->activeControlPoint2()) {
125 QPointF controlPoint2 = before->controlPoint2();
126 std::swap(controlPoint2, d->controlPoints[i].first);
127 before->setControlPoint2(controlPoint2);
128 }
129
130 if (after->activeControlPoint1()) {
131 QPointF controlPoint1 = after->controlPoint1();
132 std::swap(controlPoint1, d->controlPoints[i].second);
133 after->setControlPoint1(controlPoint1);
134 }
135
136 QList<KoPathPointIndex> segmentPoints;
137 segmentPoints << pdBefore.pointIndex;
138
139 KoPathPointIndex nextPoint(pdBefore.pointIndex.first, pdBefore.pointIndex.second + 1);
140 if (pathShape->pointByIndex(nextPoint)) {
141 segmentPoints << nextPoint;
142 }
143
144 pathShape->recommendPointSelectionChange(segmentPoints);
145 pathShape->update();
146 }
147 d->deletePoints = true;
148}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
virtual void undo()
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
KoPathPoint * removePoint(const KoPathPointIndex &pointIndex)
Removes a point from the path.
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.

References KoPathPoint::activeControlPoint1, KoPathPoint::activeControlPoint2, KoPathPoint::CloseSubpath, KoPathPoint::controlPoint1, KoPathPoint::controlPoint2, KoPathPointInsertCommandPrivate::controlPoints, d, KoPathPointInsertCommandPrivate::deletePoints, KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointInsertCommandPrivate::pointDataList, KoPathPointData::pointIndex, KoPathPointInsertCommandPrivate::points, KoPathShape::recommendPointSelectionChange(), KoPathShape::removePoint(), KoPathPoint::setControlPoint1(), KoPathPoint::setControlPoint2(), KUndo2Command::undo(), and KoShapeContainer::update().

Member Data Documentation

◆ d

KoPathPointInsertCommandPrivate* const KoPathPointInsertCommand::d
private

Definition at line 46 of file KoPathPointInsertCommand.h.


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