Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeContainer::ShapeInterface Struct Reference

#include <KoShapeContainer.h>

Public Member Functions

void addShape (KoShape *shape)
 
void removeShape (KoShape *shape)
 
 ShapeInterface (KoShapeContainer *_q)
 

Protected Attributes

KoShapeContainerq
 

Detailed Description

A special interface for KoShape to use during setParent call. Don't use these method directly for managing shapes hierarchy! Use shape->setParent() instead.

Definition at line 202 of file KoShapeContainer.h.

Constructor & Destructor Documentation

◆ ShapeInterface()

KoShapeContainer::ShapeInterface::ShapeInterface ( KoShapeContainer * _q)

Definition at line 175 of file KoShapeContainer.cpp.

176 : q(_q)
177{
178}

Member Function Documentation

◆ addShape()

void KoShapeContainer::ShapeInterface::addShape ( KoShape * shape)

Add a child to this container.

This container will NOT take over ownership of the shape. The caller or those creating the shape is responsible to delete it if not needed any longer.

Parameters
shapethe child to be managed in the container.

Definition at line 180 of file KoShapeContainer.cpp.

181{
182 KoShapeContainer::Private * const d = q->d.data();
183
185
186 if (shape->parent() == q && q->shapes().contains(shape)) {
187 return;
188 }
189
190 // TODO add a method to create a default model depending on the shape container
191 if (!d->model) {
192 d->model = new SimpleShapeContainerModel();
193 }
194
195 if (shape->parent() && shape->parent() != q) {
196 shape->parent()->shapeInterface()->removeShape(shape);
197 }
198
199 d->model->add(shape);
200 d->model->shapeHasBeenAddedToHierarchy(shape, q);
201}
KoShapeContainer::ShapeInterface shapeInterface
QList< KoShape * > shapes() const
QScopedPointer< Private > d
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KoShapeContainer::d, KIS_SAFE_ASSERT_RECOVER_RETURN, KoShape::parent(), removeShape(), KoShapeContainer::shapeInterface, and KoShapeContainer::shapes().

◆ removeShape()

void KoShapeContainer::ShapeInterface::removeShape ( KoShape * shape)

Remove a child to be completely separated from the container.

The shape will only be removed from this container but not be deleted.

Parameters
shapethe child to be removed.

Definition at line 203 of file KoShapeContainer.cpp.

204{
205 KoShapeContainer::Private * const d = q->d.data();
206
209 KIS_SAFE_ASSERT_RECOVER_RETURN(d->model->shapes().contains(shape));
210
211 d->model->shapeToBeRemovedFromHierarchy(shape, q);
212 d->model->remove(shape);
213
214 KoShapeContainer *grandparent = q->parent();
215 if (grandparent) {
216 grandparent->model()->childChanged(q, KoShape::ChildChanged);
217 }
218}
virtual void childChanged(KoShape *shape, KoShape::ChangeType type)
KoShapeContainerModel * model
@ ChildChanged
a child of a container was changed/removed. This is propagated to all parents
Definition KoShape.h:112

References KoShape::ChildChanged, KoShapeContainerModel::childChanged(), KoShapeContainer::d, KIS_SAFE_ASSERT_RECOVER_RETURN, KoShapeContainer::model, and KoShape::parent().

Member Data Documentation

◆ q

KoShapeContainer* KoShapeContainer::ShapeInterface::q
protected

Definition at line 225 of file KoShapeContainer.h.


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