QtGui: eradicate Q_FOREACH loops [already const]

(or trivially marked const) ... by replacing them
with C++11 range-for loops.

Change-Id: I3cce92b9d77a3ff96fad877d1d989145e530646f
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-01-26 14:38:54 +01:00
parent 257cc69bed
commit d09cfe04b8
16 changed files with 27 additions and 26 deletions

View File

@ -127,10 +127,10 @@ void DropArea::clear()
QPixmap DropArea::extractPixmap(const QByteArray &data, const QString &format)
{
QList<QByteArray> imageFormats = QImageReader::supportedImageFormats();
const QList<QByteArray> imageFormats = QImageReader::supportedImageFormats();
QPixmap pixmap;
foreach (const QByteArray &imageFormat, imageFormats) {
for (const QByteArray &imageFormat : imageFormats) {
if (format.mid(6) == QString(imageFormat)) {
pixmap.loadFromData(data, imageFormat);
break;

View File

@ -412,12 +412,12 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
// a massive amount of file stat (especially if the icon is not there)
auto cache = theme.m_gtkCaches.at(i);
if (cache->isValid()) {
auto result = cache->lookup(iconNameFallback);
const auto result = cache->lookup(iconNameFallback);
if (cache->isValid()) {
const QVector<QIconDirInfo> subDirsCopy = subDirs;
subDirs.clear();
subDirs.reserve(result.count());
foreach (const char *s, result) {
for (const char *s : result) {
QString path = QString::fromUtf8(s);
auto it = std::find_if(subDirsCopy.cbegin(), subDirsCopy.cend(),
[&](const QIconDirInfo &info) {

View File

@ -1008,7 +1008,7 @@ QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
QScreen *windowScreen = Q_NULLPTR;
// Find the window on the primary virtual desktop first
foreach (QScreen *screen, primaryScreens) {
for (QScreen *screen : primaryScreens) {
if (screen->geometry().contains(pos)) {
windowScreen = screen;
break;

View File

@ -454,7 +454,7 @@ QVector<T> fromNativePixels(const QVector<T> &pixelValues, const QWindow *window
return pixelValues;
QVector<T> pointValues;
foreach (const T& pixelValue, pixelValues)
for (const T &pixelValue : pixelValues)
pointValues.append(pixelValue / QHighDpiScaling::factor(window));
return pointValues;
}
@ -467,7 +467,7 @@ QVector<T> toNativePixels(const QVector<T> &pointValues, const QWindow *window)
return pointValues;
QVector<T> pixelValues;
foreach (const T& pointValue, pointValues)
for (const T &pointValue : pointValues)
pixelValues.append(pointValue * QHighDpiScaling::factor(window));
return pixelValues;
}

View File

@ -1565,9 +1565,9 @@ QList<QKeySequence> QKeySequence::listFromString(const QString &str, SequenceFor
{
QList<QKeySequence> result;
QStringList strings = str.split(QLatin1String("; "));
const QStringList strings = str.split(QLatin1String("; "));
result.reserve(strings.count());
foreach (const QString &string, strings) {
for (const QString &string : strings) {
result << fromString(string, format);
}
@ -1586,7 +1586,7 @@ QString QKeySequence::listToString(const QList<QKeySequence> &list, SequenceForm
{
QString result;
foreach (const QKeySequence &sequence, list) {
for (const QKeySequence &sequence : list) {
result += sequence.toString(format);
result += QLatin1String("; ");
}

View File

@ -554,9 +554,10 @@ static inline const QScreen *effectiveScreen(const QWindow *window)
#ifndef QT_NO_CURSOR
if (siblings.size() > 1) {
const QPoint referencePoint = window->transientParent() ? window->transientParent()->geometry().center() : QCursor::pos();
foreach (const QScreen *sibling, siblings)
for (const QScreen *sibling : siblings) {
if (sibling->geometry().contains(referencePoint))
return sibling;
}
}
#endif
return screen;

View File

@ -364,10 +364,10 @@ QRect QScreen::availableGeometry() const
QList<QScreen *> QScreen::virtualSiblings() const
{
Q_D(const QScreen);
QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
QList<QScreen *> screens;
screens.reserve(platformScreens.count());
foreach (QPlatformScreen *platformScreen, platformScreens)
for (QPlatformScreen *platformScreen : platformScreens)
screens << platformScreen->screen();
return screens;
}

View File

@ -504,7 +504,7 @@ QList<QWindowSystemInterface::TouchPoint>
{
QList<QWindowSystemInterface::TouchPoint> newList;
newList.reserve(pointList.size());
foreach (const QTouchEvent::TouchPoint &pt, pointList) {
for (const QTouchEvent::TouchPoint &pt : pointList) {
QWindowSystemInterface::TouchPoint p;
p.id = pt.id();
p.flags = pt.flags();
@ -928,7 +928,7 @@ static QList<struct QWindowSystemInterface::TouchPoint> touchPointList(const QLi
{
QList<struct QWindowSystemInterface::TouchPoint> newList;
Q_FOREACH (QTouchEvent::TouchPoint p, pointList)
for (const QTouchEvent::TouchPoint &p : pointList)
newList.append(touchPoint(p));
return newList;

View File

@ -548,7 +548,7 @@ Q_GUI_EXPORT std::set<QByteArray> *qgpu_features(const QString &filename)
{
const QSet<QString> features = QOpenGLConfig::gpuFeatures(QOpenGLConfig::Gpu::fromContext(), filename);
std::set<QByteArray> *result = new std::set<QByteArray>;
foreach (const QString &feature, features)
for (const QString &feature : features)
result->insert(feature.toUtf8());
return result;
}

View File

@ -1156,7 +1156,7 @@ QVector<GLuint> QOpenGLFramebufferObject::textures() const
if (d->format.samples() != 0)
return ids;
ids.reserve(d->colorAttachments.count());
foreach (const QOpenGLFramebufferObjectPrivate::ColorAttachment &color, d->colorAttachments)
for (const auto &color : d->colorAttachments)
ids.append(color.guard ? color.guard->id() : 0);
return ids;
}
@ -1240,7 +1240,7 @@ QVector<QSize> QOpenGLFramebufferObject::sizes() const
Q_D(const QOpenGLFramebufferObject);
QVector<QSize> sz;
sz.reserve(d->colorAttachments.size());
foreach (const QOpenGLFramebufferObjectPrivate::ColorAttachment &color, d->colorAttachments)
for (const auto &color : d->colorAttachments)
sz.append(color.size);
return sz;
}

View File

@ -728,7 +728,7 @@ QOpenGLShaderProgramPrivate::~QOpenGLShaderProgramPrivate()
bool QOpenGLShaderProgramPrivate::hasShader(QOpenGLShader::ShaderType type) const
{
foreach (QOpenGLShader *shader, shaders) {
for (QOpenGLShader *shader : shaders) {
if (shader->shaderType() == type)
return true;
}

View File

@ -252,7 +252,7 @@ static QRegion deviceRegion(const QRegion &region, QWindow *window, const QPoint
QVector<QRect> rects;
const QVector<QRect> regionRects = region.rects();
rects.reserve(regionRects.count());
foreach (const QRect &rect, regionRects)
for (const QRect &rect : regionRects)
rects.append(deviceRect(rect.translated(offset), window));
QRegion deviceRegion;

View File

@ -1831,7 +1831,7 @@ void QFont::insertSubstitutions(const QString &familyName,
QFontSubst *fontSubst = globalFontSubst();
Q_ASSERT(fontSubst != 0);
QStringList &list = (*fontSubst)[familyName.toLower()];
foreach (const QString &substituteName, substituteNames) {
for (const QString &substituteName : substituteNames) {
const QString lowerSubstituteName = substituteName.toLower();
if (!list.contains(lowerSubstituteName))
list.append(lowerSubstituteName);

View File

@ -3341,7 +3341,7 @@ void QTextEngine::drawItemDecorationList(QPainter *painter, const ItemDecoration
if (decorationList.isEmpty())
return;
foreach (const ItemDecoration &decoration, decorationList) {
for (const ItemDecoration &decoration : decorationList) {
painter->setPen(decoration.pen);
painter->drawLine(QLineF(decoration.x1, decoration.y, decoration.x2, decoration.y));
}

View File

@ -153,7 +153,7 @@ void QTextOption::setTabArray(const QList<qreal> &tabStops)
QList<QTextOption::Tab> tabs;
QTextOption::Tab tab;
tabs.reserve(tabStops.count());
foreach (qreal pos, tabStops) {
for (qreal pos : tabStops) {
tab.position = pos;
tabs.append(tab);
}

View File

@ -1022,7 +1022,7 @@ bool QZipReader::extractAll(const QString &destinationDir) const
// create directories first
const QVector<FileInfo> allFiles = fileInfoList();
foreach (const FileInfo &fi, allFiles) {
for (const FileInfo &fi : allFiles) {
const QString absPath = destinationDir + QDir::separator() + fi.filePath;
if (fi.isDir) {
if (!baseDir.mkpath(fi.filePath))
@ -1033,7 +1033,7 @@ bool QZipReader::extractAll(const QString &destinationDir) const
}
// set up symlinks
foreach (const FileInfo &fi, allFiles) {
for (const FileInfo &fi : allFiles) {
const QString absPath = destinationDir + QDir::separator() + fi.filePath;
if (fi.isSymLink) {
QString destination = QFile::decodeName(fileData(fi.filePath));
@ -1051,7 +1051,7 @@ bool QZipReader::extractAll(const QString &destinationDir) const
}
}
foreach (const FileInfo &fi, allFiles) {
for (const FileInfo &fi : allFiles) {
const QString absPath = destinationDir + QDir::separator() + fi.filePath;
if (fi.isFile) {
QFile f(absPath);