macOS: Replace foreach with ranged for loops

Change-Id: I9d0dbb60e05e4ef85219740465bb941ef8d8eb0f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-04-01 14:55:56 +02:00
parent 9ba09e26d7
commit c2efc16126
9 changed files with 12 additions and 10 deletions

View File

@ -92,6 +92,8 @@ RESOURCES += qcocoaresources.qrc
LIBS += -framework AppKit -framework CoreServices -framework Carbon -framework IOKit -framework QuartzCore -framework CoreVideo -framework Metal -framework IOSurface -lcups
DEFINES += QT_NO_FOREACH
QT += \
core-private gui-private \
clipboard_support-private theme_support-private \

View File

@ -547,7 +547,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
return nsActions;
const QStringList &supportedActionNames = QAccessibleBridgeUtils::effectiveActionNames(iface);
foreach (const QString &qtAction, supportedActionNames) {
for (const QString &qtAction : supportedActionNames) {
NSString *nsAction = QCocoaAccessible::getTranslatedAction(qtAction);
if (nsAction)
[nsActions addObject : nsAction];

View File

@ -116,7 +116,7 @@ class QFontEngineFT;
static QCocoaIntegration::Options parseOptions(const QStringList &paramList)
{
QCocoaIntegration::Options options;
foreach (const QString &param, paramList) {
for (const QString &param : paramList) {
#ifndef QT_NO_FREETYPE
if (param == QLatin1String("fontengine=freetype"))
options |= QCocoaIntegration::UseFreeTypeFontEngine;

View File

@ -191,7 +191,7 @@ void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate)
QMacAutoReleasePool pool;
QCocoaMenu *cocoaMenu = static_cast<QCocoaMenu *>(menu);
Q_FOREACH (QCocoaMenuItem *item, cocoaMenu->items())
for (QCocoaMenuItem *item : cocoaMenu->items())
cocoaMenu->syncMenuItem_helper(item, menubarUpdate);
BOOL shouldHide = YES;

View File

@ -117,7 +117,7 @@ QCocoaPrintDevice::~QCocoaPrintDevice()
{
if (m_ppd)
ppdClose(m_ppd);
foreach (PMPaper paper, m_macPapers)
for (PMPaper paper : m_macPapers)
PMRelease(paper);
// Releasing the session appears to also release the printer
if (m_session)
@ -171,7 +171,7 @@ QPageSize QCocoaPrintDevice::createPageSize(const PMPaper &paper) const
void QCocoaPrintDevice::loadPageSizes() const
{
m_pageSizes.clear();
foreach (PMPaper paper, m_macPapers)
for (PMPaper paper : m_macPapers)
PMRelease(paper);
m_macPapers.clear();
m_printableMargins.clear();

View File

@ -162,7 +162,7 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon)
qreal devicePixelRatio = qApp->devicePixelRatio();
const int maxPixmapHeight = maxImageHeight * devicePixelRatio;
QSize selectedSize;
Q_FOREACH (const QSize& size, sortByHeight(icon.availableSizes())) {
for (const QSize& size : sortByHeight(icon.availableSizes())) {
// Select a pixmap based on the height. We want the largest pixmap
// with a height smaller or equal to maxPixmapHeight. The pixmap
// may rectangular; assume it has a reasonable size. If there is

View File

@ -1833,7 +1833,7 @@ qreal QCocoaWindow::devicePixelRatio() const
QWindow *QCocoaWindow::childWindowAt(QPoint windowPoint)
{
QWindow *targetWindow = window();
foreach (QObject *child, targetWindow->children())
for (QObject *child : targetWindow->children())
if (QWindow *childWindow = qobject_cast<QWindow *>(child))
if (QPlatformWindow *handle = childWindow->handle())
if (handle->isExposed() && childWindow->geometry().contains(windowPoint))

View File

@ -184,7 +184,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
if (_touchCount != _currentTouches.size()) {
// Remove all instances, and basically start from scratch:
touchPoints.clear();
foreach (QCocoaTouch *qcocoaTouch, _currentTouches) {
for (QCocoaTouch *qcocoaTouch : _currentTouches) {
if (!_updateInternalStateOnly) {
qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased;
touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint);

View File

@ -485,7 +485,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
int bestResolution = 0;
int dpi = value.toInt();
int bestDistance = INT_MAX;
foreach (int resolution, d->m_printDevice->supportedResolutions()) {
for (int resolution : d->m_printDevice->supportedResolutions()) {
if (dpi == resolution) {
bestResolution = resolution;
break;
@ -758,7 +758,7 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const
}
case PPK_SupportedResolutions: {
QList<QVariant> list;
foreach (int resolution, d->m_printDevice->supportedResolutions())
for (int resolution : d->m_printDevice->supportedResolutions())
list << resolution;
ret = list;
break;