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

#include <SimpleShapeContainerModel.h>

+ Inheritance diagram for SimpleShapeContainerModel:

Public Member Functions

void add (KoShape *child) override
 
KoShapeManagerassociatedRootShapeManager () const
 
void containerChanged (KoShapeContainer *, KoShape::ChangeType) override
 
int count () const override
 
bool inheritsTransform (const KoShape *shape) const override
 
bool isClipped (const KoShape *shape) const override
 
void proposeMove (KoShape *shape, QPointF &move) override
 
void remove (KoShape *shape) override
 
void setAssociatedRootShapeManager (KoShapeManager *manager)
 
void setClipped (const KoShape *shape, bool value) override
 
void setInheritsTransform (const KoShape *shape, bool value) override
 
void shapeHasBeenAddedToHierarchy (KoShape *shape, KoShapeContainer *addedToSubtree) override
 
QList< KoShape * > shapes () const override
 
void shapeToBeRemovedFromHierarchy (KoShape *shape, KoShapeContainer *removedFromSubtree) override
 
 SimpleShapeContainerModel ()
 
 SimpleShapeContainerModel (const SimpleShapeContainerModel &rhs)
 
 ~SimpleShapeContainerModel () override
 
- Public Member Functions inherited from KoShapeContainerModel
virtual void childChanged (KoShape *shape, KoShape::ChangeType type)
 
void deleteOwnedShapes ()
 
 KoShapeContainerModel ()
 default constructor
 
virtual ~KoShapeContainerModel ()
 destructor
 

Private Member Functions

int indexOf (const KoShape *shape) const
 

Private Attributes

KoShapeManagerm_associatedRootShapeManager = 0
 
QList< bool > m_clipped
 
QList< bool > m_inheritsTransform
 
QList< KoShape * > m_members
 

Additional Inherited Members

- Protected Member Functions inherited from KoShapeContainerModel
 KoShapeContainerModel (const KoShapeContainerModel &rhs)
 

Detailed Description

Definition at line 15 of file SimpleShapeContainerModel.h.

Constructor & Destructor Documentation

◆ SimpleShapeContainerModel() [1/2]

SimpleShapeContainerModel::SimpleShapeContainerModel ( )
inline

Definition at line 18 of file SimpleShapeContainerModel.h.

18{}

◆ ~SimpleShapeContainerModel()

SimpleShapeContainerModel::~SimpleShapeContainerModel ( )
inlineoverride

Definition at line 19 of file SimpleShapeContainerModel.h.

19{}

◆ SimpleShapeContainerModel() [2/2]

SimpleShapeContainerModel::SimpleShapeContainerModel ( const SimpleShapeContainerModel & rhs)
inline

Definition at line 21 of file SimpleShapeContainerModel.h.

25 {
26 Q_FOREACH (KoShape *shape, rhs.m_members) {
27 KoShape *clone = shape->cloneShape();
28 KIS_SAFE_ASSERT_RECOVER_NOOP(clone && "Copying this shape is not implemented!");
29 if (clone) {
30 m_members << clone;
31 }
32 }
33
35 m_members.size() == m_clipped.size())
36 {
37 qDeleteAll(m_members);
38 m_members.clear();
39 m_inheritsTransform.clear();
40 m_clipped.clear();
41 }
42 }
KoShapeContainerModel()
default constructor
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KoShape::cloneShape(), KIS_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, m_clipped, m_inheritsTransform, and m_members.

Member Function Documentation

◆ add()

void SimpleShapeContainerModel::add ( KoShape * shape)
inlineoverridevirtual

Add a shape to this models store.

Parameters
shapethe shape to be managed in the container.

Implements KoShapeContainerModel.

Definition at line 44 of file SimpleShapeContainerModel.h.

44 {
45 if (m_members.contains(child))
46 return;
47 m_members.append(child);
48 m_clipped.append(false);
49 m_inheritsTransform.append(true);
50 }

References m_clipped, m_inheritsTransform, and m_members.

◆ associatedRootShapeManager()

KoShapeManager * SimpleShapeContainerModel::associatedRootShapeManager ( ) const
inline

Definition at line 116 of file SimpleShapeContainerModel.h.

116 {
118 }

References m_associatedRootShapeManager.

◆ containerChanged()

void SimpleShapeContainerModel::containerChanged ( KoShapeContainer * container,
KoShape::ChangeType type )
inlineoverridevirtual

This method is called as a notification that one of the properties of the container changed. This can be one of size, position, rotation and skew. Note that clipped children will automatically get all these changes, the model does not have to do anything for that.

Parameters
containerthe actual container that changed.
typethis enum shows which change the container has had.

Implements KoShapeContainerModel.

Definition at line 75 of file SimpleShapeContainerModel.h.

75{ }

◆ count()

int SimpleShapeContainerModel::count ( ) const
inlineoverridevirtual

Return the current number of children registered.

Returns
the current number of children registered.

Implements KoShapeContainerModel.

Definition at line 69 of file SimpleShapeContainerModel.h.

69 {
70 return m_members.count();
71 }

References m_members.

◆ indexOf()

int SimpleShapeContainerModel::indexOf ( const KoShape * shape) const
inlineprivate

Definition at line 142 of file SimpleShapeContainerModel.h.

142 {
143 // workaround indexOf constness!
144 return m_members.indexOf(const_cast<KoShape*>(shape));
145 }

References m_members.

◆ inheritsTransform()

bool SimpleShapeContainerModel::inheritsTransform ( const KoShape * shape) const
inlineoverridevirtual

Returns if the shape inherits the container transform.

A shape that inherits the transform of the parent container will have its share / rotation / skew etc be calculated as being the product of both its own local transformation and also that of its parent container. If you set this to true and rotate the container, the shape will get that rotation as well automatically.

Returns
if the argument shape has its 'inherits transform' property set.
Parameters
shapethe shape for which the property will be returned.

Implements KoShapeContainerModel.

Definition at line 82 of file SimpleShapeContainerModel.h.

82 {
83 const int index = indexOf(shape);
84 KIS_SAFE_ASSERT_RECOVER(index >= 0) { return true;}
85 return m_inheritsTransform[index];
86 }
int indexOf(const KoShape *shape) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References indexOf(), KIS_SAFE_ASSERT_RECOVER, and m_inheritsTransform.

◆ isClipped()

bool SimpleShapeContainerModel::isClipped ( const KoShape * shape) const
inlineoverridevirtual

Returns if the argument shape has its 'clipping' property set.

A shape that is clipped by the container will have its visible portion limited to the area where it intersects with the container. If a shape is positioned or sized such that it would be painted outside of the KoShape::outline() of its parent container, setting this property to true will clip the shape painting to the container outline.

Returns
if the argument shape has its 'clipping' property set.
Parameters
shapethe shape for which the property will be returned.

Implements KoShapeContainerModel.

Definition at line 56 of file SimpleShapeContainerModel.h.

56 {
57 const int index = indexOf(shape);
58 KIS_SAFE_ASSERT_RECOVER(index >= 0) { return false;}
59 return m_clipped[index];
60 }

References indexOf(), KIS_SAFE_ASSERT_RECOVER, and m_clipped.

◆ proposeMove()

void SimpleShapeContainerModel::proposeMove ( KoShape * shape,
QPointF & move )
inlineoverridevirtual

This method is called when the user tries to move a shape that is a shape of the container this model represents. The shape itself is not yet moved; it is proposed to be moved over the param move distance. You can alter the value of the move to affect the actual distance moved. The default implementation does nothing.

Parameters
shapethe shape of this container that the user is trying to move.
movethe distance that the user proposes to move shape from the current position.

Reimplemented from KoShapeContainerModel.

Definition at line 88 of file SimpleShapeContainerModel.h.

89 {
90 KoShapeContainer *parent = shape->parent();
91 bool allowedToMove = true;
92 while (allowedToMove && parent) {
93 allowedToMove = parent->isShapeEditable();
94 parent = parent->parent();
95 }
96 if (! allowedToMove) {
97 move.setX(0);
98 move.setY(0);
99 }
100 }
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KoShape::parent().

◆ remove()

void SimpleShapeContainerModel::remove ( KoShape * shape)
inlineoverridevirtual

Remove a shape to be completely separated from the model.

Parameters
shapethe shape to be removed.

Implements KoShapeContainerModel.

Definition at line 61 of file SimpleShapeContainerModel.h.

61 {
62 const int index = indexOf(shape);
64
65 m_members.removeAt(index);
66 m_clipped.removeAt(index);
67 m_inheritsTransform.removeAt(index);
68 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References indexOf(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_clipped, m_inheritsTransform, and m_members.

◆ setAssociatedRootShapeManager()

void SimpleShapeContainerModel::setAssociatedRootShapeManager ( KoShapeManager * manager)
inline

If the container is the root of shapes hierarchy, it should also track the content of the shape manager. Add all added/removed shapes should be also added to shapeManager.

Definition at line 125 of file SimpleShapeContainerModel.h.

125 {
127 Q_FOREACH(KoShape *shape, this->shapes()) {
129 }
130 }
131
133
135 Q_FOREACH(KoShape *shape, this->shapes()) {
137 }
138 }
139 }
void remove(KoShape *shape)
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
QList< KoShape * > shapes() const override

References KoShapeManager::addShape(), m_associatedRootShapeManager, KoShapeManager::remove(), and shapes().

◆ setClipped()

void SimpleShapeContainerModel::setClipped ( const KoShape * shape,
bool clipping )
inlineoverridevirtual

Set the argument shape to have its 'clipping' property set.

A shape that is clipped by the container will have its visible portion limited to the area where it intersects with the container. If a shape is positioned or sized such that it would be painted outside of the KoShape::outline() of its parent container, setting this property to true will clip the shape painting to the container outline.

Parameters
shapethe shape for which the property will be changed.
clippingthe new value

Implements KoShapeContainerModel.

Definition at line 51 of file SimpleShapeContainerModel.h.

51 {
52 const int index = indexOf(shape);
54 m_clipped[index] = value;
55 }
float value(const T *src, size_t ch)

References indexOf(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_clipped, and value().

◆ setInheritsTransform()

void SimpleShapeContainerModel::setInheritsTransform ( const KoShape * shape,
bool inherit )
inlineoverridevirtual

Set the shape to inherit the container transform.

A shape that inherits the transform of the parent container will have its share / rotation / skew etc be calculated as being the product of both its own local transformation and also that of its parent container. If you set this to true and rotate the container, the shape will get that rotation as well automatically.

Parameters
shapethe shape for which the property will be changed.
inheritthe new value

Implements KoShapeContainerModel.

Definition at line 77 of file SimpleShapeContainerModel.h.

77 {
78 const int index = indexOf(shape);
81 }

References indexOf(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_inheritsTransform, and value().

◆ shapeHasBeenAddedToHierarchy()

void SimpleShapeContainerModel::shapeHasBeenAddedToHierarchy ( KoShape * shape,
KoShapeContainer * addedToSubtree )
inlineoverridevirtual

Reimplemented from KoShapeContainerModel.

Definition at line 102 of file SimpleShapeContainerModel.h.

102 {
105 }
107 }
virtual void shapeHasBeenAddedToHierarchy(KoShape *shape, KoShapeContainer *addedToSubtree)

References KoShapeManager::addShape(), m_associatedRootShapeManager, and KoShapeContainerModel::shapeHasBeenAddedToHierarchy().

◆ shapes()

QList< KoShape * > SimpleShapeContainerModel::shapes ( ) const
inlineoverridevirtual

Return the list of all shapes of this model

Returns
the list of all shapes

Implements KoShapeContainerModel.

Definition at line 72 of file SimpleShapeContainerModel.h.

72 {
74 }

References m_members.

◆ shapeToBeRemovedFromHierarchy()

void SimpleShapeContainerModel::shapeToBeRemovedFromHierarchy ( KoShape * shape,
KoShapeContainer * removedFromSubtree )
inlineoverridevirtual

Reimplemented from KoShapeContainerModel.

Definition at line 109 of file SimpleShapeContainerModel.h.

109 {
112 }
114 }
virtual void shapeToBeRemovedFromHierarchy(KoShape *shape, KoShapeContainer *removedFromSubtree)

References m_associatedRootShapeManager, KoShapeManager::remove(), and KoShapeContainerModel::shapeToBeRemovedFromHierarchy().

Member Data Documentation

◆ m_associatedRootShapeManager

KoShapeManager* SimpleShapeContainerModel::m_associatedRootShapeManager = 0
private

Definition at line 151 of file SimpleShapeContainerModel.h.

◆ m_clipped

QList<bool> SimpleShapeContainerModel::m_clipped
private

Definition at line 150 of file SimpleShapeContainerModel.h.

◆ m_inheritsTransform

QList<bool> SimpleShapeContainerModel::m_inheritsTransform
private

Definition at line 149 of file SimpleShapeContainerModel.h.

◆ m_members

QList<KoShape *> SimpleShapeContainerModel::m_members
private

Definition at line 148 of file SimpleShapeContainerModel.h.


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