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

The undo / redo command for merging two subpath end points. More...

#include <KoPathPointMergeCommand.h>

+ Inheritance diagram for KoPathPointMergeCommand:

Public Types

enum  Reverse { ReverseNone = 0 , ReverseFirst = 1 , ReverseSecond = 2 }
 

Public Member Functions

bool closeSubpathMode () const
 
 KoPathPointMergeCommand (const KoPathPointData &pointData1, const KoPathPointData &pointData2, KUndo2Command *parent=0)
 
KoPathPointData mergedPointData () const
 
void mergePoints (KoPathPoint *p1, KoPathPoint *p2, KoPathPoint *dstPoint)
 
 Private (const KoPathPointData &pointData1, const KoPathPointData &pointData2)
 
void redo () override
 redo the command
 
void restorePointState (KoPathPoint *point)
 
void savePointState (KoPathPoint *point)
 
void undo () override
 revert the actions done in redo
 
 ~KoPathPointMergeCommand () override
 
 ~Private ()
 
- 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 ()
 

Public Attributes

KoPathPointIndex mergedPointIndex
 
KoPathShapepathShape
 
KoPathPointIndex pointIndex1
 
KoPathPointIndex pointIndex2
 
KoPathPointremovedPoint
 
int reverse
 
boost::optional< QPointF > savedControlPoint11
 
boost::optional< QPointF > savedControlPoint12
 
QPointF savedNodePoint1
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

The undo / redo command for merging two subpath end points.

Definition at line 18 of file KoPathPointMergeCommand.cpp.

Member Enumeration Documentation

◆ Reverse

Enumerator
ReverseNone 
ReverseFirst 
ReverseSecond 

Definition at line 79 of file KoPathPointMergeCommand.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoPathPointMergeCommand::~Private ( )
inline

Definition at line 31 of file KoPathPointMergeCommand.cpp.

32 {
33 delete removedPoint;
34 }

◆ KoPathPointMergeCommand()

KoPathPointMergeCommand::KoPathPointMergeCommand ( const KoPathPointData & pointData1,
const KoPathPointData & pointData2,
KUndo2Command * parent = 0 )

Command to merge two subpath end points.

The points have to be from the same path shape.

Parameters
pointData1the data of the first point to merge
pointData2the data of the second point to merge
parentthe parent command used for macro commands

How does is work:

The goal is to merge the point that is ending an open subpath with the one starting the same or another open subpath.

Definition at line 99 of file KoPathPointMergeCommand.cpp.

100 : KUndo2Command(parent), d(new Private(pointData1, pointData2))
101{
102 KIS_ASSERT(pointData1.pathShape == pointData2.pathShape);
103 KIS_ASSERT(d->pathShape);
104
105 KIS_ASSERT(!d->pathShape->isClosedSubpath(d->pointIndex1.first));
106 KIS_ASSERT(!d->pathShape->isClosedSubpath(d->pointIndex2.first));
107
108 KIS_ASSERT(d->pointIndex1.second == 0 ||
109 d->pointIndex1.second == d->pathShape->subpathPointCount(d->pointIndex1.first) - 1);
110
111 KIS_ASSERT(d->pointIndex2.second == 0 ||
112 d->pointIndex2.second == d->pathShape->subpathPointCount(d->pointIndex2.first) - 1);
113
114 KIS_ASSERT(d->pointIndex2 != d->pointIndex1);
115
116 if (d->pointIndex2 < d->pointIndex1) {
117 std::swap(d->pointIndex2, d->pointIndex1);
118 }
119
120 // if we have two different subpaths we might need to reverse them
121 if (!d->closeSubpathMode()) {
122 if (d->pointIndex1.second == 0 &&
123 d->pathShape->subpathPointCount(d->pointIndex1.first) > 1) {
124
125 d->reverse |= Private::ReverseFirst;
126 }
127
128 if (d->pointIndex2.second != 0 &&
129 d->pathShape->subpathPointCount(d->pointIndex2.first) > 1) {
130
131 d->reverse |= Private::ReverseSecond;
132 }
133 }
134
135 setText(kundo2_i18n("Merge points"));
136}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
KoPathShape * pathShape
path shape the path point belongs too
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)

References d, KIS_ASSERT, kundo2_i18n(), KoPathPointData::pathShape, and KUndo2Command::setText().

◆ ~KoPathPointMergeCommand()

KoPathPointMergeCommand::~KoPathPointMergeCommand ( )
override

Definition at line 138 of file KoPathPointMergeCommand.cpp.

139{
140 delete d;
141}

References d.

Member Function Documentation

◆ closeSubpathMode()

bool KoPathPointMergeCommand::closeSubpathMode ( ) const
inline

Definition at line 68 of file KoPathPointMergeCommand.cpp.

68 {
69 return pointIndex2.first == pointIndex1.first;
70 }

◆ mergedPointData()

KoPathPointData KoPathPointMergeCommand::mergedPointData ( ) const

Definition at line 224 of file KoPathPointMergeCommand.cpp.

225{
226 return KoPathPointData(d->pathShape, d->mergedPointIndex);
227}
Describe a KoPathPoint by a KoPathShape and its indices.

References d.

◆ mergePoints()

void KoPathPointMergeCommand::mergePoints ( KoPathPoint * p1,
KoPathPoint * p2,
KoPathPoint * dstPoint )
inline

Definition at line 48 of file KoPathPointMergeCommand.cpp.

49 {
50 QPointF mergePosition = 0.5 * (p1->point() + p2->point());
51
52 boost::optional<QPointF> mergedControlPoint1;
53 boost::optional<QPointF> mergedControlPoint2;
54
55 if (p1->activeControlPoint1()) {
56 mergedControlPoint1 = mergePosition + (p1->controlPoint1() - p1->point());
57 }
58
59 if (p2->activeControlPoint2()) {
60 mergedControlPoint2 = mergePosition + (p2->controlPoint2() - p2->point());
61 }
62
63 dstPoint->setPoint(mergePosition);
64 KritaUtils::restoreControlPoint(dstPoint, true, mergedControlPoint1);
65 KritaUtils::restoreControlPoint(dstPoint, false, mergedControlPoint2);
66 }
QPointF dstPoint
QPointF p2
QPointF p1
void restoreControlPoint(KoPathPoint *pt, bool restoreFirst, boost::optional< QPointF > savedPoint)

References dstPoint, p1, p2, and KritaUtils::restoreControlPoint().

◆ Private()

KoPathPointMergeCommand::Private ( const KoPathPointData & pointData1,
const KoPathPointData & pointData2 )
inline

Definition at line 21 of file KoPathPointMergeCommand.cpp.

22 : pathShape(pointData1.pathShape)
23 , pointIndex1(pointData1.pointIndex)
24 , pointIndex2(pointData2.pointIndex)
25 , removedPoint(0)
26 , mergedPointIndex(-1, -1)
28 {
29 }
KoPathPointIndex pointIndex
position of the point in the path shape

◆ redo()

void KoPathPointMergeCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 143 of file KoPathPointMergeCommand.cpp.

144{
146
147 KIS_SAFE_ASSERT_RECOVER_RETURN(!d->removedPoint);
148
149 KoPathPoint * point1 = d->pathShape->pointByIndex(d->pointIndex1);
150 KoPathPoint * point2 = d->pathShape->pointByIndex(d->pointIndex2);
151
152 d->pathShape->update();
153
154 if (d->closeSubpathMode()) {
155 d->savePointState(point1);
156 d->mergePoints(point2, point1, point1);
157 d->removedPoint = d->pathShape->removePoint(d->pointIndex2);
158
159 KoPathPointIndex newStartIndex(d->pointIndex1.first, 0);
160
161 d->pathShape->closeSubpath(newStartIndex);
162 d->mergedPointIndex = newStartIndex;
163
164 } else {
165 if (d->reverse & Private::ReverseFirst) {
166 d->pathShape->reverseSubpath(d->pointIndex1.first);
167 }
168
169 if (d->reverse & Private::ReverseSecond) {
170 d->pathShape->reverseSubpath(d->pointIndex2.first);
171 }
172
173 d->pathShape->moveSubpath(d->pointIndex2.first, d->pointIndex1.first + 1);
174 d->mergedPointIndex = d->pathShape->pathPointIndex(point1);
175 d->pathShape->join(d->pointIndex1.first);
176
177 d->savePointState(point1);
178 d->mergePoints(point1, point2, point1);
179
180 KoPathPointIndex removeIndex = d->pathShape->pathPointIndex(point2);
181 d->removedPoint = d->pathShape->removePoint(removeIndex);
182 }
183
184 d->pathShape->recommendPointSelectionChange({d->mergedPointIndex});
185 d->pathShape->update();
186}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
virtual void redo()
A KoPathPoint represents a point in a path.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and KUndo2Command::redo().

◆ restorePointState()

void KoPathPointMergeCommand::restorePointState ( KoPathPoint * point)
inline

Definition at line 42 of file KoPathPointMergeCommand.cpp.

42 {
46 }
boost::optional< QPointF > savedControlPoint12
boost::optional< QPointF > savedControlPoint11
void setPoint(const QPointF &point)
alter the point

References KritaUtils::restoreControlPoint(), and KoPathPoint::setPoint().

◆ savePointState()

void KoPathPointMergeCommand::savePointState ( KoPathPoint * point)
inline

Definition at line 36 of file KoPathPointMergeCommand.cpp.

36 {
37 savedNodePoint1 = point->point();
40 }
QPointF point
boost::optional< QPointF > fetchControlPoint(KoPathPoint *pt, bool takeFirst)

References KritaUtils::fetchControlPoint(), and KoPathPoint::point.

◆ undo()

void KoPathPointMergeCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 188 of file KoPathPointMergeCommand.cpp.

189{
191
192 d->pathShape->update();
193
194 KIS_SAFE_ASSERT_RECOVER_RETURN(d->removedPoint);
195
196 if (d->closeSubpathMode()) {
197 d->pathShape->openSubpath(d->mergedPointIndex);
198 d->pathShape->insertPoint(d->removedPoint, d->pointIndex2);
199 d->restorePointState(d->pathShape->pointByIndex(d->pointIndex1));
200 } else {
201 d->pathShape->breakAfter(d->mergedPointIndex);
202 d->pathShape->insertPoint(d->removedPoint, KoPathPointIndex(d->mergedPointIndex.first+1,0));
203 d->restorePointState(d->pathShape->pointByIndex(d->mergedPointIndex));
204 d->pathShape->moveSubpath(d->mergedPointIndex.first+1, d->pointIndex2.first);
205
206 // undo the reversion of the subpaths
207 if (d->reverse & Private::ReverseFirst) {
208 d->pathShape->reverseSubpath(d->pointIndex1.first);
209 }
210
211 if (d->reverse & Private::ReverseSecond) {
212 d->pathShape->reverseSubpath(d->pointIndex2.first);
213 }
214 }
215
216 // reset the removed point
217 d->removedPoint = 0;
218 d->mergedPointIndex = KoPathPointIndex(-1,-1);
219
220 d->pathShape->recommendPointSelectionChange({d->pointIndex1, d->pointIndex2});
221 d->pathShape->update();
222}
virtual void undo()

References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and KUndo2Command::undo().

Member Data Documentation

◆ d

Private* const KoPathPointMergeCommand::d
private

Definition at line 42 of file KoPathPointMergeCommand.h.

◆ mergedPointIndex

KoPathPointIndex KoPathPointMergeCommand::mergedPointIndex

Definition at line 77 of file KoPathPointMergeCommand.cpp.

◆ pathShape

KoPathShape* KoPathPointMergeCommand::pathShape

Definition at line 72 of file KoPathPointMergeCommand.cpp.

◆ pointIndex1

KoPathPointIndex KoPathPointMergeCommand::pointIndex1

Definition at line 73 of file KoPathPointMergeCommand.cpp.

◆ pointIndex2

KoPathPointIndex KoPathPointMergeCommand::pointIndex2

Definition at line 74 of file KoPathPointMergeCommand.cpp.

◆ removedPoint

KoPathPoint* KoPathPointMergeCommand::removedPoint

Definition at line 76 of file KoPathPointMergeCommand.cpp.

◆ reverse

int KoPathPointMergeCommand::reverse

Definition at line 85 of file KoPathPointMergeCommand.cpp.

◆ savedControlPoint11

boost::optional<QPointF> KoPathPointMergeCommand::savedControlPoint11

Definition at line 89 of file KoPathPointMergeCommand.cpp.

◆ savedControlPoint12

boost::optional<QPointF> KoPathPointMergeCommand::savedControlPoint12

Definition at line 90 of file KoPathPointMergeCommand.cpp.

◆ savedNodePoint1

QPointF KoPathPointMergeCommand::savedNodePoint1

Definition at line 87 of file KoPathPointMergeCommand.cpp.


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