Widgets: use range-based for instead of foreach
Change-Id: Id9ec2db6cfa661ff9b3b6ace9ffaa071a2d57f94 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
4aa6f54fec
commit
ba2221bd73
@ -3637,7 +3637,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
||||
break;
|
||||
w = w->parentWidget();
|
||||
}
|
||||
foreach (QGesture *g, allGestures)
|
||||
for (QGesture *g : qAsConst(allGestures))
|
||||
gestureEvent->setAccepted(g, false);
|
||||
gestureEvent->m_accept = false; // to make sure we check individual gestures
|
||||
} else {
|
||||
|
@ -916,7 +916,7 @@ QGesture *QGestureEvent::gesture(Qt::GestureType type) const
|
||||
QList<QGesture *> QGestureEvent::activeGestures() const
|
||||
{
|
||||
QList<QGesture *> gestures;
|
||||
foreach (QGesture *gesture, m_gestures) {
|
||||
for (QGesture *gesture : m_gestures) {
|
||||
if (gesture->state() != Qt::GestureCanceled)
|
||||
gestures.append(gesture);
|
||||
}
|
||||
@ -929,7 +929,7 @@ QList<QGesture *> QGestureEvent::activeGestures() const
|
||||
QList<QGesture *> QGestureEvent::canceledGestures() const
|
||||
{
|
||||
QList<QGesture *> gestures;
|
||||
foreach (QGesture *gesture, m_gestures) {
|
||||
for (QGesture *gesture : m_gestures) {
|
||||
if (gesture->state() == Qt::GestureCanceled)
|
||||
gestures.append(gesture);
|
||||
}
|
||||
|
@ -1894,7 +1894,7 @@ qreal QScrollerPrivate::nextSnapPos(qreal p, int dir, Qt::Orientation orientatio
|
||||
|
||||
if (orientation == Qt::Horizontal) {
|
||||
// the snap points in the list
|
||||
foreach (qreal snapPos, snapPositionsX) {
|
||||
for (qreal snapPos : snapPositionsX) {
|
||||
qreal snapPosDist = snapPos - p;
|
||||
if ((dir > 0 && snapPosDist < 0) ||
|
||||
(dir < 0 && snapPosDist > 0))
|
||||
@ -1941,7 +1941,7 @@ qreal QScrollerPrivate::nextSnapPos(qreal p, int dir, Qt::Orientation orientatio
|
||||
|
||||
} else { // (orientation == Qt::Vertical)
|
||||
// the snap points in the list
|
||||
foreach (qreal snapPos, snapPositionsY) {
|
||||
for (qreal snapPos : snapPositionsY) {
|
||||
qreal snapPosDist = snapPos - p;
|
||||
if ((dir > 0 && snapPosDist < 0) ||
|
||||
(dir < 0 && snapPosDist > 0))
|
||||
|
@ -2628,8 +2628,9 @@ void QDockAreaLayout::removePlaceHolder(const QString &name)
|
||||
QList<int> index = indexOfPlaceHolder(name);
|
||||
if (!index.isEmpty())
|
||||
remove(index);
|
||||
foreach (QDockWidgetGroupWindow *dwgw, mainWindow->findChildren<QDockWidgetGroupWindow *>(
|
||||
QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups) {
|
||||
index = dwgw->layoutInfo()->indexOfPlaceHolder(name);
|
||||
if (!index.isEmpty()) {
|
||||
dwgw->layoutInfo()->remove(index);
|
||||
@ -3064,8 +3065,9 @@ QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget)
|
||||
bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget)
|
||||
{
|
||||
QDockAreaLayoutItem *item = 0;
|
||||
foreach (QDockWidgetGroupWindow *dwgw, mainWindow->findChildren<QDockWidgetGroupWindow *>(
|
||||
QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups) {
|
||||
QList<int> index = dwgw->layoutInfo()->indexOfPlaceHolder(dockWidget->objectName());
|
||||
if (!index.isEmpty()) {
|
||||
dockWidget->setParent(dwgw);
|
||||
@ -3174,7 +3176,7 @@ void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks,
|
||||
if (!info->tabbed && info->o == o) {
|
||||
info->item_list[path.constLast()].size = size;
|
||||
int totalSize = 0;
|
||||
foreach (const QDockAreaLayoutItem &item, info->item_list) {
|
||||
for (const QDockAreaLayoutItem &item : qAsConst(info->item_list)) {
|
||||
if (!item.skip()) {
|
||||
if (totalSize != 0)
|
||||
totalSize += sep;
|
||||
|
@ -423,7 +423,8 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty()
|
||||
}
|
||||
|
||||
// Make sure to reparent the possibly floating or hidden QDockWidgets to the parent
|
||||
foreach (QDockWidget *dw, findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto dockWidgets = findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidget *dw : dockWidgets) {
|
||||
bool wasFloating = dw->isFloating();
|
||||
bool wasHidden = dw->isHidden();
|
||||
dw->setParent(parentWidget());
|
||||
@ -442,7 +443,8 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty()
|
||||
dw->show();
|
||||
}
|
||||
#if QT_CONFIG(tabbar)
|
||||
foreach (QTabBar *tb, findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly))
|
||||
const auto tabBars = findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QTabBar *tb : tabBars)
|
||||
tb->setParent(parentWidget());
|
||||
#endif
|
||||
deleteLater();
|
||||
@ -1034,10 +1036,10 @@ void QMainWindowLayoutState::saveState(QDataStream &stream) const
|
||||
#if QT_CONFIG(dockwidget)
|
||||
dockAreaLayout.saveState(stream);
|
||||
#if QT_CONFIG(tabbar)
|
||||
QList<QDockWidgetGroupWindow *> floatingTabs =
|
||||
const QList<QDockWidgetGroupWindow *> floatingTabs =
|
||||
mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
foreach (QDockWidgetGroupWindow *floating, floatingTabs) {
|
||||
for (QDockWidgetGroupWindow *floating : floatingTabs) {
|
||||
if (floating->layoutInfo()->isEmpty())
|
||||
continue;
|
||||
stream << uchar(QDockAreaLayout::FloatingDockWidgetTabMarker) << floating->geometry();
|
||||
@ -1525,9 +1527,9 @@ void QMainWindowLayout::setDocumentMode(bool enabled)
|
||||
_documentMode = enabled;
|
||||
|
||||
// Update the document mode for all tab bars
|
||||
foreach (QTabBar *bar, usedTabBars)
|
||||
for (QTabBar *bar : qAsConst(usedTabBars))
|
||||
bar->setDocumentMode(_documentMode);
|
||||
foreach (QTabBar *bar, unusedTabBars)
|
||||
for (QTabBar *bar : qAsConst(unusedTabBars))
|
||||
bar->setDocumentMode(_documentMode);
|
||||
}
|
||||
#endif // QT_CONFIG(tabbar)
|
||||
@ -1806,8 +1808,9 @@ QDockAreaLayoutInfo *QMainWindowLayout::dockInfo(QWidget *widget)
|
||||
QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget);
|
||||
if (info)
|
||||
return info;
|
||||
foreach (QDockWidgetGroupWindow *dwgw,
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups) {
|
||||
info = dwgw->layoutInfo()->info(widget);
|
||||
if (info)
|
||||
return info;
|
||||
@ -2074,8 +2077,9 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem)
|
||||
layoutState.remove(previousPath);
|
||||
previousPath = currentHoveredFloat->layoutInfo()->indexOf(widget);
|
||||
// Let's remove the widget from any possible group window
|
||||
foreach (QDockWidgetGroupWindow *dwgw,
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups) {
|
||||
if (dwgw == currentHoveredFloat)
|
||||
continue;
|
||||
QList<int> path = dwgw->layoutInfo()->indexOf(widget);
|
||||
@ -2103,8 +2107,9 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem)
|
||||
|
||||
#if QT_CONFIG(dockwidget)
|
||||
// Let's remove the widget from any possible group window
|
||||
foreach (QDockWidgetGroupWindow *dwgw,
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups) {
|
||||
QList<int> path = dwgw->layoutInfo()->indexOf(widget);
|
||||
if (!path.isEmpty())
|
||||
dwgw->layoutInfo()->remove(path);
|
||||
@ -2246,7 +2251,7 @@ void QMainWindowLayout::animationFinished(QWidget *widget)
|
||||
#if QT_CONFIG(dockwidget)
|
||||
parentWidget()->update(layoutState.dockAreaLayout.separatorRegion());
|
||||
#if QT_CONFIG(tabbar)
|
||||
foreach (QTabBar *tab_bar, usedTabBars)
|
||||
for (QTabBar *tab_bar : qAsConst(usedTabBars))
|
||||
tab_bar->show();
|
||||
#endif // QT_CONFIG(tabbar)
|
||||
#endif // QT_CONFIG(dockwidget)
|
||||
@ -2530,7 +2535,8 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos)
|
||||
|
||||
// Check if we are over another floating dock widget
|
||||
QVarLengthArray<QWidget *, 10> candidates;
|
||||
foreach (QObject *c, parentWidget()->children()) {
|
||||
const auto siblings = parentWidget()->children();
|
||||
for (QObject *c : siblings) {
|
||||
QWidget *w = qobject_cast<QWidget*>(c);
|
||||
if (!w)
|
||||
continue;
|
||||
@ -2540,7 +2546,8 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos)
|
||||
candidates << w;
|
||||
if (QDockWidgetGroupWindow *group = qobject_cast<QDockWidgetGroupWindow *>(w)) {
|
||||
// Sometimes, there are floating QDockWidget that have a QDockWidgetGroupWindow as a parent.
|
||||
foreach (QObject *c, group->children()) {
|
||||
const auto groupChildren = group->children();
|
||||
for (QObject *c : groupChildren) {
|
||||
if (QDockWidget *dw = qobject_cast<QDockWidget*>(c)) {
|
||||
if (dw != widget && dw->isFloating() && dw->isVisible() && !dw->isMinimized())
|
||||
candidates << dw;
|
||||
@ -2668,14 +2675,14 @@ void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animat
|
||||
{
|
||||
#if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget)
|
||||
QSet<QTabBar*> used = newState.dockAreaLayout.usedTabBars();
|
||||
foreach (QDockWidgetGroupWindow *dwgw,
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) {
|
||||
const auto groups =
|
||||
parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
for (QDockWidgetGroupWindow *dwgw : groups)
|
||||
used += dwgw->layoutInfo()->usedTabBars();
|
||||
}
|
||||
|
||||
QSet<QTabBar*> retired = usedTabBars - used;
|
||||
const QSet<QTabBar*> retired = usedTabBars - used;
|
||||
usedTabBars = used;
|
||||
foreach (QTabBar *tab_bar, retired) {
|
||||
for (QTabBar *tab_bar : retired) {
|
||||
tab_bar->hide();
|
||||
while (tab_bar->count() > 0)
|
||||
tab_bar->removeTab(0);
|
||||
@ -2683,10 +2690,10 @@ void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animat
|
||||
}
|
||||
|
||||
if (sep == 1) {
|
||||
QSet<QWidget*> usedSeps = newState.dockAreaLayout.usedSeparatorWidgets();
|
||||
QSet<QWidget*> retiredSeps = usedSeparatorWidgets - usedSeps;
|
||||
const QSet<QWidget*> usedSeps = newState.dockAreaLayout.usedSeparatorWidgets();
|
||||
const QSet<QWidget*> retiredSeps = usedSeparatorWidgets - usedSeps;
|
||||
usedSeparatorWidgets = usedSeps;
|
||||
foreach (QWidget *sepWidget, retiredSeps) {
|
||||
for (QWidget *sepWidget : retiredSeps) {
|
||||
unusedSeparatorWidgets.append(sepWidget);
|
||||
}
|
||||
}
|
||||
@ -2728,7 +2735,7 @@ bool QMainWindowLayout::restoreState(QDataStream &stream)
|
||||
#if QT_CONFIG(dockwidget)
|
||||
if (parentWidget()->isVisible()) {
|
||||
#if QT_CONFIG(tabbar)
|
||||
foreach (QTabBar *tab_bar, usedTabBars)
|
||||
for (QTabBar *tab_bar : qAsConst(usedTabBars))
|
||||
tab_bar->show();
|
||||
|
||||
#endif
|
||||
|
@ -471,8 +471,8 @@ QVector<QRect> MinOverlapPlacer::getCandidatePlacements(const QSize &size, const
|
||||
ylist.erase(std::unique(ylist.begin(), ylist.end()), ylist.end());
|
||||
|
||||
result.reserve(ylist.size() * xlist.size());
|
||||
foreach (int y, ylist)
|
||||
foreach (int x, xlist)
|
||||
for (int y : qAsConst(ylist))
|
||||
for (int x : qAsConst(xlist))
|
||||
result << QRect(QPoint(x, y), size);
|
||||
return result;
|
||||
}
|
||||
|
@ -2433,7 +2433,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
|
||||
atAction = d->defaultAction;
|
||||
// TODO: This works for first level menus, not yet sub menus
|
||||
} else {
|
||||
foreach (QAction *action, d->actions)
|
||||
for (QAction *action : qAsConst(d->actions))
|
||||
if (action->isEnabled()) {
|
||||
atAction = action;
|
||||
break;
|
||||
|
@ -169,7 +169,7 @@ QString QTextBrowserPrivate::findFile(const QUrl &name) const
|
||||
if (QFileInfo(fileName).isAbsolute())
|
||||
return fileName;
|
||||
|
||||
foreach (QString path, searchPaths) {
|
||||
for (QString path : qAsConst(searchPaths)) {
|
||||
if (!path.endsWith(QLatin1Char('/')))
|
||||
path.append(QLatin1Char('/'));
|
||||
path.append(fileName);
|
||||
|
Loading…
Reference in New Issue
Block a user