summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicssceneindex_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-10-13 14:26:28 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-01 15:51:17 +0100
commit861574ebb634b73be917ad82926e4d6faa21607b (patch)
treea9c14ac424edf36afcd4c670047dbab9257c699b /src/widgets/graphicsview/qgraphicssceneindex_p.h
parent5e99b07a072bedee239ed6980a44719da9ffa7c9 (diff)
QGraphicsSceneIndex: replace polymorphism with a function pointer
QGraphicsSceneIndexIntersector was used as a kind of polymorpic predicate in items_helper(). But it had only one function and the instances of it, which were kept around in QGraphicsSceneIndexPrivate, were re-initialised on every call to items_helper(), which means that one can just as well pass that miniscule amount of data to the function itself. Replaced the polymorphism with a function pointer and the comparison state (which is conceptually const if it wasn't for the requirement to assign to it all the time) with a const void * argument. Effects on Linux AMD64 GCC 4.9-trunk release stripped: text: -1584B data: -376B relocs: -26 I've wrapped the functions in a namespace. The only reason for this is to keep the functions, previously defined in class bodies, at the same indentation level so as not to destroy the git-blame history for them. Change-Id: I8e1f48030047a3c54e881de7c77a3325b3e1f509 Reviewed-by: Alexis Menard <alexis@webkit.org> Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicssceneindex_p.h')
-rw-r--r--src/widgets/graphicsview/qgraphicssceneindex_p.h33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/widgets/graphicsview/qgraphicssceneindex_p.h b/src/widgets/graphicsview/qgraphicssceneindex_p.h
index 29b321fb1d..215fefe9b7 100644
--- a/src/widgets/graphicsview/qgraphicssceneindex_p.h
+++ b/src/widgets/graphicsview/qgraphicssceneindex_p.h
@@ -66,15 +66,14 @@ QT_BEGIN_NAMESPACE
#if !defined(QT_NO_GRAPHICSVIEW)
-class QGraphicsSceneIndexIntersector;
-class QGraphicsSceneIndexPointIntersector;
-class QGraphicsSceneIndexRectIntersector;
-class QGraphicsSceneIndexPathIntersector;
class QGraphicsSceneIndexPrivate;
class QPointF;
class QRectF;
template<typename T> class QList;
+typedef bool (*QGraphicsSceneIndexIntersector)(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
+ const QTransform &deviceTransform, const void *data);
+
class Q_AUTOTEST_EXPORT QGraphicsSceneIndex : public QObject
{
Q_OBJECT
@@ -133,27 +132,24 @@ public:
static bool itemCollidesWithPath(const QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode);
void recursive_items_helper(QGraphicsItem *item, QRectF exposeRect,
- QGraphicsSceneIndexIntersector *intersector, QList<QGraphicsItem *> *items,
+ QGraphicsSceneIndexIntersector intersect, QList<QGraphicsItem *> *items,
const QTransform &viewTransform,
- Qt::ItemSelectionMode mode, qreal parentOpacity = 1.0) const;
- inline void items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector *intersector,
+ Qt::ItemSelectionMode mode, qreal parentOpacity, const void *intersectData) const;
+ inline void items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector intersect,
QList<QGraphicsItem *> *items, const QTransform &viewTransform,
- Qt::ItemSelectionMode mode, Qt::SortOrder order) const;
+ Qt::ItemSelectionMode mode, Qt::SortOrder order, const void *intersectData) const;
QGraphicsScene *scene;
- QGraphicsSceneIndexPointIntersector *pointIntersector;
- QGraphicsSceneIndexRectIntersector *rectIntersector;
- QGraphicsSceneIndexPathIntersector *pathIntersector;
};
-inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector *intersector,
+inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector intersect,
QList<QGraphicsItem *> *items, const QTransform &viewTransform,
- Qt::ItemSelectionMode mode, Qt::SortOrder order) const
+ Qt::ItemSelectionMode mode, Qt::SortOrder order, const void *intersectData) const
{
Q_Q(const QGraphicsSceneIndex);
const QList<QGraphicsItem *> tli = q->estimateTopLevelItems(rect, Qt::AscendingOrder);
for (int i = 0; i < tli.size(); ++i)
- recursive_items_helper(tli.at(i), rect, intersector, items, viewTransform, mode);
+ recursive_items_helper(tli.at(i), rect, intersect, items, viewTransform, mode, 1.0, intersectData);
if (order == Qt::DescendingOrder) {
const int n = items->size();
for (int i = 0; i < n / 2; ++i)
@@ -161,15 +157,6 @@ inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphi
}
}
-class QGraphicsSceneIndexIntersector
-{
-public:
- QGraphicsSceneIndexIntersector() { }
- virtual ~QGraphicsSceneIndexIntersector() { }
- virtual bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
- const QTransform &deviceTransform) const = 0;
-};
-
#endif // QT_NO_GRAPHICSVIEW
QT_END_NAMESPACE