QtWidgets: use new QRegion::begin()/end() instead of rect()

Saves ~600b in text size on optimized GCC 5.3 Linux AMD64 builds.

Change-Id: Ib542a128982fc53638780945014d903f2cbee9c3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-02-27 14:34:46 +01:00
parent 36ecf2c025
commit 9d3a415562
10 changed files with 33 additions and 54 deletions

View File

@ -1439,9 +1439,8 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con
// Determine the item's exposed area // Determine the item's exposed area
option->exposedRect = QRectF(); option->exposedRect = QRectF();
const QTransform reverseMap = worldTransform.inverted(); const QTransform reverseMap = worldTransform.inverted();
const QVector<QRect> exposedRects(exposedRegion.rects()); for (const QRect &exposedRect : exposedRegion) {
for (int i = 0; i < exposedRects.size(); ++i) { option->exposedRect |= reverseMap.mapRect(QRectF(exposedRect));
option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i)));
if (option->exposedRect.contains(brect)) if (option->exposedRect.contains(brect))
break; break;
} }
@ -5350,8 +5349,7 @@ QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) c
QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity); QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
QRegion r; QRegion r;
QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0)); QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
const auto rects = QRegion(colorMask).rects(); for (const QRect &rect : QRegion(colorMask)) {
for (const QRect &rect : rects) {
QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad)); QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
r += xrect.adjusted(-1, -1, 1, 1) & deviceRect; r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;
} }
@ -5915,9 +5913,8 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
// Append newly exposed areas. Note that the exposed region is currently // Append newly exposed areas. Note that the exposed region is currently
// in pixmap coordinates, so we have to translate it to item coordinates. // in pixmap coordinates, so we have to translate it to item coordinates.
exposed.translate(cache->boundingRect.topLeft()); exposed.translate(cache->boundingRect.topLeft());
const QVector<QRect> exposedRects = exposed.rects(); for (const QRect &exposedRect : exposed)
for (int i = 0; i < exposedRects.size(); ++i) cache->exposed += exposedRect;
cache->exposed += exposedRects.at(i);
// Trigger update. This will redraw the newly exposed area and make sure // Trigger update. This will redraw the newly exposed area and make sure
// the pixmap is re-blitted in case there are overlapping items. // the pixmap is re-blitted in case there are overlapping items.

View File

@ -4657,8 +4657,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
for (int i = 0; i < exposed.size(); ++i) for (int i = 0; i < exposed.size(); ++i)
br |= exposed.at(i); br |= exposed.at(i);
QTransform pixmapToItem = itemToPixmap.inverted(); QTransform pixmapToItem = itemToPixmap.inverted();
const auto rects = scrollExposure.rects(); for (const QRect &r : scrollExposure)
for (const QRect &r : rects)
br |= pixmapToItem.mapRect(r); br |= pixmapToItem.mapRect(r);
} }
styleOptionTmp = *option; styleOptionTmp = *option;

View File

@ -1029,9 +1029,7 @@ bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xf
if (!intersectsViewport(viewRect, viewport->width(), viewport->height())) if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))
return false; // Update region for sure outside viewport. return false; // Update region for sure outside viewport.
const QVector<QRect> &rects = region.rects(); for (QRect viewRect : region) {
for (int i = 0; i < rects.size(); ++i) {
viewRect = rects.at(i);
if (dontAdjustForAntialiasing) if (dontAdjustForAntialiasing)
viewRect.adjust(-1, -1, 1, 1); viewRect.adjust(-1, -1, 1, 1);
else else
@ -1146,8 +1144,7 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedReg
// the expose region, convert it to a path, and then search for items // the expose region, convert it to a path, and then search for items
// using QGraphicsScene::items(QPainterPath); // using QGraphicsScene::items(QPainterPath);
QRegion adjustedRegion; QRegion adjustedRegion;
const auto rects = exposedRegion.rects(); for (const QRect &r : exposedRegion)
for (const QRect &r : rects)
adjustedRegion += r.adjusted(-1, -1, 1, 1); adjustedRegion += r.adjusted(-1, -1, 1, 1);
const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion))); const QPainterPath exposedScenePath(q->mapToScene(qt_regionToPath(adjustedRegion)));
@ -2676,11 +2673,9 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects)
// Extract and reset dirty scene rect info. // Extract and reset dirty scene rect info.
QVector<QRect> dirtyViewportRects; QVector<QRect> dirtyViewportRects;
const QVector<QRect> &dirtyRects = d->dirtyRegion.rects(); dirtyViewportRects.reserve(d->dirtyRegion.rectCount() + rects.count());
const int dirtyRectsCount = dirtyRects.size(); for (const QRect &dirtyRect : d->dirtyRegion)
dirtyViewportRects.reserve(dirtyRectsCount + rects.count()); dirtyViewportRects += dirtyRect;
for (int i = 0; i < dirtyRectsCount; ++i)
dirtyViewportRects += dirtyRects.at(i);
d->dirtyRegion = QRegion(); d->dirtyRegion = QRegion();
d->dirtyBoundingRect = QRect(); d->dirtyBoundingRect = QRect();

View File

@ -1398,8 +1398,7 @@ void QTableView::paintEvent(QPaintEvent *event)
firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn); firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn);
} }
const QVector<QRect> rects = region.rects(); for (QRect dirtyArea : region) {
for (auto dirtyArea : rects) {
dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y))); dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y)));
if (rightToLeft) { if (rightToLeft) {
dirtyArea.setLeft(qMax(dirtyArea.left(), d->viewport->width() - int(x))); dirtyArea.setLeft(qMax(dirtyArea.left(), d->viewport->width() - int(x)));

View File

@ -1473,13 +1473,12 @@ void QTreeView::drawTree(QPainter *painter, const QRegion &region) const
QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos()); QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
d->hoverBranch = d->itemDecorationAt(hoverPos); d->hoverBranch = d->itemDecorationAt(hoverPos);
QVector<QRect> rects = region.rects();
QVector<int> drawn; QVector<int> drawn;
bool multipleRects = (rects.size() > 1); bool multipleRects = (region.rectCount() > 1);
for (int a = 0; a < rects.size(); ++a) { for (const QRect &a : region) {
const QRect area = (multipleRects const QRect area = (multipleRects
? QRect(0, rects.at(a).y(), viewportWidth, rects.at(a).height()) ? QRect(0, a.y(), viewportWidth, a.height())
: rects.at(a)); : a);
d->leftAndRight = d->startAndEndColumns(area); d->leftAndRight = d->startAndEndColumns(area);
int i = firstVisibleItem; // the first item at the top of the viewport int i = firstVisibleItem; // the first item at the top of the viewport

View File

@ -2398,9 +2398,8 @@ static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrus
painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush); painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
painter->restore(); painter->restore();
} else { } else {
const QVector<QRect> &rects = rgn.rects(); for (const QRect &rect : rgn)
for (int i = 0; i < rects.size(); ++i) painter->fillRect(rect, brush);
painter->fillRect(rects.at(i), brush);
} }
} }
@ -10748,10 +10747,8 @@ void QWidget::scroll(int dx, int dy)
// Graphics View maintains its own dirty region as a list of rects; // Graphics View maintains its own dirty region as a list of rects;
// until we can connect item updates directly to the view, we must // until we can connect item updates directly to the view, we must
// separately add a translated dirty region. // separately add a translated dirty region.
if (!d->dirty.isEmpty()) { for (const QRect &rect : d->dirty)
foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) proxy->update(rect.translated(dx, dy));
proxy->update(rect);
}
proxy->scroll(dx, dy, proxy->subWidgetRect(this)); proxy->scroll(dx, dy, proxy->subWidgetRect(this));
return; return;
} }
@ -10791,7 +10788,7 @@ void QWidget::scroll(int dx, int dy, const QRect &r)
// until we can connect item updates directly to the view, we must // until we can connect item updates directly to the view, we must
// separately add a translated dirty region. // separately add a translated dirty region.
if (!d->dirty.isEmpty()) { if (!d->dirty.isEmpty()) {
foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) for (const QRect &rect : d->dirty.translated(dx, dy) & r)
proxy->update(rect); proxy->update(rect);
} }
proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint())); proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));

View File

@ -158,7 +158,7 @@ static void showYellowThing_win(QWidget *widget, const QRegion &region, int msec
} }
i = (i + 1) & 3; i = (i + 1) & 3;
foreach (const QRect &rect, region.rects()) { for (const QRect &rect : region) {
RECT winRect; RECT winRect;
SetRect(&winRect, rect.left(), rect.top(), rect.right(), rect.bottom()); SetRect(&winRect, rect.left(), rect.top(), rect.right(), rect.bottom());
FillRect(hdc, &winRect, brush); FillRect(hdc, &winRect, brush);
@ -1311,9 +1311,8 @@ void QWidgetBackingStore::doSync()
updateStaticContentsSize(); updateStaticContentsSize();
dirty = QRegion(); dirty = QRegion();
updateRequestSent = false; updateRequestSent = false;
const QVector<QRect> rects(toClean.rects()); for (const QRect &rect : toClean)
for (int i = 0; i < rects.size(); ++i) tlw->d_func()->extra->proxyWidget->update(rect);
tlw->d_func()->extra->proxyWidget->update(rects.at(i));
return; return;
} }
#endif #endif

View File

@ -587,7 +587,7 @@ HIMutableShapeRef qt_mac_toHIMutableShape(const QRegion &region)
CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height()); CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height());
HIShapeUnionWithRect(shape, &cgRect); HIShapeUnionWithRect(shape, &cgRect);
} else { } else {
foreach (const QRect &qtRect, region.rects()) { for (const QRect &qtRect : region) {
CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height()); CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height());
HIShapeUnionWithRect(shape, &cgRect); HIShapeUnionWithRect(shape, &cgRect);
} }
@ -2203,9 +2203,7 @@ void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush
CGContextSaveGState(cg); CGContextSaveGState(cg);
HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted);
const QVector<QRect> &rects = rgn.rects(); for (const QRect &rect : rgn) {
for (int i = 0; i < rects.size(); ++i) {
const QRect rect(rects.at(i));
// Anchor the pattern to the top so it stays put when the window is resized. // Anchor the pattern to the top so it stays put when the window is resized.
CGContextSetPatternPhase(cg, CGSizeMake(rect.width(), rect.height())); CGContextSetPatternPhase(cg, CGSizeMake(rect.width(), rect.height()));
CGRect mac_rect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()); CGRect mac_rect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
@ -7067,11 +7065,11 @@ void qt_mac_scale_region(QRegion *region, qreal scaleFactor)
return; return;
QVector<QRect> scaledRects; QVector<QRect> scaledRects;
scaledRects.reserve(region->rects().count()); scaledRects.reserve(region->rectCount());
foreach (const QRect &rect, region->rects()) { for (const QRect &rect : *region)
scaledRects.append(QRect(rect.topLeft() * scaleFactor, rect.size() * scaleFactor)); scaledRects.append(QRect(rect.topLeft() * scaleFactor, rect.size() * scaleFactor));
}
region->setRects(&scaledRects[0], scaledRects.count()); region->setRects(&scaledRects[0], scaledRects.count());
} }

View File

@ -269,7 +269,7 @@ static HRGN qt_hrgn_from_qregion(const QRegion &region)
qt_add_rect(hRegion, region.boundingRect()); qt_add_rect(hRegion, region.boundingRect());
return hRegion; return hRegion;
} }
foreach (const QRect &rect, region.rects()) for (const QRect &rect : region)
qt_add_rect(hRegion, rect); qt_add_rect(hRegion, rect);
return hRegion; return hRegion;
} }
@ -1087,11 +1087,8 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa
painter->setClipRegion(newRegion); painter->setClipRegion(newRegion);
#if defined(DEBUG_XP_STYLE) && 0 #if defined(DEBUG_XP_STYLE) && 0
printf("Using region:\n"); printf("Using region:\n");
QVector<QRect> rects = newRegion.rects(); for (const QRect &r : newRegion)
for (int i = 0; i < rects.count(); ++i) {
const QRect &r = rects.at(i);
printf(" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom()); printf(" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
}
#endif #endif
} }

View File

@ -2670,9 +2670,8 @@ void QMdiArea::paintEvent(QPaintEvent *paintEvent)
{ {
Q_D(QMdiArea); Q_D(QMdiArea);
QPainter painter(d->viewport); QPainter painter(d->viewport);
const QVector<QRect> &exposedRects = paintEvent->region().rects(); for (const QRect &exposedRect : paintEvent->region())
for (int i = 0; i < exposedRects.size(); ++i) painter.fillRect(exposedRect, d->background);
painter.fillRect(exposedRects.at(i), d->background);
} }
/*! /*!