Krita Source Code Documentation
Loading...
Searching...
No Matches
SimpleShapeContainerModel.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006-2007, 2010 Thomas Zander <zander@kde.org>
3 * SPDX-FileCopyrightText: 2011 Boudewijn Rempt <boud@valdyas.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7#ifndef SIMPLESHAPECONTAINERMODEL_H
8#define SIMPLESHAPECONTAINERMODEL_H
9
11#include <kis_debug.h>
12#include <KoShapeManager.h>
13
16{
17public:
20
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 }
43
44 void add(KoShape *child) override {
45 if (m_members.contains(child))
46 return;
47 m_members.append(child);
48 m_clipped.append(false);
49 m_inheritsTransform.append(true);
50 }
51 void setClipped(const KoShape *shape, bool value) override {
52 const int index = indexOf(shape);
54 m_clipped[index] = value;
55 }
56 bool isClipped(const KoShape *shape) const override {
57 const int index = indexOf(shape);
58 KIS_SAFE_ASSERT_RECOVER(index >= 0) { return false;}
59 return m_clipped[index];
60 }
61 void remove(KoShape *shape) override {
62 const int index = indexOf(shape);
64
65 m_members.removeAt(index);
66 m_clipped.removeAt(index);
67 m_inheritsTransform.removeAt(index);
68 }
69 int count() const override {
70 return m_members.count();
71 }
72 QList<KoShape*> shapes() const override {
74 }
76
77 void setInheritsTransform(const KoShape *shape, bool value) override {
78 const int index = indexOf(shape);
81 }
82 bool inheritsTransform(const KoShape *shape) const override {
83 const int index = indexOf(shape);
84 KIS_SAFE_ASSERT_RECOVER(index >= 0) { return true;}
85 return m_inheritsTransform[index];
86 }
87
88 void proposeMove(KoShape *shape, QPointF &move) override
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 }
101
108
109 void shapeToBeRemovedFromHierarchy(KoShape *shape, KoShapeContainer *removedFromSubtree) override {
112 }
114 }
115
119
127 Q_FOREACH(KoShape *shape, this->shapes()) {
129 }
130 }
131
133
135 Q_FOREACH(KoShape *shape, this->shapes()) {
137 }
138 }
139 }
140
141private:
142 int indexOf(const KoShape *shape) const {
143 // workaround indexOf constness!
144 return m_members.indexOf(const_cast<KoShape*>(shape));
145 }
146
147private: // members
148 QList <KoShape *> m_members;
150 QList <bool> m_clipped;
152};
153
154#endif
float value(const T *src, size_t ch)
virtual void shapeToBeRemovedFromHierarchy(KoShape *shape, KoShapeContainer *removedFromSubtree)
virtual void shapeHasBeenAddedToHierarchy(KoShape *shape, KoShapeContainer *addedToSubtree)
void remove(KoShape *shape)
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
void proposeMove(KoShape *shape, QPointF &move) override
int indexOf(const KoShape *shape) const
bool isClipped(const KoShape *shape) const override
SimpleShapeContainerModel(const SimpleShapeContainerModel &rhs)
void shapeHasBeenAddedToHierarchy(KoShape *shape, KoShapeContainer *addedToSubtree) override
void setClipped(const KoShape *shape, bool value) override
void setAssociatedRootShapeManager(KoShapeManager *manager)
void add(KoShape *child) override
void containerChanged(KoShapeContainer *, KoShape::ChangeType) override
QList< KoShape * > shapes() const override
void remove(KoShape *shape) override
void shapeToBeRemovedFromHierarchy(KoShape *shape, KoShapeContainer *removedFromSubtree) override
KoShapeManager * associatedRootShapeManager() const
bool inheritsTransform(const KoShape *shape) const override
void setInheritsTransform(const KoShape *shape, bool value) override
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130