QGraphicsSceneBspTreeIndex Class
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for discovering items in QGraphicsScene. \since
4.6 \ingroup
graphicsview-api. More...
Header: | #include <QGraphicsSceneBspTreeIndex> |
Inherits: | QGraphicsSceneIndex |
Properties
- bspTreeDepth : int
Public Functions
QGraphicsSceneBspTreeIndex(QGraphicsScene *scene = nullptr) | |
int | bspTreeDepth() const |
void | setBspTreeDepth(int depth) |
Reimplemented Public Functions
virtual QList<QGraphicsItem *> | estimateItems(const QRectF &rect, Qt::SortOrder order) const override |
Reimplemented Protected Functions
virtual void | addItem(QGraphicsItem *item) override |
virtual void | clear() override |
virtual bool | event(QEvent *event) override |
virtual void | itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const void *const value) override |
virtual void | prepareBoundingRectChange(const QGraphicsItem *item) override |
virtual void | removeItem(QGraphicsItem *item) override |
Protected Slots
virtual void | updateSceneRect(const QRectF &rect) override |
Detailed Description
\internal
QGraphicsSceneBspTreeIndex index use a BSP(Binary Space Partitioning) implementation to discover items quickly. This implementation is very efficient for static scenes. It has a depth that you can set. The depth directly affects performance and memory usage; the latter growing exponentially with the depth of the tree. With an optimal tree depth, the index can instantly determine the locality of items, even for scenes with thousands or millions of items. This also greatly improves rendering performance.
By default, the depth value is 0, in which case Qt will guess a reasonable default depth based on the size, location and number of items in the scene. If these parameters change frequently, however, you may experience slowdowns as the index retunes the depth internally. You can avoid potential slowdowns by fixating the tree depth through setting this property.
The depth of the tree and the size of the scene rectangle decide the granularity of the scene's partitioning. The size of each scene segment is determined by the following algorithm:
The BSP tree has an optimal size when each segment contains between 0 and 10 items.
See also QGraphicsScene, QGraphicsView, and QGraphicsSceneIndex.
Property Documentation
bspTreeDepth : int
This property holds the depth of the BSP index tree \since
4.6
This value determines the depth of BSP tree. The depth directly affects performance and memory usage; the latter growing exponentially with the depth of the tree. With an optimal tree depth, the index can instantly determine the locality of items, even for scenes with thousands or millions of items. This also greatly improves rendering performance.
By default, the value is 0, in which case Qt will guess a reasonable default depth based on the size, location and number of items in the scene. If these parameters change frequently, however, you may experience slowdowns as the index retunes the depth internally. You can avoid potential slowdowns by fixating the tree depth through setting this property.
The depth of the tree and the size of the scene rectangle decide the granularity of the scene's partitioning. The size of each scene segment is determined by the following algorithm:
The BSP tree has an optimal size when each segment contains between 0 and 10 items.
Access functions:
int | bspTreeDepth() const |
void | setBspTreeDepth(int depth) |
Member Function Documentation
QGraphicsSceneBspTreeIndex::QGraphicsSceneBspTreeIndex(QGraphicsScene *scene = nullptr)
Constructs a BSP scene index for the given scene.
[override virtual protected]
void QGraphicsSceneBspTreeIndex::addItem(QGraphicsItem *item)
Add the item into the BSP index.
[override virtual protected]
void QGraphicsSceneBspTreeIndex::clear()
Reimplements: QGraphicsSceneIndex::clear().
\internal
Clear the all the BSP index.
[override virtual]
QList<QGraphicsItem *> QGraphicsSceneBspTreeIndex::estimateItems(const QRectF &rect, Qt::SortOrder order) const
Returns an estimation visible items that are either inside or intersect with the specified rect and return a list sorted using order.
deviceTransform is the transformation apply to the view.
[override virtual protected]
bool QGraphicsSceneBspTreeIndex::event(QEvent *event)
Reimplements: QObject::event(QEvent *e).
Used to catch the timer event.
\internal
[override virtual protected]
void QGraphicsSceneBspTreeIndex::itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const void *const value)
Reimplements: QGraphicsSceneIndex::itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const void *const value).
\internal
This method react to the change of the item and use the value to update the BSP tree if necessary.
[override virtual protected]
void QGraphicsSceneBspTreeIndex::prepareBoundingRectChange(const QGraphicsItem *item)
Reimplements: QGraphicsSceneIndex::prepareBoundingRectChange(const QGraphicsItem *item).
\internal
Update the BSP when the item 's bounding rect has changed.
[override virtual protected]
void QGraphicsSceneBspTreeIndex::removeItem(QGraphicsItem *item)
Remove the item from the BSP index.
[override virtual protected slot]
void QGraphicsSceneBspTreeIndex::updateSceneRect(const QRectF &rect)
Reimplements: QGraphicsSceneIndex::updateSceneRect(const QRectF &rect).
\internal
This method react to the rect change of the scene and reset the BSP tree index.