From 686dcce5fb2eef4adebfc2a247e96574ec062473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Wed, 5 Dec 2012 19:55:27 +0100 Subject: [PATCH] Make QGraphicsViewPrivate::updateRubberBand more readable This patch changes QGraphicsViewPrivate::updateRubberBand to return at once in case some of the first conditions (which were needed to do something with the rubberband) are not true. The indentation after these ifs is fixed, and there are a few style fixes, but beside the first 2 ifs, there are only white-space and new-line changes. Change-Id: I7e2edb7bfd334b35ee8ab246f733d854bff7e0f7 Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Andy Shaw --- src/widgets/graphicsview/qgraphicsview.cpp | 83 ++++++++++------------ 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index dca84f3f1b..9c04a3c193 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -709,52 +709,47 @@ QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRec void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) { Q_Q(QGraphicsView); - if (dragMode == QGraphicsView::RubberBandDrag && sceneInteractionAllowed) { - if (rubberBanding) { - // Check for enough drag distance - if ((mousePressViewPoint - event->pos()).manhattanLength() - < QApplication::startDragDistance()) { - return; - } + if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding) + return; + // Check for enough drag distance + if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) + return; - // Update old rubberband - if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { - if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) - q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); - else - updateAll(); - } - - // Stop rubber banding if the user has let go of all buttons (even - // if we didn't get the release events). - if (!event->buttons()) { - rubberBanding = false; - rubberBandRect = QRect(); - return; - } - - // Update rubberband position - const QPoint mp = q->mapFromScene(mousePressScenePoint); - const QPoint ep = event->pos(); - rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), - qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); - - // Update new rubberband - if (viewportUpdateMode != QGraphicsView::NoViewportUpdate){ - if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) - q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); - else - updateAll(); - } - // Set the new selection area - QPainterPath selectionArea; - selectionArea.addPolygon(mapToScene(rubberBandRect)); - selectionArea.closeSubpath(); - if (scene) - scene->setSelectionArea(selectionArea, rubberBandSelectionMode, - q->viewportTransform()); - } + // Update old rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); } + + // Stop rubber banding if the user has let go of all buttons (even + // if we didn't get the release events). + if (!event->buttons()) { + rubberBanding = false; + rubberBandRect = QRect(); + return; + } + + // Update rubberband position + const QPoint mp = q->mapFromScene(mousePressScenePoint); + const QPoint ep = event->pos(); + rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), + qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); + + // Update new rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) { + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); + } + // Set the new selection area + QPainterPath selectionArea; + selectionArea.addPolygon(mapToScene(rubberBandRect)); + selectionArea.closeSubpath(); + if (scene) + scene->setSelectionArea(selectionArea, rubberBandSelectionMode, q->viewportTransform()); } #endif