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
option->exposedRect = QRectF();
const QTransform reverseMap = worldTransform.inverted();
const QVector<QRect> exposedRects(exposedRegion.rects());
for (int i = 0; i < exposedRects.size(); ++i) {
option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i)));
for (const QRect &exposedRect : exposedRegion) {
option->exposedRect |= reverseMap.mapRect(QRectF(exposedRect));
if (option->exposedRect.contains(brect))
break;
}
@ -5350,8 +5349,7 @@ QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) c
QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
QRegion r;
QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
const auto rects = QRegion(colorMask).rects();
for (const QRect &rect : rects) {
for (const QRect &rect : QRegion(colorMask)) {
QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
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
// in pixmap coordinates, so we have to translate it to item coordinates.
exposed.translate(cache->boundingRect.topLeft());
const QVector<QRect> exposedRects = exposed.rects();
for (int i = 0; i < exposedRects.size(); ++i)
cache->exposed += exposedRects.at(i);
for (const QRect &exposedRect : exposed)
cache->exposed += exposedRect;
// Trigger update. This will redraw the newly exposed area and make sure
// 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)
br |= exposed.at(i);
QTransform pixmapToItem = itemToPixmap.inverted();
const auto rects = scrollExposure.rects();
for (const QRect &r : rects)
for (const QRect &r : scrollExposure)
br |= pixmapToItem.mapRect(r);
}
styleOptionTmp = *option;

View File

@ -1029,9 +1029,7 @@ bool QGraphicsViewPrivate::updateRegion(const QRectF &rect, const QTransform &xf
if (!intersectsViewport(viewRect, viewport->width(), viewport->height()))
return false; // Update region for sure outside viewport.
const QVector<QRect> &rects = region.rects();
for (int i = 0; i < rects.size(); ++i) {
viewRect = rects.at(i);
for (QRect viewRect : region) {
if (dontAdjustForAntialiasing)
viewRect.adjust(-1, -1, 1, 1);
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
// using QGraphicsScene::items(QPainterPath);
QRegion adjustedRegion;
const auto rects = exposedRegion.rects();
for (const QRect &r : rects)
for (const QRect &r : exposedRegion)
adjustedRegion += r.adjusted(-1, -1, 1, 1);
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.
QVector<QRect> dirtyViewportRects;
const QVector<QRect> &dirtyRects = d->dirtyRegion.rects();
const int dirtyRectsCount = dirtyRects.size();
dirtyViewportRects.reserve(dirtyRectsCount + rects.count());
for (int i = 0; i < dirtyRectsCount; ++i)
dirtyViewportRects += dirtyRects.at(i);
dirtyViewportRects.reserve(d->dirtyRegion.rectCount() + rects.count());
for (const QRect &dirtyRect : d->dirtyRegion)
dirtyViewportRects += dirtyRect;
d->dirtyRegion = QRegion();
d->dirtyBoundingRect = QRect();

View File

@ -1398,8 +1398,7 @@ void QTableView::paintEvent(QPaintEvent *event)
firstVisualRow, lastVisualRow, firstVisualColumn, lastVisualColumn);
}
const QVector<QRect> rects = region.rects();
for (auto dirtyArea : rects) {
for (QRect dirtyArea : region) {
dirtyArea.setBottom(qMin(dirtyArea.bottom(), int(y)));
if (rightToLeft) {
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());
d->hoverBranch = d->itemDecorationAt(hoverPos);
QVector<QRect> rects = region.rects();
QVector<int> drawn;
bool multipleRects = (rects.size() > 1);
for (int a = 0; a < rects.size(); ++a) {
bool multipleRects = (region.rectCount() > 1);
for (const QRect &a : region) {
const QRect area = (multipleRects
? QRect(0, rects.at(a).y(), viewportWidth, rects.at(a).height())
: rects.at(a));
? QRect(0, a.y(), viewportWidth, a.height())
: a);
d->leftAndRight = d->startAndEndColumns(area);
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->restore();
} else {
const QVector<QRect> &rects = rgn.rects();
for (int i = 0; i < rects.size(); ++i)
painter->fillRect(rects.at(i), brush);
for (const QRect &rect : rgn)
painter->fillRect(rect, brush);
}
}
@ -10748,10 +10747,8 @@ void QWidget::scroll(int dx, int dy)
// Graphics View maintains its own dirty region as a list of rects;
// until we can connect item updates directly to the view, we must
// separately add a translated dirty region.
if (!d->dirty.isEmpty()) {
foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects())
proxy->update(rect);
}
for (const QRect &rect : d->dirty)
proxy->update(rect.translated(dx, dy));
proxy->scroll(dx, dy, proxy->subWidgetRect(this));
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
// separately add a translated dirty region.
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->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;
foreach (const QRect &rect, region.rects()) {
for (const QRect &rect : region) {
RECT winRect;
SetRect(&winRect, rect.left(), rect.top(), rect.right(), rect.bottom());
FillRect(hdc, &winRect, brush);
@ -1311,9 +1311,8 @@ void QWidgetBackingStore::doSync()
updateStaticContentsSize();
dirty = QRegion();
updateRequestSent = false;
const QVector<QRect> rects(toClean.rects());
for (int i = 0; i < rects.size(); ++i)
tlw->d_func()->extra->proxyWidget->update(rects.at(i));
for (const QRect &rect : toClean)
tlw->d_func()->extra->proxyWidget->update(rect);
return;
}
#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());
HIShapeUnionWithRect(shape, &cgRect);
} else {
foreach (const QRect &qtRect, region.rects()) {
for (const QRect &qtRect : region) {
CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height());
HIShapeUnionWithRect(shape, &cgRect);
}
@ -2203,9 +2203,7 @@ void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush
CGContextSaveGState(cg);
HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted);
const QVector<QRect> &rects = rgn.rects();
for (int i = 0; i < rects.size(); ++i) {
const QRect rect(rects.at(i));
for (const QRect &rect : rgn) {
// Anchor the pattern to the top so it stays put when the window is resized.
CGContextSetPatternPhase(cg, CGSizeMake(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;
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));
}
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());
return hRegion;
}
foreach (const QRect &rect, region.rects())
for (const QRect &rect : region)
qt_add_rect(hRegion, rect);
return hRegion;
}
@ -1087,11 +1087,8 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa
painter->setClipRegion(newRegion);
#if defined(DEBUG_XP_STYLE) && 0
printf("Using region:\n");
QVector<QRect> rects = newRegion.rects();
for (int i = 0; i < rects.count(); ++i) {
const QRect &r = rects.at(i);
for (const QRect &r : newRegion)
printf(" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
}
#endif
}

View File

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