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

#include <KoShapeManager.h>

+ Inheritance diagram for KoShapeManager:

Classes

struct  PaintJob
 
struct  PaintJobsOrder
 
struct  ShapeInterface
 

Public Types

enum  Repaint { PaintShapeOnAdd , AddWithoutRepaint }
 enum for add() More...
 

Public Slots

void addShape (KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
 
void remove (KoShape *shape)
 

Signals

void contentChanged ()
 emitted when any object changed (moved/rotated etc)
 
void forwardUpdate ()
 Emitted upon update and used to update the canvas.
 
void selectionChanged ()
 emitted when the selection is changed
 
void selectionContentChanged ()
 emitted when an object in the selection is changed (moved/rotated etc)
 

Public Member Functions

void explicitlyIssueShapeChangedSignals ()
 
void forwardCompressedUpdate ()
 
 KoShapeManager (KoCanvasBase *canvas)
 
 KoShapeManager (KoCanvasBase *canvas, const QList< KoShape * > &shapes)
 
void notifyShapeChanged (KoShape *shape)
 
void paint (QPainter &painter)
 
void paintJob (QPainter &painter, const KoShapeManager::PaintJob &job)
 
void preparePaintJobs (PaintJobsOrder &jobsOrder, KoShape *excludeRoot)
 
 Private (KoShapeManager *shapeManager, KoCanvasBase *c)
 
KoSelectionselection () const
 return the selection shapes for this shapeManager
 
void setShapes (const QList< KoShape * > &shapes, Repaint repaint=PaintShapeOnAdd)
 
void setUpdatesBlocked (bool value)
 
KoShapeshapeAt (const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 returns the list of maintained shapes
 
QList< KoShape * > shapesAt (const QRectF &rect, bool omitHiddenShapes=true, bool containedMode=false)
 
QList< KoShape * > topLevelShapes () const
 
void unlinkFromShapesRecursively (const QList< KoShape * > &shapes)
 
void update (const QRectF &rect, const KoShape *shape=0, bool selectionHandles=false)
 
bool updatesBlocked () const
 
void updateTree ()
 
 ~KoShapeManager () override
 
 ~Private ()
 

Static Public Member Functions

static void renderSingleShape (KoShape *shape, QPainter &painter)
 renderSingleShape renders a shape on painter. This method includes all the needed steps for painting a single shape: setting transformations, clipping and masking.
 

Public Attributes

QSet< KoShape * > aggregate4update
 
KoCanvasBasecanvas
 
QRectF compressedUpdate
 
QSet< const KoShape * > compressedUpdatedShapes
 
KoShapeManagerq
 
KoSelectionselection
 
QHash< KoShape *, int > shapeIndexesBeforeUpdate
 
KoShapeManager::ShapeInterface shapeInterface
 
QList< KoShape * > shapes
 
QMutex shapesMutex
 
KoRTree< KoShape * > tree
 
QMutex treeMutex
 
bool updatesBlocked = false
 

Private Member Functions

KoCanvasBasecanvas ()
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

The shape manager hold a list of all shape which are in scope. There is one shape manager per canvas. This makes the shape manager different from QGraphicsScene, which contains the datamodel for all graphics items: KoShapeManager only contains the subset of shapes that are shown in its canvas.

The selection in the different views can be different.

Definition at line 41 of file KoShapeManager.h.

Member Enumeration Documentation

◆ Repaint

enum for add()

Enumerator
PaintShapeOnAdd 

Causes each shapes 'update()' to be called after being added to the shapeManager.

AddWithoutRepaint 

Avoids each shapes 'update()' to be called for faster addition when its possible.

Definition at line 47 of file KoShapeManager.h.

47 {
50 };
@ AddWithoutRepaint
Avoids each shapes 'update()' to be called for faster addition when its possible.
@ PaintShapeOnAdd
Causes each shapes 'update()' to be called after being added to the shapeManager.

Constructor & Destructor Documentation

◆ KoShapeManager() [1/2]

KoShapeManager::KoShapeManager ( KoCanvasBase * canvas)
explicit

Constructor.

Definition at line 336 of file KoShapeManager.cpp.

337 : d(new Private(this, canvas))
338{
339 Q_ASSERT(d->canvas); // not optional.
340 connect(d->selection, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
341
342 // see a comment in another constructor
343 this->moveToThread(qApp->thread());
344 connect(this, SIGNAL(forwardUpdate()), this, SLOT(forwardCompressedUpdate()));
345}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void forwardCompressedUpdate()
void selectionChanged()
emitted when the selection is changed
Private *const d
KoCanvasBase * canvas
void forwardUpdate()
Emitted upon update and used to update the canvas.
KisCanvas2 * canvas

References Private::canvas, connect(), d, forwardCompressedUpdate(), forwardUpdate(), and selectionChanged().

◆ KoShapeManager() [2/2]

KoShapeManager::KoShapeManager ( KoCanvasBase * canvas,
const QList< KoShape * > & shapes )

Constructor that takes a list of shapes, convenience version.

Parameters
shapesthe shapes to start out with, see also setShapes()
canvasthe canvas this shape manager is working on.

Shape manager uses uses queued signals, therefore it should belong to the GUI thread.

Definition at line 321 of file KoShapeManager.cpp.

322 : d(new Private(this, canvas))
323{
324 Q_ASSERT(d->canvas); // not optional.
325 connect(d->selection, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
327
332 this->moveToThread(qApp->thread());
333 connect(this, SIGNAL(forwardUpdate()), this, SLOT(forwardCompressedUpdate()));
334}
QList< KoShape * > shapes
void setShapes(const QList< KoShape * > &shapes, Repaint repaint=PaintShapeOnAdd)

References Private::canvas, connect(), d, forwardCompressedUpdate(), forwardUpdate(), selectionChanged(), setShapes(), and shapes.

◆ ~KoShapeManager()

KoShapeManager::~KoShapeManager ( )
override

Definition at line 359 of file KoShapeManager.cpp.

360{
361 d->unlinkFromShapesRecursively(d->shapes);
362 d->shapes.clear();
363
364 delete d;
365}

References d.

◆ ~Private()

KoShapeManager::~Private ( )
inline

Definition at line 37 of file KoShapeManager_p.h.

37 {
38 delete selection;
39 }
KoSelection * selection

Member Function Documentation

◆ addShape

void KoShapeManager::addShape ( KoShape * shape,
KoShapeManager::Repaint repaint = PaintShapeOnAdd )
slot

Add a KoShape to be displayed and managed by this manager. This will trigger a repaint of the shape.

Parameters
shapethe shape to add
repaintif true it will trigger a repaint of the shape

Definition at line 389 of file KoShapeManager.cpp.

390{
391 {
392 QMutexLocker l1(&d->shapesMutex);
393
394 if (d->shapes.contains(shape))
395 return;
396 shape->addShapeManager(this);
397 d->shapes.append(shape);
398
399 if (shapeUsedInRenderingTree(shape)) {
400 QMutexLocker l2(&d->treeMutex);
401
402 QRectF br(shape->boundingRect());
403 d->tree.insert(br, shape);
404 }
405 }
406
407 if (repaint == PaintShapeOnAdd) {
408 shape->update();
409 }
410
411 // add the children of a KoShapeContainer
412 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
413
414 if (container) {
415 foreach (KoShape *containerShape, container->shapes()) {
416 addShape(containerShape, repaint);
417 }
418 }
419}
QList< KoShape * > shapes() const
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
void addShapeManager(KoShapeManager *manager)
Definition KoShape.cpp:148
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void update() const
Definition KoShape.cpp:605

References addShape(), KoShape::addShapeManager(), KoShape::boundingRect(), d, PaintShapeOnAdd, KoShapeContainer::shapes(), and KoShape::update().

◆ canvas()

KoCanvasBase * KoShapeManager::canvas ( )
private

◆ contentChanged

void KoShapeManager::contentChanged ( )
signal

emitted when any object changed (moved/rotated etc)

◆ explicitlyIssueShapeChangedSignals()

void KoShapeManager::explicitlyIssueShapeChangedSignals ( )

The update signals are usually emitted when the owned of the manager calls to preparePaintJobs() in the beginning of the rendering cycle. This way we avoid too many signals to be emitted. But some of the canvases (e.g. KisShapeSelectionCanvas) doesn't do any rendering (yet?), so the signals should be emitted explicitly.

Definition at line 768 of file KoShapeManager.cpp.

769{
770 d->updateTree();
771}

References d.

◆ forwardCompressedUpdate()

void KoShapeManager::forwardCompressedUpdate ( )

◆ forwardUpdate

void KoShapeManager::forwardUpdate ( )
signal

Emitted upon update and used to update the canvas.

◆ notifyShapeChanged()

void KoShapeManager::notifyShapeChanged ( KoShape * shape)

Update the tree for finding the shapes. This will remove the shape from the tree and will reinsert it again. The update to the tree will be postponed until it is needed so that successive calls will be merged into one.

Parameters
shapethe shape to updated its position in the tree.

Definition at line 721 of file KoShapeManager.cpp.

722{
723 {
724 QMutexLocker l(&d->treeMutex);
725
726 Q_ASSERT(shape);
727 if (d->aggregate4update.contains(shape)) {
728 return;
729 }
730
731 d->aggregate4update.insert(shape);
732 d->shapeIndexesBeforeUpdate.insert(shape, shape->zIndex());
733 }
734
735 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
736 if (container) {
737 Q_FOREACH (KoShape *child, container->shapes())
738 notifyShapeChanged(child);
739 }
740}
void notifyShapeChanged(KoShape *shape)
qint16 zIndex() const
Definition KoShape.cpp:600

References d, notifyShapeChanged(), KoShapeContainer::shapes(), and KoShape::zIndex().

◆ paint()

void KoShapeManager::paint ( QPainter & painter)

Paint all shapes and their selection handles etc.

Parameters
painterthe painter to paint to.
forPrintif true, make sure only actual content is drawn and no decorations.
converterto convert between document and view coordinates.

Definition at line 561 of file KoShapeManager.cpp.

562{
563 d->updateTree();
564
565 QMutexLocker l1(&d->shapesMutex);
566
567 painter.setPen(Qt::NoPen); // painters by default have a black stroke, lets turn that off.
568 painter.setBrush(Qt::NoBrush);
569
570 QList<KoShape*> unsortedShapes;
571 if (painter.hasClipping()) {
572 QMutexLocker l(&d->treeMutex);
573
575 unsortedShapes = d->tree.intersects(rect);
576 } else {
577 unsortedShapes = d->shapes;
578 warnFlake << "KoShapeManager::paint Painting with a painter that has no clipping will lead to too much being painted!";
579 }
580
581 KisForest<KoShape*> renderTree;
582 buildRenderTree(unsortedShapes, renderTree);
583 renderShapes(childBegin(renderTree), childEnd(renderTree), painter);
584}
#define warnFlake
Definition FlakeDebug.h:16
ChildIterator< value_type, is_const > childBegin(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:290
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:300
QRect safeClipBoundingRect(const QPainter &painter)

References d, KisPaintingTweaks::safeClipBoundingRect(), and warnFlake.

◆ paintJob()

void KoShapeManager::paintJob ( QPainter & painter,
const KoShapeManager::PaintJob & job )

Render a job on painter. No mutable internals of the shape manager are accessed, so calling this method is safe in multithreading environment.

Parameters
paintera painter to paint on. Clip rect of the painter is expected to be setup correctly.
joba job to paint.
forPrintnot used in Krita.
See also
preparePaintJobs

Definition at line 550 of file KoShapeManager.cpp.

551{
552 painter.setPen(Qt::NoPen); // painters by default have a black stroke, lets turn that off.
553 painter.setBrush(Qt::NoBrush);
554
555 KisForest<KoShape*> renderTree;
556 buildRenderTree(job.shapes, renderTree);
557
558 renderShapes(childBegin(renderTree), childEnd(renderTree), painter);
559}
QList< KoShape * > shapes

References KoShapeManager::PaintJob::shapes.

◆ preparePaintJobs()

void KoShapeManager::preparePaintJobs ( PaintJobsOrder & jobsOrder,
KoShape * excludeRoot )

Prepare a shallow copy of all the shapes and the jobs to be rendered asynchronously later. The copies are stored in jobs, so that the user could later pass these jobs into paintJob() in a separate thread.

Parameters
jobsa list of rects that are going to be updated. docUpdateRect and viewUpdateRect should be preinitialized by the caller.
excludeRootthe root shape which should not be copied. It is basically a hack to avoid copying of KisShapeLayer, which is not copiable.
See also
paintJob()
a comment in KisShapeLayerCanvas::slotStartAsyncRepaint()

Definition at line 483 of file KoShapeManager.cpp.

485{
486 d->updateTree();
487
488 QMutexLocker l1(&d->shapesMutex);
489
490 QSet<KoShape*> rootShapesSet;
491 Q_FOREACH (KoShape *shape, d->shapes) {
492 while (shape->parent() && shape->parent() != excludeRoot) {
493 shape = shape->parent();
494 }
495
496 if (!rootShapesSet.contains(shape) && shape != excludeRoot) {
497 rootShapesSet.insert(shape);
498 }
499 }
500 const QList<KoShape*> rootShapes(rootShapesSet.begin(), rootShapesSet.end());
501 QList<KoShape*> newRootShapes;
502
503 Q_FOREACH (KoShape *srcShape, rootShapes) {
504 KIS_SAFE_ASSERT_RECOVER(srcShape->parent() == excludeRoot
505 || !srcShape->parent()) {
506 continue;
507 }
508
509 KoShape *clonedShape = srcShape->cloneShape();
510
511 KoShapeContainer *parentShape = srcShape->parent();
512
513 if (parentShape && !parentShape->transformation().isIdentity()) {
514 clonedShape->applyAbsoluteTransformation(parentShape->transformation());
515 }
516
517 newRootShapes << clonedShape;
518 }
519
520 PaintJobsOrder result;
521
522 PaintJob::SharedSafeStorage shapesStorage = std::make_shared<PaintJob::ShapesStorage>();
523 Q_FOREACH (KoShape *shape, newRootShapes) {
524 shapesStorage->emplace_back(std::unique_ptr<KoShape>(shape));
525 }
526
527 const QList<KoShape*> originalShapes = KoShape::linearizeSubtreeSorted(rootShapes);
528 const QList<KoShape*> clonedShapes = KoShape::linearizeSubtreeSorted(newRootShapes);
529 KIS_SAFE_ASSERT_RECOVER_RETURN(clonedShapes.size() == originalShapes.size());
530
531 QHash<KoShape*, KoShape*> clonedFromOriginal;
532 for (int i = 0; i < originalShapes.size(); i++) {
533 clonedFromOriginal[originalShapes[i]] = clonedShapes[i];
534 }
535
536
537 for (auto it = std::begin(jobsOrder.jobs); it != std::end(jobsOrder.jobs); ++it) {
538 QMutexLocker l(&d->treeMutex);
539 QList<KoShape*> unsortedOriginalShapes = d->tree.intersects(it->docUpdateRect);
540
541 it->allClonedShapes = shapesStorage;
542
543 Q_FOREACH (KoShape *shape, unsortedOriginalShapes) {
544 KIS_SAFE_ASSERT_RECOVER(shapeUsedInRenderingTree(shape)) { continue; }
545 it->shapes << clonedFromOriginal[shape];
546 }
547 }
548}
void applyAbsoluteTransformation(const QTransform &matrix)
Definition KoShape.cpp:400
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
static QList< KoShape * > linearizeSubtreeSorted(const QList< KoShape * > &shapes)
Definition KoShape.cpp:1397
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
std::shared_ptr< ShapesStorage > SharedSafeStorage

References KoShape::applyAbsoluteTransformation(), KoShape::cloneShape(), d, KoShapeManager::PaintJobsOrder::jobs, KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_RETURN, KoShape::linearizeSubtreeSorted(), KoShape::parent(), and KoShape::transformation().

◆ Private()

KoShapeManager::Private ( KoShapeManager * shapeManager,
KoCanvasBase * c )
inline

Definition at line 28 of file KoShapeManager_p.h.

29 : selection(new KoSelection(shapeManager)),
30 canvas(c),
31 tree(4, 2),
32 q(shapeManager),
33 shapeInterface(shapeManager)
34 {
35 }
KoShapeManager::ShapeInterface shapeInterface
KoRTree< KoShape * > tree
KoShapeManager * q

◆ remove

void KoShapeManager::remove ( KoShape * shape)
slot

Remove a KoShape from this manager

Parameters
shapethe shape to remove

Definition at line 421 of file KoShapeManager.cpp.

422{
423 QRectF dirtyRect;
424 {
425 QMutexLocker l1(&d->shapesMutex);
426 QMutexLocker l2(&d->treeMutex);
427
428 dirtyRect = shape->boundingRect();
429
430 shape->removeShapeManager(this);
431 d->selection->deselect(shape);
432 d->aggregate4update.remove(shape);
433 d->compressedUpdatedShapes.remove(shape);
434
435 if (shapeUsedInRenderingTree(shape)) {
436 d->tree.remove(shape);
437 }
438 d->shapes.removeAll(shape);
439 }
440
441 if (!dirtyRect.isEmpty()) {
442 d->canvas->updateCanvas(dirtyRect);
443 }
444
445 // remove the children of a KoShapeContainer
446 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
447 if (container) {
448 foreach (KoShape *containerShape, container->shapes()) {
449 remove(containerShape);
450 }
451 }
452}
void updateCanvas(const QRectF &rc) override
void remove(KoShape *shape)
void removeShapeManager(KoShapeManager *manager)
Definition KoShape.cpp:153

References KoShape::boundingRect(), Private::canvas, d, remove(), KoShape::removeShapeManager(), KoShapeContainer::shapes(), and KisCanvas2::updateCanvas().

◆ renderSingleShape()

void KoShapeManager::renderSingleShape ( KoShape * shape,
QPainter & painter )
static

renderSingleShape renders a shape on painter. This method includes all the needed steps for painting a single shape: setting transformations, clipping and masking.

Definition at line 586 of file KoShapeManager.cpp.

587{
588 KisForest<KoShape*> renderTree;
589
590 KoViewConverter converter;
591
592 auto root = renderTree.insert(childBegin(renderTree), shape);
593 populateRenderSubtree(shape, root, renderTree, &shapeIsVisible, &shapeIsVisible);
594 renderShapes(childBegin(renderTree), childEnd(renderTree), painter);
595}
child_iterator insert(child_iterator pos, X &&value)
Inserts element value into position pos. value becomes the child of the same parent as pos and is pla...
Definition KisForest.h:943

References KisForestDetail::Forest< T >::insert().

◆ selection()

KoSelection * KoShapeManager::selection ( ) const

return the selection shapes for this shapeManager

◆ selectionChanged

void KoShapeManager::selectionChanged ( )
signal

emitted when the selection is changed

◆ selectionContentChanged

void KoShapeManager::selectionContentChanged ( )
signal

emitted when an object in the selection is changed (moved/rotated etc)

◆ setShapes()

void KoShapeManager::setShapes ( const QList< KoShape * > & shapes,
Repaint repaint = PaintShapeOnAdd )

Remove all previously owned shapes and make the argument list the new shapes to be managed by this manager.

Parameters
shapesthe new shapes to manage.
repaintif true it will trigger a repaint of the shapes

Definition at line 367 of file KoShapeManager.cpp.

368{
369 {
370 QMutexLocker l1(&d->shapesMutex);
371 QMutexLocker l2(&d->treeMutex);
372
373 //clear selection
374 d->selection->deselectAll();
375 d->unlinkFromShapesRecursively(d->shapes);
376 d->compressedUpdate = QRect();
377 d->compressedUpdatedShapes.clear();
378 d->aggregate4update.clear();
379 d->shapeIndexesBeforeUpdate.clear();
380 d->tree.clear();
381 d->shapes.clear();
382 }
383
384 Q_FOREACH (KoShape *shape, shapes) {
385 addShape(shape, repaint);
386 }
387}

References addShape(), d, and shapes.

◆ setUpdatesBlocked()

void KoShapeManager::setUpdatesBlocked ( bool value)

Block all updates initiated with update() call. The incoming updates will be dropped completely.

Definition at line 712 of file KoShapeManager.cpp.

713{
714 d->updatesBlocked = value;
715}
float value(const T *src, size_t ch)

References d, and value().

◆ shapeAt()

KoShape * KoShapeManager::shapeAt ( const QPointF & position,
KoFlake::ShapeSelection selection = KoFlake::ShapeOnTop,
bool omitHiddenShapes = true )

Returns the shape located at a specific point in the document. If more than one shape is located at the specific point, the given selection type controls which of them is returned.

Parameters
positionthe position in the document coordinate system.
selectioncontrols which shape is returned when more than one shape is at the specific point
omitHiddenShapesif true, only visible shapes are considered

Definition at line 597 of file KoShapeManager.cpp.

598{
599 d->updateTree();
600
601 QMutexLocker l(&d->shapesMutex);
602
603 QList<KoShape*> sortedShapes;
604
605 {
606 QMutexLocker l(&d->treeMutex);
607 sortedShapes = d->tree.contains(position);
608 }
609
610 std::sort(sortedShapes.begin(), sortedShapes.end(), KoShape::compareShapeZIndex);
611 KoShape *firstUnselectedShape = 0;
612 for (int count = sortedShapes.count() - 1; count >= 0; count--) {
613 KoShape *shape = sortedShapes.at(count);
614 if (omitHiddenShapes && ! shape->isVisible())
615 continue;
616 if (! shape->hitTest(position))
617 continue;
618
619 switch (selection) {
621 if (shape->isSelectable())
622 return shape;
623 break;
625 if (d->selection->isSelected(shape))
626 return shape;
627 break;
629 if (! d->selection->isSelected(shape))
630 return shape;
631 break;
633 // we want an unselected shape
634 if (d->selection->isSelected(shape))
635 continue;
636 // memorize the first unselected shape
637 if (! firstUnselectedShape)
638 firstUnselectedShape = shape;
639 // check if the shape above is selected
640 if (count + 1 < sortedShapes.count() && d->selection->isSelected(sortedShapes.at(count + 1)))
641 return shape;
642 break;
643 }
644 }
645 // if we want the next unselected below a selected but there was none selected,
646 // return the first found unselected shape
647 if (selection == KoFlake::NextUnselected && firstUnselectedShape)
648 return firstUnselectedShape;
649
650 if (d->selection->hitTest(position))
651 return d->selection;
652
653 return 0; // missed everything
654}
bool isSelectable() const
Definition KoShape.cpp:1014
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434
virtual bool hitTest(const QPointF &position) const
Check if the shape is hit on position.
Definition KoShape.cpp:308
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979
@ Unselected
return the first unselected on top.
Definition KoFlake.h:72
@ Selected
return the first selected with the highest z-ordering (i.e. on top).
Definition KoFlake.h:71
@ ShapeOnTop
return the shape highest z-ordering, regardless of selection.
Definition KoFlake.h:74
@ NextUnselected
return the first unselected directly under a selected shape, or the top most one if nothing is select...
Definition KoFlake.h:73

References KoShape::compareShapeZIndex(), d, KoShape::hitTest(), KoShape::isSelectable(), KoShape::isVisible(), KoFlake::NextUnselected, KoFlake::Selected, selection, KoFlake::ShapeOnTop, and KoFlake::Unselected.

◆ shapeInterface()

ShapeInterface * KoShapeManager::shapeInterface ( )

◆ shapes()

QList< KoShape * > KoShapeManager::shapes ( ) const

returns the list of maintained shapes

◆ shapesAt()

QList< KoShape * > KoShapeManager::shapesAt ( const QRectF & rect,
bool omitHiddenShapes = true,
bool containedMode = false )

Returns the shapes which intersects the specific rect in the document.

Parameters
rectthe rectangle in the document coordinate system.
omitHiddenShapesif true, only visible shapes are considered
containedModeif true use contained mode

Definition at line 656 of file KoShapeManager.cpp.

657{
658 QMutexLocker l(&d->shapesMutex);
659
660 d->updateTree();
662
663 {
664 QMutexLocker l(&d->treeMutex);
665 shapes = containedMode ? d->tree.contained(rect) : d->tree.intersects(rect);
666 }
667
668 for (int count = shapes.count() - 1; count >= 0; count--) {
669
670 KoShape *shape = shapes.at(count);
671
672 if (omitHiddenShapes && !shape->isVisible()) {
673 shapes.removeAt(count);
674 } else {
675 const QPainterPath outline = shape->absoluteTransformation().map(shape->outline());
676
677 if (!containedMode && !outline.intersects(rect) && !outline.contains(rect)) {
678 shapes.removeAt(count);
679
680 } else if (containedMode) {
681
682 QPainterPath containingPath;
683 containingPath.addRect(rect);
684
685 if (!containingPath.contains(outline)) {
686 shapes.removeAt(count);
687 }
688 }
689 }
690 }
691
692 return shapes;
693}
virtual QPainterPath outline() const
Definition KoShape.cpp:630
QTransform absoluteTransformation() const
Definition KoShape.cpp:382

References KoShape::absoluteTransformation(), d, KoShape::isVisible(), KoShape::outline(), and shapes.

◆ topLevelShapes()

QList< KoShape * > KoShapeManager::topLevelShapes ( ) const

Get a list of all shapes that don't have a parent.

Definition at line 749 of file KoShapeManager.cpp.

750{
751 QMutexLocker l(&d->shapesMutex);
752
754 // get all toplevel shapes
755 Q_FOREACH (KoShape *shape, d->shapes) {
756 if (!shape->parent() || dynamic_cast<KoShapeLayer*>(shape->parent())) {
757 shapes.append(shape);
758 }
759 }
760 return shapes;
761}

References d, KoShape::parent(), and shapes.

◆ unlinkFromShapesRecursively()

void KoShapeManager::unlinkFromShapesRecursively ( const QList< KoShape * > & shapes)

Recursively detach the shapes from this shape manager

◆ update()

void KoShapeManager::update ( const QRectF & rect,
const KoShape * shape = 0,
bool selectionHandles = false )

Request a repaint to be queued. The repaint will be restricted to the parameters rectangle, which is expected to be in points (the document coordinates system of KoShape) and it is expected to be normalized and based in the global coordinates, not any local coordinates.

This method will return immediately and only request a repaint. Successive calls will be merged into an appropriate repaint action.

Parameters
rectthe rectangle (in pt) to queue for repaint.
shapethe shape that is going to be redrawn; only needed when selectionHandles=true
selectionHandlesif true; find out if the shape is selected and repaint its selection handles at the same time.

Definition at line 695 of file KoShapeManager.cpp.

696{
697 if (d->updatesBlocked) return;
698
699 {
700 QMutexLocker l(&d->shapesMutex);
701
702 d->compressedUpdate |= rect;
703
704 if (selectionHandles) {
705 d->compressedUpdatedShapes.insert(shape);
706 }
707 }
708
709 emit(forwardUpdate());
710}

References d, and forwardUpdate().

◆ updatesBlocked()

bool KoShapeManager::updatesBlocked ( ) const

◆ updateTree()

void KoShapeManager::updateTree ( )

Update the tree when there are shapes in m_aggregate4update. This is done so not all updates to the tree are done when they are asked for but when they are needed.

Member Data Documentation

◆ aggregate4update

QSet<KoShape *> KoShapeManager::aggregate4update

Definition at line 59 of file KoShapeManager_p.h.

◆ canvas

KoCanvasBase * KoShapeManager::canvas

Definition at line 57 of file KoShapeManager_p.h.

◆ compressedUpdate

QRectF KoShapeManager::compressedUpdate

Definition at line 66 of file KoShapeManager_p.h.

◆ compressedUpdatedShapes

QSet<const KoShape*> KoShapeManager::compressedUpdatedShapes

Definition at line 67 of file KoShapeManager_p.h.

◆ d

Private* const KoShapeManager::d
private

Definition at line 277 of file KoShapeManager.h.

◆ q

KoShapeManager* KoShapeManager::q

Definition at line 61 of file KoShapeManager_p.h.

◆ selection

KoSelection * KoShapeManager::selection

Definition at line 56 of file KoShapeManager_p.h.

◆ shapeIndexesBeforeUpdate

QHash<KoShape*, int> KoShapeManager::shapeIndexesBeforeUpdate

Definition at line 60 of file KoShapeManager_p.h.

◆ shapeInterface

KoShapeManager::ShapeInterface * KoShapeManager::shapeInterface

Definition at line 62 of file KoShapeManager_p.h.

◆ shapes

QList< KoShape * > KoShapeManager::shapes

Definition at line 55 of file KoShapeManager_p.h.

◆ shapesMutex

QMutex KoShapeManager::shapesMutex

Definition at line 63 of file KoShapeManager_p.h.

◆ tree

KoRTree<KoShape *> KoShapeManager::tree

Definition at line 58 of file KoShapeManager_p.h.

◆ treeMutex

QMutex KoShapeManager::treeMutex

Definition at line 64 of file KoShapeManager_p.h.

◆ updatesBlocked

bool KoShapeManager::updatesBlocked = false

Definition at line 69 of file KoShapeManager_p.h.


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