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

#include <KoShapeGroup.h>

+ Inheritance diagram for KoShapeGroup:

Classes

class  Private
 

Public Member Functions

QRectF boundingRect () const override
 a group's boundingRect
 
KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
bool hitTest (const QPointF &position) const override
 always returns false since the group itself can't be selected or hit
 
 KoShapeGroup ()
 Constructor.
 
QRectF outlineRect () const override
 
void paintComponent (QPainter &painter) const override
 This implementation is empty since a group is itself not visible.
 
void setSize (const QSizeF &size) override
 Resize the shape.
 
QSizeF size () const override
 Get the size of the shape in pt.
 
 ~KoShapeGroup () override
 destructor
 
- Public Member Functions inherited from KoShapeContainer
void addShape (KoShape *shape)
 
bool inheritsTransform (const KoShape *shape) const
 
bool isClipped (const KoShape *child) const
 
 KoShapeContainer (KoShapeContainerModel *model=0)
 
KoShapeContainerModelmodel () const
 
void paint (QPainter &painter) const override
 reimplemented
 
 Private (const Private &rhs, KoShapeContainer *q)
 
 Private (KoShapeContainer *q)
 
void removeShape (KoShape *shape)
 
void setClipped (const KoShape *child, bool clipping)
 
void setInheritsTransform (const KoShape *shape, bool inherit)
 
int shapeCount () const
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 
virtual void update () const
 
void update () const override
 reimplemented
 
 ~KoShapeContainer () override
 
virtual ~Private ()
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
KoFilterEffectStackfilterEffectStack () const
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual QPainterPath outline () const
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
int runThrough () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
virtual void setRunThrough (short int runThrough)
 
void setSelectable (bool selectable)
 
void setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 

Private Member Functions

void invalidateSizeCache ()
 Invalidate the size cache of the group.
 
 KoShapeGroup (const KoShapeGroup &rhs)
 
void shapeChanged (ChangeType type, KoShape *shape=0) override
 
void tryUpdateCachedSize () const
 

Private Attributes

QScopedPointer< Privated
 

Friends

class ShapeGroupContainerModel
 

Additional Inherited Members

- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  ChildChanged , ConnectionPointChanged , ClipPathChanged , ClipMaskChanged ,
  TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 
- Public Attributes inherited from KoShapeContainer
KoShapeContainerModelmodel
 
KoShapeContainer::ShapeInterface shapeInterface
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 
- Protected Member Functions inherited from KoShapeContainer
 KoShapeContainer (const KoShapeContainer &rhs)
 
void setModel (KoShapeContainerModel *model)
 
void setModelInit (KoShapeContainerModel *model)
 
virtual void shapeCountChanged ()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Detailed Description

Provide grouping for shapes. The group shape allows you to add children which will then be grouped in selections and actions.

If you have a set of shapes that together make up a bigger shape it is often useful to group them together so the user will perceive the different shapes as actually being one. This means that if the user clicks on one shape, all shapes in the group will be selected at once, making the tools that works on selections alter all of them at the same time.

Note that while this object is also a shape, it is not actually visible and the user can't interact with it.

WARNING: this class is NOT threadsafe, it caches the size in an unsafe way

Definition at line 34 of file KoShapeGroup.h.

Constructor & Destructor Documentation

◆ KoShapeGroup() [1/2]

KoShapeGroup::KoShapeGroup ( )

Constructor.

Definition at line 88 of file KoShapeGroup.cpp.

90 , d(new Private)
91{
93}
void setModelInit(KoShapeContainerModel *model)
KoShapeContainer(KoShapeContainerModel *model=0)
QScopedPointer< Private > d
friend class ShapeGroupContainerModel

References KoShapeContainer::setModelInit(), and ShapeGroupContainerModel.

◆ ~KoShapeGroup()

KoShapeGroup::~KoShapeGroup ( )
override

destructor

HACK alert: model will use KoShapeGroup::invalidateSizeCache(), which uses KoShapeGroup's d-pointer. We have to manually remove child shapes from the model in the destructor of KoShapeGroup as the instance d is no longer accessible since ~KoShapeGroup() is executed

Definition at line 104 of file KoShapeGroup.cpp.

105{
113}
KoShapeContainerModel * model

References KoShapeContainerModel::deleteOwnedShapes(), and KoShapeContainer::model.

◆ KoShapeGroup() [2/2]

KoShapeGroup::KoShapeGroup ( const KoShapeGroup & rhs)
private

Definition at line 95 of file KoShapeGroup.cpp.

96 : KoShapeContainer(rhs)
97 , d(new Private(*rhs.d))
98{
99 ShapeGroupContainerModel *otherModel = dynamic_cast<ShapeGroupContainerModel*>(rhs.model());
100 KIS_ASSERT_RECOVER_RETURN(otherModel);
101 setModelInit(new ShapeGroupContainerModel(*otherModel, this));
102}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KIS_ASSERT_RECOVER_RETURN, KoShapeContainer::model, KoShapeContainer::setModelInit(), and ShapeGroupContainerModel.

Member Function Documentation

◆ boundingRect()

QRectF KoShapeGroup::boundingRect ( ) const
overridevirtual

a group's boundingRect

Reimplemented from KoShape.

Definition at line 169 of file KoShapeGroup.cpp.

170{
171 QRectF groupBound = KoShape::boundingRect(shapes());
172
173 if (shadow()) {
174 KoInsets insets;
175 shadow()->insets(insets);
176 groupBound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
177 }
178 return groupBound;
179}
QList< KoShape * > shapes() const
void insets(KoInsets &insets) const
Fills the insets object with the space the shadow takes around a shape.
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
Definition KoShape.cpp:1116
qreal bottom
Bottom inset.
Definition KoInsets.h:50
qreal right
Right inset.
Definition KoInsets.h:52
qreal top
Top inset.
Definition KoInsets.h:49
qreal left
Left inset.
Definition KoInsets.h:51

References KoInsets::bottom, KoShape::boundingRect(), KoShapeShadow::insets(), KoInsets::left, KoInsets::right, KoShape::shadow(), KoShapeContainer::shapes(), and KoInsets::top.

◆ cloneShape()

KoShape * KoShapeGroup::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 115 of file KoShapeGroup.cpp.

116{
117 return new KoShapeGroup(*this);
118}
KoShapeGroup()
Constructor.

References KoShapeGroup().

◆ hitTest()

bool KoShapeGroup::hitTest ( const QPointF & position) const
overridevirtual

always returns false since the group itself can't be selected or hit

Reimplemented from KoShape.

Definition at line 125 of file KoShapeGroup.cpp.

126{
127 Q_UNUSED(position);
128 return false;
129}
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References KoShape::position().

◆ invalidateSizeCache()

void KoShapeGroup::invalidateSizeCache ( )
private

Invalidate the size cache of the group.

The group shape caches the size of itself as it can be quite expensive to recalculate the size if there are a lot of subshapes. This function is called when the cache needs to be invalidated.

Definition at line 195 of file KoShapeGroup.cpp.

196{
197 d->sizeCached = false;
198}

References d.

◆ outlineRect()

QRectF KoShapeGroup::outlineRect ( ) const
overridevirtual

returns the outline of the shape in the form of a rect. The outlineRect returned will always be relative to the position() of the shape, so moving the shape will not alter the result. The outline is used to calculate the boundingRect.

Returns
the outline of the shape in the form of a rect.

Reimplemented from KoShape.

Definition at line 163 of file KoShapeGroup.cpp.

164{
166 return d->savedOutlineRect;
167}
void tryUpdateCachedSize() const

References d, and tryUpdateCachedSize().

◆ paintComponent()

void KoShapeGroup::paintComponent ( QPainter & painter) const
overridevirtual

This implementation is empty since a group is itself not visible.

Implements KoShapeContainer.

Definition at line 120 of file KoShapeGroup.cpp.

121{
122 Q_UNUSED(painter);
123}

◆ setSize()

void KoShapeGroup::setSize ( const QSizeF & size)
overridevirtual

Resize the shape.

Parameters
sizethe new size of the shape. This is different from scaling as scaling is a so called secondary operation which is comparable to zooming in instead of changing the size of the basic shape. Easiest example of this difference is that using this method will not distort the size of pattern-fills and strokes.

Reimplemented from KoShape.

Definition at line 150 of file KoShapeGroup.cpp.

151{
152 QSizeF oldSize = this->size();
153 if (!shapeCount() || oldSize.isNull()) return;
154
155 const QTransform scale =
156 QTransform::fromScale(size.width() / oldSize.width(), size.height() / oldSize.height());
157
159
161}
QSizeF size() const override
Get the size of the shape in pt.
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:417
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:237
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:276

References KoShape::scale(), KoShape::setSize(), KoShape::setTransformation(), KoShapeContainer::shapeCount(), size(), and KoShape::transformation().

◆ shapeChanged()

void KoShapeGroup::shapeChanged ( ChangeType type,
KoShape * shape = 0 )
overrideprivatevirtual

A hook that allows inheriting classes to do something after a KoShape property changed This is called whenever the shape, position rotation or scale properties were altered.

Parameters
typean indicator which type was changed.
shapethe shape.

Reimplemented from KoShapeContainer.

Definition at line 181 of file KoShapeGroup.cpp.

182{
183 Q_UNUSED(shape);
185 switch (type) {
187 break;
188 default:
189 break;
190 }
191
193}
void shapeChanged(ChangeType type, KoShape *shape=0) override
void invalidateSizeCache()
Invalidate the size cache of the group.
@ StrokeChanged
the shapes stroke has changed
Definition KoShape.h:105

References invalidateSizeCache(), KoShapeContainer::shapeChanged(), and KoShape::StrokeChanged.

◆ size()

QSizeF KoShapeGroup::size ( ) const
overridevirtual

Get the size of the shape in pt.

The size is in shape coordinates.

Returns
the size of the shape as set by setSize()

Reimplemented from KoShape.

Definition at line 144 of file KoShapeGroup.cpp.

145{
147 return KoShape::size();
148}
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:820

References KoShape::size(), and tryUpdateCachedSize().

◆ tryUpdateCachedSize()

void KoShapeGroup::tryUpdateCachedSize ( ) const
private

Definition at line 131 of file KoShapeGroup.cpp.

132{
133 if (!d->sizeCached) {
134 QRectF bound;
135 Q_FOREACH (KoShape *shape, shapes()) {
136 bound |= shape->transformation().mapRect(shape->outlineRect());
137 }
138 d->savedOutlineRect = bound;
139 KoShape::setSizeImpl(bound.size());
140 d->sizeCached = true;
141 }
142}
virtual QRectF outlineRect() const
Definition KoShape.cpp:637
void setSizeImpl(const QSizeF &size) const
Definition KoShape.cpp:290

References d, KoShape::outlineRect(), KoShape::setSizeImpl(), KoShapeContainer::shapes(), and KoShape::transformation().

Friends And Related Symbol Documentation

◆ ShapeGroupContainerModel

friend class ShapeGroupContainerModel
friend

Definition at line 55 of file KoShapeGroup.h.

Member Data Documentation

◆ d

QScopedPointer<Private> KoShapeGroup::d
private

Definition at line 75 of file KoShapeGroup.h.


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