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

#include <kis_shape_selection_model.h>

+ Inheritance diagram for KisShapeSelectionModel:

Public Member Functions

void add (KoShape *child) override
 
void childChanged (KoShape *child, KoShape::ChangeType type) override
 
void containerChanged (KoShapeContainer *, KoShape::ChangeType) override
 
int count () const override
 
bool inheritsTransform (const KoShape *shape) const override
 
bool isClipped (const KoShape *child) const override
 
 KisShapeSelectionModel (KisImageResolutionProxySP resolutionProxy, KisSelectionWSP selection, KisShapeSelection *shapeSelection)
 
void remove (KoShape *child) override
 
KisImageResolutionProxySP resolutionProxy () const
 
void setClipped (const KoShape *child, bool clipping) override
 
void setInheritsTransform (const KoShape *shape, bool inherit) override
 
void setResolutionProxy (KisImageResolutionProxySP newResolutionProxy)
 
void setShapeSelection (KisShapeSelection *selection)
 
void setUpdatesEnabled (bool enabled)
 
QList< KoShape * > shapes () const override
 
bool updatesEnabled () const
 
 ~KisShapeSelectionModel () override
 
- Public Member Functions inherited from KoShapeContainerModel
void deleteOwnedShapes ()
 
 KoShapeContainerModel ()
 default constructor
 
virtual void proposeMove (KoShape *shape, QPointF &move)
 
virtual void shapeHasBeenAddedToHierarchy (KoShape *shape, KoShapeContainer *addedToSubtree)
 
virtual void shapeToBeRemovedFromHierarchy (KoShape *shape, KoShapeContainer *removedFromSubtree)
 
virtual ~KoShapeContainerModel ()
 destructor
 

Private Slots

void requestUpdate (const QRect &updateRect)
 

Private Attributes

KisSelectionWSP m_parentSelection
 
KisImageResolutionProxySP m_resolutionProxy
 
QMap< KoShape *, QRectF > m_shapeMap
 
KisShapeSelectionm_shapeSelection
 
bool m_updatesEnabled
 

Additional Inherited Members

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

Detailed Description

Definition at line 22 of file kis_shape_selection_model.h.

Constructor & Destructor Documentation

◆ KisShapeSelectionModel()

KisShapeSelectionModel::KisShapeSelectionModel ( KisImageResolutionProxySP resolutionProxy,
KisSelectionWSP selection,
KisShapeSelection * shapeSelection )

Definition at line 20 of file kis_shape_selection_model.cpp.

22 , m_parentSelection(selection)
23 , m_shapeSelection(shapeSelection)
24 , m_updatesEnabled(true)
25{
26}
KisShapeSelection * m_shapeSelection
KisImageResolutionProxySP resolutionProxy() const
KisImageResolutionProxySP m_resolutionProxy

◆ ~KisShapeSelectionModel()

KisShapeSelectionModel::~KisShapeSelectionModel ( )
override

Definition at line 28 of file kis_shape_selection_model.cpp.

29{
31}

References m_parentSelection.

Member Function Documentation

◆ add()

void KisShapeSelectionModel::add ( KoShape * shape)
overridevirtual

Add a shape to this models store.

Parameters
shapethe shape to be managed in the container.

Implements KoShapeContainerModel.

Definition at line 58 of file kis_shape_selection_model.cpp.

59{
60 if (!m_shapeSelection) return;
61
62 if (m_shapeMap.contains(child))
63 return;
64
65 child->setStroke(KoShapeStrokeModelSP());
66 child->setBackground( QSharedPointer<KoShapeBackground>(0));
67 m_shapeMap.insert(child, child->boundingRect());
69
70 QRect updateRect = child->boundingRect().toAlignedRect();
71 QTransform matrix;
72 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
73 updateRect = matrix.mapRect(updateRect);
74
75 if (m_shapeMap.count() == 1) {
76 // The shape is the first one, so the shape selection just got created
77 // Pixel selection provides no longer the datamanager of the selection
78 // so update the whole selection
79 requestUpdate(QRect());
80 } else {
81 requestUpdate(updateRect);
82 }
83}
QSharedPointer< KoShapeStrokeModel > KoShapeStrokeModelSP
QMap< KoShape *, QRectF > m_shapeMap
void requestUpdate(const QRect &updateRect)
KoShapeManager * shapeManager() const
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)

References KoShapeManager::addShape(), KoShape::boundingRect(), m_resolutionProxy, m_shapeMap, m_shapeSelection, requestUpdate(), KoShape::setBackground(), KoShape::setStroke(), and KisShapeSelection::shapeManager().

◆ childChanged()

void KisShapeSelectionModel::childChanged ( KoShape * shape,
KoShape::ChangeType type )
overridevirtual

This method is called when one of the shape shapes has been modified. When a shape is rotated, moved or scaled/skewed this method will be called to inform the container of such a change. The change has already happened at the time this method is called. The base implementation notifies the grand parent of the shape that there was a change in a shape. A reimplementation if this function should call this method when overriding the function.

Parameters
shapethe shape that has been changed
typethis enum shows which change the shape has had.

Reimplemented from KoShapeContainerModel.

Definition at line 150 of file kis_shape_selection_model.cpp.

151{
152 if (!m_shapeSelection) return;
153
154 // TODO: check if still needed
155 if (type == KoShape::ParentChanged) return;
156
157 QRectF changedRect = m_shapeMap[child];
158 changedRect = changedRect.united(child->boundingRect());
159 m_shapeMap[child] = child->boundingRect();
160
161 QTransform matrix;
162 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
163 changedRect = matrix.mapRect(changedRect);
164
165 requestUpdate(changedRect.toAlignedRect());
166}
@ ParentChanged
used after a setParent()
Definition KoShape.h:103

References KoShape::boundingRect(), m_resolutionProxy, m_shapeMap, m_shapeSelection, KoShape::ParentChanged, and requestUpdate().

◆ containerChanged()

void KisShapeSelectionModel::containerChanged ( KoShapeContainer * container,
KoShape::ChangeType type )
overridevirtual

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 146 of file kis_shape_selection_model.cpp.

147{
148}

◆ count()

int KisShapeSelectionModel::count ( ) const
overridevirtual

Return the current number of children registered.

Returns
the current number of children registered.

Implements KoShapeContainerModel.

Definition at line 137 of file kis_shape_selection_model.cpp.

138{
139 return m_shapeMap.count();
140}

References m_shapeMap.

◆ inheritsTransform()

bool KisShapeSelectionModel::inheritsTransform ( const KoShape * shape) const
overridevirtual

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 131 of file kis_shape_selection_model.cpp.

132{
133 Q_UNUSED(shape);
134 return false;
135}

◆ isClipped()

bool KisShapeSelectionModel::isClipped ( const KoShape * shape) const
overridevirtual

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 119 of file kis_shape_selection_model.cpp.

120{
121 Q_UNUSED(child);
122 return false;
123}

◆ remove()

void KisShapeSelectionModel::remove ( KoShape * shape)
overridevirtual

Remove a shape to be completely separated from the model.

Parameters
shapethe shape to be removed.

Implements KoShapeContainerModel.

Definition at line 85 of file kis_shape_selection_model.cpp.

86{
87 if (!m_shapeMap.contains(child)) return;
88
89 QRect updateRect = child->boundingRect().toAlignedRect();
90 m_shapeMap.remove(child);
91
92 if (m_shapeSelection) {
94 }
95 QTransform matrix;
96 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
97 updateRect = matrix.mapRect(updateRect);
98 if (m_shapeSelection) { // No m_shapeSelection indicates the selection is being deleted
99 requestUpdate(updateRect);
100 }
101}
void remove(KoShape *shape)

References KoShape::boundingRect(), m_resolutionProxy, m_shapeMap, m_shapeSelection, KoShapeManager::remove(), requestUpdate(), and KisShapeSelection::shapeManager().

◆ requestUpdate

void KisShapeSelectionModel::requestUpdate ( const QRect & updateRect)
privateslot

◆ resolutionProxy()

KisImageResolutionProxySP KisShapeSelectionModel::resolutionProxy ( ) const

Definition at line 53 of file kis_shape_selection_model.cpp.

54{
55 return m_resolutionProxy;
56}

References m_resolutionProxy.

◆ setClipped()

void KisShapeSelectionModel::setClipped ( const KoShape * shape,
bool clipping )
overridevirtual

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 113 of file kis_shape_selection_model.cpp.

114{
115 Q_UNUSED(child);
116 Q_UNUSED(clipping);
117}

◆ setInheritsTransform()

void KisShapeSelectionModel::setInheritsTransform ( const KoShape * shape,
bool inherit )
overridevirtual

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 125 of file kis_shape_selection_model.cpp.

126{
127 Q_UNUSED(shape);
128 Q_UNUSED(inherit);
129}

◆ setResolutionProxy()

void KisShapeSelectionModel::setResolutionProxy ( KisImageResolutionProxySP newResolutionProxy)

Definition at line 42 of file kis_shape_selection_model.cpp.

43{
44 const bool resolutionChanged = !m_resolutionProxy->compareResolution(*newResolutionProxy);
45
46 m_resolutionProxy = newResolutionProxy;
47
48 if (resolutionChanged) {
49 requestUpdate(QRect());
50 }
51}

References m_resolutionProxy, and requestUpdate().

◆ setShapeSelection()

void KisShapeSelectionModel::setShapeSelection ( KisShapeSelection * selection)

Definition at line 168 of file kis_shape_selection_model.cpp.

169{
170 m_shapeSelection = selection;
171}

References m_shapeSelection.

◆ setUpdatesEnabled()

void KisShapeSelectionModel::setUpdatesEnabled ( bool enabled)

Definition at line 103 of file kis_shape_selection_model.cpp.

104{
105 m_updatesEnabled = enabled;
106}

References m_updatesEnabled.

◆ shapes()

QList< KoShape * > KisShapeSelectionModel::shapes ( ) const
overridevirtual

Return the list of all shapes of this model

Returns
the list of all shapes

Implements KoShapeContainerModel.

Definition at line 142 of file kis_shape_selection_model.cpp.

143{
144 return QList<KoShape*>(m_shapeMap.keys());
145}

References m_shapeMap.

◆ updatesEnabled()

bool KisShapeSelectionModel::updatesEnabled ( ) const

Definition at line 108 of file kis_shape_selection_model.cpp.

109{
110 return m_updatesEnabled;
111}

References m_updatesEnabled.

Member Data Documentation

◆ m_parentSelection

KisSelectionWSP KisShapeSelectionModel::m_parentSelection
private

Definition at line 56 of file kis_shape_selection_model.h.

◆ m_resolutionProxy

KisImageResolutionProxySP KisShapeSelectionModel::m_resolutionProxy
private

Definition at line 55 of file kis_shape_selection_model.h.

◆ m_shapeMap

QMap<KoShape*, QRectF> KisShapeSelectionModel::m_shapeMap
private

Definition at line 54 of file kis_shape_selection_model.h.

◆ m_shapeSelection

KisShapeSelection* KisShapeSelectionModel::m_shapeSelection
private

Definition at line 57 of file kis_shape_selection_model.h.

◆ m_updatesEnabled

bool KisShapeSelectionModel::m_updatesEnabled
private

Definition at line 59 of file kis_shape_selection_model.h.


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