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

The Shape class The shape class is a wrapper around Krita's vector objects. More...

#include <Shape.h>

+ Inheritance diagram for Shape:

Classes

struct  Private
 

Public Slots

QTransform absoluteTransformation () const
 transformation the 2D transformation matrix of the shape including all grandparent transforms.
 
QRectF boundingBox () const
 boundingBox the bounding box of the shape in points
 
void deselect ()
 deselect deselects the shape.
 
bool geometryProtected () const
 geometryProtected
 
bool isSelected ()
 isSelected
 
QString name () const
 name
 
ShapeparentShape () const
 parentShape
 
QPointF position () const
 position the position of the shape in points.
 
bool remove ()
 remove delete the shape.
 
void select ()
 select selects the shape.
 
bool selectable () const
 selectable
 
void setGeometryProtected (bool protect)
 setGeometryProtected
 
void setName (const QString &name)
 setName
 
void setPosition (QPointF point)
 setPosition set the position of the shape.
 
void setSelectable (bool selectable)
 setSelectable
 
void setTransformation (QTransform matrix)
 setTransformation set the 2D transformation matrix of the shape.
 
void setVisible (bool visible)
 setVisible
 
void setZIndex (int zindex)
 setZIndex
 
QString toSvg (bool prependStyles=false, bool stripTextMode=true)
 toSvg convert the shape to svg, will not include style definitions.
 
QTransform transformation () const
 transformation the 2D transformation matrix of the shape.
 
virtual QString type () const
 type
 
void update ()
 update queue the shape update.
 
void updateAbsolute (QRectF box)
 updateAbsolute queue the shape update in the specified rectangle.
 
bool visible () const
 visible
 
int zIndex () const
 zIndex
 

Public Member Functions

bool operator!= (const Shape &other) const
 
bool operator== (const Shape &other) const
 
 Shape (KoShape *shape, QObject *parent=0)
 
 ~Shape ()
 

Private Member Functions

KoShapeshape ()
 

Private Attributes

Private *const d
 

Friends

class GroupShape
 
class VectorLayer
 

Detailed Description

The Shape class The shape class is a wrapper around Krita's vector objects.

Some example code to parse through interesting information in a given vector layer with shapes.

import sys
from krita import *
doc = Application.activeDocument()
root = doc.rootNode()
for layer in root.childNodes():
print (str(layer.type())+" "+str(layer.name()))
if (str(layer.type())=="vectorlayer"):
for shape in layer.shapes():
print(shape.name())
print(shape.toSvg())
KoShape * shape()
Definition Shape.cpp:236
QString name() const
name
Definition Shape.cpp:53
QString toSvg(bool prependStyles=false, bool stripTextMode=true)
toSvg convert the shape to svg, will not include style definitions.
Definition Shape.cpp:172

Definition at line 37 of file Shape.h.

Constructor & Destructor Documentation

◆ Shape()

Shape::Shape ( KoShape * shape,
QObject * parent = 0 )
explicit

Definition at line 31 of file Shape.cpp.

32 : QObject(parent)
33 , d(new Private)
34{
35 d->shape = shape;
36}
Private *const d
Definition Shape.h:206
KoShape * shape
Definition Shape.cpp:28

References d, Shape::Private::shape, and shape().

◆ ~Shape()

Shape::~Shape ( )

Definition at line 38 of file Shape.cpp.

39{
40 delete d;
41}

References d.

Member Function Documentation

◆ absoluteTransformation

QTransform Shape::absoluteTransformation ( ) const
slot

transformation the 2D transformation matrix of the shape including all grandparent transforms.

Returns
the 2D transformation matrix.

Definition at line 133 of file Shape.cpp.

134{
135 return d->shape->absoluteTransformation();
136}
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), d, and Shape::Private::shape.

◆ boundingBox

QRectF Shape::boundingBox ( ) const
slot

boundingBox the bounding box of the shape in points

Returns
RectF containing the bounding box.

Definition at line 108 of file Shape.cpp.

109{
110 return d->shape->boundingRect();
111}
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335

References KoShape::boundingRect(), d, and Shape::Private::shape.

◆ deselect

void Shape::deselect ( )
slot

deselect deselects the shape.

Definition at line 203 of file Shape.cpp.

204{
205 if (!d->shape) return;
206
208 KoSelection *selection = activeView->canvasBase()->shapeManager()->selection();
209
210 selection->deselect(d->shape);
211}
KoShapeManager shapeManager
QPointer< KisView > activeView
static KisPart * instance()
Definition KisPart.cpp:131
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
KisCanvas2 * canvasBase() const
Definition KisView.cpp:427
void deselect(KoShape *shape)
KoSelection * selection

References KisMainWindow::activeView, KisView::canvasBase(), KisPart::currentMainwindow(), d, KoSelection::deselect(), KisPart::instance(), KoShapeManager::selection, Shape::Private::shape, and KisCanvas2::shapeManager.

◆ geometryProtected

bool Shape::geometryProtected ( ) const
slot

geometryProtected

Returns
whether the shape is protected from user changing the shape geometry.

Definition at line 88 of file Shape.cpp.

89{
90 return d->shape->isGeometryProtected();
91}
bool isGeometryProtected() const
Definition KoShape.cpp:1024

References d, KoShape::isGeometryProtected(), and Shape::Private::shape.

◆ isSelected

bool Shape::isSelected ( )
slot

isSelected

Returns
whether the shape is selected.

Definition at line 213 of file Shape.cpp.

214{
215 if (!d->shape) return false;
216
218 KoSelection *selection = activeView->canvasBase()->shapeManager()->selection();
219
220 return selection->isSelected(d->shape);
221}
bool isSelected(const KoShape *shape) const
return true if the shape is selected

References KisMainWindow::activeView, KisView::canvasBase(), KisPart::currentMainwindow(), d, KisPart::instance(), KoSelection::isSelected(), KoShapeManager::selection, Shape::Private::shape, and KisCanvas2::shapeManager.

◆ name

QString Shape::name ( ) const
slot

name

Returns
the name of the shape

Definition at line 53 of file Shape.cpp.

54{
55 return d->shape->name();
56}
QString name() const
Definition KoShape.cpp:1150

References d, KoShape::name(), and Shape::Private::shape.

◆ operator!=()

bool Shape::operator!= ( const Shape & other) const

Definition at line 48 of file Shape.cpp.

49{
50 return !(operator==(other));
51}
bool operator==(const Shape &other) const
Definition Shape.cpp:43

References operator==().

◆ operator==()

bool Shape::operator== ( const Shape & other) const

Definition at line 43 of file Shape.cpp.

44{
45 return (d->shape == other.d->shape);
46}

References d, and Shape::Private::shape.

◆ parentShape

Shape * Shape::parentShape ( ) const
slot

parentShape

Returns
the parent GroupShape of the current shape.

Definition at line 223 of file Shape.cpp.

224{
225 if (!d->shape) return 0;
226 if (!d->shape->parent()) return 0;
227
228 if (dynamic_cast<KoShapeGroup*>(d->shape->parent())) {
229 return new GroupShape(dynamic_cast<KoShapeGroup*>(d->shape->parent()));
230 } else {
231 return 0;
232 }
233}
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
friend class GroupShape
Definition Shape.h:202

References d, GroupShape, KoShape::parent(), and Shape::Private::shape.

◆ position

QPointF Shape::position ( ) const
slot

position the position of the shape in points.

Returns
the position of the shape in points.

Definition at line 113 of file Shape.cpp.

114{
115 return d->shape->position();
116}
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References d, KoShape::position(), and Shape::Private::shape.

◆ remove

bool Shape::remove ( )
slot

remove delete the shape.

Definition at line 148 of file Shape.cpp.

149{
150 if (!d->shape) return false;
151 if (!d->shape->parent()) return false;
152
153 bool removeStatus = false;
154 Document *document = Krita::instance()->activeDocument();
155
156 if (KisPart::instance()->viewCount(document->document()) > 0) {
157 for (QPointer<KisView> view : KisPart::instance()->views()) {
158 if (view && view->document() == document->document()) {
159 KisProcessingApplicator::runSingleCommandStroke(view->image(), view->canvasBase()->shapeController()->removeShape(d->shape));
160 view->image()->waitForDone();
161 removeStatus = true;
162 break;
163 }
164 }
165 }
166
167 delete document;
168
169 return removeStatus;
170}
PythonPluginManager * instance
static void runSingleCommandStroke(KisImageSP image, KUndo2Command *cmd, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
runSingleCommandStroke creates a stroke and runs cmd in it. The text() field of cmd is used as a titl...
Document * activeDocument() const
Definition Krita.cpp:104
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:390

References Krita::activeDocument(), d, Krita::instance(), KisPart::instance(), KoShape::parent(), KisProcessingApplicator::runSingleCommandStroke(), Shape::Private::shape, and KisPart::views.

◆ select

void Shape::select ( )
slot

select selects the shape.

Definition at line 193 of file Shape.cpp.

194{
195 if (!d->shape) return;
196
198 KoSelection *selection = activeView->canvasBase()->shapeManager()->selection();
199
200 selection->select(d->shape);
201}
void select(KoShape *shape)

References KisMainWindow::activeView, KisView::canvasBase(), KisPart::currentMainwindow(), d, KisPart::instance(), KoSelection::select(), KoShapeManager::selection, Shape::Private::shape, and KisCanvas2::shapeManager.

◆ selectable

bool Shape::selectable ( ) const
slot

selectable

Returns
whether the shape is user selectable.

Definition at line 78 of file Shape.cpp.

79{
80 return d->shape->isSelectable();
81}
bool isSelectable() const
Definition KoShape.cpp:1014

References d, KoShape::isSelectable(), and Shape::Private::shape.

◆ setGeometryProtected

void Shape::setGeometryProtected ( bool protect)
slot

setGeometryProtected

Parameters
protectwhether the shape should be geometry protected from the user.

Definition at line 93 of file Shape.cpp.

94{
95 d->shape->setGeometryProtected(protect);
96}
void setGeometryProtected(bool on)
Definition KoShape.cpp:1019

References d, KoShape::setGeometryProtected(), and Shape::Private::shape.

◆ setName

void Shape::setName ( const QString & name)
slot

setName

Parameters
namewhich name the shape should have.

Definition at line 58 of file Shape.cpp.

59{
61}
void setName(const QString &name)
Definition KoShape.cpp:1155

References d, name(), KoShape::setName(), and Shape::Private::shape.

◆ setPosition

void Shape::setPosition ( QPointF point)
slot

setPosition set the position of the shape.

Parameters
pointthe new position in points

Definition at line 118 of file Shape.cpp.

119{
120 d->shape->setPosition(point);
121}
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295

References d, KoShape::setPosition(), and Shape::Private::shape.

◆ setSelectable

void Shape::setSelectable ( bool selectable)
slot

setSelectable

Parameters
selectablewhether the shape should be user selectable.

Definition at line 83 of file Shape.cpp.

84{
86}
void setSelectable(bool selectable)
Definition KoShape.cpp:1009
bool selectable() const
selectable
Definition Shape.cpp:78

References d, selectable(), KoShape::setSelectable(), and Shape::Private::shape.

◆ setTransformation

void Shape::setTransformation ( QTransform matrix)
slot

setTransformation set the 2D transformation matrix of the shape.

Parameters
matrixthe new 2D transformation matrix.

Definition at line 128 of file Shape.cpp.

129{
130 d->shape->setTransformation(matrix);
131}
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:417

References d, KoShape::setTransformation(), and Shape::Private::shape.

◆ setVisible

void Shape::setVisible ( bool visible)
slot

setVisible

Parameters
visiblewhether the shape should be visible.

Definition at line 103 of file Shape.cpp.

104{
106}
void setVisible(bool on)
Definition KoShape.cpp:972
bool visible() const
visible
Definition Shape.cpp:98

References d, KoShape::setVisible(), Shape::Private::shape, and visible().

◆ setZIndex

void Shape::setZIndex ( int zindex)
slot

setZIndex

Parameters
zindexset the shape zindex value.

Definition at line 73 of file Shape.cpp.

74{
75 d->shape->setZIndex(zindex);
76}
void setZIndex(qint16 zIndex)
Definition KoShape.cpp:954

References d, KoShape::setZIndex(), and Shape::Private::shape.

◆ shape()

KoShape * Shape::shape ( )
private

Definition at line 236 of file Shape.cpp.

237{
238 return d->shape;
239}

References d, and Shape::Private::shape.

◆ toSvg

QString Shape::toSvg ( bool prependStyles = false,
bool stripTextMode = true )
slot

toSvg convert the shape to svg, will not include style definitions.

Parameters
prependStylesprepend the style data. Default: false
stripTextModeenable strip text mode. Default: true
Returns
the svg in a string.

Definition at line 172 of file Shape.cpp.

173{
174 QBuffer shapesBuffer;
175 QBuffer stylesBuffer;
176
177 shapesBuffer.open(QIODevice::WriteOnly);
178 stylesBuffer.open(QIODevice::WriteOnly);
179
180 {
181 SvgSavingContext savingContext(shapesBuffer, stylesBuffer);
182 savingContext.setStrippedTextMode(stripTextMode);
183 SvgWriter writer({d->shape});
184 writer.saveDetached(savingContext);
185 }
186
187 shapesBuffer.close();
188 stylesBuffer.close();
189
190 return (prependStyles ? QString::fromUtf8(stylesBuffer.data()):"") + QString::fromUtf8(shapesBuffer.data());
191}
Context for saving svg files.
Implements exporting shapes to SVG.
Definition SvgWriter.h:33
bool saveDetached(QIODevice &outputDevice)

References d, SvgWriter::saveDetached(), SvgSavingContext::setStrippedTextMode(), and Shape::Private::shape.

◆ transformation

QTransform Shape::transformation ( ) const
slot

transformation the 2D transformation matrix of the shape.

Returns
the 2D transformation matrix.

Definition at line 123 of file Shape.cpp.

124{
125 return d->shape->transformation();
126}
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424

References d, Shape::Private::shape, and KoShape::transformation().

◆ type

QString Shape::type ( ) const
virtualslot

type

Returns
the type of shape.

Definition at line 63 of file Shape.cpp.

64{
65 return d->shape->shapeId();
66}
QString shapeId() const
Definition KoShape.cpp:1057

References d, Shape::Private::shape, and KoShape::shapeId().

◆ update

void Shape::update ( )
slot

update queue the shape update.

Definition at line 138 of file Shape.cpp.

139{
140 return d->shape->update();
141}
virtual void update() const
Definition KoShape.cpp:605

References d, Shape::Private::shape, and KoShape::update().

◆ updateAbsolute

void Shape::updateAbsolute ( QRectF box)
slot

updateAbsolute queue the shape update in the specified rectangle.

Parameters
boxthe RectF rectangle to update.

Definition at line 143 of file Shape.cpp.

144{
145 return d->shape->updateAbsolute(box);
146}
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616

References d, Shape::Private::shape, and KoShape::updateAbsolute().

◆ visible

bool Shape::visible ( ) const
slot

visible

Returns
whether the shape is visible.

Definition at line 98 of file Shape.cpp.

99{
100 return d->shape->isVisible();
101}
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979

References d, KoShape::isVisible(), and Shape::Private::shape.

◆ zIndex

int Shape::zIndex ( ) const
slot

zIndex

Returns
the zindex of the shape.

Definition at line 68 of file Shape.cpp.

69{
70 return d->shape->zIndex();
71}
qint16 zIndex() const
Definition KoShape.cpp:600

References d, Shape::Private::shape, and KoShape::zIndex().

Friends And Related Symbol Documentation

◆ GroupShape

friend class GroupShape
friend

Definition at line 202 of file Shape.h.

◆ VectorLayer

friend class VectorLayer
friend

Definition at line 203 of file Shape.h.

Member Data Documentation

◆ d

Private* const Shape::d
private

Definition at line 206 of file Shape.h.


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