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, KoColorDisplayRendererInterface *renderInterface)
 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
 
- Public Member Functions inherited from KoShape::ShapeChangeListener
virtual ~ShapeChangeListener ()
 

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 29 of file KoPathToolSelection.h.

Member Typedef Documentation

◆ PathShapePointMap

Definition at line 142 of file KoPathToolSelection.h.

Constructor & Destructor Documentation

◆ KoPathToolSelection()

KoPathToolSelection::KoPathToolSelection ( KoPathTool * tool)
explicit

Definition at line 23 of file KoPathToolSelection.cpp.

24 : m_tool(tool)
25{
26}

◆ ~KoPathToolSelection()

KoPathToolSelection::~KoPathToolSelection ( )
override

Definition at line 28 of file KoPathToolSelection.cpp.

29{
30}

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 48 of file KoPathToolSelection.cpp.

49{
50 if(! point)
51 return;
52
53 bool alreadyIn = false;
54 if (clear) {
55 if (size() == 1 && m_selectedPoints.contains(point)) {
56 alreadyIn = true;
57 } else {
58 this->clear();
59 }
60 } else {
61 alreadyIn = m_selectedPoints.contains(point);
62 }
63
64 if (!alreadyIn) {
65 m_selectedPoints.insert(point);
66 KoPathShape * pathShape = point->parent();
67 PathShapePointMap::iterator it(m_shapePointMap.find(pathShape));
68 if (it == m_shapePointMap.end()) {
69 it = m_shapePointMap.insert(pathShape, QSet<KoPathPoint *>());
70 }
71 it.value().insert(point);
72 Q_EMIT selectionChanged();
73 }
74}
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 88 of file KoPathToolSelection.cpp.

89{
90 m_selectedPoints.clear();
91 m_shapePointMap.clear();
92 Q_EMIT selectionChanged();
93}

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 137 of file KoPathToolSelection.cpp.

138{
139 return m_selectedPoints.contains(point);
140}

References m_selectedPoints.

◆ hasSelection()

bool KoPathToolSelection::hasSelection ( )
overridevirtual

reimplemented from KoToolSelection

Reimplemented from KoToolSelection.

Definition at line 242 of file KoPathToolSelection.cpp.

243{
244 return !m_selectedPoints.isEmpty();
245}

References m_selectedPoints.

◆ notifyPathPointsChanged()

void KoPathToolSelection::notifyPathPointsChanged ( KoPathShape * shape)
overridevirtual

Implements KoPathShape::PointSelectionChangeListener.

Definition at line 265 of file KoPathToolSelection.cpp.

266{
267 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(shape, QSet<KoPathPoint*>());
268
269 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
270 m_selectedPoints.remove(point);
271 }
272 m_shapePointMap.remove(shape);
273
275
276 Q_EMIT selectionChanged();
277}
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 )
overridevirtual

Implements KoShape::ShapeChangeListener.

Definition at line 279 of file KoPathToolSelection.cpp.

280{
281 if (type == KoShape::Deleted) {
282 // we cannot select non-path shapes, so static cast is safe here
284
285 if (KoPathShape *pathShape = static_cast<KoPathShape*>(shape)) {
286
287 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(pathShape, QSet<KoPathPoint*>());
288 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
289 m_selectedPoints.remove(point);
290 }
291 m_shapePointMap.remove(pathShape);
292 m_selectedShapes.removeAll(pathShape);
293 }
294 }
295
297}
#define KoPathShapeId
Definition KoPathShape.h:20
QList< KoPathShape * > m_selectedShapes
QString shapeId() const
Definition KoShape.cpp:875
@ Deleted
the shape was deleted
Definition KoShape.h:101
#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 127 of file KoPathToolSelection.cpp.

128{
129 return m_shapePointMap.size();
130}

References m_shapePointMap.

◆ paint()

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

Draw the selected points.

Definition at line 32 of file KoPathToolSelection.cpp.

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

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

◆ recommendPointSelectionChange()

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

Implements KoPathShape::PointSelectionChangeListener.

Definition at line 247 of file KoPathToolSelection.cpp.

248{
249 QSet<KoPathPoint*> selectedShapePoints = m_shapePointMap.value(shape, QSet<KoPathPoint*>());
250
251 Q_FOREACH (KoPathPoint *point, selectedShapePoints) {
252 remove(point);
253 }
254
255 Q_FOREACH (const KoPathPointIndex &index, newSelection) {
256 KoPathPoint *point = shape->pointByIndex(index);
257 KIS_SAFE_ASSERT_RECOVER(point) { continue; }
258
259 add(point, false);
260 }
261
262 Q_EMIT selectionChanged();
263}
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 76 of file KoPathToolSelection.cpp.

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

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

◆ selectAll()

void KoPathToolSelection::selectAll ( )

Definition at line 113 of file KoPathToolSelection.cpp.

114{
115 blockSignals(true);
116 Q_FOREACH (KoPathShape* shape, m_selectedShapes) {
117 KoParameterShape *parameterShape = dynamic_cast<KoParameterShape*>(shape);
118 if (parameterShape && parameterShape->isParametricShape())
119 continue;
120 Q_FOREACH (KoPathPoint* point, shape->pointsAt(shape->outlineRect().adjusted(-2, -2, 2, 2)))
121 add(point, false);
122 }
123 blockSignals(false);
124 Q_EMIT selectionChanged();
125}
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 142 of file KoPathToolSelection.cpp.

143{
144 return m_selectedPoints;
145}

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 147 of file KoPathToolSelection.cpp.

148{
149 QList<KoPathPointData> pointData;
150 Q_FOREACH (KoPathPoint* p, m_selectedPoints) {
151 KoPathShape * pathShape = p->parent();
152 pointData.append(KoPathPointData(pathShape, pathShape->pathPointIndex(p)));
153 }
154 return pointData;
155}
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:857

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 157 of file KoPathToolSelection.cpp.

158{
159 QList<KoPathPointData> pointData;
160
162 std::sort(pd.begin(), pd.end());
163
164 KoPathPointData last(0, KoPathPointIndex(-1, -1));
165 KoPathPointData lastSubpathStart(0, KoPathPointIndex(-1, -1));
166
167 QList<KoPathPointData>::const_iterator it(pd.constBegin());
168 for (; it != pd.constEnd(); ++it) {
169 if (it->pointIndex.second == 0)
170 lastSubpathStart = *it;
171
172 if (last.pathShape == it->pathShape
173 && last.pointIndex.first == it->pointIndex.first
174 && last.pointIndex.second + 1 == it->pointIndex.second) {
175 pointData.append(last);
176 }
177
178 if (lastSubpathStart.pathShape == it->pathShape
179 && it->pathShape->pointByIndex(it->pointIndex)->properties() & KoPathPoint::CloseSubpath
180 && (it->pathShape->pointByIndex(it->pointIndex)->properties() & KoPathPoint::StartSubpath) == 0) {
181 pointData.append(*it);
182 }
183
184 last = *it;
185 }
186
187 return pointData;
188}
@ 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 190 of file KoPathToolSelection.cpp.

191{
192 return m_selectedShapes;
193}

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 95 of file KoPathToolSelection.cpp.

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

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 195 of file KoPathToolSelection.cpp.

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

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 132 of file KoPathToolSelection.cpp.

133{
134 return m_selectedPoints.size();
135}

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 208 of file KoPathToolSelection.cpp.

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

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 144 of file KoPathToolSelection.h.

◆ m_selectedShapes

QList<KoPathShape*> KoPathToolSelection::m_selectedShapes
private

Definition at line 147 of file KoPathToolSelection.h.

◆ m_shapePointMap

PathShapePointMap KoPathToolSelection::m_shapePointMap
private

Definition at line 145 of file KoPathToolSelection.h.

◆ m_tool

KoPathTool* KoPathToolSelection::m_tool
private

Definition at line 146 of file KoPathToolSelection.h.


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