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>bb10
parent
feea236d92
commit
e3e0240c77
|
|
@ -908,6 +908,9 @@ protected:
|
|||
friend class QGuiApplicationPrivate;
|
||||
friend class QApplication;
|
||||
friend class QApplicationPrivate;
|
||||
#ifndef QT_NO_GRAPHICSVIEW
|
||||
friend class QGraphicsScenePrivate; // direct access to _touchPoints
|
||||
#endif
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue