diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-30 12:19:31 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-12-16 17:41:50 +0000 |
commit | 0516487237145ad41b2fd13ecb5f63ba4325c02f (patch) | |
tree | 8dbc353c28857742882610cc5d810c8c64052f0f /src/widgets/accessible/qaccessiblewidget.cpp | |
parent | b69751863472b186aaad08db6b9b08de81e95dc4 (diff) |
QtWidgets: replace some index-based for loops with C++11 range-for
This needs to be handled a bit carefully, because Qt containers
will detach upon being iteratoed over using range-for.
In the cases of this patch, that cannot happen, because all
containers are marked as const (either by this patch or before).
Separate patches will deal with other situations.
Apart from being more readable, range-for loops are also the
most efficient for loop.
This patch shaves almost 2K of text size off an optimized Linux
AMD64 GCC 4.9 build.
Change-Id: I53810c7b25420b4fd449d20c90c07503c5e76a66
Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets/accessible/qaccessiblewidget.cpp')
-rw-r--r-- | src/widgets/accessible/qaccessiblewidget.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index ed5b6f86fd..e540980a14 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -53,10 +53,9 @@ QT_BEGIN_NAMESPACE static QList<QWidget*> childWidgets(const QWidget *widget) { - QList<QObject*> list = widget->children(); QList<QWidget*> widgets; - for (int i = 0; i < list.size(); ++i) { - QWidget *w = qobject_cast<QWidget *>(list.at(i)); + for (QObject *o : widget->children()) { + QWidget *w = qobject_cast<QWidget *>(o); if (w && !w->isWindow() && !qobject_cast<QFocusFrame*>(w) #if !defined(QT_NO_MENU) @@ -77,9 +76,8 @@ static QString buddyString(const QWidget *widget) if (!parent) return QString(); #ifndef QT_NO_SHORTCUT - QObjectList ol = parent->children(); - for (int i = 0; i < ol.size(); ++i) { - QLabel *label = qobject_cast<QLabel*>(ol.at(i)); + for (QObject *o : parent->children()) { + QLabel *label = qobject_cast<QLabel*>(o); if (label && label->buddy() == widget) return label->text(); } @@ -302,8 +300,8 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel // ideally we would go through all objects and check, but that // will be too expensive const QList<QWidget*> kids = childWidgets(parent); - for (int i = 0; i < kids.count(); ++i) { - if (QLabel *labelSibling = qobject_cast<QLabel*>(kids.at(i))) { + for (QWidget *kid : kids) { + if (QLabel *labelSibling = qobject_cast<QLabel*>(kid)) { if (labelSibling->buddy() == widget()) { QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(labelSibling); rels.append(qMakePair(iface, rel)); |