Add a few qAsConst() to range-for to prevent detachments

places indicated by clazy

As a drive-by, fixed minor styling issues in the affected lines.

Change-Id: I88d3fc0c8573cde0e61f19a18dd9ea697ee40c34
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
bb10
Sergio Martins 2018-12-05 19:48:05 +00:00 committed by Sérgio Martins
parent fc85a6b6b9
commit 3464e1e5c7
10 changed files with 25 additions and 27 deletions

View File

@ -445,10 +445,10 @@ void QMimeBinaryProvider::addAllMimeTypes(QList<QMimeType> &result)
loadMimeTypeList();
if (result.isEmpty()) {
result.reserve(m_mimetypeNames.count());
for (const QString &name : m_mimetypeNames)
for (const QString &name : qAsConst(m_mimetypeNames))
result.append(mimeTypeForNameUnchecked(name));
} else {
for (const QString &name : m_mimetypeNames)
for (const QString &name : qAsConst(m_mimetypeNames))
if (std::find_if(result.constBegin(), result.constEnd(), [name](const QMimeType &mime) -> bool { return mime.name() == name; })
== result.constEnd())
result.append(mimeTypeForNameUnchecked(name));

View File

@ -465,7 +465,7 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path,
cpPriv->state |= QNetworkConfiguration::Active;
if (deviceType == DEVICE_TYPE_ETHERNET) {
for (const auto *interfaceDevice : interfaceDevices) {
for (auto interfaceDevice : qAsConst(interfaceDevices)) {
if (interfaceDevice->deviceType() == deviceType) {
auto *wiredDevice = wiredDevices.value(interfaceDevice->path());
if (wiredDevice && wiredDevice->carrier()) {
@ -716,7 +716,7 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i
if (!ptr->isValid)
return QNetworkSession::Invalid;
for (QNetworkManagerConnectionActive *activeConnection : activeConnectionsList) {
for (QNetworkManagerConnectionActive *activeConnection : qAsConst(activeConnectionsList)) {
const QString identifier = activeConnection->connection().path();
if (id == identifier) {

View File

@ -169,7 +169,7 @@ void QTuioHandler::processPackets()
messages.push_back(msg);
}
for (const QOscMessage &message : messages) {
for (const QOscMessage &message : qAsConst(messages)) {
if (message.addressPattern() == "/tuio/2Dcur") {
QList<QVariant> arguments = message.arguments();
if (arguments.count() == 0) {
@ -368,12 +368,12 @@ void QTuioHandler::process2DCurFseq(const QOscMessage &message)
QList<QWindowSystemInterface::TouchPoint> tpl;
tpl.reserve(m_activeCursors.size() + m_deadCursors.size());
for (const QTuioCursor &tc : m_activeCursors) {
for (const QTuioCursor &tc : qAsConst(m_activeCursors)) {
QWindowSystemInterface::TouchPoint tp = cursorToTouchPoint(tc, win);
tpl.append(tp);
}
for (const QTuioCursor &tc : m_deadCursors) {
for (const QTuioCursor &tc : qAsConst(m_deadCursors)) {
QWindowSystemInterface::TouchPoint tp = cursorToTouchPoint(tc, win);
tp.state = Qt::TouchPointReleased;
tpl.append(tp);
@ -542,12 +542,12 @@ void QTuioHandler::process2DObjFseq(const QOscMessage &message)
QList<QWindowSystemInterface::TouchPoint> tpl;
tpl.reserve(m_activeTokens.size() + m_deadTokens.size());
for (const QTuioToken & t : m_activeTokens) {
for (const QTuioToken & t : qAsConst(m_activeTokens)) {
QWindowSystemInterface::TouchPoint tp = tokenToTouchPoint(t, win);
tpl.append(tp);
}
for (const QTuioToken & t : m_deadTokens) {
for (const QTuioToken & t : qAsConst(m_deadTokens)) {
QWindowSystemInterface::TouchPoint tp = tokenToTouchPoint(t, win);
tp.state = Qt::TouchPointReleased;
tp.velocity = QVector2D();

View File

@ -423,7 +423,7 @@ void QEglFSKmsGbmScreen::updateFlipStatus()
if (m_flipPending)
return;
for (const CloneDestination &d : m_cloneDests) {
for (const CloneDestination &d : qAsConst(m_cloneDests)) {
if (d.cloneFlipPending)
return;
}

View File

@ -600,7 +600,7 @@ void QVncClientCursor::changeCursor(QCursor *widgetCursor, QWindow *window)
cursor = *platformImage.image();
hotspot = platformImage.hotspot();
}
for (auto client : clients)
for (auto client : qAsConst(clients))
client->setDirtyCursor();
}
@ -638,16 +638,14 @@ void QVncServer::init()
QVncServer::~QVncServer()
{
for (auto client : clients) {
delete client;
}
qDeleteAll(clients);
}
void QVncServer::setDirty()
{
for (auto client : clients) {
for (auto client : qAsConst(clients))
client->setDirty(qvnc_screen->dirtyRegion);
}
qvnc_screen->clearDirty();
}

View File

@ -75,7 +75,7 @@ bool QVncScreen::initialize()
mDepth = 32;
mPhysicalSize = QSizeF(mGeometry.width()/96.*25.4, mGeometry.height()/96.*25.4);
for (const QString &arg : mArgs) {
for (const QString &arg : qAsConst(mArgs)) {
QRegularExpressionMatch match;
if (arg.contains(mmSizeRx, &match)) {
mPhysicalSize = QSizeF(match.captured("width").toDouble(), match.captured("height").toDouble());

View File

@ -637,7 +637,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
qreal nx = -1.0, ny = -1.0;
qreal w = 0.0, h = 0.0;
bool majorAxisIsY = touchPoint.area.height() > touchPoint.area.width();
for (const TouchDeviceData::ValuatorClassInfo vci : dev->valuatorInfo) {
for (const TouchDeviceData::ValuatorClassInfo &vci : qAsConst(dev->valuatorInfo)) {
double value;
if (!xi2GetValuatorValueIfSet(xiDeviceEvent, vci.number, &value))
continue;
@ -823,7 +823,7 @@ bool QXcbConnection::xi2SetMouseGrabEnabled(xcb_window_t w, bool grab)
| XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
| XCB_INPUT_XI_EVENT_MASK_TOUCH_END;
for (int id : m_xiMasterPointerIds) {
for (int id : qAsConst(m_xiMasterPointerIds)) {
xcb_generic_error_t *error = nullptr;
auto cookie = xcb_input_xi_grab_device(xcb_connection(), w, XCB_CURRENT_TIME, XCB_CURSOR_NONE, id,
XCB_INPUT_GRAB_MODE_22_ASYNC, XCB_INPUT_GRAB_MODE_22_ASYNC,
@ -841,7 +841,7 @@ bool QXcbConnection::xi2SetMouseGrabEnabled(xcb_window_t w, bool grab)
free(reply);
}
} else { // ungrab
for (int id : m_xiMasterPointerIds) {
for (int id : qAsConst(m_xiMasterPointerIds)) {
auto cookie = xcb_input_xi_ungrab_device_checked(xcb_connection(), XCB_CURRENT_TIME, id);
xcb_generic_error_t *error = xcb_request_check(xcb_connection(), cookie);
if (error) {

View File

@ -163,7 +163,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
if (pageSize.id() != QPageSize::Custom) {
for (const QPageSize &ps : m_pageSizes) {
for (const QPageSize &ps : qAsConst(m_pageSizes)) {
if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
return ps;
}
@ -171,7 +171,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// Next try match on id only if not custom
if (pageSize.id() != QPageSize::Custom) {
for (const QPageSize &ps : m_pageSizes) {
for (const QPageSize &ps : qAsConst(m_pageSizes)) {
if (ps.id() == pageSize.id())
return ps;
}
@ -186,7 +186,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSize
if (!m_havePageSizes)
loadPageSizes();
for (const QPageSize &ps : m_pageSizes) {
for (const QPageSize &ps : qAsConst(m_pageSizes)) {
if (ps.id() == pageSizeId)
return ps;
}
@ -200,7 +200,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
if (!m_havePageSizes)
loadPageSizes();
for (const QPageSize &ps : m_pageSizes) {
for (const QPageSize &ps : qAsConst(m_pageSizes)) {
if (ps.name() == pageName)
return ps;
}
@ -233,7 +233,7 @@ QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize
return pageSize;
// Try to find a supported page size based on point size
for (const QPageSize &ps : m_pageSizes) {
for (const QPageSize &ps : qAsConst(m_pageSizes)) {
if (ps.sizePoints() == pageSize.sizePoints())
return ps;
}

View File

@ -619,7 +619,7 @@ void Generator::generateCode()
fprintf(out, "// a) You are using a NOTIFY signal that does not exist. Fix it.\n");
fprintf(out, "// b) You are using a NOTIFY signal that does exist (in a parent class) but has a non-empty parameter list. This is a moc limitation.\n");
fprintf(out, "Q_DECL_UNUSED static void checkNotifySignalValidity_%s(%s *t) {\n", qualifiedClassNameIdentifier.constData(), cdef->qualified.constData());
for (const QByteArray &nonClassSignal : cdef->nonClassSignalList)
for (const QByteArray &nonClassSignal : qAsConst(cdef->nonClassSignalList))
fprintf(out, " t->%s();\n", nonClassSignal.constData());
fprintf(out, "}\n");
}

View File

@ -769,7 +769,7 @@ void QWizardPrivate::reset()
for (int i = history.count() - 1; i >= 0; --i)
q->cleanupPage(history.at(i));
history.clear();
for (QWizardPage *page : pageMap)
for (QWizardPage *page : qAsConst(pageMap))
page->d_func()->initialized = false;
current = -1;