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

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

#include <KoSubpathJoinCommand.h>

+ Inheritance diagram for KoSubpathJoinCommand:

Public Member Functions

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

enum  Reverse { ReverseFirst = 1 , ReverseSecond = 2 }
 

Private Member Functions

bool closeSubpathMode () const
 

Private Attributes

KoPathPoint::PointProperties m_oldProperties1
 
KoPathPoint::PointProperties m_oldProperties2
 
KoPathPointData m_pointData1
 
KoPathPointData m_pointData2
 
int m_reverse
 
boost::optional< QPointF > m_savedControlPoint1
 
boost::optional< QPointF > m_savedControlPoint2
 
KoPathPointIndex m_splitIndex
 

Detailed Description

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

Definition at line 18 of file KoSubpathJoinCommand.h.

Member Enumeration Documentation

◆ Reverse

Enumerator
ReverseFirst 
ReverseSecond 

Definition at line 52 of file KoSubpathJoinCommand.h.

Constructor & Destructor Documentation

◆ KoSubpathJoinCommand()

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

Command to join two subpath end points.

The points have to be from the same path shape.

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

Definition at line 14 of file KoSubpathJoinCommand.cpp.

15 : KUndo2Command(parent)
16 , m_pointData1(pointData1)
17 , m_pointData2(pointData2)
21 , m_reverse(0)
22{
27 m_pointData1.pointIndex.second == pathShape->subpathPointCount(m_pointData1.pointIndex.first) - 1);
30 m_pointData2.pointIndex.second == pathShape->subpathPointCount(m_pointData2.pointIndex.first) - 1);
31 //TODO check that points are not the same
32
34 std::swap(m_pointData1, m_pointData2);
35 }
36
37 if (!closeSubpathMode()) {
38 if (m_pointData1.pointIndex.second == 0 &&
39 pathShape->subpathPointCount(m_pointData1.pointIndex.first) > 1)
41 if (m_pointData2.pointIndex.second != 0)
43 setText(kundo2_i18n("Join subpaths"));
44 } else {
45 setText(kundo2_i18n("Close subpath"));
46 }
47
48 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
49 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
50
53
54 m_oldProperties1 = point1->properties();
55 m_oldProperties2 = point2->properties();
56}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
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.
PointProperties properties
@ Normal
it has no control points
Definition KoPathPoint.h:37
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.
KoPathPoint::PointProperties m_oldProperties1
KoPathPointIndex m_splitIndex
boost::optional< QPointF > m_savedControlPoint1
boost::optional< QPointF > m_savedControlPoint2
KoPathPoint::PointProperties m_oldProperties2
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
boost::optional< QPointF > fetchControlPoint(KoPathPoint *pt, bool takeFirst)

References closeSubpathMode(), KritaUtils::fetchControlPoint(), KoPathShape::isClosedSubpath(), KIS_ASSERT, kundo2_i18n(), m_oldProperties1, m_oldProperties2, m_pointData1, m_pointData2, m_reverse, m_savedControlPoint1, m_savedControlPoint2, KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KoPathPoint::properties, ReverseFirst, ReverseSecond, KUndo2Command::setText(), and KoPathShape::subpathPointCount().

◆ ~KoSubpathJoinCommand()

KoSubpathJoinCommand::~KoSubpathJoinCommand ( )
override

Definition at line 58 of file KoSubpathJoinCommand.cpp.

59{
60}

Member Function Documentation

◆ closeSubpathMode()

bool KoSubpathJoinCommand::closeSubpathMode ( ) const
private

Definition at line 156 of file KoSubpathJoinCommand.cpp.

157{
158 return m_pointData1.pointIndex.first == m_pointData2.pointIndex.first;
159}

References m_pointData1, m_pointData2, and KoPathPointData::pointIndex.

◆ redo()

void KoSubpathJoinCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 64 of file KoSubpathJoinCommand.cpp.

65{
68
69 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
70 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
71
74
75 // if the endpoint has a control point create a control point for the new segment to be
76 // at the symmetric position to the exiting one
77
78 if (closeSubpathMode()) {
79 KritaUtils::makeSymmetric(point1, false);
80 KritaUtils::makeSymmetric(point2, true);
81 } else {
84 }
85
86 if (closeSubpathMode()) {
88 } else {
89 if (m_reverse & ReverseFirst) {
90 pathShape->reverseSubpath(m_pointData1.pointIndex.first);
91 }
93 pathShape->reverseSubpath(m_pointData2.pointIndex.first);
94 }
95 pathShape->moveSubpath(m_pointData2.pointIndex.first, m_pointData1.pointIndex.first + 1);
97 m_splitIndex.second = pathShape->subpathPointCount(m_pointData1.pointIndex.first) - 1;
98 pathShape->join(m_pointData1.pointIndex.first);
99 }
100
101 QList<KoPathPointIndex> pointIndexes;
102 pointIndexes << pathShape->pathPointIndex(point1);
103 pointIndexes << pathShape->pathPointIndex(point2);
104 pathShape->recommendPointSelectionChange(pointIndexes);
105
106 pathShape->normalize();
107 pathShape->update();
108}
virtual void redo()
bool reverseSubpath(int subpathIndex)
Reverse subpath.
void recommendPointSelectionChange(const QList< KoPathPointIndex > &newSelection)
virtual QPointF normalize()
Normalizes the path data.
bool moveSubpath(int oldSubpathIndex, int newSubpathIndex)
Moves the position of a subpath within a path.
bool join(int subpathIndex)
Joins the given subpath with the following one.
KoPathPointIndex closeSubpath(const KoPathPointIndex &pointIndex)
Close a open subpath.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
void update() const override
reimplemented
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
void makeSymmetric(KoPathPoint *pt, bool copyFromFirst)

References KoPathShape::closeSubpath(), closeSubpathMode(), KoPathShape::join(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_pointData1, m_pointData2, m_reverse, m_splitIndex, KritaUtils::makeSymmetric(), KoPathShape::moveSubpath(), KoPathShape::normalize(), KoPathShape::pathPointIndex(), KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KoPathShape::recommendPointSelectionChange(), KUndo2Command::redo(), ReverseFirst, ReverseSecond, KoPathShape::reverseSubpath(), KoPathShape::subpathPointCount(), and KoShapeContainer::update().

◆ undo()

void KoSubpathJoinCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 110 of file KoSubpathJoinCommand.cpp.

111{
113 KoPathShape * pathShape = m_pointData1.pathShape;
114 pathShape->update();
115
116 if (closeSubpathMode()) {
118 } else {
119 pathShape->breakAfter(m_splitIndex);
120 pathShape->moveSubpath(m_pointData1.pointIndex.first + 1, m_pointData2.pointIndex.first);
121
122 if (m_reverse & ReverseSecond) {
123 pathShape->reverseSubpath(m_pointData2.pointIndex.first);
124 }
125 if (m_reverse & ReverseFirst) {
126 pathShape->reverseSubpath(m_pointData1.pointIndex.first);
127 }
128 }
129 KoPathPoint * point1 = pathShape->pointByIndex(m_pointData1.pointIndex);
130 KoPathPoint * point2 = pathShape->pointByIndex(m_pointData2.pointIndex);
131
134
135 // restore the old end points
136 if (closeSubpathMode()) {
139 } else {
142 }
143
146
147 QList<KoPathPointIndex> pointIndexes;
148 pointIndexes << pathShape->pathPointIndex(point1);
149 pointIndexes << pathShape->pathPointIndex(point2);
150 pathShape->recommendPointSelectionChange(pointIndexes);
151
152 pathShape->normalize();
153 pathShape->update();
154}
virtual void undo()
void setProperties(PointProperties properties)
Set the properties of a point.
bool breakAfter(const KoPathPointIndex &pointIndex)
Breaks the path after the point index.
KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex)
Opens a closed subpath.
void restoreControlPoint(KoPathPoint *pt, bool restoreFirst, boost::optional< QPointF > savedPoint)

References KoPathShape::breakAfter(), closeSubpathMode(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_oldProperties1, m_oldProperties2, m_pointData1, m_pointData2, m_reverse, m_savedControlPoint1, m_savedControlPoint2, m_splitIndex, KoPathShape::moveSubpath(), KoPathShape::normalize(), KoPathShape::openSubpath(), KoPathShape::pathPointIndex(), KoPathPointData::pathShape, KoPathShape::pointByIndex(), KoPathPointData::pointIndex, KoPathShape::recommendPointSelectionChange(), KritaUtils::restoreControlPoint(), ReverseFirst, ReverseSecond, KoPathShape::reverseSubpath(), KoPathPoint::setProperties(), KUndo2Command::undo(), and KoShapeContainer::update().

Member Data Documentation

◆ m_oldProperties1

KoPathPoint::PointProperties KoSubpathJoinCommand::m_oldProperties1
private

Definition at line 50 of file KoSubpathJoinCommand.h.

◆ m_oldProperties2

KoPathPoint::PointProperties KoSubpathJoinCommand::m_oldProperties2
private

Definition at line 51 of file KoSubpathJoinCommand.h.

◆ m_pointData1

KoPathPointData KoSubpathJoinCommand::m_pointData1
private

Definition at line 42 of file KoSubpathJoinCommand.h.

◆ m_pointData2

KoPathPointData KoSubpathJoinCommand::m_pointData2
private

Definition at line 43 of file KoSubpathJoinCommand.h.

◆ m_reverse

int KoSubpathJoinCommand::m_reverse
private

Definition at line 56 of file KoSubpathJoinCommand.h.

◆ m_savedControlPoint1

boost::optional<QPointF> KoSubpathJoinCommand::m_savedControlPoint1
private

Definition at line 47 of file KoSubpathJoinCommand.h.

◆ m_savedControlPoint2

boost::optional<QPointF> KoSubpathJoinCommand::m_savedControlPoint2
private

Definition at line 48 of file KoSubpathJoinCommand.h.

◆ m_splitIndex

KoPathPointIndex KoSubpathJoinCommand::m_splitIndex
private

Definition at line 44 of file KoSubpathJoinCommand.h.


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