80 #include <QtCore/qglobal.h> 82 #ifndef QT_NO_GRAPHICSVIEW 84 #include <private/qgraphicsscene_p.h> 85 #include <private/qgraphicsscenebsptreeindex_p.h> 86 #include <private/qgraphicssceneindex_p.h> 88 #include <QtCore/qmath.h> 89 #include <QtCore/qdebug.h> 105 restartIndexTimer(false),
106 regenerateIndex(true),
109 sortCacheEnabled(false),
110 updatingSortCache(false)
137 Q_ASSERT(!item->d_ptr->itemDiscovered);
140 item->d_func()->index = freeIndex;
153 static const int slack = 100;
171 if (item->d_ptr->itemIsUntransformable()) {
178 bsp.
insertItem(item, item->d_ptr->sceneEffectiveBoundingRect());
236 item->d_ptr->index = -1;
237 Q_ASSERT(!item->d_ptr->itemDiscovered);
256 for (
int i = 0; i < childList.
size(); ++i) {
262 for (
int i = 0; i < childList.
size(); ++i) {
284 int stackingOrder = 0;
288 for (
int i = 0; i < items.
size(); ++i) {
295 for (
int i = 0; i < topLevels.
size(); ++i)
334 qWarning(
"QGraphicsSceneBspTreeIndex::addItem: item has already been added to this BSP");
344 bool moveToUnindexedItems)
376 if (moveToUnindexedItems)
386 bool onlyTopLevelItems)
389 if (onlyTopLevelItems && rect.
isNull())
390 return q->QGraphicsSceneIndex::estimateTopLevelItems(rect, order);
397 if (onlyTopLevelItems) {
404 if (!rectItems.contains(item))
427 if (onlyTopLevelItems) {
435 if (sortCacheEnabled) {
462 for (
int i = 0; i <
d->indexedItems.size(); ++i) {
465 Q_ASSERT(!item->d_ptr->itemDiscovered);
466 item->d_ptr->index = -1;
482 d->lastItemCount = 0;
483 d->freeItemIndexes.clear();
484 for (
int i = 0; i <
d->indexedItems.size(); ++i) {
487 Q_ASSERT(!item->d_ptr->itemDiscovered);
488 item->d_ptr->index = -1;
491 d->indexedItems.clear();
492 d->unindexedItems.clear();
493 d->untransformableItems.clear();
494 d->regenerateIndex =
true;
534 d->removeItem(thatItem,
false,
true);
571 if (
d->freeItemIndexes.isEmpty()) {
572 if (
d->unindexedItems.isEmpty()) {
573 itemList =
d->indexedItems;
575 itemList =
d->indexedItems +
d->unindexedItems;
587 d->sortItems(&itemList, order,
d->sortCacheEnabled);
625 return d->bspTreeDepth;
631 if (
d->bspTreeDepth == depth)
633 d->bspTreeDepth = depth;
668 QGraphicsItem::GraphicsItemFlags newFlags = *
static_cast<const QGraphicsItem::GraphicsItemFlags *
>(value);
673 if ((ignoredTransform != willIgnoreTransform) || (clipsChildren != willClipChildren)) {
679 d->removeItem(thatItem,
true,
true);
684 d->invalidateSortCache();
687 d->invalidateSortCache();
694 bool ancestorWillClipChildren = newParent
697 if ((ignoredTransform != willIgnoreTransform) || (ancestorClippedChildren != ancestorWillClipChildren)) {
703 d->removeItem(thatItem,
true,
true);
724 switch (event->
type()) {
726 if (
d->indexTimerId && static_cast<QTimerEvent *>(event)->timerId() ==
d->indexTimerId) {
727 if (
d->restartIndexTimer) {
728 d->restartIndexTimer =
false;
743 #include "moc_qgraphicsscenebsptreeindex_p.cpp" 745 #endif // QT_NO_GRAPHICSVIEW
void _q_updateSortCache()
QList< QGraphicsItem * > estimateItems(const QRectF &, Qt::SortOrder, bool b=false)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QRectF sceneEffectiveBoundingRect() const
Returns the effective bounding rect of this item in scene coordinates, by combining sceneTransform() ...
#define QT_END_NAMESPACE
This macro expands to.
QSet< QGraphicsItem * > removedItems
QScopedPointer< QGraphicsItemPrivate > d_ptr
QGraphicsSceneBspTreeIndexPrivate(QGraphicsScene *scene)
Constructs a private scene bsp index.
void clear()
Clear the all the BSP index.
void addItem(QGraphicsItem *item)
Add the item into the BSP index.
QGraphicsSceneBspTree bsp
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
void initialize(const QRectF &rect, int depth)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
QList< QGraphicsItem * > estimateTopLevelItems(const QRectF &rect, Qt::SortOrder order) const
bool event(QEvent *event)
Used to catch the timer event.
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
QList< QGraphicsItem * > items(const QRectF &rect, bool onlyTopLevelItems=false) const
void updateSceneRect(const QRectF &rect)
This method react to the rect change of the scene and reset the BSP tree index.
Q_DECL_CONSTEXPR T qAbs(const T &t)
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
static bool closestItemLast_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
void purgeRemovedItems()
Removes stale pointers from all data structures.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
bool qt_closestItemLast(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item2 is on top of item1.
static bool closestItemFirst_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
static void climbTree(QGraphicsItem *item, int *stackingOrder)
void addItem(QGraphicsItem *item, bool recursive=false)
bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item1 is on top of item2.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
T takeFirst()
Removes the first item in the list and returns it.
bool itemIsUntransformable() const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
const T & at(int i) const
Returns the item at index position i in the list.
QList< int > freeItemIndexes
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::DescendingOrder) const
Return all items in the BSP index and sort them using order.
Q_CORE_EXPORT void qWarning(const char *,...)
void itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const void *const value)
This method react to the change of the item and use the value to update the BSP tree if necessary...
static void sortItems(QList< QGraphicsItem *> *itemList, Qt::SortOrder order, bool cached, bool onlyTopLevelItems=false)
Sort a list of itemList in a specific order and use the cache if requested.
QGraphicsItem * topLevelItem() const
Returns this item's top-level item.
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
void clear()
Removes all items from the list.
GraphicsItemFlags flags() const
Returns this item's flags.
void insertItem(QGraphicsItem *item, const QRectF &rect)
void _q_updateIndex()
This method will update the BSP index by removing the items from the temporary unindexed list and add...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
QList< QGraphicsItem * > indexedItems
void startIndexTimer(int interval=QGRAPHICSSCENE_INDEXTIMER_TIMEOUT)
Starts or restarts the timer used for reindexing unindexed items.
void invalidateSortCache()
void setBspTreeDepth(int depth)
QList< QGraphicsItem * > untransformableItems
static int intmaxlog(int n)
QList< QGraphicsItem * > estimateItems(const QRectF &rect, Qt::SortOrder order) const
Returns an estimation visible items that are either inside or intersect with the specified rect and r...
int size() const
Returns the number of items in the list.
void prepareBoundingRectChange(const QGraphicsItem *item)
Update the BSP when the item 's bounding rect has changed.
void removeItems(const QSet< QGraphicsItem *> &items)
QList< QGraphicsItem * > children
QList< QGraphicsItem * > unindexedItems
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
QGraphicsSceneBspTreeIndex(QGraphicsScene *scene=0)
Constructs a BSP scene index for the given scene.
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
void removeItem(QGraphicsItem *item, const QRectF &rect)
void removeItem(QGraphicsItem *item)
Remove the item from the BSP index.
bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
The QList class is a template class that provides lists.
void removeItem(QGraphicsItem *item, bool recursive=false, bool moveToUnindexedItems=false)
~QGraphicsSceneBspTreeIndex()