cleanup: replace Q_FOREACH and foreach by range base for

Q_FOREACH and foreach are anachronisms.

Range based for may cause a performance regression: it can
lead to a copy of shared containers (one reason why Qt's
COW containers are broken). However, as long as there is no
user noticeable delay, there is no point in analyzing each case.
And also no point in slapping an 'asConst' on every container
that is looped over.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-16 16:50:43 +01:00 committed by bstoeger
parent 41cb916060
commit 5ac64ab2cd
16 changed files with 32 additions and 35 deletions

View file

@ -111,7 +111,7 @@ void KMessageWidgetPrivate::createLayout()
qDeleteAll(buttons);
buttons.clear();
Q_FOREACH (QAction *action, q->actions()) {
for (QAction *action: q->actions()) {
QToolButton *button = new QToolButton(content);
button->setDefaultAction(action);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
@ -131,7 +131,7 @@ void KMessageWidgetPrivate::createLayout()
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
Q_FOREACH (QToolButton *button, buttons) {
for (QToolButton *button: buttons) {
// For some reason, calling show() is necessary if wordwrap is true,
// otherwise the buttons do not show up. It is not needed if
// wordwrap is false.
@ -145,9 +145,8 @@ void KMessageWidgetPrivate::createLayout()
layout->addWidget(iconLabel);
layout->addWidget(textLabel);
Q_FOREACH (QToolButton *button, buttons) {
for (QToolButton *button: buttons)
layout->addWidget(button);
}
layout->addWidget(closeButton);
};