QtGui: eradicate Q_FOREACH loops [rvalues]
... by replacing them with C++11 range-for loops. This is the simplest of the patch series: Q_FOREACH took a copy, so we do, too. Except we don't, since we're just catching the return value that comes out of the function (RVO). We can't feed the rvalues into range-for, because they are non-const and would thus detach. Change-Id: I457942159015ff153bdfc6d5f031a3f0a0f6e9ac Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>bb10
parent
276d6cf239
commit
bcd7d223f0
|
|
@ -89,7 +89,8 @@ QSize MyWidget::sizeHint() const
|
|||
//! [4]
|
||||
void showAllHiddenTopLevelWidgets()
|
||||
{
|
||||
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
||||
const auto topLevelWidgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *widget : topLevelWidgets) {
|
||||
if (widget->isHidden())
|
||||
widget->show();
|
||||
}
|
||||
|
|
@ -100,7 +101,8 @@ void showAllHiddenTopLevelWidgets()
|
|||
//! [5]
|
||||
void updateAllWidgets()
|
||||
{
|
||||
foreach (QWidget *widget, QApplication::allWidgets())
|
||||
const auto topLevelWidgets = QApplication::topLevelWidgets();
|
||||
for (QWidget *widget : topLevelWidgets)
|
||||
widget->update();
|
||||
}
|
||||
//! [5]
|
||||
|
|
|
|||
|
|
@ -2714,7 +2714,8 @@ void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate:
|
|||
emit s->availableGeometryChanged(s->availableGeometry());
|
||||
|
||||
if (geometryChanged || availableGeometryChanged) {
|
||||
foreach (QScreen* sibling, s->virtualSiblings())
|
||||
const auto siblings = s->virtualSiblings();
|
||||
for (QScreen* sibling : siblings)
|
||||
emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,7 +267,8 @@ void QHighDpiScaling::updateHighDpiScaling()
|
|||
return;
|
||||
|
||||
if (m_usePixelDensity && !m_pixelDensityScalingActive) {
|
||||
Q_FOREACH (QScreen *screen, QGuiApplication::screens()) {
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (QScreen *screen : screens) {
|
||||
if (!qFuzzyCompare(screenSubfactor(screen->handle()), qreal(1))) {
|
||||
m_pixelDensityScalingActive = true;
|
||||
break;
|
||||
|
|
@ -276,7 +277,8 @@ void QHighDpiScaling::updateHighDpiScaling()
|
|||
}
|
||||
if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
|
||||
int i = 0;
|
||||
Q_FOREACH (const QByteArray &spec, qgetenv(screenFactorsEnvVar).split(';')) {
|
||||
const auto specs = qgetenv(screenFactorsEnvVar).split(';');
|
||||
for (const QByteArray &spec : specs) {
|
||||
QScreen *screen = 0;
|
||||
int equalsPos = spec.lastIndexOf('=');
|
||||
double factor = 0;
|
||||
|
|
@ -287,7 +289,8 @@ void QHighDpiScaling::updateHighDpiScaling()
|
|||
bool ok;
|
||||
factor = f.toDouble(&ok);
|
||||
if (ok) {
|
||||
Q_FOREACH (QScreen *s, QGuiApplication::screens()) {
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (QScreen *s : screens) {
|
||||
if (s->name() == QString::fromLocal8Bit(name)) {
|
||||
screen = s;
|
||||
break;
|
||||
|
|
@ -327,7 +330,8 @@ void QHighDpiScaling::setGlobalFactor(qreal factor)
|
|||
m_globalScalingActive = !qFuzzyCompare(factor, qreal(1));
|
||||
m_factor = m_globalScalingActive ? factor : qreal(1);
|
||||
m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
|
||||
Q_FOREACH (QScreen *screen, QGuiApplication::screens())
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (QScreen *screen : screens)
|
||||
screen->d_func()->updateHighDpi();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -381,7 +381,8 @@ inline QRegion fromNativeLocalRegion(const QRegion &pixelRegion, const QWindow *
|
|||
|
||||
qreal scaleFactor = QHighDpiScaling::factor(window);
|
||||
QRegion pointRegion;
|
||||
foreach (const QRect &rect, pixelRegion.rects()) {
|
||||
const auto rects = pixelRegion.rects();
|
||||
for (const QRect &rect : rects) {
|
||||
pointRegion += QRect(fromNative(rect.topLeft(), scaleFactor),
|
||||
fromNative(rect.size(), scaleFactor));
|
||||
}
|
||||
|
|
@ -395,7 +396,8 @@ inline QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *wi
|
|||
|
||||
qreal scaleFactor = QHighDpiScaling::factor(window);
|
||||
QRegion pixelRegon;
|
||||
foreach (const QRect &rect, pointRegion.rects()) {
|
||||
const auto rects = pointRegion.rects();
|
||||
for (const QRect &rect : rects) {
|
||||
pixelRegon += QRect(toNative(rect.topLeft(), scaleFactor),
|
||||
toNative(rect.size(), scaleFactor));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
|
|||
const QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) const
|
||||
{
|
||||
if (!geometry().contains(point)) {
|
||||
Q_FOREACH (const QPlatformScreen* screen, virtualSiblings()) {
|
||||
const auto screens = virtualSiblings();
|
||||
for (const QPlatformScreen *screen : screens) {
|
||||
if (screen->geometry().contains(point))
|
||||
return screen;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -494,7 +494,8 @@ QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) co
|
|||
const QPoint center = newGeometry.isEmpty() ? newGeometry.topLeft() : newGeometry.center();
|
||||
|
||||
if (!parent() && currentScreen && !currentScreen->geometry().contains(center)) {
|
||||
Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) {
|
||||
const auto screens = currentScreen->virtualSiblings();
|
||||
for (QPlatformScreen *screen : screens) {
|
||||
if (screen->geometry().contains(center))
|
||||
return screen;
|
||||
if (screen->geometry().intersects(newGeometry))
|
||||
|
|
|
|||
|
|
@ -122,7 +122,8 @@ QScreen::~QScreen()
|
|||
bool movingFromVirtualSibling = primaryScreen && primaryScreen->handle()->virtualSiblings().contains(handle());
|
||||
|
||||
// Move any leftover windows to the primary screen
|
||||
foreach (QWindow *window, QGuiApplication::allWindows()) {
|
||||
const auto allWindows = QGuiApplication::allWindows();
|
||||
for (QWindow *window : allWindows) {
|
||||
if (!window->isTopLevel() || window->screen() != this)
|
||||
continue;
|
||||
|
||||
|
|
@ -399,7 +400,8 @@ QSize QScreen::virtualSize() const
|
|||
QRect QScreen::virtualGeometry() const
|
||||
{
|
||||
QRect result;
|
||||
foreach (QScreen *screen, virtualSiblings())
|
||||
const auto screens = virtualSiblings();
|
||||
for (QScreen *screen : screens)
|
||||
result |= screen->geometry();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -432,7 +434,8 @@ QSize QScreen::availableVirtualSize() const
|
|||
QRect QScreen::availableVirtualGeometry() const
|
||||
{
|
||||
QRect result;
|
||||
foreach (QScreen *screen, virtualSiblings())
|
||||
const auto screens = virtualSiblings();
|
||||
for (QScreen *screen : screens)
|
||||
result |= screen->availableGeometry();
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1509,7 +1509,8 @@ QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry)
|
|||
QScreen *fallback = currentScreen;
|
||||
QPoint center = newGeometry.center();
|
||||
if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
|
||||
Q_FOREACH (QScreen* screen, currentScreen->virtualSiblings()) {
|
||||
const auto screens = currentScreen->virtualSiblings();
|
||||
for (QScreen* screen : screens) {
|
||||
if (screen->geometry().contains(center))
|
||||
return screen;
|
||||
if (screen->geometry().intersects(newGeometry))
|
||||
|
|
|
|||
|
|
@ -176,8 +176,8 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
\code
|
||||
|
||||
QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
|
||||
foreach (const QOpenGLDebugMessage &message, messages)
|
||||
const QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
|
||||
for (const QOpenGLDebugMessage &message : messages)
|
||||
qDebug() << message;
|
||||
|
||||
\endcode
|
||||
|
|
|
|||
Loading…
Reference in New Issue