From 978cf2724888f13ba1a0ebab65056c05fe112dad Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 29 Apr 2009 09:49:17 +1000 Subject: Some foreach remove/improve. --- src/declarative/fx/qfxgridview.cpp | 4 ++-- src/declarative/fx/qfximageitem.cpp | 15 +++++++++------ src/declarative/fx/qfxitem.cpp | 34 ++++++++++++++++++++-------------- src/declarative/fx/qfxlistview.cpp | 5 ++--- src/declarative/fx/qfxpathview.cpp | 2 +- src/declarative/util/qmlanimation.cpp | 2 +- src/declarative/util/qmlconnection.cpp | 2 +- src/declarative/util/qmllistmodel.cpp | 2 +- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index b2fb1a1..15d3b70 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -1330,8 +1330,8 @@ void QFxGridView::itemsInserted(int modelIndex, int count) } } // everything is in order now - emit add() signal - foreach(FxGridItem *item, added) - item->attached->emitAdd(); + for (int j = 0; j < added.count(); ++j) + added.at(j)->attached->emitAdd(); d->layout(); emit countChanged(); } diff --git a/src/declarative/fx/qfximageitem.cpp b/src/declarative/fx/qfximageitem.cpp index a6f6d8f..26a5b53 100644 --- a/src/declarative/fx/qfximageitem.cpp +++ b/src/declarative/fx/qfximageitem.cpp @@ -119,8 +119,7 @@ void QFxImageItem::dirtyCache(const QRect& rect) void QFxImageItem::clearCache() { Q_D(QFxImageItem); - foreach (QFxImageItemPrivate::ImageCacheItem* i, d->imagecache) - delete i; + qDeleteAll(d->imagecache); d->imagecache.clear(); } @@ -232,8 +231,9 @@ void QFxImageItem::paintGLContents(GLPainter &p) return; #if defined(QFX_RENDER_QPAINTER) + bool oldAntiAliasing = p.testRenderHint(QPainter::Antialiasing); + bool oldSmoothPixmap = p.testRenderHint(QPainter::SmoothPixmapTransform); if(d->smooth) { - p.save(); p.setRenderHints(QPainter::Antialiasing, true); p.setRenderHints(QPainter::SmoothPixmapTransform, true); } @@ -303,7 +303,8 @@ void QFxImageItem::paintGLContents(GLPainter &p) } const QRegion bigger = QRegion(biggerrect) & uncached; const QVector rects = bigger.rects(); - foreach (QRect r, rects) { + for (int i = 0; i < rects.count(); ++i) { + const QRect &r = rects.at(i); #if defined(QFX_RENDER_QPAINTER) QImage img(r.size(),QImage::Format_ARGB32_Premultiplied); #else @@ -335,8 +336,10 @@ void QFxImageItem::paintGLContents(GLPainter &p) glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif #if defined(QFX_RENDER_QPAINTER) - if(d->smooth) - p.restore(); + if(d->smooth) { + p.setRenderHints(QPainter::Antialiasing, oldAntiAliasing); + p.setRenderHints(QPainter::SmoothPixmapTransform, oldSmoothPixmap); + } #endif } diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index e3568e0..adf76f4 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -151,12 +151,15 @@ void QFxContents::calcHeight() int top = INT_MAX; int bottom = 0; - foreach(const QSimpleCanvasItem *child, - _item->QSimpleCanvasItem::children()) { - if (child->y() + child->height() > bottom) - bottom = (int)child->y() + child->height(); - if (child->y() < top) - top = (int)child->y(); + + const QList &children = _item->QSimpleCanvasItem::children(); + for (int i = 0; i < children.count(); ++i) { + const QSimpleCanvasItem *child = children.at(i); + int y = int(child->y()); + if (y + child->height() > bottom) + bottom = y + child->height(); + if (y < top) + top = y; } _height = bottom - top; @@ -171,12 +174,14 @@ void QFxContents::calcWidth() int left = INT_MAX; int right = 0; - foreach(const QSimpleCanvasItem *child, - _item->QSimpleCanvasItem::children()) { - if (child->x() + child->width() > right) - right = (int)child->x() + child->width(); - if (child->x() < left) - left = (int)child->x(); + const QList &children = _item->QSimpleCanvasItem::children(); + for (int i = 0; i < children.count(); ++i) { + const QSimpleCanvasItem *child = children.at(i); + int x = int(child->x()); + if (x + child->width() > right) + right = x + child->width(); + if (x < left) + left = x; } _width = right - left; @@ -188,8 +193,9 @@ void QFxContents::setItem(QFxItem *item) { _item = item; - foreach(const QSimpleCanvasItem *child, - _item->QSimpleCanvasItem::children()) { + const QList &children = _item->QSimpleCanvasItem::children(); + for (int i = 0; i < children.count(); ++i) { + const QSimpleCanvasItem *child = children.at(i); connect(child, SIGNAL(bottomChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(rightChanged()), this, SLOT(calcWidth())); } diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 76f7e11..20a2c0c 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1546,9 +1546,8 @@ void QFxListView::itemsInserted(int modelIndex, int count) } } // everything is in order now - emit add() signal - foreach(FxListItem *item, added) - item->attached->emitAdd(); - + for (int j = 0; j < added.count(); ++j) + added.at(j)->attached->emitAdd(); emit countChanged(); } diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 59c7cd1..8bf0a25 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -616,7 +616,7 @@ void QFxPathViewPrivate::regenerate() void QFxPathViewPrivate::updateItem(QFxItem *item, qreal percent) { if(QObject *obj = QFxPathView::attachedProperties.value(item)) { - foreach(QString attr, path->attributes()) + foreach(const QString &attr, path->attributes()) static_cast(obj)->setValue(attr.toLatin1(), path->attributeAt(attr, percent)); } diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 91a5361..4a6987a 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -104,7 +104,7 @@ QEasingCurve stringToCurve(const QString &curve) easingCurve.setType((QEasingCurve::Type)value); if (hasParams) { - foreach(QString str, props) { + foreach(const QString &str, props) { int sep = str.indexOf(QLatin1Char(':')); if(sep == -1) { diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index b2fd450..500e728 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -165,7 +165,7 @@ void QmlConnection::connectIfValid() QList sigparams; if (lparen >= 0 && d->signal.length() > lparen+2) { QStringList l = d->signal.mid(lparen+1,d->signal.length()-lparen-2).split(QLatin1Char(',')); - foreach (QString s, l) { + foreach (const QString &s, l) { sigparams.append(s.toLatin1()); } } diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 24f2d5c..cf1272b 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -388,7 +388,7 @@ void ListModel::checkRoles() const for(int ii = 0; ii < _root->values.count(); ++ii) { ModelNode *node = qvariant_cast(_root->values.at(ii)); if(node) { - foreach(QString role, node->properties.keys()) + foreach(const QString &role, node->properties.keys()) addRole(role); } } -- cgit v0.12