summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicssceneindex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraphicssceneindex.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicssceneindex.cpp70
1 files changed, 26 insertions, 44 deletions
diff --git a/src/widgets/graphicsview/qgraphicssceneindex.cpp b/src/widgets/graphicsview/qgraphicssceneindex.cpp
index 398e72e4c3..40f63937f4 100644
--- a/src/widgets/graphicsview/qgraphicssceneindex.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneindex.cpp
@@ -67,12 +67,13 @@
QT_BEGIN_NAMESPACE
-class QGraphicsSceneIndexRectIntersector : public QGraphicsSceneIndexIntersector
-{
-public:
- bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
- const QTransform &deviceTransform) const
+namespace QtPrivate { // just to keep indentation of the following functions at the same level
+
+ static bool intersect_rect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
+ const QTransform &deviceTransform, const void *intersectData)
{
+ const QRectF sceneRect = *static_cast<const QRectF *>(intersectData);
+
QRectF brect = item->boundingRect();
_q_adjustRect(&brect);
@@ -117,15 +118,11 @@ public:
return keep;
}
- QRectF sceneRect;
-};
-
-class QGraphicsSceneIndexPointIntersector : public QGraphicsSceneIndexIntersector
-{
-public:
- bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
- const QTransform &deviceTransform) const
+ static bool intersect_point(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
+ const QTransform &deviceTransform, const void *intersectData)
{
+ const QPointF scenePoint = *static_cast<const QPointF *>(intersectData);
+
QRectF brect = item->boundingRect();
_q_adjustRect(&brect);
@@ -163,15 +160,11 @@ public:
return keep;
}
- QPointF scenePoint;
-};
-
-class QGraphicsSceneIndexPathIntersector : public QGraphicsSceneIndexIntersector
-{
-public:
- bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
- const QTransform &deviceTransform) const
+ static bool intersect_path(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
+ const QTransform &deviceTransform, const void *intersectData)
{
+ const QPainterPath scenePath = *static_cast<const QPainterPath *>(intersectData);
+
QRectF brect = item->boundingRect();
_q_adjustRect(&brect);
@@ -211,17 +204,13 @@ public:
return keep;
}
- QPainterPath scenePath;
-};
+} // namespace QtPrivate
/*!
Constructs a private scene index.
*/
QGraphicsSceneIndexPrivate::QGraphicsSceneIndexPrivate(QGraphicsScene *scene) : scene(scene)
{
- pointIntersector = new QGraphicsSceneIndexPointIntersector;
- rectIntersector = new QGraphicsSceneIndexRectIntersector;
- pathIntersector = new QGraphicsSceneIndexPathIntersector;
}
/*!
@@ -229,9 +218,6 @@ QGraphicsSceneIndexPrivate::QGraphicsSceneIndexPrivate(QGraphicsScene *scene) :
*/
QGraphicsSceneIndexPrivate::~QGraphicsSceneIndexPrivate()
{
- delete pointIntersector;
- delete rectIntersector;
- delete pathIntersector;
}
/*!
@@ -268,11 +254,11 @@ bool QGraphicsSceneIndexPrivate::itemCollidesWithPath(const QGraphicsItem *item,
This function returns the items in ascending order.
*/
void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRectF exposeRect,
- QGraphicsSceneIndexIntersector *intersector,
+ QGraphicsSceneIndexIntersector intersect,
QList<QGraphicsItem *> *items,
const QTransform &viewTransform,
Qt::ItemSelectionMode mode,
- qreal parentOpacity) const
+ qreal parentOpacity, const void *intersectData) const
{
Q_ASSERT(item);
if (!item->d_ptr->visible)
@@ -295,7 +281,7 @@ void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRe
const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
bool processItem = !itemIsFullyTransparent;
if (processItem) {
- processItem = intersector->intersect(item, exposeRect, mode, viewTransform);
+ processItem = intersect(item, exposeRect, mode, viewTransform, intersectData);
if (!processItem && (!itemHasChildren || itemClipsChildrenToShape)) {
if (wasDirtyParentSceneTransform)
item->d_ptr->invalidateChildrenSceneTransform();
@@ -326,8 +312,8 @@ void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRe
break;
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
continue;
- recursive_items_helper(child, exposeRect, intersector, items, viewTransform,
- mode, opacity);
+ recursive_items_helper(child, exposeRect, intersect, items, viewTransform,
+ mode, opacity, intersectData);
}
}
@@ -343,8 +329,8 @@ void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRe
child->d_ptr->dirtySceneTransform = 1;
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
continue;
- recursive_items_helper(child, exposeRect, intersector, items, viewTransform,
- mode, opacity);
+ recursive_items_helper(child, exposeRect, intersect, items, viewTransform,
+ mode, opacity, intersectData);
}
}
}
@@ -419,8 +405,7 @@ QList<QGraphicsItem *> QGraphicsSceneIndex::items(const QPointF &pos, Qt::ItemSe
Q_D(const QGraphicsSceneIndex);
QList<QGraphicsItem *> itemList;
- d->pointIntersector->scenePoint = pos;
- d->items_helper(QRectF(pos, QSizeF(1, 1)), d->pointIntersector, &itemList, deviceTransform, mode, order);
+ d->items_helper(QRectF(pos, QSizeF(1, 1)), &QtPrivate::intersect_point, &itemList, deviceTransform, mode, order, &pos);
return itemList;
}
@@ -453,8 +438,7 @@ QList<QGraphicsItem *> QGraphicsSceneIndex::items(const QRectF &rect, Qt::ItemSe
QRectF exposeRect = rect;
_q_adjustRect(&exposeRect);
QList<QGraphicsItem *> itemList;
- d->rectIntersector->sceneRect = rect;
- d->items_helper(exposeRect, d->rectIntersector, &itemList, deviceTransform, mode, order);
+ d->items_helper(exposeRect, &QtPrivate::intersect_rect, &itemList, deviceTransform, mode, order, &rect);
return itemList;
}
@@ -489,8 +473,7 @@ QList<QGraphicsItem *> QGraphicsSceneIndex::items(const QPolygonF &polygon, Qt::
_q_adjustRect(&exposeRect);
QPainterPath path;
path.addPolygon(polygon);
- d->pathIntersector->scenePath = path;
- d->items_helper(exposeRect, d->pathIntersector, &itemList, deviceTransform, mode, order);
+ d->items_helper(exposeRect, &QtPrivate::intersect_path, &itemList, deviceTransform, mode, order, &path);
return itemList;
}
@@ -523,8 +506,7 @@ QList<QGraphicsItem *> QGraphicsSceneIndex::items(const QPainterPath &path, Qt::
QList<QGraphicsItem *> itemList;
QRectF exposeRect = path.controlPointRect();
_q_adjustRect(&exposeRect);
- d->pathIntersector->scenePath = path;
- d->items_helper(exposeRect, d->pathIntersector, &itemList, deviceTransform, mode, order);
+ d->items_helper(exposeRect, &QtPrivate::intersect_path, &itemList, deviceTransform, mode, order, &path);
return itemList;
}