Eradicate Q_FOREACH loops [1/2]: trivial cases
In this patch, we port Q_FOREACH loops to C++11 ranged-for loops. All cases are trivial in the sense that either the argument is already const or is trivially marked as const, either by qAsConst(), or, in the case of rvalues, by storing to a const auto temporary first. In addition, all loop bodies are clear enough to confirm that the container we iterate over is not changed under iteration. This does not exclude cases where a loop is prematurely exited just after calling a modifier on the container, as that is safe, if not especially elegant. Change-Id: I87a63f07797437d421567d60e52305391a3c4f21 Reviewed-by: Johan Helsing <johan.helsing@qt.io>
This commit is contained in:
parent
0899b4287b
commit
9f64f52e23
@ -49,7 +49,8 @@ namespace QtWaylandClient {
|
|||||||
|
|
||||||
bool QWaylandWlShellIntegration::initialize(QWaylandDisplay *display)
|
bool QWaylandWlShellIntegration::initialize(QWaylandDisplay *display)
|
||||||
{
|
{
|
||||||
Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
|
const auto globals = display->globals();
|
||||||
|
for (QWaylandDisplay::RegistryGlobal global : globals) {
|
||||||
if (global.interface == QLatin1String("wl_shell")) {
|
if (global.interface == QLatin1String("wl_shell")) {
|
||||||
m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1);
|
m_wlShell = new QtWayland::wl_shell(display->wl_registry(), global.id, 1);
|
||||||
break;
|
break;
|
||||||
|
@ -51,7 +51,8 @@ namespace QtWaylandClient {
|
|||||||
|
|
||||||
bool QWaylandXdgShellV5Integration::initialize(QWaylandDisplay *display)
|
bool QWaylandXdgShellV5Integration::initialize(QWaylandDisplay *display)
|
||||||
{
|
{
|
||||||
Q_FOREACH (QWaylandDisplay::RegistryGlobal global, display->globals()) {
|
const auto globals = display->globals();
|
||||||
|
for (QWaylandDisplay::RegistryGlobal global : globals) {
|
||||||
if (global.interface == QLatin1String("xdg_shell")) {
|
if (global.interface == QLatin1String("xdg_shell")) {
|
||||||
m_xdgShell.reset(new QWaylandXdgShellV5(display->wl_registry(), global.id));
|
m_xdgShell.reset(new QWaylandXdgShellV5(display->wl_registry(), global.id));
|
||||||
break;
|
break;
|
||||||
|
@ -60,7 +60,8 @@ QWaylandDataSource::QWaylandDataSource(QWaylandDataDeviceManager *dataDeviceMana
|
|||||||
{
|
{
|
||||||
if (!mimeData)
|
if (!mimeData)
|
||||||
return;
|
return;
|
||||||
Q_FOREACH (const QString &format, mimeData->formats()) {
|
const auto formats = mimeData->formats();
|
||||||
|
for (const QString &format : formats) {
|
||||||
offer(format);
|
offer(format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ void QWaylandDisplay::registry_global_remove(uint32_t id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QWaylandScreen *screen, mScreens) {
|
for (QWaylandScreen *screen : qAsConst(mScreens)) {
|
||||||
if (screen->outputId() == id) {
|
if (screen->outputId() == id) {
|
||||||
mScreens.removeOne(screen);
|
mScreens.removeOne(screen);
|
||||||
QWindowSystemInterface::handleScreenRemoved(screen);
|
QWindowSystemInterface::handleScreenRemoved(screen);
|
||||||
|
@ -221,11 +221,11 @@ void QWaylandTextInput::zwp_text_input_v2_leave(uint32_t serial, ::wl_surface *s
|
|||||||
|
|
||||||
void QWaylandTextInput::zwp_text_input_v2_modifiers_map(wl_array *map)
|
void QWaylandTextInput::zwp_text_input_v2_modifiers_map(wl_array *map)
|
||||||
{
|
{
|
||||||
QList<QByteArray> modifiersMap = QByteArray::fromRawData(static_cast<const char*>(map->data), map->size).split('\0');
|
const QList<QByteArray> modifiersMap = QByteArray::fromRawData(static_cast<const char*>(map->data), map->size).split('\0');
|
||||||
|
|
||||||
m_modifiersMap.clear();
|
m_modifiersMap.clear();
|
||||||
|
|
||||||
Q_FOREACH (const QByteArray &modifier, modifiersMap) {
|
for (const QByteArray &modifier : modifiersMap) {
|
||||||
if (modifier == "Shift")
|
if (modifier == "Shift")
|
||||||
m_modifiersMap.append(Qt::ShiftModifier);
|
m_modifiersMap.append(Qt::ShiftModifier);
|
||||||
else if (modifier == "Control")
|
else if (modifier == "Control")
|
||||||
|
@ -1349,7 +1349,7 @@ bool QWaylandInputDevice::Touch::allTouchPointsReleased()
|
|||||||
|
|
||||||
void QWaylandInputDevice::Touch::releasePoints()
|
void QWaylandInputDevice::Touch::releasePoints()
|
||||||
{
|
{
|
||||||
Q_FOREACH (const QWindowSystemInterface::TouchPoint &previousPoint, mPrevTouchPoints) {
|
for (const QWindowSystemInterface::TouchPoint &previousPoint : qAsConst(mPrevTouchPoints)) {
|
||||||
QWindowSystemInterface::TouchPoint tp = previousPoint;
|
QWindowSystemInterface::TouchPoint tp = previousPoint;
|
||||||
tp.state = Qt::TouchPointReleased;
|
tp.state = Qt::TouchPointReleased;
|
||||||
mTouchPoints.append(tp);
|
mTouchPoints.append(tp);
|
||||||
|
@ -421,7 +421,7 @@ void QWaylandIntegration::initializeShellIntegration()
|
|||||||
preferredShells << QLatin1String("wl-shell") << QLatin1String("ivi-shell");
|
preferredShells << QLatin1String("wl-shell") << QLatin1String("ivi-shell");
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_FOREACH (QString preferredShell, preferredShells) {
|
for (const QString &preferredShell : qAsConst(preferredShells)) {
|
||||||
mShellIntegration.reset(createShellIntegration(preferredShell));
|
mShellIntegration.reset(createShellIntegration(preferredShell));
|
||||||
if (mShellIntegration) {
|
if (mShellIntegration) {
|
||||||
qCDebug(lcQpaWayland, "Using the '%s' shell integration", qPrintable(preferredShell));
|
qCDebug(lcQpaWayland, "Using the '%s' shell integration", qPrintable(preferredShell));
|
||||||
|
@ -175,7 +175,8 @@ QList<QPlatformScreen *> QWaylandScreen::virtualSiblings() const
|
|||||||
|
|
||||||
void QWaylandScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
|
void QWaylandScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
|
||||||
{
|
{
|
||||||
foreach (QWindow *window, QGuiApplication::allWindows()) {
|
const auto allWindows = QGuiApplication::allWindows();
|
||||||
|
for (QWindow *window : allWindows) {
|
||||||
QWaylandWindow *w = static_cast<QWaylandWindow *>(window->handle());
|
QWaylandWindow *w = static_cast<QWaylandWindow *>(window->handle());
|
||||||
if (w && w->waylandScreen() == this)
|
if (w && w->waylandScreen() == this)
|
||||||
w->setOrientationMask(mask);
|
w->setOrientationMask(mask);
|
||||||
|
@ -243,7 +243,8 @@ void QWaylandShmBackingStore::resize(const QSize &size, const QRegion &)
|
|||||||
|
|
||||||
QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size)
|
QWaylandShmBuffer *QWaylandShmBackingStore::getBuffer(const QSize &size)
|
||||||
{
|
{
|
||||||
foreach (QWaylandShmBuffer *b, mBuffers) {
|
const auto copy = mBuffers; // remove when ported to vector<unique_ptr> + remove_if
|
||||||
|
for (QWaylandShmBuffer *b : copy) {
|
||||||
if (!b->busy()) {
|
if (!b->busy()) {
|
||||||
if (b->size() == size) {
|
if (b->size() == size) {
|
||||||
return b;
|
return b;
|
||||||
|
@ -94,7 +94,8 @@ QWaylandWindow::~QWaylandWindow()
|
|||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
const QWindow *parent = window();
|
const QWindow *parent = window();
|
||||||
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
|
const auto tlw = QGuiApplication::topLevelWindows();
|
||||||
|
for (QWindow *w : tlw) {
|
||||||
if (w->transientParent() == parent)
|
if (w->transientParent() == parent)
|
||||||
QWindowSystemInterface::handleCloseEvent(w);
|
QWindowSystemInterface::handleCloseEvent(w);
|
||||||
}
|
}
|
||||||
@ -786,7 +787,7 @@ bool QWaylandWindow::createDecoration()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hadDecoration != (bool)mWindowDecoration) {
|
if (hadDecoration != (bool)mWindowDecoration) {
|
||||||
foreach (QWaylandSubSurface *subsurf, mChildren) {
|
for (QWaylandSubSurface *subsurf : qAsConst(mChildren)) {
|
||||||
QPoint pos = subsurf->window()->geometry().topLeft();
|
QPoint pos = subsurf->window()->geometry().topLeft();
|
||||||
QMargins m = frameMargins();
|
QMargins m = frameMargins();
|
||||||
subsurf->set_position(pos.x() + m.left(), pos.y() + m.top());
|
subsurf->set_position(pos.x() + m.left(), pos.y() + m.top());
|
||||||
|
@ -157,7 +157,7 @@ QInputMethodEvent QWaylandInputMethodEventBuilder::buildPreedit(const QString &t
|
|||||||
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, indexFromWayland(text, m_preeditCursor), 1, QVariant()));
|
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, indexFromWayland(text, m_preeditCursor), 1, QVariant()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_FOREACH (const QInputMethodEvent::Attribute &attr, m_preeditStyles) {
|
for (const QInputMethodEvent::Attribute &attr : qAsConst(m_preeditStyles)) {
|
||||||
int start = indexFromWayland(text, attr.start);
|
int start = indexFromWayland(text, attr.start);
|
||||||
int length = indexFromWayland(text, attr.start + attr.length) - start;
|
int length = indexFromWayland(text, attr.start + attr.length) - start;
|
||||||
attributes.append(QInputMethodEvent::Attribute(attr.type, start, length, attr.value));
|
attributes.append(QInputMethodEvent::Attribute(attr.type, start, length, attr.value));
|
||||||
|
@ -542,7 +542,7 @@ bool Scanner::process()
|
|||||||
|
|
||||||
if (hasEvents) {
|
if (hasEvents) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
foreach (const WaylandEvent &e, interface.events) {
|
for (const WaylandEvent &e : interface.events) {
|
||||||
printf(" void send_");
|
printf(" void send_");
|
||||||
printEvent(e);
|
printEvent(e);
|
||||||
printf(";\n");
|
printf(";\n");
|
||||||
@ -563,7 +563,7 @@ bool Scanner::process()
|
|||||||
|
|
||||||
if (hasRequests) {
|
if (hasRequests) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
foreach (const WaylandEvent &e, interface.requests) {
|
for (const WaylandEvent &e : interface.requests) {
|
||||||
printf(" virtual void %s_", interfaceNameStripped);
|
printf(" virtual void %s_", interfaceNameStripped);
|
||||||
printEvent(e);
|
printEvent(e);
|
||||||
printf(";\n");
|
printf(";\n");
|
||||||
@ -826,7 +826,7 @@ bool Scanner::process()
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" };\n");
|
printf(" };\n");
|
||||||
|
|
||||||
foreach (const WaylandEvent &e, interface.requests) {
|
for (const WaylandEvent &e : interface.requests) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" void %s::%s_", interfaceName, interfaceNameStripped);
|
printf(" void %s::%s_", interfaceName, interfaceNameStripped);
|
||||||
printEvent(e, true);
|
printEvent(e, true);
|
||||||
@ -996,7 +996,7 @@ bool Scanner::process()
|
|||||||
|
|
||||||
if (!interface.requests.isEmpty()) {
|
if (!interface.requests.isEmpty()) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
foreach (const WaylandEvent &e, interface.requests) {
|
for (const WaylandEvent &e : interface.requests) {
|
||||||
const WaylandArgument *new_id = newIdArgument(e.arguments);
|
const WaylandArgument *new_id = newIdArgument(e.arguments);
|
||||||
QByteArray new_id_str = "void ";
|
QByteArray new_id_str = "void ";
|
||||||
if (new_id) {
|
if (new_id) {
|
||||||
@ -1016,7 +1016,7 @@ bool Scanner::process()
|
|||||||
if (hasEvents) {
|
if (hasEvents) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" protected:\n");
|
printf(" protected:\n");
|
||||||
foreach (const WaylandEvent &e, interface.events) {
|
for (const WaylandEvent &e : interface.events) {
|
||||||
printf(" virtual void %s_", interfaceNameStripped);
|
printf(" virtual void %s_", interfaceNameStripped);
|
||||||
printEvent(e);
|
printEvent(e);
|
||||||
printf(";\n");
|
printf(";\n");
|
||||||
|
@ -221,8 +221,8 @@ QSharedPointer<MockSurface> MockCompositor::surface()
|
|||||||
QSharedPointer<MockSurface> result;
|
QSharedPointer<MockSurface> result;
|
||||||
lock();
|
lock();
|
||||||
{
|
{
|
||||||
QVector<Impl::Surface *> surfaces = m_compositor->surfaces();
|
const QVector<Impl::Surface *> surfaces = m_compositor->surfaces();
|
||||||
foreach (Impl::Surface *surface, surfaces) {
|
for (Impl::Surface *surface : surfaces) {
|
||||||
// we don't want to mistake the cursor surface for a window surface
|
// we don't want to mistake the cursor surface for a window surface
|
||||||
if (surface->isMapped()) {
|
if (surface->isMapped()) {
|
||||||
result = surface->mockSurface();
|
result = surface->mockSurface();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user