Commit a24327cd authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Elvis Angelaccio
Browse files

Compile without foreach

parent 360a8dd8
......@@ -16,6 +16,7 @@ remove_definitions(
-DQT_NO_SIGNALS_SLOTS_KEYWORDS
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
-DQT_NO_FOREACH
)
##########################################
......
......@@ -163,7 +163,7 @@ void DolphinContextMenu::openTrashItemContextMenu()
if (exec(m_pos) == restoreAction) {
QList<QUrl> selectedUrls;
selectedUrls.reserve(m_selectedItems.count());
foreach (const KFileItem &item, m_selectedItems) {
for (const KFileItem &item : qAsConst(m_selectedItems)) {
selectedUrls.append(item.url());
}
......
......@@ -427,7 +427,7 @@ void DolphinMainWindow::openInNewTab()
const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
bool tabCreated = false;
foreach (const KFileItem& item, list) {
for (const KFileItem& item : list) {
const QUrl& url = DolphinView::openItemAsFolderUrl(item);
if (!url.isEmpty()) {
openNewTabAfterCurrentTab(url);
......@@ -861,7 +861,8 @@ void DolphinMainWindow::replaceLocation()
void DolphinMainWindow::togglePanelLockState()
{
const bool newLockState = !GeneralSettings::lockPanels();
foreach (QObject* child, children()) {
const auto childrenObjects = children();
for (QObject* child : childrenObjects) {
DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
if (dock) {
dock->setLocked(newLockState);
......@@ -2083,7 +2084,8 @@ bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)
Q_ASSERT(menu);
const KToolBar* toolBarWidget = toolBar();
foreach (const QWidget* widget, action->associatedWidgets()) {
const auto associatedWidgets = action->associatedWidgets();
for (const QWidget* widget : associatedWidgets) {
if (widget == toolBarWidget) {
return false;
}
......
......@@ -362,7 +362,7 @@ void DolphinPart::slotItemActivated(const KFileItem& item)
void DolphinPart::slotItemsActivated(const KFileItemList& items)
{
foreach (const KFileItem& item, items) {
for (const KFileItem& item : items) {
slotItemActivated(item);
}
}
......
......@@ -216,7 +216,7 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
// for each directory. If the "split view" option is enabled, two
// directories are shown inside one tab (see openDirectories()).
QList<QUrl> dirs;
foreach (const QUrl& url, files) {
for (const QUrl& url : files) {
const QUrl dir(url.adjusted(QUrl::RemoveFilename));
if (!dirs.contains(dir)) {
dirs.append(dir);
......
......@@ -22,7 +22,7 @@ QList<QUrl> Dolphin::validateUris(const QStringList& uriList)
{
const QString currentDir = QDir::currentPath();
QList<QUrl> urls;
foreach (const QString& str, uriList) {
for (const QString& str : uriList) {
const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile);
if (url.isValid()) {
urls.append(url);
......
......@@ -420,7 +420,8 @@ int KFileItemModel::index(const QUrl& url) const
indexesForUrl.insert(m_itemData.at(i)->item.url(), i);
}
foreach (const QUrl& url, indexesForUrl.uniqueKeys()) {
const auto uniqueKeys = indexesForUrl.uniqueKeys();
for (const QUrl& url : uniqueKeys) {
if (indexesForUrl.count(url) > 1) {
qCWarning(DolphinDebug) << "Multiple items found with the URL" << url;
......@@ -524,7 +525,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
m_dirLister->openUrl(url, KDirLister::Keep);
const QVariantList previouslyExpandedChildren = m_itemData.at(index)->values.value("previouslyExpandedChildren").value<QVariantList>();
foreach (const QVariant& var, previouslyExpandedChildren) {
for (const QVariant& var : previouslyExpandedChildren) {
m_urlsToExpand.insert(var.toUrl());
}
} else {
......@@ -728,7 +729,7 @@ void KFileItemModel::removeFilteredChildren(const KItemRangeList& itemRanges)
}
QSet<ItemData*> parents;
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
for (int index = range.index; index < range.index + range.count; ++index) {
parents.insert(m_itemData.at(index));
}
......@@ -848,7 +849,7 @@ void KFileItemModel::resortAllItems()
// been moved because of the resorting.
QList<QUrl> oldUrls;
oldUrls.reserve(itemCount);
foreach (const ItemData* itemData, m_itemData) {
for (const ItemData* itemData : qAsConst(m_itemData)) {
oldUrls.append(itemData->item.url());
}
......@@ -916,7 +917,7 @@ void KFileItemModel::slotCompleted()
// Note that the parent folder must be expanded before any of its subfolders become visible.
// Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
// -> we expand the first visible URL we find in m_restoredExpandedUrls.
foreach (const QUrl& url, m_urlsToExpand) {
for (const QUrl& url : qAsConst(m_urlsToExpand)) {
const int indexForUrl = index(url);
if (indexForUrl >= 0) {
m_urlsToExpand.remove(url);
......@@ -982,7 +983,7 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis
}
}
QList<ItemData*> itemDataList = createItemDataList(parentUrl, items);
const QList<ItemData*> itemDataList = createItemDataList(parentUrl, items);
if (!m_filter.hasSetFilters()) {
m_pendingItemsToInsert.append(itemDataList);
......@@ -990,7 +991,7 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis
// The name or type filter is active. Hide filtered items
// before inserting them into the model and remember
// the filtered items in m_filteredItems.
foreach (ItemData* itemData, itemDataList) {
for (ItemData* itemData : itemDataList) {
if (m_filter.matches(itemData->item)) {
m_pendingItemsToInsert.append(itemData);
} else {
......@@ -1013,7 +1014,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
QVector<int> indexesToRemove;
indexesToRemove.reserve(items.count());
foreach (const KFileItem& item, items) {
for (const KFileItem& item : items) {
const int indexForItem = index(item);
if (indexForItem >= 0) {
indexesToRemove.append(indexForItem);
......@@ -1035,7 +1036,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
indexesToRemoveWithChildren.reserve(m_itemData.count());
const int itemCount = m_itemData.count();
foreach (int index, indexesToRemove) {
for (int index : qAsConst(indexesToRemove)) {
indexesToRemoveWithChildren.append(index);
const int parentLevel = expandedParentsCount(index);
......@@ -1275,7 +1276,7 @@ void KFileItemModel::removeItems(const KItemRangeList& itemRanges, RemoveItemsBe
// Step 1: Remove the items from m_itemData, and free the ItemData.
int removedItemsCount = 0;
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
removedItemsCount += range.count;
for (int index = range.index; index < range.index + range.count; ++index) {
......@@ -1329,7 +1330,7 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl&
QList<ItemData*> itemDataList;
itemDataList.reserve(items.count());
foreach (const KFileItem& item, items) {
for (const KFileItem& item : items) {
ItemData* itemData = new ItemData();
itemData->item = item;
itemData->parent = parentItem;
......@@ -1350,7 +1351,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
case DeletionTimeRole:
// These roles can be determined with retrieveData, and they have to be stored
// in the QHash "values" for the sorting.
foreach (ItemData* itemData, itemDataList) {
for (ItemData* itemData : qAsConst(itemDataList)) {
if (itemData->values.isEmpty()) {
itemData->values = retrieveData(itemData->item, itemData->parent);
}
......@@ -1359,7 +1360,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
case TypeRole:
// At least store the data including the file type for items with known MIME type.
foreach (ItemData* itemData, itemDataList) {
for (ItemData* itemData : qAsConst(itemDataList)) {
if (itemData->values.isEmpty()) {
const KFileItem item = itemData->item;
if (item.isDir() || item.isMimeTypeKnown()) {
......@@ -1432,7 +1433,7 @@ void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList& i
// Trigger a resorting if necessary. Note that this can happen even if the sort
// role has not changed at all because the file name can be used as a fallback.
if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) {
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
bool needsResorting = false;
const int first = range.index;
......@@ -2365,7 +2366,7 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout)
{
QElapsedTimer timer;
timer.start();
foreach (const KFileItem& item, items) { // krazy:exclude=foreach
for (const KFileItem& item : items) {
// Only determine mime types for files here. For directories,
// KFileItem::determineMimeType() reads the .directory file inside to
// load the icon, but this is not necessary at all if we just need the
......
......@@ -113,8 +113,8 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result,
this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived);
auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, qApp);
foreach (QObject *it, plugins) {
const auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, qApp);
for (QObject *it : plugins) {
auto plugin = qobject_cast<KOverlayIconPlugin*>(it);
if (plugin) {
m_overlayIconsPlugin.append(plugin);
......@@ -324,7 +324,7 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRan
// Determine the sort role synchronously for as many items as possible.
if (m_resolvableRoles.contains(m_model->sortRole())) {
int insertedCount = 0;
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
const int lastIndex = insertedCount + range.index + range.count - 1;
for (int i = insertedCount + range.index; i <= lastIndex; ++i) {
if (timer.elapsed() < MaxBlockTimeout) {
......@@ -364,7 +364,8 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
m_balooFileMonitor->clear();
} else {
QStringList newFileList;
foreach (const QString& file, m_balooFileMonitor->files()) {
const QStringList oldFileList = m_balooFileMonitor->files();
for (const QString& file : oldFileList) {
if (m_model->index(QUrl::fromLocalFile(file)) >= 0) {
newFileList.append(file);
}
......@@ -424,7 +425,7 @@ void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRang
QSet<KFileItem>& targetSet = itemsChangedRecently ? m_recentlyChangedItems : m_changedItems;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
int index = itemRange.index;
for (int count = itemRange.count; count > 0; --count) {
const KFileItem item = m_model->fileItem(index);
......@@ -537,7 +538,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
// It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional
// setup time.
foreach (const QString& overlay, overlays) {
for (const QString& overlay : overlays) {
if (!overlay.isEmpty()) {
// There is at least one overlay, draw all overlays above m_pixmap
// and cancel the check
......@@ -722,7 +723,8 @@ void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem &
const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance();
QHash<QByteArray, QVariant> data;
foreach (const QByteArray& role, rolesProvider.roles()) {
const auto roles = rolesProvider.roles();
for (const QByteArray& role : roles) {
// Overwrite all the role values with an empty QVariant, because the roles
// provider doesn't overwrite it when the property value list is empty.
// See bug 322348
......@@ -808,7 +810,7 @@ void KFileItemModelRolesUpdater::startUpdating()
m_pendingPreviewItems.clear();
m_pendingPreviewItems.reserve(indexes.count());
foreach (int index, indexes) {
for (int index : qAsConst(indexes)) {
const KFileItem item = m_model->fileItem(index);
if (!m_finishedItems.contains(item)) {
m_pendingPreviewItems.append(item);
......@@ -941,7 +943,7 @@ void KFileItemModelRolesUpdater::updateChangedItems()
QList<int> visibleChangedIndexes;
QList<int> invisibleChangedIndexes;
foreach (const KFileItem& item, m_changedItems) {
for (const KFileItem& item : qAsConst(m_changedItems)) {
const int index = m_model->index(item);
if (index < 0) {
......@@ -959,11 +961,11 @@ void KFileItemModelRolesUpdater::updateChangedItems()
std::sort(visibleChangedIndexes.begin(), visibleChangedIndexes.end());
if (m_previewShown) {
foreach (int index, visibleChangedIndexes) {
for (int index : qAsConst(visibleChangedIndexes)) {
m_pendingPreviewItems.append(m_model->fileItem(index));
}
foreach (int index, invisibleChangedIndexes) {
for (int index : qAsConst(invisibleChangedIndexes)) {
m_pendingPreviewItems.append(m_model->fileItem(index));
}
......@@ -1078,7 +1080,7 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
}
QStringList overlays = item.overlays();
foreach(KOverlayIconPlugin *it, m_overlayIconsPlugin) {
for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) {
overlays.append(it->getOverlays(item.url()));
}
data.insert("iconOverlays", overlays);
......@@ -1101,7 +1103,7 @@ void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl& url, const QStr
const int index = m_model->index(item);
QHash<QByteArray, QVariant> data = m_model->data(index);
QStringList overlays = item.overlays();
foreach (KOverlayIconPlugin *it, m_overlayIconsPlugin) {
for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) {
overlays.append(it->getOverlays(url));
}
data.insert("iconOverlays", overlays);
......
......@@ -864,7 +864,8 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const
return false;
}
foreach (KItemListWidget* widget, m_view->visibleItemListWidgets()) {
const auto widgets = m_view->visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
if (widget->isHovered()) {
widget->setHovered(false);
emit itemUnhovered(widget->index());
......@@ -1195,7 +1196,8 @@ void KItemListController::slotRubberBandChanged()
KItemSet selectedItems;
// Select all visible items that intersect with the rubberband
foreach (const KItemListWidget* widget, m_view->visibleItemListWidgets()) {
const auto widgets = m_view->visibleItemListWidgets();
for (const KItemListWidget* widget : widgets) {
const int index = widget->index();
const QRectF widgetRect = m_view->itemRect(index);
......@@ -1284,7 +1286,8 @@ KItemListWidget* KItemListController::hoveredWidget() const
{
Q_ASSERT(m_view);
foreach (KItemListWidget* widget, m_view->visibleItemListWidgets()) {
const auto widgets = m_view->visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
if (widget->isHovered()) {
return widget;
}
......@@ -1297,7 +1300,8 @@ KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const
{
Q_ASSERT(m_view);
foreach (KItemListWidget* widget, m_view->visibleItemListWidgets()) {
const auto widgets = m_view->visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
const QPointF mappedPos = widget->mapFromItem(m_view, pos);
const bool hovered = widget->contains(mappedPos) &&
......
......@@ -45,7 +45,8 @@ qreal KItemListHeader::columnWidth(const QByteArray& role) const
void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths)
{
if (!m_headerWidget->automaticColumnResizing()) {
foreach (const QByteArray& role, m_view->visibleRoles()) {
const auto visibleRoles = m_view->visibleRoles();
for (const QByteArray& role : visibleRoles) {
const qreal width = columnWidths.value(role);
m_headerWidget->setColumnWidth(role, width);
}
......
......@@ -222,7 +222,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
} else {
const int previousCurrent = m_currentItem;
int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
if (m_currentItem < itemRange.index) {
break;
}
......@@ -242,7 +242,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
m_anchorItem = 0;
} else {
int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
if (m_anchorItem < itemRange.index) {
break;
}
......@@ -258,7 +258,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
for (int index: previous) {
int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
if (index < itemRange.index) {
break;
}
......@@ -376,7 +376,7 @@ int KItemListSelectionManager::indexAfterRangesRemoving(int index, const KItemRa
const RangesRemovingBehaviour behaviour) const
{
int dec = 0;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
if (index < itemRange.index) {
break;
}
......
......@@ -230,7 +230,7 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
if (!m_headerWidget->automaticColumnResizing()) {
// The column-width of new roles are still 0. Apply the preferred
// column-width as default with.
foreach (const QByteArray& role, m_visibleRoles) {
for (const QByteArray& role : qAsConst(m_visibleRoles)) {
if (m_headerWidget->columnWidth(role) == 0) {
const qreal width = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, width);
......@@ -1029,7 +1029,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
m_sizeHintResolver->itemsInserted(itemRanges);
int previouslyInsertedCount = 0;
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
// range.index is related to the model before anything has been inserted.
// As in each loop the current item-range gets inserted the index must
// be increased by the already previously inserted items.
......@@ -1155,7 +1155,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
QVector<int> itemsToMove;
// Remove all KItemListWidget instances that got deleted
foreach (KItemListWidget* widget, m_visibleItems) {
for (KItemListWidget* widget : qAsConst(m_visibleItems)) {
const int i = widget->index();
if (i < firstRemovedIndex) {
continue;
......@@ -1191,7 +1191,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
// after the deleted items. It is important to update them in ascending
// order to prevent overlaps when setting the new index.
std::sort(itemsToMove.begin(), itemsToMove.end());
foreach (int i, itemsToMove) {
for (int i : qAsConst(itemsToMove)) {
KItemListWidget* widget = m_visibleItems.value(i);
Q_ASSERT(widget);
const int newIndex = i - count;
......@@ -1269,7 +1269,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
updatePreferredColumnWidths(itemRanges);
}
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
const int index = itemRange.index;
const int count = itemRange.count;
......@@ -1823,7 +1823,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
}
// Delete invisible KItemListWidget instances that have not been reused
foreach (int index, reusableItems) {
for (int index : qAsConst(reusableItems)) {
recycleWidget(m_visibleItems.value(index));
}
......@@ -2197,7 +2197,7 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi
const QFontMetricsF fontMetrics(m_headerWidget->font());
const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin);
const int headerMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderMargin);
foreach (const QByteArray& visibleRole, visibleRoles()) {
for (const QByteArray& visibleRole : qAsConst(m_visibleRoles)) {
const QString headerText = m_model->roleDescription(visibleRole);
const qreal headerWidth = fontMetrics.width(headerText) + gripMargin + headerMargin * 2;
widths.insert(visibleRole, headerWidth);
......@@ -2208,12 +2208,12 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi
const KItemListWidgetCreatorBase* creator = widgetCreator();
int calculatedItemCount = 0;
bool maxTimeExceeded = false;
foreach (const KItemRange& itemRange, itemRanges) {
for (const KItemRange& itemRange : itemRanges) {
const int startIndex = itemRange.index;
const int endIndex = startIndex + itemRange.count - 1;
for (int i = startIndex; i <= endIndex; ++i) {
foreach (const QByteArray& visibleRole, visibleRoles()) {
for (const QByteArray& visibleRole : qAsConst(m_visibleRoles)) {
qreal maxWidth = widths.value(visibleRole, 0);
const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this);
maxWidth = qMax(width, maxWidth);
......@@ -2255,7 +2255,7 @@ void KItemListView::applyColumnWidthsFromHeader()
void KItemListView::updateWidgetColumnWidths(KItemListWidget* widget)
{
foreach (const QByteArray& role, m_visibleRoles) {
for (const QByteArray& role : qAsConst(m_visibleRoles)) {
widget->setColumnWidth(role, m_headerWidget->columnWidth(role));
}
}
......@@ -2265,13 +2265,13 @@ void KItemListView::updatePreferredColumnWidths(const KItemRangeList& itemRanges
Q_ASSERT(m_itemSize.isEmpty());
const int itemCount = m_model->count();
int rangesItemCount = 0;
foreach (const KItemRange& range, itemRanges) {
for (const KItemRange& range : itemRanges) {
rangesItemCount += range.count;
}
if (itemCount == rangesItemCount) {
const QHash<QByteArray, qreal> preferredWidths = preferredColumnWidths(itemRanges);
foreach (const QByteArray& role, m_visibleRoles) {
for (const QByteArray& role : qAsConst(m_visibleRoles)) {
m_headerWidget->setPreferredColumnWidth(role, preferredWidths.value(role));
}
} else {
......@@ -2326,7 +2326,7 @@ void KItemListView::applyAutomaticColumnWidths()
// size does not use the available view-size the size of the
// first role will get stretched.
foreach (const QByteArray& role, m_visibleRoles) {
for (const QByteArray& role : qAsConst(m_visibleRoles)) {
const qreal preferredWidth = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, preferredWidth);
}
......@@ -2373,7 +2373,7 @@ void KItemListView::applyAutomaticColumnWidths()
qreal KItemListView::columnWidthsSum() const
{
qreal widthsSum = 0;
foreach (const QByteArray& role, m_visibleRoles) {
for (const QByteArray& role : qAsConst(m_visibleRoles)) {
widthsSum += m_headerWidget->columnWidth(role);
}
return widthsSum;
......
......@@ -31,7 +31,7 @@ KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) :
KItemListViewAccessible::~KItemListViewAccessible()
{
foreach (AccessibleIdWrapper idWrapper, m_cells) {
for (AccessibleIdWrapper idWrapper : qAsConst(m_cells)) {
if (idWrapper.isValid) {
QAccessible::deleteAccessibleInterface(idWrapper.id);
}
......
......@@ -80,7 +80,7 @@ void KItemListWidget::setData(const QHash<QByteArray, QVariant>& data,
m_data = data;
dataChanged(m_data);
} else {
foreach (const QByteArray& role, roles) {
for (const QByteArray& role : roles) {
m_data[role] = data[role];
}
dataChanged(m_data, roles);
......
......@@ -197,14 +197,14 @@ KItemSet KItemSet::operator^(const KItemSet& other) const
const QVector<int>::iterator end = rangeBoundaries.end();
QVector<int>::iterator it = begin;
foreach (const KItemRange& range, m_itemRanges) {
for (const KItemRange& range : qAsConst(m_itemRanges)) {
*it++ = range.index;
*it++ = range.index + range.count;
}
const QVector<int>::iterator middle = it;
foreach (const KItemRange& range, other.m_itemRanges) {
for (const KItemRange& range : qAsConst(other.m_itemRanges)) {
*it++ = range.index;
*it++ = range.index + range.count;
}
......
......@@ -303,7 +303,7 @@ inline KItemSet& KItemSet::operator=(const KItemSet& other)
inline int KItemSet::count() const
{
int result = 0;
foreach (const KItemRange& range, m_itemRanges) {
for (const KItemRange& range : qAsConst(m_itemRanges)) {
result += range.count;
}
return result;
......
......@@ -80,7 +80,8 @@ bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& c
// Even if the icons have a different size they are always aligned within
// the area defined by KItemStyleOption.iconSize and hence result in no
// change of the item-size.
foreach (const QByteArray& role, visibleRoles()) {
const auto roles = visibleRoles();
for (const QByteArray& role : roles) {
if (changedRoles.contains(role)) {
return true;
}
......@@ -152,7 +153,8 @@ void KStandardItemListView::applyDefaultStyleOption(int iconSize,
void KStandardItemListView::updateLayoutOfVisibleItems()
{
if (model()) {
foreach (KItemListWidget* widget, visibleItemListWidgets()) {
const auto widgets = visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
initializeItemListWidget(widget);
}
}
......
......@@ -204,7 +204,7 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
maximumRequiredWidth = fontMetrics.horizontalAdvance(itemText(index, view));