| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | | - |
| 49 | | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | #include <QtCore/qglobal.h> | - |
| 76 | | - |
| 77 | #ifndef QT_NO_GRAPHICSVIEW | - |
| 78 | | - |
| 79 | #include <private/qgraphicsscene_p.h> | - |
| 80 | #include <private/qgraphicsscenebsptreeindex_p.h> | - |
| 81 | #include <private/qgraphicssceneindex_p.h> | - |
| 82 | | - |
| 83 | #include <QtCore/qmath.h> | - |
| 84 | #include <QtCore/qdebug.h> | - |
| 85 | | - |
| 86 | #include <algorithm> | - |
| 87 | | - |
| 88 | QT_BEGIN_NAMESPACE | - |
| 89 | | - |
| 90 | static inline int intmaxlog(int n) | - |
| 91 | { | - |
| 92 | return (n > 0 ? qMax(qCeil(qLn(qreal(n)) / qLn(qreal(2))), 5) : 0); | - |
| 93 | } | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | QGraphicsSceneBspTreeIndexPrivate::QGraphicsSceneBspTreeIndexPrivate(QGraphicsScene *scene) | - |
| 99 | : QGraphicsSceneIndexPrivate(scene), | - |
| 100 | bspTreeDepth(0), | - |
| 101 | indexTimerId(0), | - |
| 102 | restartIndexTimer(false), | - |
| 103 | regenerateIndex(true), | - |
| 104 | lastItemCount(0), | - |
| 105 | purgePending(false), | - |
| 106 | sortCacheEnabled(false), | - |
| 107 | updatingSortCache(false) | - |
| 108 | { | - |
| 109 | } | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | void QGraphicsSceneBspTreeIndexPrivate::_q_updateIndex() | - |
| 121 | { | - |
| 122 | Q_Q(QGraphicsSceneBspTreeIndex); | - |
| 123 | if (!indexTimerId) | - |
| 124 | return; | - |
| 125 | | - |
| 126 | q->killTimer(indexTimerId); | - |
| 127 | indexTimerId = 0; | - |
| 128 | | - |
| 129 | purgeRemovedItems(); | - |
| 130 | | - |
| 131 | | - |
| 132 | for (int i = 0; i < unindexedItems.size(); ++i) { | - |
| 133 | if (QGraphicsItem *item = unindexedItems.at(i)) { | - |
| 134 | Q_ASSERT(!item->d_ptr->itemDiscovered); | - |
| 135 | if (!freeItemIndexes.isEmpty()) { | - |
| 136 | int freeIndex = freeItemIndexes.takeFirst(); | - |
| 137 | item->d_func()->index = freeIndex; | - |
| 138 | indexedItems[freeIndex] = item; | - |
| 139 | } else { | - |
| 140 | item->d_func()->index = indexedItems.size(); | - |
| 141 | indexedItems << item; | - |
| 142 | } | - |
| 143 | } | - |
| 144 | } | - |
| 145 | | - |
| 146 | | - |
| 147 | if (bspTreeDepth == 0) { | - |
| 148 | int oldDepth = intmaxlog(lastItemCount); | - |
| 149 | bspTreeDepth = intmaxlog(indexedItems.size()); | - |
| 150 | static const int slack = 100; | - |
| 151 | if (bsp.leafCount() == 0 || (oldDepth != bspTreeDepth && qAbs(lastItemCount - indexedItems.size()) > slack)) { | - |
| 152 | | - |
| 153 | regenerateIndex = true; | - |
| 154 | } | - |
| 155 | } | - |
| 156 | | - |
| 157 | | - |
| 158 | if (regenerateIndex) { | - |
| 159 | regenerateIndex = false; | - |
| 160 | bsp.initialize(sceneRect, bspTreeDepth); | - |
| 161 | unindexedItems = indexedItems; | - |
| 162 | lastItemCount = indexedItems.size(); | - |
| 163 | } | - |
| 164 | | - |
| 165 | | - |
| 166 | for (int i = 0; i < unindexedItems.size(); ++i) { | - |
| 167 | if (QGraphicsItem *item = unindexedItems.at(i)) { | - |
| 168 | if (item->d_ptr->itemIsUntransformable()) { | - |
| 169 | untransformableItems << item; | - |
| 170 | continue; | - |
| 171 | } | - |
| 172 | if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren | - |
| 173 | || item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren) | - |
| 174 | continue; | - |
| 175 | | - |
| 176 | bsp.insertItem(item, item->d_ptr->sceneEffectiveBoundingRect()); | - |
| 177 | } | - |
| 178 | } | - |
| 179 | unindexedItems.clear(); | - |
| 180 | } | - |
| 181 | | - |
| 182 | | - |
| 183 | | - |
| 184 | | - |
| 185 | | - |
| 186 | | - |
| 187 | | - |
| 188 | void QGraphicsSceneBspTreeIndexPrivate::purgeRemovedItems() | - |
| 189 | { | - |
| 190 | if (!purgePending && removedItems.isEmpty()) | - |
| 191 | return; | - |
| 192 | | - |
| 193 | | - |
| 194 | bsp.removeItems(removedItems); | - |
| 195 | | - |
| 196 | removedItems.clear(); | - |
| 197 | freeItemIndexes.clear(); | - |
| 198 | for (int i = 0; i < indexedItems.size(); ++i) { | - |
| 199 | if (!indexedItems.at(i)) | - |
| 200 | freeItemIndexes << i; | - |
| 201 | } | - |
| 202 | purgePending = false; | - |
| 203 | } | - |
| 204 | | - |
| 205 | | - |
| 206 | | - |
| 207 | | - |
| 208 | | - |
| 209 | | - |
| 210 | void QGraphicsSceneBspTreeIndexPrivate::startIndexTimer(int interval) | - |
| 211 | { | - |
| 212 | Q_Q(QGraphicsSceneBspTreeIndex); | - |
| 213 | if (indexTimerId) { | - |
| 214 | restartIndexTimer = true; | - |
| 215 | } else { | - |
| 216 | indexTimerId = q->startTimer(interval); | - |
| 217 | } | - |
| 218 | } | - |
| 219 | | - |
| 220 | | - |
| 221 | | - |
| 222 | | - |
| 223 | void QGraphicsSceneBspTreeIndexPrivate::resetIndex() | - |
| 224 | { | - |
| 225 | purgeRemovedItems(); | - |
| 226 | for (int i = 0; i < indexedItems.size(); ++i) { | - |
| 227 | if (QGraphicsItem *item = indexedItems.at(i)) { | - |
| 228 | item->d_ptr->index = -1; | - |
| 229 | Q_ASSERT(!item->d_ptr->itemDiscovered); | - |
| 230 | unindexedItems << item; | - |
| 231 | } | - |
| 232 | } | - |
| 233 | indexedItems.clear(); | - |
| 234 | freeItemIndexes.clear(); | - |
| 235 | untransformableItems.clear(); | - |
| 236 | regenerateIndex = true; | - |
| 237 | startIndexTimer(); | - |
| 238 | } | - |
| 239 | | - |
| 240 | | - |
| 241 | | - |
| 242 | | - |
| 243 | void QGraphicsSceneBspTreeIndexPrivate::climbTree(QGraphicsItem *item, int *stackingOrder) | - |
| 244 | { | - |
| 245 | if (!item->d_ptr->children.isEmpty()) { | - |
| 246 | QList<QGraphicsItem *> childList = item->d_ptr->children; | - |
| 247 | std::sort(childList.begin(), childList.end(), qt_closestLeaf); | - |
| 248 | for (int i = 0; i < childList.size(); ++i) { | - |
| 249 | QGraphicsItem *item = childList.at(i); | - |
| 250 | if (!(item->flags() & QGraphicsItem::ItemStacksBehindParent)) | - |
| 251 | climbTree(childList.at(i), stackingOrder); | - |
| 252 | } | - |
| 253 | item->d_ptr->globalStackingOrder = (*stackingOrder)++; | - |
| 254 | for (int i = 0; i < childList.size(); ++i) { | - |
| 255 | QGraphicsItem *item = childList.at(i); | - |
| 256 | if (item->flags() & QGraphicsItem::ItemStacksBehindParent) | - |
| 257 | climbTree(childList.at(i), stackingOrder); | - |
| 258 | } | - |
| 259 | } else { | - |
| 260 | item->d_ptr->globalStackingOrder = (*stackingOrder)++; | - |
| 261 | } | - |
| 262 | } | - |
| 263 | | - |
| 264 | | - |
| 265 | | - |
| 266 | | - |
| 267 | void QGraphicsSceneBspTreeIndexPrivate::_q_updateSortCache() | - |
| 268 | { | - |
| 269 | Q_Q(QGraphicsSceneBspTreeIndex); | - |
| 270 | _q_updateIndex(); | - |
| 271 | | - |
| 272 | if (!sortCacheEnabled || !updatingSortCache) | - |
| 273 | return; | - |
| 274 | | - |
| 275 | updatingSortCache = false; | - |
| 276 | int stackingOrder = 0; | - |
| 277 | | - |
| 278 | QList<QGraphicsItem *> topLevels; | - |
| 279 | const QList<QGraphicsItem *> items = q->items(); | - |
| 280 | for (int i = 0; i < items.size(); ++i) { | - |
| 281 | QGraphicsItem *item = items.at(i); | - |
| 282 | if (item && !item->d_ptr->parent) | - |
| 283 | topLevels << item; | - |
| 284 | } | - |
| 285 | | - |
| 286 | std::sort(topLevels.begin(), topLevels.end(), qt_closestLeaf); | - |
| 287 | for (int i = 0; i < topLevels.size(); ++i) | - |
| 288 | climbTree(topLevels.at(i), &stackingOrder); | - |
| 289 | } | - |
| 290 | | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | void QGraphicsSceneBspTreeIndexPrivate::invalidateSortCache() | - |
| 295 | { | - |
| 296 | Q_Q(QGraphicsSceneBspTreeIndex); | - |
| 297 | if (!sortCacheEnabled || updatingSortCache) | - |
| 298 | return; | - |
| 299 | | - |
| 300 | updatingSortCache = true; | - |
| 301 | QMetaObject::invokeMethod(q, "_q_updateSortCache", Qt::QueuedConnection); | - |
| 302 | } | - |
| 303 | | - |
| 304 | void QGraphicsSceneBspTreeIndexPrivate::addItem(QGraphicsItem *item, bool recursive) | - |
| 305 | { | - |
| 306 | if (!item) | - |
| 307 | return; | - |
| 308 | | - |
| 309 | | - |
| 310 | purgeRemovedItems(); | - |
| 311 | | - |
| 312 | | - |
| 313 | | - |
| 314 | item->d_ptr->globalStackingOrder = -1; | - |
| 315 | invalidateSortCache(); | - |
| 316 | | - |
| 317 | | - |
| 318 | | - |
| 319 | | - |
| 320 | if (item->d_ptr->index == -1) { | - |
| 321 | Q_ASSERT(!unindexedItems.contains(item)); | - |
| 322 | unindexedItems << item; | - |
| 323 | startIndexTimer(0); | - |
| 324 | } else { | - |
| 325 | Q_ASSERT(indexedItems.contains(item)); | - |
| 326 | qWarning("QGraphicsSceneBspTreeIndex::addItem: item has already been added to this BSP"); | - |
| 327 | } | - |
| 328 | | - |
| 329 | if (recursive) { | - |
| 330 | for (int i = 0; i < item->d_ptr->children.size(); ++i) | - |
| 331 | addItem(item->d_ptr->children.at(i), recursive); | - |
| 332 | } | - |
| 333 | } | - |
| 334 | | - |
| 335 | void QGraphicsSceneBspTreeIndexPrivate::removeItem(QGraphicsItem *item, bool recursive, | - |
| 336 | bool moveToUnindexedItems) | - |
| 337 | { | - |
| 338 | if (!item) | - |
| 339 | return; | - |
| 340 | | - |
| 341 | if (item->d_ptr->index != -1) { | - |
| 342 | Q_ASSERT(item->d_ptr->index < indexedItems.size()); | - |
| 343 | Q_ASSERT(indexedItems.at(item->d_ptr->index) == item); | - |
| 344 | Q_ASSERT(!item->d_ptr->itemDiscovered); | - |
| 345 | freeItemIndexes << item->d_ptr->index; | - |
| 346 | indexedItems[item->d_ptr->index] = 0; | - |
| 347 | item->d_ptr->index = -1; | - |
| 348 | | - |
| 349 | if (item->d_ptr->itemIsUntransformable()) { | - |
| 350 | untransformableItems.removeOne(item); | - |
| 351 | } else if (item->d_ptr->inDestructor) { | - |
| 352 | | - |
| 353 | purgePending = true; | - |
| 354 | removedItems << item; | - |
| 355 | } else if (!(item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren | - |
| 356 | || item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren)) { | - |
| 357 | bsp.removeItem(item, item->d_ptr->sceneEffectiveBoundingRect()); | - |
| 358 | } | - |
| 359 | } else { | - |
| 360 | unindexedItems.removeOne(item); | - |
| 361 | } | - |
| 362 | invalidateSortCache(); | - |
| 363 | | - |
| 364 | Q_ASSERT(item->d_ptr->index == -1); | - |
| 365 | Q_ASSERT(!indexedItems.contains(item)); | - |
| 366 | Q_ASSERT(!unindexedItems.contains(item)); | - |
| 367 | Q_ASSERT(!untransformableItems.contains(item)); | - |
| 368 | | - |
| 369 | if (moveToUnindexedItems) | - |
| 370 | addItem(item); | - |
| 371 | | - |
| 372 | if (recursive) { | - |
| 373 | for (int i = 0; i < item->d_ptr->children.size(); ++i) | - |
| 374 | removeItem(item->d_ptr->children.at(i), recursive, moveToUnindexedItems); | - |
| 375 | } | - |
| 376 | } | - |
| 377 | | - |
| 378 | QList<QGraphicsItem *> QGraphicsSceneBspTreeIndexPrivate::estimateItems(const QRectF &rect, Qt::SortOrder order, | - |
| 379 | bool onlyTopLevelItems) | - |
| 380 | { | - |
| 381 | Q_Q(QGraphicsSceneBspTreeIndex); | - |
| 382 | if (onlyTopLevelItems && rect.isNull()) | - |
| 383 | return q->QGraphicsSceneIndex::estimateTopLevelItems(rect, order); | - |
| 384 | | - |
| 385 | purgeRemovedItems(); | - |
| 386 | _q_updateSortCache(); | - |
| 387 | Q_ASSERT(unindexedItems.isEmpty()); | - |
| 388 | | - |
| 389 | QList<QGraphicsItem *> rectItems = bsp.items(rect, onlyTopLevelItems); | - |
| 390 | if (onlyTopLevelItems) { | - |
| 391 | for (int i = 0; i < untransformableItems.size(); ++i) { | - |
| 392 | QGraphicsItem *item = untransformableItems.at(i); | - |
| 393 | if (!item->d_ptr->parent) { | - |
| 394 | rectItems << item; | - |
| 395 | } else { | - |
| 396 | item = item->topLevelItem(); | - |
| 397 | if (!rectItems.contains(item)) | - |
| 398 | rectItems << item; | - |
| 399 | } | - |
| 400 | } | - |
| 401 | } else { | - |
| 402 | rectItems += untransformableItems; | - |
| 403 | } | - |
| 404 | | - |
| 405 | sortItems(&rectItems, order, sortCacheEnabled, onlyTopLevelItems); | - |
| 406 | return rectItems; | - |
| 407 | } | - |
| 408 | | - |
| 409 | | - |
| 410 | | - |
| 411 | | - |
| 412 | | - |
| 413 | | - |
| 414 | void QGraphicsSceneBspTreeIndexPrivate::sortItems(QList<QGraphicsItem *> *itemList, Qt::SortOrder order, | - |
| 415 | bool sortCacheEnabled, bool onlyTopLevelItems) | - |
| 416 | { | - |
| 417 | if (order == Qt::SortOrder(-1)) | - |
| 418 | return; | - |
| 419 | | - |
| 420 | if (onlyTopLevelItems) { | - |
| 421 | if (order == Qt::DescendingOrder) | - |
| 422 | std::sort(itemList->begin(), itemList->end(), qt_closestLeaf); | - |
| 423 | else if (order == Qt::AscendingOrder) | - |
| 424 | std::sort(itemList->begin(), itemList->end(), qt_notclosestLeaf); | - |
| 425 | return; | - |
| 426 | } | - |
| 427 | | - |
| 428 | if (sortCacheEnabled) { | - |
| 429 | if (order == Qt::DescendingOrder) { | - |
| 430 | std::sort(itemList->begin(), itemList->end(), closestItemFirst_withCache); | - |
| 431 | } else if (order == Qt::AscendingOrder) { | - |
| 432 | std::sort(itemList->begin(), itemList->end(), closestItemLast_withCache); | - |
| 433 | } | - |
| 434 | } else { | - |
| 435 | if (order == Qt::DescendingOrder) { | - |
| 436 | std::sort(itemList->begin(), itemList->end(), qt_closestItemFirst); | - |
| 437 | } else if (order == Qt::AscendingOrder) { | - |
| 438 | std::sort(itemList->begin(), itemList->end(), qt_closestItemLast); | - |
| 439 | } | - |
| 440 | } | - |
| 441 | } | - |
| 442 | | - |
| 443 | | - |
| 444 | | - |
| 445 | | - |
| 446 | QGraphicsSceneBspTreeIndex::QGraphicsSceneBspTreeIndex(QGraphicsScene *scene) | - |
| 447 | : QGraphicsSceneIndex(*new QGraphicsSceneBspTreeIndexPrivate(scene), scene) | - |
| 448 | { | - |
| 449 | | - |
| 450 | } | - |
| 451 | | - |
| 452 | QGraphicsSceneBspTreeIndex::~QGraphicsSceneBspTreeIndex() | - |
| 453 | { | - |
| 454 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 455 | for (int i = 0; i < d->indexedItems.size(); ++i) { | - |
| 456 | | - |
| 457 | if (QGraphicsItem *item = d->indexedItems.at(i)) { | - |
| 458 | Q_ASSERT(!item->d_ptr->itemDiscovered); | - |
| 459 | item->d_ptr->index = -1; | - |
| 460 | } | - |
| 461 | } | - |
| 462 | } | - |
| 463 | | - |
| 464 | | - |
| 465 | | - |
| 466 | | - |
| 467 | | - |
| 468 | void QGraphicsSceneBspTreeIndex::clear() | - |
| 469 | { | - |
| 470 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 471 | d->bsp.clear(); | - |
| 472 | d->lastItemCount = 0; | - |
| 473 | d->freeItemIndexes.clear(); | - |
| 474 | for (int i = 0; i < d->indexedItems.size(); ++i) { | - |
| 475 | | - |
| 476 | if (QGraphicsItem *item = d->indexedItems.at(i)) { | - |
| 477 | Q_ASSERT(!item->d_ptr->itemDiscovered); | - |
| 478 | item->d_ptr->index = -1; | - |
| 479 | } | - |
| 480 | } | - |
| 481 | d->indexedItems.clear(); | - |
| 482 | d->unindexedItems.clear(); | - |
| 483 | d->untransformableItems.clear(); | - |
| 484 | d->regenerateIndex = true; | - |
| 485 | } | - |
| 486 | | - |
| 487 | | - |
| 488 | | - |
| 489 | | - |
| 490 | void QGraphicsSceneBspTreeIndex::addItem(QGraphicsItem *item) | - |
| 491 | { | - |
| 492 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 493 | d->addItem(item); | - |
| 494 | } | - |
| 495 | | - |
| 496 | | - |
| 497 | | - |
| 498 | | - |
| 499 | void QGraphicsSceneBspTreeIndex::removeItem(QGraphicsItem *item) | - |
| 500 | { | - |
| 501 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 502 | d->removeItem(item); | - |
| 503 | } | - |
| 504 | | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | | - |
| 509 | void QGraphicsSceneBspTreeIndex::prepareBoundingRectChange(const QGraphicsItem *item) | - |
| 510 | { | - |
| 511 | if (!item) | - |
| 512 | return; | - |
| 513 | | - |
| 514 | if (item->d_ptr->index == -1 || item->d_ptr->itemIsUntransformable() | - |
| 515 | || (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren | - |
| 516 | || item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren)) { | - |
| 517 | return; | - |
| 518 | } | - |
| 519 | | - |
| 520 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 521 | QGraphicsItem *thatItem = const_cast<QGraphicsItem *>(item); | - |
| 522 | d->removeItem(thatItem, false, true); | - |
| 523 | for (int i = 0; i < item->d_ptr->children.size(); ++i) | - |
| 524 | prepareBoundingRectChange(item->d_ptr->children.at(i)); | - |
| 525 | } | - |
| 526 | | - |
| 527 | | - |
| 528 | | - |
| 529 | | - |
| 530 | | - |
| 531 | | - |
| 532 | | - |
| 533 | | - |
| 534 | QList<QGraphicsItem *> QGraphicsSceneBspTreeIndex::estimateItems(const QRectF &rect, Qt::SortOrder order) const | - |
| 535 | { | - |
| 536 | Q_D(const QGraphicsSceneBspTreeIndex); | - |
| 537 | return const_cast<QGraphicsSceneBspTreeIndexPrivate*>(d)->estimateItems(rect, order); | - |
| 538 | } | - |
| 539 | | - |
| 540 | QList<QGraphicsItem *> QGraphicsSceneBspTreeIndex::estimateTopLevelItems(const QRectF &rect, Qt::SortOrder order) const | - |
| 541 | { | - |
| 542 | Q_D(const QGraphicsSceneBspTreeIndex); | - |
| 543 | return const_cast<QGraphicsSceneBspTreeIndexPrivate*>(d)->estimateItems(rect, order, true); | - |
| 544 | } | - |
| 545 | | - |
| 546 | | - |
| 547 | | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | QList<QGraphicsItem *> QGraphicsSceneBspTreeIndex::items(Qt::SortOrder order) const | - |
| 552 | { | - |
| 553 | Q_D(const QGraphicsSceneBspTreeIndex); | - |
| 554 | const_cast<QGraphicsSceneBspTreeIndexPrivate*>(d)->purgeRemovedItems(); | - |
| 555 | QList<QGraphicsItem *> itemList; | - |
| 556 | ifitemList.reserve(d->freeItemIndexesindexedItems.isEmpty()) { | - |
| if (size() + d->unindexedItems.isEmpty()) { | |
| itemListsize()); | |
| 557 | | - |
| 558 | | - |
| 559 | | - |
| 560 | QGraphicsItem *null = d->indexedItemsnullptr; } else { | - |
| itemList = | |
| 561 | | - |
| 562 | | - |
| 563 | std::remove_copy(d->indexedItems+.cbegin(), d->unindexedItems; | - |
| } | |
| } else { | |
| foreachindexedItems.cend(), | |
| 564 | std::back_inserter(QGraphicsItem *item,itemList), null); | - |
| 565 | std::remove_copy(d->indexedItems +unindexedItems.cbegin(), d->unindexedItems) { | - |
| if.cend(), | |
| 566 | std::back_inserter(item)itemList<< item; | - |
| } | |
| }), null); | |
| 567 | | - |
| 568 | d->sortItems(&itemList, order, d->sortCacheEnabled); | - |
| 569 | return itemList; never executed: return itemList; | 0 |
| 570 | } | - |
| 571 | | - |
| 572 | | - |
| 573 | | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | | - |
| 579 | | - |
| 580 | | - |
| 581 | | - |
| 582 | | - |
| 583 | | - |
| 584 | | - |
| 585 | | - |
| 586 | | - |
| 587 | | - |
| 588 | | - |
| 589 | | - |
| 590 | | - |
| 591 | | - |
| 592 | | - |
| 593 | | - |
| 594 | | - |
| 595 | | - |
| 596 | | - |
| 597 | | - |
| 598 | | - |
| 599 | int QGraphicsSceneBspTreeIndex::bspTreeDepth() const | - |
| 600 | { | - |
| 601 | Q_D(const QGraphicsSceneBspTreeIndex); | - |
| 602 | return d->bspTreeDepth; | - |
| 603 | } | - |
| 604 | | - |
| 605 | void QGraphicsSceneBspTreeIndex::setBspTreeDepth(int depth) | - |
| 606 | { | - |
| 607 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 608 | if (d->bspTreeDepth == depth) | - |
| 609 | return; | - |
| 610 | d->bspTreeDepth = depth; | - |
| 611 | d->resetIndex(); | - |
| 612 | } | - |
| 613 | | - |
| 614 | | - |
| 615 | | - |
| 616 | | - |
| 617 | | - |
| 618 | | - |
| 619 | | - |
| 620 | void QGraphicsSceneBspTreeIndex::updateSceneRect(const QRectF &rect) | - |
| 621 | { | - |
| 622 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 623 | d->sceneRect = rect; | - |
| 624 | d->resetIndex(); | - |
| 625 | } | - |
| 626 | | - |
| 627 | | - |
| 628 | | - |
| 629 | | - |
| 630 | | - |
| 631 | | - |
| 632 | | - |
| 633 | void QGraphicsSceneBspTreeIndex::itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const void *const value) | - |
| 634 | { | - |
| 635 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 636 | switch (change) { | - |
| 637 | case QGraphicsItem::ItemFlagsChange: { | - |
| 638 | | - |
| 639 | QGraphicsItem::GraphicsItemFlags newFlags = *static_cast<const QGraphicsItem::GraphicsItemFlags *>(value); | - |
| 640 | bool ignoredTransform = item->d_ptr->flags & QGraphicsItem::ItemIgnoresTransformations; | - |
| 641 | bool willIgnoreTransform = newFlags & QGraphicsItem::ItemIgnoresTransformations; | - |
| 642 | bool clipsChildren = item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape | - |
| 643 | || item->d_ptr->flags & QGraphicsItem::ItemContainsChildrenInShape; | - |
| 644 | bool willClipChildren = newFlags & QGraphicsItem::ItemClipsChildrenToShape | - |
| 645 | || newFlags & QGraphicsItem::ItemContainsChildrenInShape; | - |
| 646 | if ((ignoredTransform != willIgnoreTransform) || (clipsChildren != willClipChildren)) { | - |
| 647 | QGraphicsItem *thatItem = const_cast<QGraphicsItem *>(item); | - |
| 648 | | - |
| 649 | | - |
| 650 | | - |
| 651 | | - |
| 652 | d->removeItem(thatItem, true, true); | - |
| 653 | } | - |
| 654 | break; | - |
| 655 | } | - |
| 656 | case QGraphicsItem::ItemZValueChange: | - |
| 657 | d->invalidateSortCache(); | - |
| 658 | break; | - |
| 659 | case QGraphicsItem::ItemParentChange: { | - |
| 660 | d->invalidateSortCache(); | - |
| 661 | | - |
| 662 | const QGraphicsItem *newParent = static_cast<const QGraphicsItem *>(value); | - |
| 663 | bool ignoredTransform = item->d_ptr->itemIsUntransformable(); | - |
| 664 | bool willIgnoreTransform = (item->d_ptr->flags & QGraphicsItem::ItemIgnoresTransformations) | - |
| 665 | || (newParent && newParent->d_ptr->itemIsUntransformable()); | - |
| 666 | bool ancestorClippedChildren = item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren | - |
| 667 | || item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren; | - |
| 668 | bool ancestorWillClipChildren = newParent | - |
| 669 | && ((newParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape | - |
| 670 | || newParent->d_ptr->flags & QGraphicsItem::ItemContainsChildrenInShape) | - |
| 671 | || (newParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren | - |
| 672 | || newParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren)); | - |
| 673 | if ((ignoredTransform != willIgnoreTransform) || (ancestorClippedChildren != ancestorWillClipChildren)) { | - |
| 674 | QGraphicsItem *thatItem = const_cast<QGraphicsItem *>(item); | - |
| 675 | | - |
| 676 | | - |
| 677 | | - |
| 678 | | - |
| 679 | d->removeItem(thatItem, true, true); | - |
| 680 | } | - |
| 681 | break; | - |
| 682 | } | - |
| 683 | default: | - |
| 684 | break; | - |
| 685 | } | - |
| 686 | } | - |
| 687 | | - |
| 688 | | - |
| 689 | | - |
| 690 | | - |
| 691 | | - |
| 692 | | - |
| 693 | | - |
| 694 | bool QGraphicsSceneBspTreeIndex::event(QEvent *event) | - |
| 695 | { | - |
| 696 | Q_D(QGraphicsSceneBspTreeIndex); | - |
| 697 | if (event->type() == QEvent::Timer) { | - |
| 698 | if (d->indexTimerId && static_cast<QTimerEvent *>(event)->timerId() == d->indexTimerId) { | - |
| 699 | if (d->restartIndexTimer) { | - |
| 700 | d->restartIndexTimer = false; | - |
| 701 | } else { | - |
| 702 | | - |
| 703 | d->_q_updateIndex(); | - |
| 704 | } | - |
| 705 | } | - |
| 706 | } | - |
| 707 | return QObject::event(event); | - |
| 708 | } | - |
| 709 | | - |
| 710 | QT_END_NAMESPACE | - |
| 711 | | - |
| 712 | #include "moc_qgraphicsscenebsptreeindex_p.cpp" | - |
| 713 | | - |
| 714 | #endif // QT_NO_GRAPHICSVIEW | - |
| 715 | | - |
| | |