From fea9109b3b80756be2a03b0c1e429c7598bae420 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 1 Nov 2023 10:24:48 +0100 Subject: [PATCH] QWindowStyle: misc cleanup Misc cleanup in QWindowsStyle: - use range-base for loop - use std::array instead raw c-array - use std::swap instead custom implementation Change-Id: I479c014d4e19556e1c0a6ce3fbb8ddacd4e179ae Reviewed-by: Axel Spoerl --- src/widgets/styles/qwindowsstyle.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index fd1f8e1c17..8f3d9d6d9a 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -117,19 +117,20 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) widget = widget->window(); // Alt has been pressed - find all widgets that care - QList l = widget->findChildren(); + const QList children = widget->findChildren(); auto ignorable = [](QWidget *w) { return w->isWindow() || !w->isVisible() || w->style()->styleHint(SH_UnderlineShortcut, nullptr, w); }; - l.removeIf(ignorable); // Update states before repainting d->seenAlt.append(widget); d->alt_down = true; // Repaint all relevant widgets - for (int pos = 0; pos < l.size(); ++pos) - l.at(pos)->update(); + for (QWidget *w : children) { + if (!ignorable(w)) + w->update(); + } } break; case QEvent::KeyRelease: @@ -139,9 +140,9 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) // Update state and repaint the menu bars. d->alt_down = false; #if QT_CONFIG(menubar) - QList l = widget->findChildren(); - for (int i = 0; i < l.size(); ++i) - l.at(i)->update(); + const QList menuBars = widget->findChildren(); + for (QWidget *w : menuBars) + w->update(); #endif } break; @@ -808,7 +809,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } #endif // QT_CONFIG(itemviews) if (!(opt->state & State_Off)) { - QPointF points[6]; + std::array points; qreal scaleh = opt->rect.width() / 12.0; qreal scalev = opt->rect.height() / 12.0; points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev }; @@ -819,7 +820,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev }; p->setPen(QPen(opt->palette.text().color(), 0)); p->setBrush(opt->palette.text().color()); - p->drawPolygon(points, 6); + p->drawPolygon(points.data(), static_cast(points.size())); } if (doRestore) p->restore(); @@ -1571,11 +1572,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai default: break; } - if (opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end - bool tmp = paintLeftBorder; - paintRightBorder=paintLeftBorder; - paintLeftBorder=tmp; - } + if (opt->direction == Qt::RightToLeft) //reverse layout changes the order of Beginning/end + std::swap(paintLeftBorder, paintRightBorder); break; case Qt::RightToolBarArea : switch (toolbar->positionOfLine){