diff --git a/autotests/kacceleratormanagertest.cpp b/autotests/kacceleratormanagertest.cpp
--- a/autotests/kacceleratormanagertest.cpp
+++ b/autotests/kacceleratormanagertest.cpp
@@ -31,7 +31,8 @@
QStringList ret;
bool lastIsSeparator = false;
- foreach (const QAction *action, menu.actions()) {
+ const auto menuActions = menu.actions();
+ for (const QAction *action : menuActions) {
if (action->isSeparator()) {
if (!lastIsSeparator) { // Qt gets rid of duplicate separators, so we should too
ret.append(QStringLiteral("separator"));
diff --git a/autotests/kdatetimeedittest.cpp b/autotests/kdatetimeedittest.cpp
--- a/autotests/kdatetimeedittest.cpp
+++ b/autotests/kdatetimeedittest.cpp
@@ -210,7 +210,8 @@
QCOMPARE(m_edit->timeZone(), QDateTime::currentDateTime().timeZone());
QList zones;
- foreach (const QByteArray &zoneId, QTimeZone::availableTimeZoneIds()) {
+ const auto zoneIds = QTimeZone::availableTimeZoneIds();
+ for (const QByteArray &zoneId : zoneIds) {
zones << QTimeZone(zoneId);
}
QCOMPARE(m_edit->timeZones(), zones);
@@ -229,7 +230,8 @@
template
static T findVisibleChild(QWidget *parent)
{
- foreach (T child, parent->findChildren()) {
+ const auto children = parent->findChildren();
+ for (T child : children) {
if (child->isVisible()) {
return child;
}
diff --git a/src/common_helpers.cpp b/src/common_helpers.cpp
--- a/src/common_helpers.cpp
+++ b/src/common_helpers.cpp
@@ -82,7 +82,7 @@
// ampersand beforehand.
if (!accmarkRemoved) {
bool hasCJK = false;
- foreach (const QChar c, label) {
+ for (const QChar c : qAsConst(label)) {
if (c.unicode() >= 0x2e00) { // rough, but should be sufficient
hasCJK = true;
break;
diff --git a/src/fonthelpers.cpp b/src/fonthelpers.cpp
--- a/src/fonthelpers.cpp
+++ b/src/fonthelpers.cpp
@@ -94,10 +94,11 @@
QHash *trToRawNames)
{
// Generic fonts, in the inverse of desired order.
- QStringList genericNames;
- genericNames.append(QStringLiteral("Monospace"));
- genericNames.append(QStringLiteral("Serif"));
- genericNames.append(QStringLiteral("Sans Serif"));
+ const QStringList genericNames {
+ QStringLiteral("Monospace"),
+ QStringLiteral("Serif"),
+ QStringLiteral("Sans Serif"),
+ };
// Translate fonts, but do not add generics to the list right away.
QStringList trNames;
@@ -114,7 +115,7 @@
std::sort(trNames.begin(), trNames.end(), localeLessThan);
// Prepend generic fonts, in the predefined order.
- Q_FOREACH (const QString &genericName, genericNames) {
+ for (const QString &genericName : genericNames) {
const QString trGenericName = translateFontName(genericName);
if (trMap.contains(trGenericName)) {
trNames.prepend(trGenericName);
diff --git a/src/kacceleratormanager.cpp b/src/kacceleratormanager.cpp
--- a/src/kacceleratormanager.cpp
+++ b/src/kacceleratormanager.cpp
@@ -121,16 +121,17 @@
// collect the contents
KAccelStringList contents;
- Q_FOREACH (Item *it, *item->m_children) {
+ contents.reserve(item->m_children->size());
+ for (Item *it : qAsConst(*item->m_children)) {
contents << it->m_content;
}
// find the right accelerators
KAccelManagerAlgorithm::findAccelerators(contents, used);
// write them back into the widgets
int cnt = -1;
- Q_FOREACH (Item *it, *item->m_children) {
+ for (Item *it : qAsConst(*item->m_children)) {
cnt++;
QDockWidget *dock = qobject_cast(it->m_widget);
@@ -179,17 +180,17 @@
}
// calculate the accelerators for the children
- Q_FOREACH (Item *it, *item->m_children) {
+ for (Item *it : qAsConst(*item->m_children)) {
if (it->m_widget && it->m_widget->isVisibleTo(item->m_widget)) {
calculateAccelerators(it, used);
}
}
}
void KAcceleratorManagerPrivate::traverseChildren(QWidget *widget, Item *item)
{
- QList childList = widget->findChildren();
- Q_FOREACH (QWidget *w, childList) {
+ const QList childList = widget->findChildren();
+ for (QWidget *w : childList) {
// Ignore unless we have the direct parent
if (qobject_cast(w->parent()) != widget) {
continue;
@@ -742,7 +743,8 @@
list.clear();
// read out the menu entries
- Q_FOREACH (QAction *maction, m_popup->actions()) {
+ const auto menuActions = m_popup->actions();
+ for (QAction *maction : menuActions) {
if (maction->isSeparator()) {
continue;
}
@@ -779,7 +781,8 @@
void KPopupAccelManager::setMenuEntries(const KAccelStringList &list)
{
uint cnt = 0;
- Q_FOREACH (QAction *maction, m_popup->actions()) {
+ const auto menuActions = m_popup->actions();
+ for (QAction *maction : menuActions) {
if (maction->isSeparator()) {
continue;
}
diff --git a/src/kactionselector.cpp b/src/kactionselector.cpp
--- a/src/kactionselector.cpp
+++ b/src/kactionselector.cpp
@@ -433,8 +433,8 @@
void KActionSelectorPrivate::buttonAddClicked()
{
// move all selected items from available to selected listbox
- QList list = availableListWidget->selectedItems();
- Q_FOREACH (QListWidgetItem *item, list) {
+ const QList list = availableListWidget->selectedItems();
+ for (QListWidgetItem *item : list) {
availableListWidget->takeItem(availableListWidget->row(item));
selectedListWidget->insertItem(insertionIndex(selectedListWidget, selectedInsertionPolicy), item);
selectedListWidget->setCurrentItem(item);
@@ -449,8 +449,8 @@
void KActionSelectorPrivate::buttonRemoveClicked()
{
// move all selected items from selected to available listbox
- QList list = selectedListWidget->selectedItems();
- Q_FOREACH (QListWidgetItem *item, list) {
+ const QList list = selectedListWidget->selectedItems();
+ for (QListWidgetItem *item : list) {
selectedListWidget->takeItem(selectedListWidget->row(item));
availableListWidget->insertItem(insertionIndex(availableListWidget, availableInsertionPolicy), item);
availableListWidget->setCurrentItem(item);
diff --git a/src/kcharselect.cpp b/src/kcharselect.cpp
--- a/src/kcharselect.cpp
+++ b/src/kcharselect.cpp
@@ -608,7 +608,9 @@
qFatal("You must use KCharSelect::displayedCodePoints instead of KCharSelect::displayedChars");
}
QList result;
- foreach (uint c, d->charTable->displayedChars()) {
+ const auto displayedChars = d->charTable->displayedChars();
+ result.reserve(displayedChars.size());
+ for (uint c : displayedChars) {
result.append(QChar(c));
}
return result;
@@ -785,35 +787,35 @@
//is name ever empty?
should always be there...
html += tr("Name: ") + name.toHtmlEscaped() + QLatin1String("");
}
- QStringList aliases = s_data()->aliases(c);
- QStringList notes = s_data()->notes(c);
- QVector seeAlso = s_data()->seeAlso(c);
- QStringList equivalents = s_data()->equivalents(c);
- QStringList approxEquivalents = s_data()->approximateEquivalents(c);
- QVector decomposition = s_data()->decomposition(c);
+ const QStringList aliases = s_data()->aliases(c);
+ const QStringList notes = s_data()->notes(c);
+ const QVector seeAlso = s_data()->seeAlso(c);
+ const QStringList equivalents = s_data()->equivalents(c);
+ const QStringList approxEquivalents = s_data()->approximateEquivalents(c);
+ const QVector decomposition = s_data()->decomposition(c);
if (!(aliases.isEmpty() && notes.isEmpty() && seeAlso.isEmpty() && equivalents.isEmpty() && approxEquivalents.isEmpty() && decomposition.isEmpty())) {
html += QLatin1String("") + tr("Annotations and Cross References") + QLatin1String("
");
}
if (!aliases.isEmpty()) {
html += QLatin1String("") + tr("Alias names:") + QLatin1String("
");
- foreach (const QString &alias, aliases) {
+ for (const QString &alias : aliases) {
html += QLatin1String("- ") + alias.toHtmlEscaped() + QLatin1String("
");
}
html += QLatin1String("
");
}
if (!notes.isEmpty()) {
html += QLatin1String("") + tr("Notes:") + QLatin1String("
");
- foreach (const QString ¬e, notes) {
+ for (const QString ¬e : notes) {
html += QLatin1String("- ") + createLinks(note.toHtmlEscaped()) + QLatin1String("
");
}
html += QLatin1String("
");
}
if (!seeAlso.isEmpty()) {
html += QLatin1String("") + tr("See also:") + QLatin1String("
");
- foreach (uint c2, seeAlso) {
+ for (uint c2 : seeAlso) {
if (!allPlanesEnabled && QChar::requiresSurrogates(c2)) {
continue;
}
@@ -828,23 +830,23 @@
if (!equivalents.isEmpty()) {
html += QLatin1String("") + tr("Equivalents:") + QLatin1String("
");
- foreach (const QString &equivalent, equivalents) {
+ for (const QString &equivalent : equivalents) {
html += QLatin1String("- ") + createLinks(equivalent.toHtmlEscaped()) + QLatin1String("
");
}
html += QLatin1String("
");
}
if (!approxEquivalents.isEmpty()) {
html += QLatin1String("") + tr("Approximate equivalents:") + QLatin1String("
");
- foreach (const QString &approxEquivalent, approxEquivalents) {
+ for (const QString &approxEquivalent : approxEquivalents) {
html += QLatin1String("- ") + createLinks(approxEquivalent.toHtmlEscaped()) + QLatin1String("
");
}
html += QLatin1String("
");
}
if (!decomposition.isEmpty()) {
html += QLatin1String("") + tr("Decomposition:") + QLatin1String("
");
- foreach (uint c2, decomposition) {
+ for (uint c2 : decomposition) {
if (!allPlanesEnabled && QChar::requiresSurrogates(c2)) {
continue;
}
@@ -910,11 +912,11 @@
html += tr("Block: ") + s_data()->block(c) + QLatin1String("
");
html += tr("Unicode category: ") + s_data()->categoryText(s_data()->category(c)) + QLatin1String("");
- QByteArray utf8 = QString::fromUcs4(&c, 1).toUtf8();
+ const QByteArray utf8 = QString::fromUcs4(&c, 1).toUtf8();
html += QLatin1String("") + tr("Various Useful Representations") + QLatin1String("
");
html += tr("UTF-8:");
- foreach (unsigned char c, utf8) {
+ for (unsigned char c : utf8) {
html += QLatin1Char(' ') + s_data()->formatCode(c, 2, QStringLiteral("0x"));
}
html += QLatin1String("
") + tr("UTF-16: ");
@@ -925,7 +927,7 @@
html += s_data()->formatCode(c, 4, QStringLiteral("0x"));
}
html += QLatin1String("
") + tr("C octal escaped UTF-8: ");
- foreach (unsigned char c, utf8) {
+ for (unsigned char c : utf8) {
html += s_data()->formatCode(c, 3, QStringLiteral("\\"), 8);
}
html += QLatin1String("
") + tr("XML decimal entity:") + QLatin1String(" &#") + QString::number(c) + QLatin1String(";
");
@@ -945,8 +947,8 @@
pos += rx.matchedLength();
}
- QSet chars2 = QSet::fromList(chars);
- foreach (const QString &c, chars2) {
+ const QSet chars2 = QSet::fromList(chars);
+ for (const QString &c : chars2) {
int unicode = c.toInt(nullptr, 16);
if (!allPlanesEnabled && QChar::requiresSurrogates(unicode)) {
continue;
@@ -965,8 +967,8 @@
void KCharSelect::KCharSelectPrivate::_k_sectionSelected(int index)
{
blockCombo->clear();
- QVector blocks = s_data()->sectionContents(index);
- foreach (int block, blocks) {
+ const QVector blocks = s_data()->sectionContents(index);
+ for (int block : blocks) {
if (!allPlanesEnabled) {
const QVector contents = s_data()->blockContents(block);
if (!contents.isEmpty() && QChar::requiresSurrogates(contents.at(0))) {
diff --git a/src/kcharselectdata.cpp b/src/kcharselectdata.cpp
--- a/src/kcharselectdata.cpp
+++ b/src/kcharselectdata.cpp
@@ -884,7 +884,7 @@
}
bool firstSubString = true;
- foreach (const QString &s, searchStrings) {
+ for (const QString &s : qAsConst(searchStrings)) {
QSet partResult = getMatchingChars(s.toLower());
if (firstSubString) {
result = partResult;
@@ -896,7 +896,7 @@
// remove results found by matching the code point to prevent duplicate results
// while letting these characters stay at the beginning
- foreach (uint c, returnRes) {
+ for (uint c : qAsConst(returnRes)) {
result.remove(c);
}
@@ -922,7 +922,7 @@
QSet result;
while (pos != index.constEnd() && pos.key().startsWith(s)) {
- foreach (quint16 c, pos.value()) {
+ for (quint16 c : pos.value()) {
result.insert(mapDataBaseToCodePoint(c));
}
++pos;
@@ -956,7 +956,7 @@
void KCharSelectData::appendToIndex(Index *index, quint16 unicode, const QString &s)
{
const QStringList strings = splitString(s);
- foreach (const QString &s, strings) {
+ for (const QString &s : strings) {
(*index)[s.toLower()].append(unicode);
}
}
diff --git a/src/kcollapsiblegroupbox.cpp b/src/kcollapsiblegroupbox.cpp
--- a/src/kcollapsiblegroupbox.cpp
+++ b/src/kcollapsiblegroupbox.cpp
@@ -332,7 +332,8 @@
void KCollapsibleGroupBoxPrivate::updateChildrenFocus(bool expanded)
{
- foreach (QObject *child, q->children()) {
+ const auto children = q->children();
+ for (QObject *child : children) {
QWidget *widget = qobject_cast(child);
if (!widget) {
continue;
diff --git a/src/kcolumnresizer.cpp b/src/kcolumnresizer.cpp
--- a/src/kcolumnresizer.cpp
+++ b/src/kcolumnresizer.cpp
@@ -124,14 +124,14 @@
void updateWidth()
{
int width = 0;
- Q_FOREACH(QWidget *widget, m_widgets) {
+ for (QWidget *widget : qAsConst(m_widgets)) {
width = qMax(widget->sizeHint().width(), width);
}
- Q_FOREACH(FormLayoutWidgetItem *item, m_formWidgetItemList) {
+ for (FormLayoutWidgetItem *item : qAsConst(m_formWidgetItemList)) {
item->setWidth(width);
item->formLayout()->update();
}
- Q_FOREACH(const GridColumnInfo &info, m_gridColumnInfoList) {
+ for (const GridColumnInfo &info : qAsConst(m_gridColumnInfoList)) {
info.layout->setColumnMinimumWidth(info.column, width);
}
}
diff --git a/src/kdatetimeedit.cpp b/src/kdatetimeedit.cpp
--- a/src/kdatetimeedit.cpp
+++ b/src/kdatetimeedit.cpp
@@ -75,7 +75,9 @@
m_dateTime = QDateTime::currentDateTime();
m_dateTime.setTime(QTime(0, 0, 0));
m_calendarLocales << q->locale();
- foreach (const QByteArray &zoneId, QTimeZone::availableTimeZoneIds()) {
+ const auto zoneIds = QTimeZone::availableTimeZoneIds();
+ m_zones.reserve(zoneIds.size());
+ for (const QByteArray &zoneId : zoneIds) {
m_zones << QTimeZone(zoneId);
}
}
@@ -149,7 +151,7 @@
{
ui.m_calendarCombo->blockSignals(true);
ui.m_calendarCombo->clear();
- foreach (const QLocale &calendarLocale, m_calendarLocales) {
+ for (const QLocale &calendarLocale : qAsConst(m_calendarLocales)) {
ui.m_calendarCombo->addItem(calendarLocale.name(), calendarLocale);
}
ui.m_calendarCombo->setCurrentIndex(ui.m_calendarCombo->findData(q->locale()));
@@ -183,7 +185,7 @@
ui.m_timeZoneCombo->clear();
ui.m_timeZoneCombo->addItem(KDateTimeEdit::tr("UTC", "UTC time zone"), QByteArray("UTC"));
ui.m_timeZoneCombo->addItem(KDateTimeEdit::tr("Floating", "No specific time zone"), QByteArray());
- foreach (const QTimeZone &zone, m_zones) {
+ for (const QTimeZone &zone : qAsConst(m_zones)) {
ui.m_timeZoneCombo->addItem(QString::fromUtf8(zone.id()), zone.id());
}
ui.m_timeZoneCombo->setVisible((m_options & KDateTimeEdit::ShowTimeZone) == KDateTimeEdit::ShowTimeZone);
diff --git a/src/kfontaction.cpp b/src/kfontaction.cpp
--- a/src/kfontaction.cpp
+++ b/src/kfontaction.cpp
@@ -72,7 +72,8 @@
const QFontComboBox::FontFilters scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts);
const QFontComboBox::FontFilters spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts);
- foreach (const QString &family, dbase.families()) {
+ const auto allFamilies = dbase.families();
+ for (const QString &family : allFamilies) {
if ((fontFilters & scalableMask) && (fontFilters & scalableMask) != scalableMask) {
if (bool(fontFilters & QFontComboBox::ScalableFonts) != dbase.isSmoothlyScalable(family)) {
continue;
@@ -170,7 +171,8 @@
// Suppress triggered(QString) signal and prevent recursive call to ourself.
d->settingFont++;
- foreach (QWidget *w, createdWidgets()) {
+ const auto createdWidgets = this->createdWidgets();
+ for (QWidget *w : createdWidgets) {
QFontComboBox *cb = qobject_cast(w);
// qCDebug(KWidgetsAddonsLog) << "\tw=" << w << "cb=" << cb;
diff --git a/src/kfontrequester.cpp b/src/kfontrequester.cpp
--- a/src/kfontrequester.cpp
+++ b/src/kfontrequester.cpp
@@ -60,12 +60,12 @@
// Check if the family has the requested size.
// Only for bitmap fonts.
if (!dbase.isSmoothlyScalable(family, style)) {
- QList sizes = dbase.smoothSizes(family, style);
+ const QList sizes = dbase.smoothSizes(family, style);
if (!sizes.contains(size)) {
// Find nearest available size.
int mindiff = 1000;
int refsize = size;
- Q_FOREACH (int lsize, sizes) {
+ for (int lsize : sizes) {
int diff = qAbs(refsize - lsize);
if (mindiff > diff) {
mindiff = diff;
diff --git a/src/kfontsizeaction.cpp b/src/kfontsizeaction.cpp
--- a/src/kfontsizeaction.cpp
+++ b/src/kfontsizeaction.cpp
@@ -89,7 +89,8 @@
{
if (size == fontSize()) {
const QString test = QString::number(size);
- Q_FOREACH (QAction *action, actions()) {
+ const auto actions = this->actions();
+ for (QAction *action : actions) {
if (action->text() == test) {
setCurrentAction(action);
return;
diff --git a/src/kmessagebox_p.cpp b/src/kmessagebox_p.cpp
--- a/src/kmessagebox_p.cpp
+++ b/src/kmessagebox_p.cpp
@@ -37,7 +37,8 @@
{
m_filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + QCoreApplication::instance()->applicationName() + QLatin1String(".kmessagebox");
QSettings s(m_filePath, QSettings::IniFormat);
- foreach (const QString &key, s.allKeys()) {
+ const auto keys = s.allKeys();
+ for (const QString &key : keys) {
m_saved.insert(key, static_cast(s.value(key).toInt()));
}
}
diff --git a/src/kmessagewidget.cpp b/src/kmessagewidget.cpp
--- a/src/kmessagewidget.cpp
+++ b/src/kmessagewidget.cpp
@@ -116,7 +116,9 @@
qDeleteAll(buttons);
buttons.clear();
- Q_FOREACH (QAction *action, q->actions()) {
+ const auto actions = q->actions();
+ buttons.reserve(actions.size());
+ for (QAction *action : actions) {
QToolButton *button = new QToolButton(content);
button->setDefaultAction(action);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
@@ -141,7 +143,7 @@
// Use an additional layout in row 1 for the buttons.
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
- Q_FOREACH (QToolButton *button, buttons) {
+ for (QToolButton *button : qAsConst(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.
diff --git a/src/kmimetypechooser.cpp b/src/kmimetypechooser.cpp
--- a/src/kmimetypechooser.cpp
+++ b/src/kmimetypechooser.cpp
@@ -145,7 +145,7 @@
QTreeWidgetItem *idefault = nullptr; //open this, if all other fails
QTreeWidgetItem *firstChecked = nullptr; // make this one visible after the loop
- foreach (const QMimeType &mt, mimetypes) {
+ for (const QMimeType &mt : mimetypes) {
const QString mimetype = mt.name();
const int index = mimetype.indexOf(QLatin1Char('/'));
const QString maj = mimetype.left(index);
@@ -262,7 +262,8 @@
QStringList mimeList;
QList checkedItems;
getCheckedItems(checkedItems, d->mimeTypeTree);
- foreach (QTreeWidgetItem *item, checkedItems) {
+ mimeList.reserve(checkedItems.size());
+ for (QTreeWidgetItem *item : qAsConst(checkedItems)) {
mimeList.append(item->parent()->text(0) + QLatin1Char('/') + item->text(0));
}
return mimeList;
@@ -274,7 +275,7 @@
QList checkedItems;
getCheckedItems(checkedItems, d->mimeTypeTree);
QMimeDatabase db;
- foreach (QTreeWidgetItem *item, checkedItems) {
+ for (QTreeWidgetItem *item : qAsConst(checkedItems)) {
QMimeType mime = db.mimeTypeForName(item->parent()->text(0) + QLatin1Char('/') + item->text(0));
Q_ASSERT(mime.isValid());
patternList += mime.globPatterns();
diff --git a/src/kselectaction.cpp b/src/kselectaction.cpp
--- a/src/kselectaction.cpp
+++ b/src/kselectaction.cpp
@@ -192,7 +192,8 @@
compare = text.toLower();
}
- foreach (QAction *action, selectableActionGroup()->actions()) {
+ const auto selectableActions = selectableActionGroup()->actions();
+ for (QAction *action : selectableActions) {
const QString text = ::DropAmpersands(action->text());
if (cs == Qt::CaseSensitive) {
if (text == compare) {
@@ -224,7 +225,7 @@
d->m_comboWidth = width;
- foreach (QComboBox *box, d->m_comboBoxes) {
+ for (QComboBox *box : qAsConst(d->m_comboBoxes)) {
box->setMaximumWidth(d->m_comboWidth);
}
@@ -236,14 +237,15 @@
Q_D(KSelectAction);
d->m_maxComboViewCount = n;
- foreach (QComboBox *box, d->m_comboBoxes)
+ for (QComboBox *box : qAsConst(d->m_comboBoxes)) {
if (d->m_maxComboViewCount != -1) {
box->setMaxVisibleItems(d->m_maxComboViewCount);
} else
// hardcoded qt default
{
box->setMaxVisibleItems(10);
}
+ }
emit changed();
}
@@ -291,12 +293,12 @@
bool hasActions = selectableActionGroup()->actions().isEmpty();
setEnabled(!hasActions);
- foreach (QToolButton *button, d->m_buttons) {
+ for (QToolButton *button : qAsConst(d->m_buttons)) {
button->setEnabled(!hasActions);
button->removeAction(action);
}
- foreach (QComboBox *comboBox, d->m_comboBoxes) {
+ for (QComboBox *comboBox : qAsConst(d->m_comboBoxes)) {
comboBox->setEnabled(!hasActions);
comboBox->removeAction(action);
}
@@ -315,12 +317,12 @@
setEnabled(true);
// Keep in sync with createToolBarWidget()
- foreach (QToolButton *button, d->m_buttons) {
+ for (QToolButton *button : qAsConst(d->m_buttons)) {
button->setEnabled(true);
button->insertAction(before, action);
}
- foreach (QComboBox *comboBox, d->m_comboBoxes) {
+ for (QComboBox *comboBox : qAsConst(d->m_comboBoxes)) {
comboBox->setEnabled(true);
comboBox->insertAction(before, action);
}
@@ -351,7 +353,9 @@
Q_D(const KSelectAction);
QStringList ret;
- foreach (QAction *action, d->m_actionGroup->actions()) {
+ const auto actions = d->m_actionGroup->actions();
+ ret.reserve(actions.size());
+ for (QAction *action : actions) {
ret << ::DropAmpersands(action->text());
}
@@ -376,7 +380,7 @@
clear();
- foreach (const QString &string, lst) {
+ for (const QString &string : lst) {
if (!string.isEmpty()) {
addAction(string);
} else {
@@ -429,7 +433,7 @@
Q_D(KSelectAction);
d->m_edit = edit;
- foreach (QComboBox *comboBox, d->m_comboBoxes) {
+ for (QComboBox *comboBox : qAsConst(d->m_comboBoxes)) {
comboBox->setEditable(edit);
}
@@ -476,11 +480,7 @@
void KSelectActionPrivate::_k_comboBoxDeleted(QObject *object)
{
- foreach (QComboBox *comboBox, m_comboBoxes)
- if (object == comboBox) {
- m_comboBoxes.removeAll(static_cast(object));
- break;
- }
+ m_comboBoxes.removeAll(static_cast(object));
}
void KSelectActionPrivate::_k_comboBoxCurrentIndexChanged(int index)
@@ -587,11 +587,12 @@
comboBox->setWhatsThis(whatsThis());
comboBox->setStatusTip(statusTip());
- foreach (QAction *action, selectableActionGroup()->actions()) {
+ const auto selectableActions = selectableActionGroup()->actions();
+ for (QAction *action : selectableActions) {
comboBox->addAction(action);
}
- if (selectableActionGroup()->actions().isEmpty()) {
+ if (selectableActions.isEmpty()) {
comboBox->setEnabled(false);
}
@@ -621,12 +622,12 @@
{
Q_D(KSelectAction);
if (event->type() == QEvent::ActionChanged) {
- Q_FOREACH (QComboBox *comboBox, d->m_comboBoxes) {
+ for (QComboBox *comboBox : qAsConst(d->m_comboBoxes)) {
comboBox->setToolTip(toolTip());
comboBox->setWhatsThis(whatsThis());
comboBox->setStatusTip(statusTip());
}
- Q_FOREACH (QToolButton *toolButton, d->m_buttons) {
+ for (QToolButton *toolButton : qAsConst(d->m_buttons)) {
toolButton->setToolTip(toolTip());
toolButton->setWhatsThis(whatsThis());
toolButton->setStatusTip(statusTip());
@@ -652,16 +653,19 @@
QAction *curAction = sa->currentAction();
//qCDebug(KWidgetsAddonsLog) << "\tTrueCurrentItem(" << sa << ") curAction=" << curAction;
- foreach (QAction *action, sa->actions()) {
+ const auto actions = sa->actions();
+ int i = 0;
+ for (QAction *action : actions) {
if (action->isChecked()) {
//qCDebug(KWidgetsAddonsLog) << "\t\taction " << action << " (text=" << action->text () << ") isChecked";
// 2 actions checked case?
if (action != curAction) {
//qCDebug(KWidgetsAddonsLog) << "\t\t\tmust be newly selected one";
- return sa->actions().indexOf(action);
+ return i;
}
}
+ ++i;
}
//qCDebug(KWidgetsAddonsLog) << "\t\tcurrent action still selected? " << (curAction && curAction->isChecked ());
diff --git a/src/kselectaction_p.h b/src/kselectaction_p.h
--- a/src/kselectaction_p.h
+++ b/src/kselectaction_p.h
@@ -57,10 +57,10 @@
{
// unhook the event filter, as the deletion of the actiongroup
// will trigger it
- Q_FOREACH (QComboBox *box, m_comboBoxes) {
+ for (QComboBox *box : qAsConst(m_comboBoxes)) {
box->removeEventFilter(q_ptr);
}
- Q_FOREACH (QToolButton *button, m_buttons) {
+ for (QToolButton *button : qAsConst(m_buttons)) {
button->removeEventFilter(q_ptr);
}
delete m_actionGroup;
diff --git a/src/ksqueezedtextlabel.cpp b/src/ksqueezedtextlabel.cpp
--- a/src/ksqueezedtextlabel.cpp
+++ b/src/ksqueezedtextlabel.cpp
@@ -115,7 +115,9 @@
const int labelWidth = contentsRect().width();
QStringList squeezedLines;
bool squeezed = false;
- Q_FOREACH (const QString &line, d->fullText.split(QLatin1Char('\n'))) {
+ const auto textLines = d->fullText.split(QLatin1Char('\n'));
+ squeezedLines.reserve(textLines.size());
+ for (const QString &line : textLines) {
int lineWidth = fm.width(line);
if (lineWidth > labelWidth) {
squeezed = true;
diff --git a/src/ktimecombobox.cpp b/src/ktimecombobox.cpp
--- a/src/ktimecombobox.cpp
+++ b/src/ktimecombobox.cpp
@@ -200,7 +200,7 @@
}
q->addItem(formatTime(endTime), endTime);
} else {
- foreach (const QTime &thisTime, m_timeList) {
+ for (const QTime &thisTime : qAsConst(m_timeList)) {
if (thisTime.isValid() && thisTime >= m_minTime && thisTime <= m_maxTime) {
q->addItem(formatTime(thisTime), thisTime);
}
@@ -467,7 +467,7 @@
{
if (timeList != d->m_timeList) {
d->m_timeList.clear();
- foreach (const QTime &time, timeList) {
+ for (const QTime &time : qAsConst(timeList)) {
if (time.isValid() && !d->m_timeList.contains(time)) {
d->m_timeList.append(time);
}
diff --git a/src/ktoolbarlabelaction.cpp b/src/ktoolbarlabelaction.cpp
--- a/src/ktoolbarlabelaction.cpp
+++ b/src/ktoolbarlabelaction.cpp
@@ -58,20 +58,23 @@
d->buddy = buddy;
QList labels;
- Q_FOREACH (QWidget *widget, associatedWidgets())
+ const auto associatedWidgets = this->associatedWidgets();
+ for (QWidget *widget : associatedWidgets) {
if (QToolBar *toolBar = qobject_cast(widget))
if (QLabel *label = qobject_cast(toolBar->widgetForAction(this))) {
labels.append(label);
}
-
- Q_FOREACH (QWidget *widget, buddy->associatedWidgets())
+ }
+ const auto buddysAssociatedWidgets = buddy->associatedWidgets();
+ for (QWidget *widget : buddysAssociatedWidgets) {
if (QToolBar *toolBar = qobject_cast(widget)) {
QWidget *newBuddy = toolBar->widgetForAction(buddy);
for (QLabel *label : qAsConst(labels)) {
label->setBuddy(newBuddy);
}
return;
}
+ }
}
QAction *KToolBarLabelAction::buddy() const
@@ -94,7 +97,8 @@
bool KToolBarLabelAction::eventFilter(QObject *watched, QEvent *event)
{
if (d->label && d->buddy && event->type() == QEvent::PolishRequest && watched == d->label) {
- Q_FOREACH (QWidget *widget, d->buddy->associatedWidgets()) {
+ const auto buddysAssociatedWidgets = d->buddy->associatedWidgets();
+ for (QWidget *widget : buddysAssociatedWidgets) {
if (QToolBar *toolBar = qobject_cast(widget)) {
QWidget *newBuddy = toolBar->widgetForAction(d->buddy);
d->label->setBuddy(newBuddy);
diff --git a/src/kviewstateserializer.h b/src/kviewstateserializer.h
--- a/src/kviewstateserializer.h
+++ b/src/kviewstateserializer.h
@@ -123,15 +123,15 @@
void selectItems(const QList &items)
{
QStringList itemStrings;
- Q_FOREACH(qint64 item, items)
+ for (qint64 item : items)
itemStrings << QString::number(item);
restoreSelection(itemStrings);
}
void expandItems(const QList &items)
{
QStringList itemStrings;
- Q_FOREACH(qint64 item, items)
+ for (qint64 item : items)
itemStrings << QString::number(item);
restoreSelection(itemStrings);
}