QGraphicsView: replace some Q_FOREACH loops over const locals with C++11 range-for
This needs to be handled a bit carefully, because Qt containers will detach upon being iterated over using range-for. In the cases of this patch, that cannot happen, because all containers are local and marked as const (either by this patch or before). Separate patches will deal with other situations. Range-for loops are much more efficient than foreach loops. This patch shaves ~1.8KiB of text size off an optimized Linux AMD64 GCC 4.9 build. Change-Id: I5c58658937ac4323594161bf94a2fce3c5667914 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
4e628397b0
commit
2d4295f167
|
|
@ -2588,7 +2588,7 @@ void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &
|
|||
{
|
||||
QSet<QGraphicsLayoutItem *> nonFloating;
|
||||
|
||||
foreach (const AnchorData *ad, visited)
|
||||
for (const AnchorData *ad : visited)
|
||||
identifyNonFloatItems_helper(ad, &nonFloating);
|
||||
|
||||
QSet<QGraphicsLayoutItem *> allItems;
|
||||
|
|
|
|||
|
|
@ -2437,7 +2437,7 @@ QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *>
|
|||
QGraphicsItemGroup *group = new QGraphicsItemGroup(commonAncestor);
|
||||
if (!commonAncestor)
|
||||
addItem(group);
|
||||
foreach (QGraphicsItem *item, items)
|
||||
for (QGraphicsItem *item : items)
|
||||
group->addToGroup(item);
|
||||
return group;
|
||||
}
|
||||
|
|
@ -4149,9 +4149,9 @@ void QGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||
void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
|
||||
{
|
||||
Q_D(QGraphicsScene);
|
||||
QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(),
|
||||
wheelEvent->scenePos(),
|
||||
wheelEvent->widget());
|
||||
const QList<QGraphicsItem *> wheelCandidates = d->itemsAtPosition(wheelEvent->screenPos(),
|
||||
wheelEvent->scenePos(),
|
||||
wheelEvent->widget());
|
||||
|
||||
#ifdef Q_DEAD_CODE_FROM_QT4_MAC
|
||||
// On Mac, ignore the event if the first item under the mouse is not the last opened
|
||||
|
|
@ -4173,7 +4173,7 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
|
|||
#endif
|
||||
|
||||
bool hasSetFocus = false;
|
||||
foreach (QGraphicsItem *item, wheelCandidates) {
|
||||
for (QGraphicsItem *item : wheelCandidates) {
|
||||
if (!hasSetFocus && item->isEnabled()
|
||||
&& ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
|
||||
if (item->isWidget() && static_cast<QGraphicsWidget *>(item)->focusPolicy() == Qt::WheelFocus) {
|
||||
|
|
@ -6181,7 +6181,7 @@ void QGraphicsScenePrivate::gestureTargetsAtHotSpots(const QSet<QGesture *> &ges
|
|||
QSet<QGesture *> *conflicts)
|
||||
{
|
||||
QSet<QGesture *> normalGestures; // that are not in conflicted state.
|
||||
foreach (QGesture *gesture, gestures) {
|
||||
for (QGesture *gesture : gestures) {
|
||||
if (!gesture->hasHotSpot())
|
||||
continue;
|
||||
const Qt::GestureType gestureType = gesture->gestureType();
|
||||
|
|
@ -6229,7 +6229,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
if (!graphicsView)
|
||||
return;
|
||||
|
||||
QList<QGesture *> allGestures = event->gestures();
|
||||
const QList<QGesture *> allGestures = event->gestures();
|
||||
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
|
||||
<< "Gestures:" << allGestures;
|
||||
|
||||
|
|
@ -6237,7 +6237,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
QPoint delta = viewport->mapFromGlobal(QPoint());
|
||||
QTransform toScene = QTransform::fromTranslate(delta.x(), delta.y())
|
||||
* graphicsView->viewportTransform().inverted();
|
||||
foreach (QGesture *gesture, allGestures) {
|
||||
for (QGesture *gesture : allGestures) {
|
||||
// cache scene coordinates of the hot spot
|
||||
if (gesture->hasHotSpot()) {
|
||||
gesture->d_func()->sceneHotSpot = toScene.map(gesture->hotSpot());
|
||||
|
|
@ -6272,7 +6272,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
QPointer<QGraphicsObject> item = cachedTargetItems.at(i);
|
||||
|
||||
// get gestures to deliver to the current item
|
||||
QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data());
|
||||
const QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data());
|
||||
if (gestures.isEmpty())
|
||||
continue;
|
||||
|
||||
|
|
@ -6285,11 +6285,11 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
ev.setWidget(event->widget());
|
||||
// mark event and individual gestures as ignored
|
||||
ev.ignore();
|
||||
foreach(QGesture *g, gestures)
|
||||
for (QGesture *g : gestures)
|
||||
ev.setAccepted(g, false);
|
||||
sendEvent(item.data(), &ev);
|
||||
// mark all accepted gestures to deliver them as normal gesture events
|
||||
foreach (QGesture *g, gestures) {
|
||||
for (QGesture *g : gestures) {
|
||||
if (ev.isAccepted() || ev.isAccepted(g)) {
|
||||
conflictedGestures.remove(g);
|
||||
// mark the item as a gesture target
|
||||
|
|
@ -6339,7 +6339,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
// deliver all gesture events
|
||||
QSet<QGesture *> undeliveredGestures;
|
||||
QSet<QGesture *> parentPropagatedGestures;
|
||||
foreach (QGesture *gesture, allGestures) {
|
||||
for (QGesture *gesture : allGestures) {
|
||||
if (QGraphicsObject *target = gestureTargets.value(gesture, 0)) {
|
||||
cachedItemGestures[target].insert(gesture);
|
||||
cachedTargetItems.append(target);
|
||||
|
|
@ -6451,7 +6451,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||
}
|
||||
|
||||
// forget about targets for gestures that have ended
|
||||
foreach (QGesture *g, allGestures) {
|
||||
for (QGesture *g : allGestures) {
|
||||
switch (g->state()) {
|
||||
case Qt::GestureFinished:
|
||||
case Qt::GestureCanceled:
|
||||
|
|
@ -6511,12 +6511,12 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
|
|||
}
|
||||
Q_ASSERT(target);
|
||||
|
||||
QList<QGesture *> list = gestures.toList();
|
||||
const QList<QGesture *> list = gestures.toList();
|
||||
QGestureEvent ev(list);
|
||||
sendEvent(target, &ev);
|
||||
|
||||
if (!ev.isAccepted()) {
|
||||
foreach (QGesture *g, list) {
|
||||
for (QGesture *g : list) {
|
||||
|
||||
if (ev.isAccepted(g))
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -2467,7 +2467,7 @@ QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const
|
|||
{
|
||||
QPolygonF poly;
|
||||
poly.reserve(polygon.count());
|
||||
foreach (const QPoint &point, polygon)
|
||||
for (const QPoint &point : polygon)
|
||||
poly << mapToScene(point);
|
||||
return poly;
|
||||
}
|
||||
|
|
@ -2563,7 +2563,7 @@ QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const
|
|||
{
|
||||
QPolygon poly;
|
||||
poly.reserve(polygon.count());
|
||||
foreach (const QPointF &point, polygon)
|
||||
for (const QPointF &point : polygon)
|
||||
poly << mapFromScene(point);
|
||||
return poly;
|
||||
}
|
||||
|
|
@ -2696,7 +2696,7 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects)
|
|||
QTransform transform = viewportTransform();
|
||||
|
||||
// Convert scene rects to viewport rects.
|
||||
foreach (const QRectF &rect, rects) {
|
||||
for (const QRectF &rect : rects) {
|
||||
QRect xrect = transform.mapRect(rect).toAlignedRect();
|
||||
if (!(d->optimizationFlags & DontAdjustForAntialiasing))
|
||||
xrect.adjust(-2, -2, 2, 2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue