6#include <QtCore/qstring.h>
7#include <private/qgraphicsitem_p.h>
25 nodes.resize((1 << (
depth + 1)) - 1);
28 leaves.
fill(QList<QGraphicsItem *>());
42 climbTree([
item](QList<QGraphicsItem *> *
items){
49 climbTree([
item](QList<QGraphicsItem *> *
items){
56 for (
int i = 0;
i < leaves.
size(); ++
i) {
57 QList<QGraphicsItem *> newItemList;
58 const QList<QGraphicsItem *> &oldItemList = leaves[
i];
59 for (
int j = 0;
j < oldItemList.size(); ++
j) {
64 leaves[
i] = newItemList;
70 QList<QGraphicsItem *> foundItems;
71 climbTree([&foundItems, onlyTopLevelItems](QList<QGraphicsItem *> *
items) {
77 item->d_func()->itemDiscovered = 1;
78 foundItems.prepend(
item);
83 for (
const auto &foundItem : std::as_const(foundItems))
84 foundItem->d_ptr->itemDiscovered = 0;
103 .arg(
rect.width()).arg(
rect.height())
124 node->offset =
rect.center().y();
130 qreal offset1, offset2;
135 rect2.setRect(rect1.left(), rect1.bottom(), rect1.width(),
rect.height() - rect1.height());
136 offset1 = rect1.center().x();
137 offset2 = rect2.center().x();
141 rect2.setRect(rect1.right(), rect1.top(),
rect.width() - rect1.width(), rect1.height());
142 offset1 = rect1.center().y();
143 offset2 = rect2.center().y();
149 child->offset = offset1;
152 child = &nodes[childIndex + 1];
153 child->offset = offset2;
160 node->leafIndex = leafCnt++;
164template<
typename Visitor>
165void QGraphicsSceneBspTree::climbTree(Visitor &&visitor,
const QRectF &
rect,
int index)
const
175 visitor(
const_cast<QList<QGraphicsItem*>*
>(&leaves[node.leafIndex]));
179 if (
rect.left() < node.offset) {
180 climbTree(visitor, rect, childIndex);
181 if (
rect.right() >= node.offset)
182 climbTree(visitor, rect, childIndex + 1);
184 climbTree(visitor, rect, childIndex + 1);
188 if (
rect.top() < node.offset) {
189 climbTree(visitor, rect, childIndex);
190 if (
rect.bottom() >= node.offset)
191 climbTree(visitor, rect, childIndex + 1);
193 climbTree(visitor, rect, childIndex + 1);
198QRectF QGraphicsSceneBspTree::rectForIndex(
int index)
const
205 const Node *parent = &nodes.at(parentIdx);
209 rect.setRight(parent->offset);
211 rect.setLeft(parent->offset);
214 rect.setBottom(parent->offset);
216 rect.setTop(parent->offset);
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsItem * topLevelItem() const
Returns this item's top-level item.
void removeItem(QGraphicsItem *item, const QRectF &rect)
void removeItems(const QSet< QGraphicsItem * > &items)
int firstChildIndex(int index) const
void initialize(const QRectF &rect, int depth)
int parentIndex(int index) const
QList< QGraphicsItem * > items(const QRectF &rect, bool onlyTopLevelItems=false) const
void insertItem(QGraphicsItem *item, const QRectF &rect)
QString debug(int index) const
qsizetype size() const noexcept
QList< T > & fill(parameter_type t, qsizetype size=-1)
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype removeAll(const AT &t)
void prepend(rvalue_ref t)
void resize(qsizetype size)
\inmodule QtCore\reentrant
constexpr void setRect(qreal x, qreal y, qreal w, qreal h) noexcept
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width an...
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
GLint GLenum GLsizei GLsizei GLsizei depth
bool contains(const AT &t) const noexcept