diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-12-21 11:14:29 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-12-22 07:25:04 +0000 |
commit | e3e0240c7798009d5cce9c4897b906fbce40dd24 (patch) | |
tree | 4aed60e155dd3f71b0bc428f6a9daa5825b199fc /src/widgets/graphicsview/qgraphicsscene.cpp | |
parent | feea236d92656ef1a7cd2b94e3f3ca99c19f4e96 (diff) | |
download | qtbase-e3e0240c7798009d5cce9c4897b906fbce40dd24.tar.gz |
QGraphicsScene: prevent lots of detaching d/t editing of copies
QTouchEvent::touchPoints() returns a const-&, but the old
code took a copy, over which it then iterated, modifying
the touch points, causing (necessary) detaches of both the
list and the touch points.
Befriend QTouchEvent and modify the list in-place, avoiding
all detaches in the likely case that QTouchPoint contains the
only copy of the touch point list.
This is all the more important as the function is called once
for every item-under-mouse in sendTouchBeginEvent().
Port to C++11 range-for as a drive-by.
Change-Id: I2f74d19845711d97e3566886123b5d18d55db74c
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsscene.cpp')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 77bc8d4fcd..75ec8a3223 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -5834,14 +5834,11 @@ void QGraphicsScenePrivate::removeView(QGraphicsView *view) void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent) { - QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); - for (int i = 0; i < touchPoints.count(); ++i) { - QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; + for (auto &touchPoint : touchEvent->_touchPoints) { touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect()); touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), static_cast<QWidget *>(touchEvent->target()))); touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), static_cast<QWidget *>(touchEvent->target()))); } - touchEvent->setTouchPoints(touchPoints); } int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos) |