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

Handle the selection of points. More...

#include <KoPathToolSelection.h>

+ Inheritance diagram for KoPathToolSelection:

Signals

void selectionChanged ()
 

Public Member Functions

void add (KoPathPoint *point, bool clear)
 Add a point to the selection.
 
void clear ()
 Clear the selection.
 
bool contains (KoPathPoint *point)
 Check if a point is in the selection.
 
bool hasSelection () override
 reimplemented from KoToolSelection
 
 KoPathToolSelection (KoPathTool *tool)
 
void notifyPathPointsChanged (KoPathShape *shape) override
 
void notifyShapeChanged (KoShape::ChangeType type, KoShape *shape) override
 
int objectCount () const
 Get the number of path objects in the selection.
 
void paint (QPainter &painter, const KoViewConverter &converter, qreal handleRadius)
 Draw the selected points.
 
void recommendPointSelectionChange (KoPathShape *shape, const QList< KoPathPointIndex > &newSelection) override
 
void remove (KoPathPoint *point)
 Remove a point form the selection.
 
void selectAll ()
 
const QSet< KoPathPoint * > & selectedPoints () const
 Get all selected points.
 
QList< KoPathPointDataselectedPointsData () const
 Get the point data of all selected points.
 
QList< KoPathPointDataselectedSegmentsData () const
 Get the point data of all selected segments.
 
QList< KoPathShape * > selectedShapes () const
 Returns list of selected shapes.
 
void selectPoints (const QRectF &rect, bool clearSelection)
 Select points in rect.
 
void setSelectedShapes (const QList< KoPathShape * > shapes)
 Sets list of selected shapes.
 
int size () const
 Get the number of path points in the selection.
 
void update ()
 Update the selection to contain only valid points.
 
 ~KoPathToolSelection () override
 
- Public Member Functions inherited from KoToolSelection
 KoToolSelection (QObject *parent=0)
 
 ~KoToolSelection () override
 
- Public Member Functions inherited from KoPathShape::PointSelectionChangeListener
void notifyShapeChanged (ChangeType type, KoShape *shape) override
 

Private Types

typedef QMap< KoPathShape *, QSet< KoPathPoint * > > PathShapePointMap
 

Private Attributes

QSet< KoPathPoint * > m_selectedPoints
 
QList< KoPathShape * > m_selectedShapes
 
PathShapePointMap m_shapePointMap
 
KoPathToolm_tool
 

Detailed Description

Handle the selection of points.

This class handles the selection of points. It makes sure the canvas is repainted when the selection changes.

Definition at line 28 of file KoPathToolSelection.h.

Member Typedef Documentation

◆ PathShapePointMap

Definition at line 141 of file KoPathToolSelection.h.

Constructor & Destructor Documentation

◆ KoPathToolSelection()

KoPathToolSelection::KoPathToolSelection ( KoPathTool * tool)
explicit

Definition at line 22 of file KoPathToolSelection.cpp.

23 : m_tool(tool)
24{
25}

◆ ~KoPathToolSelection()

KoPathToolSelection::~KoPathToolSelection ( )
override

Definition at line 27 of file KoPathToolSelection.cpp.

28{
29}

Member Function Documentation

◆ add()

void KoPathToolSelection::add ( KoPathPoint * point,
bool clear )

Add a point to the selection.

Parameters
pointto add to the selection
clearif true the selection will be cleared before adding the point

Definition at line 46 of file KoPathToolSelection.cpp.

47{
48 if(! point)
49 return;
50
51 bool alreadyIn = false;
52 if (clear) {
53 if (size() == 1 && m_selectedPoints.contains(point)) {
54 alreadyIn = true;
55 } else {
56 this->clear();
57 }
58 } else {
59 alreadyIn = m_selectedPoints.contains(point);
60 }
61
62 if (!alreadyIn) {
63 m_selectedPoints.insert(point);
64 KoPathShape * pathShape = point->parent();
65 PathShapePointMap::iterator it(m_shapePointMap.find(pathShape));
66 if (it == m_shapePointMap.end()) {
67 it = m_shapePointMap.insert(pathShape, QSet<KoPathPoint *>());
68 }
69 it.value().insert(point);
70 Q_EMIT selectionChanged();
71 }
72}
KoPathShape * parent() const
Get the path shape the point belongs to.
The position of a path point within a path shape.
Definition KoPathShape.h:63
int size() const
Get the number of path points in the selection.
void clear()
Clear the selection.
QSet< KoPathPoint * > m_selectedPoints
PathShapePointMap m_shapePointMap

References clear(), m_selectedPoints, m_shapePointMap, KoPathPoint::parent(), selectionChanged(), and size().

◆ clear()

void KoPathToolSelection::clear ( )

Clear the selection.

Definition at line 86 of file KoPathToolSelection.cpp.

87{
88 m_selectedPoints.clear();
89 m_shapePointMap.clear();
90 Q_EMIT selectionChanged();
91}

References m_selectedPoints, m_shapePointMap, and selectionChanged().

◆ contains()

bool KoPathToolSelection::contains ( KoPathPoint * point)

Check if a point is in the selection.

Returns
true when the point is in the selection, false otherwise

Definition at line 135 of file KoPathToolSelection.cpp.

136{
137 return m_selectedPoints.contains(point);
138}

References m_selectedPoints.

◆ hasSelection()

bool KoPathToolSelection::hasSelection ( )
overridevirtual

reimplemented from KoToolSelection

Reimplemented from KoToolSelection.

Definition at line 240 of file KoPathToolSelection.cpp.

241{
242 return !m_selectedPoints.isEmpty();
243}

References m_selectedPoints.

◆ notifyPathPointsChanged()

void KoPathToolSelection::notifyPathPointsChanged ( KoPathShape * shape)
overridevirtual

Implements KoPathShape::PointSelectionChangeListener.

Definition at line 263 of file KoPathToolSelection.cpp.

264{
265 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(shape, QSet<KoPathPoint*>());
266
267 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
268 m_selectedPoints.remove(point);
269 }
270 m_shapePointMap.remove(shape);
271
273
274 Q_EMIT selectionChanged();
275}
A KoPathPoint represents a point in a path.
void notifyPathPointsChanged(KoPathShape *shape)

References m_selectedPoints, m_shapePointMap, m_tool, KoPathTool::notifyPathPointsChanged(), and selectionChanged().

◆ notifyShapeChanged()

void KoPathToolSelection::notifyShapeChanged ( KoShape::ChangeType type,
KoShape * shape )
override

Definition at line 277 of file KoPathToolSelection.cpp.

278{
279 if (type == KoShape::Deleted) {
280 // we cannot select non-path shapes, so static cast is safe here
282
283 if (KoPathShape *pathShape = static_cast<KoPathShape*>(shape)) {
284
285 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(pathShape, QSet<KoPathPoint*>());
286 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
287 m_selectedPoints.remove(point);
288 }
289 m_shapePointMap.remove(pathShape);
290 m_selectedShapes.removeAll(pathShape);
291 }
292 }
293
295}
#define KoPathShapeId
Definition KoPathShape.h:20
QList< KoPathShape * > m_selectedShapes
QString shapeId() const
Definition KoShape.cpp:1057
@ Deleted
the shape was deleted
Definition KoShape.h:104
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
void notifyShapeChanged(ChangeType type, KoShape *shape) override

References KoShape::Deleted, KIS_SAFE_ASSERT_RECOVER_NOOP, KoPathShapeId, m_selectedPoints, m_selectedShapes, m_shapePointMap, KoPathShape::PointSelectionChangeListener::notifyShapeChanged(), and KoShape::shapeId().

◆ objectCount()

int KoPathToolSelection::objectCount ( ) const

Get the number of path objects in the selection.

Returns
number of path object in the point selection

Definition at line 125 of file KoPathToolSelection.cpp.

126{
127 return m_shapePointMap.size();
128}

References m_shapePointMap.

◆ paint()

void KoPathToolSelection::paint ( QPainter & painter,
const KoViewConverter & converter,
qreal handleRadius )

Draw the selected points.

Definition at line 31 of file KoPathToolSelection.cpp.

32{
33 int decorationThickness = m_tool? m_tool->decorationThickness(): 1;
34 PathShapePointMap::iterator it(m_shapePointMap.begin());
35 for (; it != m_shapePointMap.end(); ++it) {
37 KoShape::createHandlePainterHelperView(&painter, it.key(), converter, handleRadius, decorationThickness);
39
40 Q_FOREACH (KoPathPoint *p, it.value()) {
41 p->paint(helper, KoPathPoint::All);
42 }
43 }
44}
const Params2D p
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void setHandleStyle(const KisHandleStyle &style)
static KisHandleStyle & selectedPrimaryHandles()
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:1177
int decorationThickness() const
decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen ...

References KoPathPoint::All, KoShape::createHandlePainterHelperView(), KoToolBase::decorationThickness(), m_shapePointMap, m_tool, p, KisHandleStyle::selectedPrimaryHandles(), and KisHandlePainterHelper::setHandleStyle().

◆ recommendPointSelectionChange()

void KoPathToolSelection::recommendPointSelectionChange ( KoPathShape * shape,
const QList< KoPathPointIndex > & newSelection )
overridevirtual

Implements KoPathShape::PointSelectionChangeListener.

Definition at line 245 of file KoPathToolSelection.cpp.

246{
247 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(shape, QSet<KoPathPoint*>());
248
249 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
250 remove(point);
251 }
252
253 Q_FOREACH (const KoPathPointIndex &index, newSelection) {
254 KoPathPoint *point = shape->pointByIndex(index);
255 KIS_SAFE_ASSERT_RECOVER(point) { continue; }
256
257 add(point, false);
258 }
259
260 Q_EMIT selectionChanged();
261}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
KoPathPoint * pointByIndex(const KoPathPointIndex &pointIndex) const
Returns the path point specified by a path point index.
void add(KoPathPoint *point, bool clear)
Add a point to the selection.
void remove(KoPathPoint *point)
Remove a point form the selection.
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References add(), KIS_SAFE_ASSERT_RECOVER, m_shapePointMap, KoPathShape::pointByIndex(), remove(), and selectionChanged().

◆ remove()

void KoPathToolSelection::remove ( KoPathPoint * point)

Remove a point form the selection.

Parameters
pointto remove from the selection

Definition at line 74 of file KoPathToolSelection.cpp.

75{
76 if (m_selectedPoints.remove(point)) {
77 KoPathShape * pathShape = point->parent();
78 m_shapePointMap[pathShape].remove(point);
79 if (m_shapePointMap[pathShape].size() == 0) {
80 m_shapePointMap.remove(pathShape);
81 }
82 Q_EMIT selectionChanged();
83 }
84}

References m_selectedPoints, m_shapePointMap, KoPathPoint::parent(), selectionChanged(), and size().

◆ selectAll()

void KoPathToolSelection::selectAll ( )

Definition at line 111 of file KoPathToolSelection.cpp.

112{
113 blockSignals(true);
114 Q_FOREACH (KoPathShape* shape, m_selectedShapes) {
115 KoParameterShape *parameterShape = dynamic_cast<KoParameterShape*>(shape);
116 if (parameterShape && parameterShape->isParametricShape())
117 continue;
118 Q_FOREACH (KoPathPoint* point, shape->pointsAt(shape->outlineRect().adjusted(-2, -2, 2, 2)))
119 add(point, false);
120 }
121 blockSignals(false);
122 Q_EMIT selectionChanged();
123}
bool isParametricShape() const
Check if object is a parametric shape.
QRectF outlineRect() const override
reimplemented
QList< KoPathPoint * > pointsAt(const QRectF &rect, const bool useControlPoints=false) const
Returns the path points within the given rectangle.

References add(), KoParameterShape::isParametricShape(), m_selectedShapes, KoPathShape::outlineRect(), KoPathShape::pointsAt(), and selectionChanged().

◆ selectedPoints()

const QSet< KoPathPoint * > & KoPathToolSelection::selectedPoints ( ) const

Get all selected points.

Returns
set of selected points

Definition at line 140 of file KoPathToolSelection.cpp.

141{
142 return m_selectedPoints;
143}

References m_selectedPoints.

◆ selectedPointsData()

QList< KoPathPointData > KoPathToolSelection::selectedPointsData ( ) const

Get the point data of all selected points.

This is subject to change

Definition at line 145 of file KoPathToolSelection.cpp.

146{
147 QList<KoPathPointData> pointData;
148 Q_FOREACH (KoPathPoint* p, m_selectedPoints) {
149 KoPathShape * pathShape = p->parent();
150 pointData.append(KoPathPointData(pathShape, pathShape->pathPointIndex(p)));
151 }
152 return pointData;
153}
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pathPointIndex(const KoPathPoint *point) const
Returns the path point index of a given path point.
KoShapeContainer * parent() const
Definition KoShape.cpp:1039

References m_selectedPoints, p, KoShape::parent(), and KoPathShape::pathPointIndex().

◆ selectedSegmentsData()

QList< KoPathPointData > KoPathToolSelection::selectedSegmentsData ( ) const

Get the point data of all selected segments.

This is subject to change

Definition at line 155 of file KoPathToolSelection.cpp.

156{
157 QList<KoPathPointData> pointData;
158
160 std::sort(pd.begin(), pd.end());
161
162 KoPathPointData last(0, KoPathPointIndex(-1, -1));
163 KoPathPointData lastSubpathStart(0, KoPathPointIndex(-1, -1));
164
165 QList<KoPathPointData>::const_iterator it(pd.constBegin());
166 for (; it != pd.constEnd(); ++it) {
167 if (it->pointIndex.second == 0)
168 lastSubpathStart = *it;
169
170 if (last.pathShape == it->pathShape
171 && last.pointIndex.first == it->pointIndex.first
172 && last.pointIndex.second + 1 == it->pointIndex.second) {
173 pointData.append(last);
174 }
175
176 if (lastSubpathStart.pathShape == it->pathShape
177 && it->pathShape->pointByIndex(it->pointIndex)->properties() & KoPathPoint::CloseSubpath
178 && (it->pathShape->pointByIndex(it->pointIndex)->properties() & KoPathPoint::StartSubpath) == 0) {
179 pointData.append(*it);
180 }
181
182 last = *it;
183 }
184
185 return pointData;
186}
@ StartSubpath
it starts a new subpath by a moveTo command
Definition KoPathPoint.h:38
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
QList< KoPathPointData > selectedPointsData() const
Get the point data of all selected points.

References KoPathPoint::CloseSubpath, KoPathPointData::pathShape, KoPathPointData::pointIndex, selectedPointsData(), and KoPathPoint::StartSubpath.

◆ selectedShapes()

QList< KoPathShape * > KoPathToolSelection::selectedShapes ( ) const

Returns list of selected shapes.

Definition at line 188 of file KoPathToolSelection.cpp.

189{
190 return m_selectedShapes;
191}

References m_selectedShapes.

◆ selectionChanged

void KoPathToolSelection::selectionChanged ( )
signal

◆ selectPoints()

void KoPathToolSelection::selectPoints ( const QRectF & rect,
bool clearSelection )

Select points in rect.

Parameters
rectthe selection rectangle in document coordinates
clearSelectionif set clear the current selection before the selection

Definition at line 93 of file KoPathToolSelection.cpp.

94{
95 if (clearSelection) {
96 clear();
97 }
98
99 blockSignals(true);
100 Q_FOREACH (KoPathShape* shape, m_selectedShapes) {
101 KoParameterShape *parameterShape = dynamic_cast<KoParameterShape*>(shape);
102 if (parameterShape && parameterShape->isParametricShape())
103 continue;
104 Q_FOREACH (KoPathPoint* point, shape->pointsAt(shape->documentToShape(rect)))
105 add(point, false);
106 }
107 blockSignals(false);
108 Q_EMIT selectionChanged();
109}
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211

References add(), clear(), KoShape::documentToShape(), KoParameterShape::isParametricShape(), m_selectedShapes, KoPathShape::pointsAt(), and selectionChanged().

◆ setSelectedShapes()

void KoPathToolSelection::setSelectedShapes ( const QList< KoPathShape * > shapes)

Sets list of selected shapes.

Definition at line 193 of file KoPathToolSelection.cpp.

194{
195 Q_FOREACH(KoPathShape *shape, m_selectedShapes) {
196 shape->removeShapeChangeListener(this);
197 }
198
199 m_selectedShapes = shapes;
200
201 Q_FOREACH(KoPathShape *shape, m_selectedShapes) {
202 shape->addShapeChangeListener(this);
203 }
204}
void addShapeChangeListener(ShapeChangeListener *listener)
Definition KoShape.cpp:1360
void removeShapeChangeListener(ShapeChangeListener *listener)
Definition KoShape.cpp:1368

References KoShape::addShapeChangeListener(), m_selectedShapes, and KoShape::removeShapeChangeListener().

◆ size()

int KoPathToolSelection::size ( ) const

Get the number of path points in the selection.

Returns
number of points in the selection

Definition at line 130 of file KoPathToolSelection.cpp.

131{
132 return m_selectedPoints.size();
133}

References m_selectedPoints.

◆ update()

void KoPathToolSelection::update ( )

Update the selection to contain only valid points.

This function checks which points are no longer valid and removes them from the selection. If e.g. some points are selected and the shape which contains the points is removed by undo, the points are no longer valid and have therefore to be removed from the selection.

Definition at line 206 of file KoPathToolSelection.cpp.

207{
208 bool selectionHasChanged = false;
209
210 PathShapePointMap::iterator it(m_shapePointMap.begin());
211 while (it != m_shapePointMap.end()) {
212 KoParameterShape *parameterShape = dynamic_cast<KoParameterShape*>(it.key());
213 bool isParametricShape = parameterShape && parameterShape->isParametricShape();
214 if (! m_selectedShapes.contains(it.key()) || isParametricShape) {
215 QSet<KoPathPoint *>::iterator pointIt(it.value().begin());
216 for (; pointIt != it.value().end(); ++pointIt) {
217 m_selectedPoints.remove(*pointIt);
218 }
219 it = m_shapePointMap.erase(it);
220 selectionHasChanged = true;
221 } else {
222 QSet<KoPathPoint *>::iterator pointIt(it.value().begin());
223 while (pointIt != it.value().end()) {
224 if ((*pointIt)->parent()->pathPointIndex(*pointIt) == KoPathPointIndex(-1, -1)) {
225 m_selectedPoints.remove(*pointIt);
226 pointIt = it.value().erase(pointIt);
227 selectionHasChanged = true;
228 } else {
229 ++pointIt;
230 }
231 }
232 ++it;
233 }
234 }
235
236 if (selectionHasChanged)
237 Q_EMIT selectionChanged();
238}

References KoParameterShape::isParametricShape(), m_selectedPoints, m_selectedShapes, m_shapePointMap, and selectionChanged().

Member Data Documentation

◆ m_selectedPoints

QSet<KoPathPoint *> KoPathToolSelection::m_selectedPoints
private

Definition at line 143 of file KoPathToolSelection.h.

◆ m_selectedShapes

QList<KoPathShape*> KoPathToolSelection::m_selectedShapes
private

Definition at line 146 of file KoPathToolSelection.h.

◆ m_shapePointMap

PathShapePointMap KoPathToolSelection::m_shapePointMap
private

Definition at line 144 of file KoPathToolSelection.h.

◆ m_tool

KoPathTool* KoPathToolSelection::m_tool
private

Definition at line 145 of file KoPathToolSelection.h.


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