Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QGraphicsSceneBspTreeIndexPrivate Class Reference

#include <qgraphicsscenebsptreeindex_p.h>

Inheritance diagram for QGraphicsSceneBspTreeIndexPrivate:
QGraphicsSceneIndexPrivate QObjectPrivate QObjectData

Public Functions

void _q_updateIndex ()
 This method will update the BSP index by removing the items from the temporary unindexed list and add them in the indexedItems list. More...
 
void _q_updateSortCache ()
 
void addItem (QGraphicsItem *item, bool recursive=false)
 
QList< QGraphicsItem * > estimateItems (const QRectF &, Qt::SortOrder, bool b=false)
 
void invalidateSortCache ()
 
void purgeRemovedItems ()
 Removes stale pointers from all data structures. More...
 
 QGraphicsSceneBspTreeIndexPrivate (QGraphicsScene *scene)
 Constructs a private scene bsp index. More...
 
void removeItem (QGraphicsItem *item, bool recursive=false, bool moveToUnindexedItems=false)
 
void resetIndex ()
 
void startIndexTimer (int interval=QGRAPHICSSCENE_INDEXTIMER_TIMEOUT)
 Starts or restarts the timer used for reindexing unindexed items. More...
 
- Public Functions inherited from QGraphicsSceneIndexPrivate
void init ()
 
void items_helper (const QRectF &rect, QGraphicsSceneIndexIntersector *intersector, QList< QGraphicsItem *> *items, const QTransform &viewTransform, Qt::ItemSelectionMode mode, Qt::SortOrder order) const
 
 QGraphicsSceneIndexPrivate (QGraphicsScene *scene)
 Constructs a private scene index. More...
 
void recursive_items_helper (QGraphicsItem *item, QRectF exposeRect, QGraphicsSceneIndexIntersector *intersector, QList< QGraphicsItem *> *items, const QTransform &viewTransform, Qt::ItemSelectionMode mode, qreal parentOpacity=1.0) const
 This function returns the items in ascending order. More...
 
 ~QGraphicsSceneIndexPrivate ()
 Destructor of private scene index. More...
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static void climbTree (QGraphicsItem *item, int *stackingOrder)
 
static bool closestItemFirst_withCache (const QGraphicsItem *item1, const QGraphicsItem *item2)
 
static bool closestItemLast_withCache (const QGraphicsItem *item1, const QGraphicsItem *item2)
 
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. More...
 
- Static Public Functions inherited from QGraphicsSceneIndexPrivate
static bool itemCollidesWithPath (const QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode)
 Checks if item collides with the path and mode, but also checks that if it doesn't collide, maybe its frame rect will. More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QGraphicsSceneBspTree bsp
 
int bspTreeDepth
 
QList< int > freeItemIndexes
 
QList< QGraphicsItem * > indexedItems
 
int indexTimerId
 
int lastItemCount
 
bool purgePending
 
bool regenerateIndex
 
QSet< QGraphicsItem * > removedItems
 
bool restartIndexTimer
 
QRectF sceneRect
 
bool sortCacheEnabled
 
QList< QGraphicsItem * > unindexedItems
 
QList< QGraphicsItem * > untransformableItems
 
bool updatingSortCache
 
- Public Variables inherited from QGraphicsSceneIndexPrivate
QGraphicsSceneIndexPathIntersectorpathIntersector
 
QGraphicsSceneIndexPointIntersectorpointIntersector
 
QGraphicsSceneIndexRectIntersectorrectIntersector
 
QGraphicsScenescene
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 112 of file qgraphicsscenebsptreeindex_p.h.

Constructors and Destructors

◆ QGraphicsSceneBspTreeIndexPrivate()

QGraphicsSceneBspTreeIndexPrivate::QGraphicsSceneBspTreeIndexPrivate ( QGraphicsScene scene)

Functions

◆ _q_updateIndex()

void QGraphicsSceneBspTreeIndexPrivate::_q_updateIndex ( )

This method will update the BSP index by removing the items from the temporary unindexed list and add them in the indexedItems list.

This will also update the growingItemsBoundingRect if needed. This will update the BSP implementation as well.

Warning
This function is not part of the public interface.

Definition at line 123 of file qgraphicsscenebsptreeindex.cpp.

Referenced by _q_updateSortCache().

124 {
126  if (!indexTimerId)
127  return;
128 
129  q->killTimer(indexTimerId);
130  indexTimerId = 0;
131 
133 
134  // Add unindexedItems to indexedItems
135  for (int i = 0; i < unindexedItems.size(); ++i) {
136  if (QGraphicsItem *item = unindexedItems.at(i)) {
137  Q_ASSERT(!item->d_ptr->itemDiscovered);
138  if (!freeItemIndexes.isEmpty()) {
139  int freeIndex = freeItemIndexes.takeFirst();
140  item->d_func()->index = freeIndex;
141  indexedItems[freeIndex] = item;
142  } else {
143  item->d_func()->index = indexedItems.size();
144  indexedItems << item;
145  }
146  }
147  }
148 
149  // Determine whether we should regenerate the BSP tree.
150  if (bspTreeDepth == 0) {
151  int oldDepth = intmaxlog(lastItemCount);
153  static const int slack = 100;
154  if (bsp.leafCount() == 0 || (oldDepth != bspTreeDepth && qAbs(lastItemCount - indexedItems.size()) > slack)) {
155  // ### Crude algorithm.
156  regenerateIndex = true;
157  }
158  }
159 
160  // Regenerate the tree.
161  if (regenerateIndex) {
162  regenerateIndex = false;
166  }
167 
168  // Insert all unindexed items into the tree.
169  for (int i = 0; i < unindexedItems.size(); ++i) {
170  if (QGraphicsItem *item = unindexedItems.at(i)) {
171  if (item->d_ptr->itemIsUntransformable()) {
172  untransformableItems << item;
173  continue;
174  }
175  if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
176  continue;
177 
178  bsp.insertItem(item, item->d_ptr->sceneEffectiveBoundingRect());
179  }
180  }
182 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void initialize(const QRectF &rect, int depth)
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void purgeRemovedItems()
Removes stale pointers from all data structures.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
void insertItem(QGraphicsItem *item, const QRectF &rect)
static int intmaxlog(int n)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ _q_updateSortCache()

void QGraphicsSceneBspTreeIndexPrivate::_q_updateSortCache ( )
Warning
This function is not part of the public interface.

Definition at line 275 of file qgraphicsscenebsptreeindex.cpp.

Referenced by estimateItems().

276 {
278  _q_updateIndex();
279 
281  return;
282 
283  updatingSortCache = false;
284  int stackingOrder = 0;
285 
286  QList<QGraphicsItem *> topLevels;
287  const QList<QGraphicsItem *> items = q->items();
288  for (int i = 0; i < items.size(); ++i) {
289  QGraphicsItem *item = items.at(i);
290  if (item && !item->d_ptr->parent)
291  topLevels << item;
292  }
293 
294  qSort(topLevels.begin(), topLevels.end(), qt_closestLeaf);
295  for (int i = 0; i < topLevels.size(); ++i)
296  climbTree(topLevels.at(i), &stackingOrder);
297 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
#define Q_Q(Class)
Definition: qglobal.h:2483
static void climbTree(QGraphicsItem *item, int *stackingOrder)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
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)
Definition: qalgorithms.h:177
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ addItem()

void QGraphicsSceneBspTreeIndexPrivate::addItem ( QGraphicsItem item,
bool  recursive = false 
)

Definition at line 312 of file qgraphicsscenebsptreeindex.cpp.

Referenced by removeItem().

313 {
314  if (!item)
315  return;
316 
317  // Prevent reusing a recently deleted pointer: purge all removed item from our lists.
319 
320  // Invalidate any sort caching; arrival of a new item means we need to resort.
321  // Update the scene's sort cache settings.
322  item->d_ptr->globalStackingOrder = -1;
324 
325  // Indexing requires sceneBoundingRect(), but because \a item might
326  // not be completely constructed at this point, we need to store it in
327  // a temporary list and schedule an indexing for later.
328  if (item->d_ptr->index == -1) {
330  unindexedItems << item;
331  startIndexTimer(0);
332  } else {
334  qWarning("QGraphicsSceneBspTreeIndex::addItem: item has already been added to this BSP");
335  }
336 
337  if (recursive) {
338  for (int i = 0; i < item->d_ptr->children.size(); ++i)
339  addItem(item->d_ptr->children.at(i), recursive);
340  }
341 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void purgeRemovedItems()
Removes stale pointers from all data structures.
void addItem(QGraphicsItem *item, bool recursive=false)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
void startIndexTimer(int interval=QGRAPHICSSCENE_INDEXTIMER_TIMEOUT)
Starts or restarts the timer used for reindexing unindexed items.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QGraphicsItem * > children

◆ climbTree()

void QGraphicsSceneBspTreeIndexPrivate::climbTree ( QGraphicsItem item,
int *  stackingOrder 
)
static
Warning
This function is not part of the public interface.

Definition at line 251 of file qgraphicsscenebsptreeindex.cpp.

Referenced by _q_updateSortCache().

252 {
253  if (!item->d_ptr->children.isEmpty()) {
254  QList<QGraphicsItem *> childList = item->d_ptr->children;
255  qSort(childList.begin(), childList.end(), qt_closestLeaf);
256  for (int i = 0; i < childList.size(); ++i) {
257  QGraphicsItem *item = childList.at(i);
259  climbTree(childList.at(i), stackingOrder);
260  }
261  item->d_ptr->globalStackingOrder = (*stackingOrder)++;
262  for (int i = 0; i < childList.size(); ++i) {
263  QGraphicsItem *item = childList.at(i);
265  climbTree(childList.at(i), stackingOrder);
266  }
267  } else {
268  item->d_ptr->globalStackingOrder = (*stackingOrder)++;
269  }
270 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static void climbTree(QGraphicsItem *item, int *stackingOrder)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QGraphicsItem * > children
bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ closestItemFirst_withCache()

static bool QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withCache ( const QGraphicsItem item1,
const QGraphicsItem item2 
)
inlinestatic

Definition at line 149 of file qgraphicsscenebsptreeindex_p.h.

Referenced by sortItems().

150  {
151  return item1->d_ptr->globalStackingOrder < item2->d_ptr->globalStackingOrder;
152  }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ closestItemLast_withCache()

static bool QGraphicsSceneBspTreeIndexPrivate::closestItemLast_withCache ( const QGraphicsItem item1,
const QGraphicsItem item2 
)
inlinestatic

Definition at line 153 of file qgraphicsscenebsptreeindex_p.h.

Referenced by sortItems().

154  {
155  return item1->d_ptr->globalStackingOrder >= item2->d_ptr->globalStackingOrder;
156  }
QScopedPointer< QGraphicsItemPrivate > d_ptr

◆ estimateItems()

QList< QGraphicsItem * > QGraphicsSceneBspTreeIndexPrivate::estimateItems ( const QRectF rect,
Qt::SortOrder  order,
bool  b = false 
)

Definition at line 385 of file qgraphicsscenebsptreeindex.cpp.

387 {
389  if (onlyTopLevelItems && rect.isNull())
390  return q->QGraphicsSceneIndex::estimateTopLevelItems(rect, order);
391 
395 
396  QList<QGraphicsItem *> rectItems = bsp.items(rect, onlyTopLevelItems);
397  if (onlyTopLevelItems) {
398  for (int i = 0; i < untransformableItems.size(); ++i) {
400  if (!item->d_ptr->parent) {
401  rectItems << item;
402  } else {
403  item = item->topLevelItem();
404  if (!rectItems.contains(item))
405  rectItems << item;
406  }
407  }
408  } else {
409  rectItems += untransformableItems;
410  }
411 
412  sortItems(&rectItems, order, sortCacheEnabled, onlyTopLevelItems);
413  return rectItems;
414 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
QList< QGraphicsItem * > items(const QRectF &rect, bool onlyTopLevelItems=false) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void purgeRemovedItems()
Removes stale pointers from all data structures.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
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&#39;s top-level item.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ invalidateSortCache()

void QGraphicsSceneBspTreeIndexPrivate::invalidateSortCache ( )
Warning
This function is not part of the public interface.

Definition at line 302 of file qgraphicsscenebsptreeindex.cpp.

Referenced by addItem(), and removeItem().

303 {
306  return;
307 
308  updatingSortCache = true;
309  QMetaObject::invokeMethod(q, "_q_updateSortCache", Qt::QueuedConnection);
310 }
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
#define Q_Q(Class)
Definition: qglobal.h:2483
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ purgeRemovedItems()

void QGraphicsSceneBspTreeIndexPrivate::purgeRemovedItems ( )

Removes stale pointers from all data structures.

Warning
This function is not part of the public interface.

Definition at line 193 of file qgraphicsscenebsptreeindex.cpp.

Referenced by _q_updateIndex(), addItem(), estimateItems(), and resetIndex().

194 {
196  return;
197 
198  // Remove stale items from the BSP tree.
200  // Purge this list.
203  for (int i = 0; i < indexedItems.size(); ++i) {
204  if (!indexedItems.at(i))
205  freeItemIndexes << i;
206  }
207  purgePending = false;
208 }
bool isEmpty() const
Definition: qset.h:77
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Definition: qset.h:87
void clear()
Removes all items from the list.
Definition: qlist.h:764
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void removeItems(const QSet< QGraphicsItem *> &items)

◆ removeItem()

void QGraphicsSceneBspTreeIndexPrivate::removeItem ( QGraphicsItem item,
bool  recursive = false,
bool  moveToUnindexedItems = false 
)

Definition at line 343 of file qgraphicsscenebsptreeindex.cpp.

345 {
346  if (!item)
347  return;
348 
349  if (item->d_ptr->index != -1) {
350  Q_ASSERT(item->d_ptr->index < indexedItems.size());
351  Q_ASSERT(indexedItems.at(item->d_ptr->index) == item);
352  Q_ASSERT(!item->d_ptr->itemDiscovered);
353  freeItemIndexes << item->d_ptr->index;
354  indexedItems[item->d_ptr->index] = 0;
355  item->d_ptr->index = -1;
356 
357  if (item->d_ptr->itemIsUntransformable()) {
359  } else if (item->d_ptr->inDestructor) {
360  // Avoid virtual function calls from the destructor.
361  purgePending = true;
362  removedItems << item;
365  }
366  } else {
368  }
369  invalidateSortCache(); // ### Only do this when removing from BSP?
370 
371  Q_ASSERT(item->d_ptr->index == -1);
375 
376  if (moveToUnindexedItems)
377  addItem(item);
378 
379  if (recursive) {
380  for (int i = 0; i < item->d_ptr->children.size(); ++i)
381  removeItem(item->d_ptr->children.at(i), recursive, moveToUnindexedItems);
382  }
383 }
QRectF sceneEffectiveBoundingRect() const
Returns the effective bounding rect of this item in scene coordinates, by combining sceneTransform() ...
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
void addItem(QGraphicsItem *item, bool recursive=false)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool itemIsUntransformable() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QGraphicsItem * > children
void removeItem(QGraphicsItem *item, const QRectF &rect)
void removeItem(QGraphicsItem *item, bool recursive=false, bool moveToUnindexedItems=false)

◆ resetIndex()

void QGraphicsSceneBspTreeIndexPrivate::resetIndex ( )
Warning
This function is not part of the public interface.

Definition at line 231 of file qgraphicsscenebsptreeindex.cpp.

232 {
234  for (int i = 0; i < indexedItems.size(); ++i) {
235  if (QGraphicsItem *item = indexedItems.at(i)) {
236  item->d_ptr->index = -1;
237  Q_ASSERT(!item->d_ptr->itemDiscovered);
238  unindexedItems << item;
239  }
240  }
244  regenerateIndex = true;
245  startIndexTimer();
246 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void purgeRemovedItems()
Removes stale pointers from all data structures.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
void startIndexTimer(int interval=QGRAPHICSSCENE_INDEXTIMER_TIMEOUT)
Starts or restarts the timer used for reindexing unindexed items.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ sortItems()

void QGraphicsSceneBspTreeIndexPrivate::sortItems ( QList< QGraphicsItem *> *  itemList,
Qt::SortOrder  order,
bool  sortCacheEnabled,
bool  onlyTopLevelItems = false 
)
static

Sort a list of itemList in a specific order and use the cache if requested.

Warning
This function is not part of the public interface.

Definition at line 421 of file qgraphicsscenebsptreeindex.cpp.

Referenced by estimateItems().

423 {
424  if (order == Qt::SortOrder(-1))
425  return;
426 
427  if (onlyTopLevelItems) {
428  if (order == Qt::DescendingOrder)
429  qSort(itemList->begin(), itemList->end(), qt_closestLeaf);
430  else if (order == Qt::AscendingOrder)
431  qSort(itemList->begin(), itemList->end(), qt_notclosestLeaf);
432  return;
433  }
434 
435  if (sortCacheEnabled) {
436  if (order == Qt::DescendingOrder) {
437  qSort(itemList->begin(), itemList->end(), closestItemFirst_withCache);
438  } else if (order == Qt::AscendingOrder) {
439  qSort(itemList->begin(), itemList->end(), closestItemLast_withCache);
440  }
441  } else {
442  if (order == Qt::DescendingOrder) {
443  qSort(itemList->begin(), itemList->end(), qt_closestItemFirst);
444  } else if (order == Qt::AscendingOrder) {
445  qSort(itemList->begin(), itemList->end(), qt_closestItemLast);
446  }
447  }
448 }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
static bool closestItemLast_withCache(const QGraphicsItem *item1, const QGraphicsItem *item2)
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 qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item1 is on top of item2.
SortOrder
Definition: qnamespace.h:189
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
bool qt_closestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)

◆ startIndexTimer()

void QGraphicsSceneBspTreeIndexPrivate::startIndexTimer ( int  interval = QGRAPHICSSCENE_INDEXTIMER_TIMEOUT)

Starts or restarts the timer used for reindexing unindexed items.

Warning
This function is not part of the public interface.

Definition at line 218 of file qgraphicsscenebsptreeindex.cpp.

Referenced by addItem(), and resetIndex().

219 {
221  if (indexTimerId) {
222  restartIndexTimer = true;
223  } else {
224  indexTimerId = q->startTimer(interval);
225  }
226 }
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
#define Q_Q(Class)
Definition: qglobal.h:2483

Properties

◆ bsp

QGraphicsSceneBspTree QGraphicsSceneBspTreeIndexPrivate::bsp

◆ bspTreeDepth

int QGraphicsSceneBspTreeIndexPrivate::bspTreeDepth

Definition at line 120 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateIndex().

◆ freeItemIndexes

QList<int> QGraphicsSceneBspTreeIndexPrivate::freeItemIndexes

◆ indexedItems

QList<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::indexedItems

◆ indexTimerId

int QGraphicsSceneBspTreeIndexPrivate::indexTimerId

Definition at line 121 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateIndex(), and startIndexTimer().

◆ lastItemCount

int QGraphicsSceneBspTreeIndexPrivate::lastItemCount

Definition at line 124 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateIndex().

◆ purgePending

bool QGraphicsSceneBspTreeIndexPrivate::purgePending

Definition at line 131 of file qgraphicsscenebsptreeindex_p.h.

Referenced by purgeRemovedItems(), and removeItem().

◆ regenerateIndex

bool QGraphicsSceneBspTreeIndexPrivate::regenerateIndex

Definition at line 123 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateIndex(), and resetIndex().

◆ removedItems

QSet<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::removedItems

Definition at line 132 of file qgraphicsscenebsptreeindex_p.h.

Referenced by purgeRemovedItems(), and removeItem().

◆ restartIndexTimer

bool QGraphicsSceneBspTreeIndexPrivate::restartIndexTimer

Definition at line 122 of file qgraphicsscenebsptreeindex_p.h.

Referenced by startIndexTimer().

◆ sceneRect

QRectF QGraphicsSceneBspTreeIndexPrivate::sceneRect

Definition at line 119 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateIndex().

◆ sortCacheEnabled

bool QGraphicsSceneBspTreeIndexPrivate::sortCacheEnabled

◆ unindexedItems

QList<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::unindexedItems

◆ untransformableItems

QList<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::untransformableItems

◆ updatingSortCache

bool QGraphicsSceneBspTreeIndexPrivate::updatingSortCache

Definition at line 141 of file qgraphicsscenebsptreeindex_p.h.

Referenced by _q_updateSortCache(), and invalidateSortCache().


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