Compile without foreach

This commit is contained in:
Alexander Lohnau 2020-10-23 19:48:22 +02:00 committed by Elvis Angelaccio
parent 360a8dd883
commit a24327cd50
38 changed files with 140 additions and 121 deletions

View file

@ -16,6 +16,7 @@ remove_definitions(
-DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_NO_SIGNALS_SLOTS_KEYWORDS
-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_TO_ASCII
-DQT_NO_FOREACH
) )
########################################## ##########################################

View file

@ -163,7 +163,7 @@ void DolphinContextMenu::openTrashItemContextMenu()
if (exec(m_pos) == restoreAction) { if (exec(m_pos) == restoreAction) {
QList<QUrl> selectedUrls; QList<QUrl> selectedUrls;
selectedUrls.reserve(m_selectedItems.count()); selectedUrls.reserve(m_selectedItems.count());
foreach (const KFileItem &item, m_selectedItems) { for (const KFileItem &item : qAsConst(m_selectedItems)) {
selectedUrls.append(item.url()); selectedUrls.append(item.url());
} }

View file

@ -427,7 +427,7 @@ void DolphinMainWindow::openInNewTab()
const KFileItemList& list = m_activeViewContainer->view()->selectedItems(); const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
bool tabCreated = false; bool tabCreated = false;
foreach (const KFileItem& item, list) { for (const KFileItem& item : list) {
const QUrl& url = DolphinView::openItemAsFolderUrl(item); const QUrl& url = DolphinView::openItemAsFolderUrl(item);
if (!url.isEmpty()) { if (!url.isEmpty()) {
openNewTabAfterCurrentTab(url); openNewTabAfterCurrentTab(url);
@ -861,7 +861,8 @@ void DolphinMainWindow::replaceLocation()
void DolphinMainWindow::togglePanelLockState() void DolphinMainWindow::togglePanelLockState()
{ {
const bool newLockState = !GeneralSettings::lockPanels(); const bool newLockState = !GeneralSettings::lockPanels();
foreach (QObject* child, children()) { const auto childrenObjects = children();
for (QObject* child : childrenObjects) {
DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child); DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
if (dock) { if (dock) {
dock->setLocked(newLockState); dock->setLocked(newLockState);
@ -2083,7 +2084,8 @@ bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)
Q_ASSERT(menu); Q_ASSERT(menu);
const KToolBar* toolBarWidget = toolBar(); const KToolBar* toolBarWidget = toolBar();
foreach (const QWidget* widget, action->associatedWidgets()) { const auto associatedWidgets = action->associatedWidgets();
for (const QWidget* widget : associatedWidgets) {
if (widget == toolBarWidget) { if (widget == toolBarWidget) {
return false; return false;
} }

View file

@ -362,7 +362,7 @@ void DolphinPart::slotItemActivated(const KFileItem& item)
void DolphinPart::slotItemsActivated(const KFileItemList& items) void DolphinPart::slotItemsActivated(const KFileItemList& items)
{ {
foreach (const KFileItem& item, items) { for (const KFileItem& item : items) {
slotItemActivated(item); slotItemActivated(item);
} }
} }

View file

@ -216,7 +216,7 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
// for each directory. If the "split view" option is enabled, two // for each directory. If the "split view" option is enabled, two
// directories are shown inside one tab (see openDirectories()). // directories are shown inside one tab (see openDirectories()).
QList<QUrl> dirs; QList<QUrl> dirs;
foreach (const QUrl& url, files) { for (const QUrl& url : files) {
const QUrl dir(url.adjusted(QUrl::RemoveFilename)); const QUrl dir(url.adjusted(QUrl::RemoveFilename));
if (!dirs.contains(dir)) { if (!dirs.contains(dir)) {
dirs.append(dir); dirs.append(dir);

View file

@ -22,7 +22,7 @@ QList<QUrl> Dolphin::validateUris(const QStringList& uriList)
{ {
const QString currentDir = QDir::currentPath(); const QString currentDir = QDir::currentPath();
QList<QUrl> urls; QList<QUrl> urls;
foreach (const QString& str, uriList) { for (const QString& str : uriList) {
const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile); const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile);
if (url.isValid()) { if (url.isValid()) {
urls.append(url); urls.append(url);

View file

@ -420,7 +420,8 @@ int KFileItemModel::index(const QUrl& url) const
indexesForUrl.insert(m_itemData.at(i)->item.url(), i); 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) { if (indexesForUrl.count(url) > 1) {
qCWarning(DolphinDebug) << "Multiple items found with the URL" << url; 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); m_dirLister->openUrl(url, KDirLister::Keep);
const QVariantList previouslyExpandedChildren = m_itemData.at(index)->values.value("previouslyExpandedChildren").value<QVariantList>(); 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()); m_urlsToExpand.insert(var.toUrl());
} }
} else { } else {
@ -728,7 +729,7 @@ void KFileItemModel::removeFilteredChildren(const KItemRangeList& itemRanges)
} }
QSet<ItemData*> parents; QSet<ItemData*> parents;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
for (int index = range.index; index < range.index + range.count; ++index) { for (int index = range.index; index < range.index + range.count; ++index) {
parents.insert(m_itemData.at(index)); parents.insert(m_itemData.at(index));
} }
@ -848,7 +849,7 @@ void KFileItemModel::resortAllItems()
// been moved because of the resorting. // been moved because of the resorting.
QList<QUrl> oldUrls; QList<QUrl> oldUrls;
oldUrls.reserve(itemCount); oldUrls.reserve(itemCount);
foreach (const ItemData* itemData, m_itemData) { for (const ItemData* itemData : qAsConst(m_itemData)) {
oldUrls.append(itemData->item.url()); 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. // 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 // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet
// -> we expand the first visible URL we find in m_restoredExpandedUrls. // -> 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); const int indexForUrl = index(url);
if (indexForUrl >= 0) { if (indexForUrl >= 0) {
m_urlsToExpand.remove(url); 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()) { if (!m_filter.hasSetFilters()) {
m_pendingItemsToInsert.append(itemDataList); 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 // The name or type filter is active. Hide filtered items
// before inserting them into the model and remember // before inserting them into the model and remember
// the filtered items in m_filteredItems. // the filtered items in m_filteredItems.
foreach (ItemData* itemData, itemDataList) { for (ItemData* itemData : itemDataList) {
if (m_filter.matches(itemData->item)) { if (m_filter.matches(itemData->item)) {
m_pendingItemsToInsert.append(itemData); m_pendingItemsToInsert.append(itemData);
} else { } else {
@ -1013,7 +1014,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
QVector<int> indexesToRemove; QVector<int> indexesToRemove;
indexesToRemove.reserve(items.count()); indexesToRemove.reserve(items.count());
foreach (const KFileItem& item, items) { for (const KFileItem& item : items) {
const int indexForItem = index(item); const int indexForItem = index(item);
if (indexForItem >= 0) { if (indexForItem >= 0) {
indexesToRemove.append(indexForItem); indexesToRemove.append(indexForItem);
@ -1035,7 +1036,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
indexesToRemoveWithChildren.reserve(m_itemData.count()); indexesToRemoveWithChildren.reserve(m_itemData.count());
const int itemCount = m_itemData.count(); const int itemCount = m_itemData.count();
foreach (int index, indexesToRemove) { for (int index : qAsConst(indexesToRemove)) {
indexesToRemoveWithChildren.append(index); indexesToRemoveWithChildren.append(index);
const int parentLevel = expandedParentsCount(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. // Step 1: Remove the items from m_itemData, and free the ItemData.
int removedItemsCount = 0; int removedItemsCount = 0;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
removedItemsCount += range.count; removedItemsCount += range.count;
for (int index = range.index; index < range.index + range.count; ++index) { 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; QList<ItemData*> itemDataList;
itemDataList.reserve(items.count()); itemDataList.reserve(items.count());
foreach (const KFileItem& item, items) { for (const KFileItem& item : items) {
ItemData* itemData = new ItemData(); ItemData* itemData = new ItemData();
itemData->item = item; itemData->item = item;
itemData->parent = parentItem; itemData->parent = parentItem;
@ -1350,7 +1351,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
case DeletionTimeRole: case DeletionTimeRole:
// These roles can be determined with retrieveData, and they have to be stored // These roles can be determined with retrieveData, and they have to be stored
// in the QHash "values" for the sorting. // in the QHash "values" for the sorting.
foreach (ItemData* itemData, itemDataList) { for (ItemData* itemData : qAsConst(itemDataList)) {
if (itemData->values.isEmpty()) { if (itemData->values.isEmpty()) {
itemData->values = retrieveData(itemData->item, itemData->parent); itemData->values = retrieveData(itemData->item, itemData->parent);
} }
@ -1359,7 +1360,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
case TypeRole: case TypeRole:
// At least store the data including the file type for items with known MIME type. // 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()) { if (itemData->values.isEmpty()) {
const KFileItem item = itemData->item; const KFileItem item = itemData->item;
if (item.isDir() || item.isMimeTypeKnown()) { 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 // 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. // role has not changed at all because the file name can be used as a fallback.
if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) { if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) {
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
bool needsResorting = false; bool needsResorting = false;
const int first = range.index; const int first = range.index;
@ -2365,7 +2366,7 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout)
{ {
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
foreach (const KFileItem& item, items) { // krazy:exclude=foreach for (const KFileItem& item : items) {
// Only determine mime types for files here. For directories, // Only determine mime types for files here. For directories,
// KFileItem::determineMimeType() reads the .directory file inside to // KFileItem::determineMimeType() reads the .directory file inside to
// load the icon, but this is not necessary at all if we just need the // load the icon, but this is not necessary at all if we just need the

View file

@ -113,8 +113,8 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result, connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result,
this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived); this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived);
auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, qApp); const auto plugins = KPluginLoader::instantiatePlugins(QStringLiteral("kf5/overlayicon"), nullptr, qApp);
foreach (QObject *it, plugins) { for (QObject *it : plugins) {
auto plugin = qobject_cast<KOverlayIconPlugin*>(it); auto plugin = qobject_cast<KOverlayIconPlugin*>(it);
if (plugin) { if (plugin) {
m_overlayIconsPlugin.append(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. // Determine the sort role synchronously for as many items as possible.
if (m_resolvableRoles.contains(m_model->sortRole())) { if (m_resolvableRoles.contains(m_model->sortRole())) {
int insertedCount = 0; int insertedCount = 0;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
const int lastIndex = insertedCount + range.index + range.count - 1; const int lastIndex = insertedCount + range.index + range.count - 1;
for (int i = insertedCount + range.index; i <= lastIndex; ++i) { for (int i = insertedCount + range.index; i <= lastIndex; ++i) {
if (timer.elapsed() < MaxBlockTimeout) { if (timer.elapsed() < MaxBlockTimeout) {
@ -364,7 +364,8 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
m_balooFileMonitor->clear(); m_balooFileMonitor->clear();
} else { } else {
QStringList newFileList; 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) { if (m_model->index(QUrl::fromLocalFile(file)) >= 0) {
newFileList.append(file); newFileList.append(file);
} }
@ -424,7 +425,7 @@ void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRang
QSet<KFileItem>& targetSet = itemsChangedRecently ? m_recentlyChangedItems : m_changedItems; QSet<KFileItem>& targetSet = itemsChangedRecently ? m_recentlyChangedItems : m_changedItems;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
int index = itemRange.index; int index = itemRange.index;
for (int count = itemRange.count; count > 0; --count) { for (int count = itemRange.count; count > 0; --count) {
const KFileItem item = m_model->fileItem(index); 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() // It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional // assumes that an overlay will be drawn and has some additional
// setup time. // setup time.
foreach (const QString& overlay, overlays) { for (const QString& overlay : overlays) {
if (!overlay.isEmpty()) { if (!overlay.isEmpty()) {
// There is at least one overlay, draw all overlays above m_pixmap // There is at least one overlay, draw all overlays above m_pixmap
// and cancel the check // and cancel the check
@ -722,7 +723,8 @@ void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem &
const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance(); const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance();
QHash<QByteArray, QVariant> data; 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 // Overwrite all the role values with an empty QVariant, because the roles
// provider doesn't overwrite it when the property value list is empty. // provider doesn't overwrite it when the property value list is empty.
// See bug 322348 // See bug 322348
@ -808,7 +810,7 @@ void KFileItemModelRolesUpdater::startUpdating()
m_pendingPreviewItems.clear(); m_pendingPreviewItems.clear();
m_pendingPreviewItems.reserve(indexes.count()); m_pendingPreviewItems.reserve(indexes.count());
foreach (int index, indexes) { for (int index : qAsConst(indexes)) {
const KFileItem item = m_model->fileItem(index); const KFileItem item = m_model->fileItem(index);
if (!m_finishedItems.contains(item)) { if (!m_finishedItems.contains(item)) {
m_pendingPreviewItems.append(item); m_pendingPreviewItems.append(item);
@ -941,7 +943,7 @@ void KFileItemModelRolesUpdater::updateChangedItems()
QList<int> visibleChangedIndexes; QList<int> visibleChangedIndexes;
QList<int> invisibleChangedIndexes; QList<int> invisibleChangedIndexes;
foreach (const KFileItem& item, m_changedItems) { for (const KFileItem& item : qAsConst(m_changedItems)) {
const int index = m_model->index(item); const int index = m_model->index(item);
if (index < 0) { if (index < 0) {
@ -959,11 +961,11 @@ void KFileItemModelRolesUpdater::updateChangedItems()
std::sort(visibleChangedIndexes.begin(), visibleChangedIndexes.end()); std::sort(visibleChangedIndexes.begin(), visibleChangedIndexes.end());
if (m_previewShown) { if (m_previewShown) {
foreach (int index, visibleChangedIndexes) { for (int index : qAsConst(visibleChangedIndexes)) {
m_pendingPreviewItems.append(m_model->fileItem(index)); m_pendingPreviewItems.append(m_model->fileItem(index));
} }
foreach (int index, invisibleChangedIndexes) { for (int index : qAsConst(invisibleChangedIndexes)) {
m_pendingPreviewItems.append(m_model->fileItem(index)); m_pendingPreviewItems.append(m_model->fileItem(index));
} }
@ -1078,7 +1080,7 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte
} }
QStringList overlays = item.overlays(); QStringList overlays = item.overlays();
foreach(KOverlayIconPlugin *it, m_overlayIconsPlugin) { for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) {
overlays.append(it->getOverlays(item.url())); overlays.append(it->getOverlays(item.url()));
} }
data.insert("iconOverlays", overlays); data.insert("iconOverlays", overlays);
@ -1101,7 +1103,7 @@ void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl& url, const QStr
const int index = m_model->index(item); const int index = m_model->index(item);
QHash<QByteArray, QVariant> data = m_model->data(index); QHash<QByteArray, QVariant> data = m_model->data(index);
QStringList overlays = item.overlays(); QStringList overlays = item.overlays();
foreach (KOverlayIconPlugin *it, m_overlayIconsPlugin) { for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) {
overlays.append(it->getOverlays(url)); overlays.append(it->getOverlays(url));
} }
data.insert("iconOverlays", overlays); data.insert("iconOverlays", overlays);

View file

@ -864,7 +864,8 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const
return false; return false;
} }
foreach (KItemListWidget* widget, m_view->visibleItemListWidgets()) { const auto widgets = m_view->visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
if (widget->isHovered()) { if (widget->isHovered()) {
widget->setHovered(false); widget->setHovered(false);
emit itemUnhovered(widget->index()); emit itemUnhovered(widget->index());
@ -1195,7 +1196,8 @@ void KItemListController::slotRubberBandChanged()
KItemSet selectedItems; KItemSet selectedItems;
// Select all visible items that intersect with the rubberband // 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 int index = widget->index();
const QRectF widgetRect = m_view->itemRect(index); const QRectF widgetRect = m_view->itemRect(index);
@ -1284,7 +1286,8 @@ KItemListWidget* KItemListController::hoveredWidget() const
{ {
Q_ASSERT(m_view); Q_ASSERT(m_view);
foreach (KItemListWidget* widget, m_view->visibleItemListWidgets()) { const auto widgets = m_view->visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
if (widget->isHovered()) { if (widget->isHovered()) {
return widget; return widget;
} }
@ -1297,7 +1300,8 @@ KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const
{ {
Q_ASSERT(m_view); 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 QPointF mappedPos = widget->mapFromItem(m_view, pos);
const bool hovered = widget->contains(mappedPos) && const bool hovered = widget->contains(mappedPos) &&

View file

@ -45,7 +45,8 @@ qreal KItemListHeader::columnWidth(const QByteArray& role) const
void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths) void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths)
{ {
if (!m_headerWidget->automaticColumnResizing()) { 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); const qreal width = columnWidths.value(role);
m_headerWidget->setColumnWidth(role, width); m_headerWidget->setColumnWidth(role, width);
} }

View file

@ -222,7 +222,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
} else { } else {
const int previousCurrent = m_currentItem; const int previousCurrent = m_currentItem;
int inc = 0; int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
if (m_currentItem < itemRange.index) { if (m_currentItem < itemRange.index) {
break; break;
} }
@ -242,7 +242,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
m_anchorItem = 0; m_anchorItem = 0;
} else { } else {
int inc = 0; int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
if (m_anchorItem < itemRange.index) { if (m_anchorItem < itemRange.index) {
break; break;
} }
@ -258,7 +258,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges)
for (int index: previous) { for (int index: previous) {
int inc = 0; int inc = 0;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
if (index < itemRange.index) { if (index < itemRange.index) {
break; break;
} }
@ -376,7 +376,7 @@ int KItemListSelectionManager::indexAfterRangesRemoving(int index, const KItemRa
const RangesRemovingBehaviour behaviour) const const RangesRemovingBehaviour behaviour) const
{ {
int dec = 0; int dec = 0;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
if (index < itemRange.index) { if (index < itemRange.index) {
break; break;
} }

View file

@ -230,7 +230,7 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
if (!m_headerWidget->automaticColumnResizing()) { if (!m_headerWidget->automaticColumnResizing()) {
// The column-width of new roles are still 0. Apply the preferred // The column-width of new roles are still 0. Apply the preferred
// column-width as default with. // column-width as default with.
foreach (const QByteArray& role, m_visibleRoles) { for (const QByteArray& role : qAsConst(m_visibleRoles)) {
if (m_headerWidget->columnWidth(role) == 0) { if (m_headerWidget->columnWidth(role) == 0) {
const qreal width = m_headerWidget->preferredColumnWidth(role); const qreal width = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, width); m_headerWidget->setColumnWidth(role, width);
@ -1029,7 +1029,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
m_sizeHintResolver->itemsInserted(itemRanges); m_sizeHintResolver->itemsInserted(itemRanges);
int previouslyInsertedCount = 0; 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. // 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 // As in each loop the current item-range gets inserted the index must
// be increased by the already previously inserted items. // be increased by the already previously inserted items.
@ -1155,7 +1155,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
QVector<int> itemsToMove; QVector<int> itemsToMove;
// Remove all KItemListWidget instances that got deleted // Remove all KItemListWidget instances that got deleted
foreach (KItemListWidget* widget, m_visibleItems) { for (KItemListWidget* widget : qAsConst(m_visibleItems)) {
const int i = widget->index(); const int i = widget->index();
if (i < firstRemovedIndex) { if (i < firstRemovedIndex) {
continue; continue;
@ -1191,7 +1191,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
// after the deleted items. It is important to update them in ascending // after the deleted items. It is important to update them in ascending
// order to prevent overlaps when setting the new index. // order to prevent overlaps when setting the new index.
std::sort(itemsToMove.begin(), itemsToMove.end()); std::sort(itemsToMove.begin(), itemsToMove.end());
foreach (int i, itemsToMove) { for (int i : qAsConst(itemsToMove)) {
KItemListWidget* widget = m_visibleItems.value(i); KItemListWidget* widget = m_visibleItems.value(i);
Q_ASSERT(widget); Q_ASSERT(widget);
const int newIndex = i - count; const int newIndex = i - count;
@ -1269,7 +1269,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
updatePreferredColumnWidths(itemRanges); updatePreferredColumnWidths(itemRanges);
} }
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
const int index = itemRange.index; const int index = itemRange.index;
const int count = itemRange.count; 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 // Delete invisible KItemListWidget instances that have not been reused
foreach (int index, reusableItems) { for (int index : qAsConst(reusableItems)) {
recycleWidget(m_visibleItems.value(index)); recycleWidget(m_visibleItems.value(index));
} }
@ -2197,7 +2197,7 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi
const QFontMetricsF fontMetrics(m_headerWidget->font()); const QFontMetricsF fontMetrics(m_headerWidget->font());
const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin); const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin);
const int headerMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderMargin); 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 QString headerText = m_model->roleDescription(visibleRole);
const qreal headerWidth = fontMetrics.width(headerText) + gripMargin + headerMargin * 2; const qreal headerWidth = fontMetrics.width(headerText) + gripMargin + headerMargin * 2;
widths.insert(visibleRole, headerWidth); widths.insert(visibleRole, headerWidth);
@ -2208,12 +2208,12 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi
const KItemListWidgetCreatorBase* creator = widgetCreator(); const KItemListWidgetCreatorBase* creator = widgetCreator();
int calculatedItemCount = 0; int calculatedItemCount = 0;
bool maxTimeExceeded = false; bool maxTimeExceeded = false;
foreach (const KItemRange& itemRange, itemRanges) { for (const KItemRange& itemRange : itemRanges) {
const int startIndex = itemRange.index; const int startIndex = itemRange.index;
const int endIndex = startIndex + itemRange.count - 1; const int endIndex = startIndex + itemRange.count - 1;
for (int i = startIndex; i <= endIndex; ++i) { 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); qreal maxWidth = widths.value(visibleRole, 0);
const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this); const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this);
maxWidth = qMax(width, maxWidth); maxWidth = qMax(width, maxWidth);
@ -2255,7 +2255,7 @@ void KItemListView::applyColumnWidthsFromHeader()
void KItemListView::updateWidgetColumnWidths(KItemListWidget* widget) 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)); widget->setColumnWidth(role, m_headerWidget->columnWidth(role));
} }
} }
@ -2265,13 +2265,13 @@ void KItemListView::updatePreferredColumnWidths(const KItemRangeList& itemRanges
Q_ASSERT(m_itemSize.isEmpty()); Q_ASSERT(m_itemSize.isEmpty());
const int itemCount = m_model->count(); const int itemCount = m_model->count();
int rangesItemCount = 0; int rangesItemCount = 0;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
rangesItemCount += range.count; rangesItemCount += range.count;
} }
if (itemCount == rangesItemCount) { if (itemCount == rangesItemCount) {
const QHash<QByteArray, qreal> preferredWidths = preferredColumnWidths(itemRanges); 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)); m_headerWidget->setPreferredColumnWidth(role, preferredWidths.value(role));
} }
} else { } else {
@ -2326,7 +2326,7 @@ void KItemListView::applyAutomaticColumnWidths()
// size does not use the available view-size the size of the // size does not use the available view-size the size of the
// first role will get stretched. // 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); const qreal preferredWidth = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, preferredWidth); m_headerWidget->setColumnWidth(role, preferredWidth);
} }
@ -2373,7 +2373,7 @@ void KItemListView::applyAutomaticColumnWidths()
qreal KItemListView::columnWidthsSum() const qreal KItemListView::columnWidthsSum() const
{ {
qreal widthsSum = 0; qreal widthsSum = 0;
foreach (const QByteArray& role, m_visibleRoles) { for (const QByteArray& role : qAsConst(m_visibleRoles)) {
widthsSum += m_headerWidget->columnWidth(role); widthsSum += m_headerWidget->columnWidth(role);
} }
return widthsSum; return widthsSum;

View file

@ -31,7 +31,7 @@ KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) :
KItemListViewAccessible::~KItemListViewAccessible() KItemListViewAccessible::~KItemListViewAccessible()
{ {
foreach (AccessibleIdWrapper idWrapper, m_cells) { for (AccessibleIdWrapper idWrapper : qAsConst(m_cells)) {
if (idWrapper.isValid) { if (idWrapper.isValid) {
QAccessible::deleteAccessibleInterface(idWrapper.id); QAccessible::deleteAccessibleInterface(idWrapper.id);
} }

View file

@ -80,7 +80,7 @@ void KItemListWidget::setData(const QHash<QByteArray, QVariant>& data,
m_data = data; m_data = data;
dataChanged(m_data); dataChanged(m_data);
} else { } else {
foreach (const QByteArray& role, roles) { for (const QByteArray& role : roles) {
m_data[role] = data[role]; m_data[role] = data[role];
} }
dataChanged(m_data, roles); dataChanged(m_data, roles);

View file

@ -197,14 +197,14 @@ KItemSet KItemSet::operator^(const KItemSet& other) const
const QVector<int>::iterator end = rangeBoundaries.end(); const QVector<int>::iterator end = rangeBoundaries.end();
QVector<int>::iterator it = begin; QVector<int>::iterator it = begin;
foreach (const KItemRange& range, m_itemRanges) { for (const KItemRange& range : qAsConst(m_itemRanges)) {
*it++ = range.index; *it++ = range.index;
*it++ = range.index + range.count; *it++ = range.index + range.count;
} }
const QVector<int>::iterator middle = it; 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;
*it++ = range.index + range.count; *it++ = range.index + range.count;
} }

View file

@ -303,7 +303,7 @@ inline KItemSet& KItemSet::operator=(const KItemSet& other)
inline int KItemSet::count() const inline int KItemSet::count() const
{ {
int result = 0; int result = 0;
foreach (const KItemRange& range, m_itemRanges) { for (const KItemRange& range : qAsConst(m_itemRanges)) {
result += range.count; result += range.count;
} }
return result; return result;

View file

@ -80,7 +80,8 @@ bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& c
// Even if the icons have a different size they are always aligned within // Even if the icons have a different size they are always aligned within
// the area defined by KItemStyleOption.iconSize and hence result in no // the area defined by KItemStyleOption.iconSize and hence result in no
// change of the item-size. // change of the item-size.
foreach (const QByteArray& role, visibleRoles()) { const auto roles = visibleRoles();
for (const QByteArray& role : roles) {
if (changedRoles.contains(role)) { if (changedRoles.contains(role)) {
return true; return true;
} }
@ -152,7 +153,8 @@ void KStandardItemListView::applyDefaultStyleOption(int iconSize,
void KStandardItemListView::updateLayoutOfVisibleItems() void KStandardItemListView::updateLayoutOfVisibleItems()
{ {
if (model()) { if (model()) {
foreach (KItemListWidget* widget, visibleItemListWidgets()) { const auto widgets = visibleItemListWidgets();
for (KItemListWidget* widget : widgets) {
initializeItemListWidget(widget); initializeItemListWidget(widget);
} }
} }

View file

@ -204,7 +204,7 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect
maximumRequiredWidth = fontMetrics.horizontalAdvance(itemText(index, view)); maximumRequiredWidth = fontMetrics.horizontalAdvance(itemText(index, view));
} else { } else {
const QHash<QByteArray, QVariant>& values = view->model()->data(index); const QHash<QByteArray, QVariant>& values = view->model()->data(index);
foreach (const QByteArray& role, visibleRoles) { for (const QByteArray& role : visibleRoles) {
const QString& text = roleText(role, values); const QString& text = roleText(role, values);
const qreal requiredWidth = fontMetrics.horizontalAdvance(text); const qreal requiredWidth = fontMetrics.horizontalAdvance(text);
maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth); maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
@ -1205,7 +1205,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
// Calculate the position for each additional information // Calculate the position for each additional information
qreal y = nameTextInfo->pos.y() + nameHeight; qreal y = nameTextInfo->pos.y() + nameHeight;
foreach (const QByteArray& role, m_sortedVisibleRoles) { for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
if (role == "text") { if (role == "text") {
continue; continue;
} }
@ -1268,7 +1268,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache()
const qreal x = option.padding * 3 + scaledIconSize; const qreal x = option.padding * 3 + scaledIconSize;
qreal y = qRound((widgetHeight - textLinesHeight) / 2); qreal y = qRound((widgetHeight - textLinesHeight) / 2);
const qreal maxWidth = size().width() - x - option.padding; const qreal maxWidth = size().width() - x - option.padding;
foreach (const QByteArray& role, m_sortedVisibleRoles) { for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
const QString text = roleText(role, values); const QString text = roleText(role, values);
TextInfo* textInfo = m_textInfo.value(role); TextInfo* textInfo = m_textInfo.value(role);
textInfo->staticText.setText(text); textInfo->staticText.setText(text);
@ -1319,7 +1319,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
qreal x = firstColumnInc; qreal x = firstColumnInc;
const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2); const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2);
foreach (const QByteArray& role, m_sortedVisibleRoles) { for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) {
QString text = roleText(role, values); QString text = roleText(role, values);
// Elide the text in case it does not fit into the available column-width // Elide the text in case it does not fit into the available column-width
@ -1493,7 +1493,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
// It is more efficient to do it here, as KIconLoader::drawOverlays() // It is more efficient to do it here, as KIconLoader::drawOverlays()
// assumes that an overlay will be drawn and has some additional // assumes that an overlay will be drawn and has some additional
// setup time. // setup time.
foreach (const QString& overlay, overlays) { for (const QString& overlay : overlays) {
if (!overlay.isEmpty()) { if (!overlay.isEmpty()) {
int state = KIconLoader::DefaultState; int state = KIconLoader::DefaultState;

View file

@ -96,7 +96,7 @@ bool KFileItemModelFilter::matchesPattern(const KFileItem& item) const
bool KFileItemModelFilter::matchesType(const KFileItem& item) const bool KFileItemModelFilter::matchesType(const KFileItem& item) const
{ {
foreach (const QString& mimeType, m_mimeTypes) { for (const QString& mimeType : qAsConst(m_mimeTypes)) {
if (item.mimetype() == mimeType) { if (item.mimetype() == mimeType) {
return true; return true;
} }

View file

@ -78,7 +78,7 @@ bool KItemListHeaderWidget::automaticColumnResizing() const
void KItemListHeaderWidget::setColumns(const QList<QByteArray>& roles) void KItemListHeaderWidget::setColumns(const QList<QByteArray>& roles)
{ {
foreach (const QByteArray& role, roles) { for (const QByteArray& role : roles) {
if (!m_columnWidths.contains(role)) { if (!m_columnWidths.contains(role)) {
m_preferredColumnWidths.remove(role); m_preferredColumnWidths.remove(role);
} }
@ -155,7 +155,7 @@ void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsI
qreal x = -m_offset; qreal x = -m_offset;
int orderIndex = 0; int orderIndex = 0;
foreach (const QByteArray& role, m_columns) { for (const QByteArray& role : qAsConst(m_columns)) {
const qreal roleWidth = m_columnWidths.value(role); const qreal roleWidth = m_columnWidths.value(role);
const QRectF rect(x, 0, roleWidth, size().height()); const QRectF rect(x, 0, roleWidth, size().height());
paintRole(painter, role, rect, orderIndex, widget); paintRole(painter, role, rect, orderIndex, widget);
@ -468,7 +468,7 @@ int KItemListHeaderWidget::roleIndexAt(const QPointF& pos) const
int index = -1; int index = -1;
qreal x = -m_offset; qreal x = -m_offset;
foreach (const QByteArray& role, m_columns) { for (const QByteArray& role : qAsConst(m_columns)) {
++index; ++index;
x += m_columnWidths.value(role); x += m_columnWidths.value(role);
if (pos.x() <= x) { if (pos.x() <= x) {
@ -549,7 +549,7 @@ int KItemListHeaderWidget::targetOfMovingRole() const
qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const
{ {
qreal x = -m_offset; qreal x = -m_offset;
foreach (const QByteArray& visibleRole, m_columns) { for (const QByteArray& visibleRole : qAsConst(m_columns)) {
if (visibleRole == role) { if (visibleRole == role) {
return x; return x;
} }

View file

@ -35,7 +35,7 @@ QSizeF KItemListSizeHintResolver::sizeHint(int index)
void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges) void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges)
{ {
int insertedCount = 0; int insertedCount = 0;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
insertedCount += range.count; insertedCount += range.count;
} }

View file

@ -139,10 +139,10 @@ void TreeViewContextMenu::open(const QPoint& pos)
popup->addAction(propertiesAction); popup->addAction(propertiesAction);
} }
QList<QAction*> customActions = m_parent->customContextMenuActions(); const QList<QAction*> customActions = m_parent->customContextMenuActions();
if (!customActions.isEmpty()) { if (!customActions.isEmpty()) {
popup->addSeparator(); popup->addSeparator();
foreach (QAction* action, customActions) { for (QAction* action : customActions) {
popup->addAction(action); popup->addAction(action);
} }
} }

View file

@ -322,7 +322,8 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
menu.addMenu(iconSizeSubMenu); menu.addMenu(iconSizeSubMenu);
menu.addSeparator(); menu.addSeparator();
foreach (QAction* action, customContextMenuActions()) { const auto actions = customContextMenuActions();
for (QAction* action : actions) {
menu.addAction(action); menu.addAction(action);
} }

View file

@ -111,7 +111,7 @@ void DolphinQuery::parseBalooQuery()
QString fileName; QString fileName;
const QStringList subTerms = splitOutsideQuotes(query.searchString()); const QStringList subTerms = splitOutsideQuotes(query.searchString());
foreach (const QString& subTerm, subTerms) { for (const QString& subTerm : subTerms) {
const QString token = searchTermToken(subTerm); const QString token = searchTermToken(subTerm);
const QString value = stripQuotes(subTerm.mid(token.length())); const QString value = stripQuotes(subTerm.mid(token.length()));

View file

@ -39,7 +39,7 @@ ApplyViewPropsJob::~ApplyViewPropsJob()
void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list) void ApplyViewPropsJob::slotEntries(KIO::Job*, const KIO::UDSEntryList& list)
{ {
foreach (const KIO::UDSEntry& entry, list) { for (const KIO::UDSEntry& entry : list) {
const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME);
if (name != QLatin1Char('.') && name != QLatin1String("..") && entry.isDir()) { if (name != QLatin1Char('.') && name != QLatin1String("..") && entry.isDir()) {
++m_progress; ++m_progress;

View file

@ -118,7 +118,7 @@ void DolphinSettingsDialog::enableApply()
void DolphinSettingsDialog::applySettings() void DolphinSettingsDialog::applySettings()
{ {
foreach (SettingsPageBase* page, m_pages) { for (SettingsPageBase* page : qAsConst(m_pages)) {
page->applySettings(); page->applySettings();
} }
@ -137,7 +137,7 @@ void DolphinSettingsDialog::applySettings()
void DolphinSettingsDialog::restoreDefaults() void DolphinSettingsDialog::restoreDefaults()
{ {
foreach (SettingsPageBase* page, m_pages) { for (SettingsPageBase* page : qAsConst(m_pages)) {
page->restoreDefaults(); page->restoreDefaults();
} }
} }

View file

@ -59,14 +59,14 @@ GeneralSettingsPage::~GeneralSettingsPage()
void GeneralSettingsPage::applySettings() void GeneralSettingsPage::applySettings()
{ {
foreach (SettingsPageBase* page, m_pages) { for (SettingsPageBase* page : qAsConst(m_pages)) {
page->applySettings(); page->applySettings();
} }
} }
void GeneralSettingsPage::restoreDefaults() void GeneralSettingsPage::restoreDefaults()
{ {
foreach (SettingsPageBase* page, m_pages) { for (SettingsPageBase* page : qAsConst(m_pages)) {
page->restoreDefaults(); page->restoreDefaults();
} }
} }

View file

@ -168,7 +168,7 @@ void PreviewsSettingsPage::loadPreviewPlugins()
QAbstractItemModel* model = m_listView->model(); QAbstractItemModel* model = m_listView->model();
const KService::List plugins = KServiceTypeTrader::self()->query(QStringLiteral("ThumbCreator")); const KService::List plugins = KServiceTypeTrader::self()->query(QStringLiteral("ThumbCreator"));
foreach (const KService::Ptr& service, plugins) { for (const KService::Ptr& service : plugins) {
const bool configurable = service->property(QStringLiteral("Configurable"), QVariant::Bool).toBool(); const bool configurable = service->property(QStringLiteral("Configurable"), QVariant::Bool).toBool();
const bool show = m_enabledPreviewPlugins.contains(service->desktopEntryName()); const bool show = m_enabledPreviewPlugins.contains(service->desktopEntryName());

View file

@ -51,14 +51,14 @@ ViewSettingsPage::~ViewSettingsPage()
void ViewSettingsPage::applySettings() void ViewSettingsPage::applySettings()
{ {
foreach (ViewSettingsTab* tab, m_tabs) { for (ViewSettingsTab* tab : qAsConst(m_tabs)) {
tab->applySettings(); tab->applySettings();
} }
} }
void ViewSettingsPage::restoreDefaults() void ViewSettingsPage::restoreDefaults()
{ {
foreach (ViewSettingsTab* tab, m_tabs) { for (ViewSettingsTab* tab : qAsConst(m_tabs)) {
tab->restoreDefaultSettings(); tab->restoreDefaultSettings();
} }
} }

View file

@ -78,7 +78,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
m_sorting = new QComboBox(); m_sorting = new QComboBox();
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { for (const KFileItemModel::RoleInfo& info : rolesInfo) {
m_sorting->addItem(info.translation, info.role); m_sorting->addItem(info.translation, info.role);
} }
@ -116,7 +116,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged); connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged);
m_listWidget->setSelectionMode(QAbstractItemView::NoSelection); m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { for (const KFileItemModel::RoleInfo& info : rolesInfo) {
QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget); QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked); item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
@ -325,7 +325,7 @@ void ViewPropertiesDialog::applyViewProperties()
QList<QByteArray> visibleRoles; QList<QByteArray> visibleRoles;
int index = 0; int index = 0;
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { for (const KFileItemModel::RoleInfo& info : rolesInfo) {
const QListWidgetItem* item = m_listWidget->item(index); const QListWidgetItem* item = m_listWidget->item(index);
if (item->checkState() == Qt::Checked) { if (item->checkState() == Qt::Checked) {
visibleRoles.append(info.role); visibleRoles.append(info.role);

View file

@ -67,7 +67,7 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems_data()
QList<int> sizes; QList<int> sizes;
sizes << 100000; sizes << 100000;
foreach (int n, sizes) { for (int n : qAsConst(sizes)) {
QStringList allStrings; QStringList allStrings;
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
allStrings << QString::number(i); allStrings << QString::number(i);
@ -197,7 +197,7 @@ KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fil
qInstallMessageHandler(myMessageOutput); qInstallMessageHandler(myMessageOutput);
KFileItemList result; KFileItemList result;
foreach (const QString& name, fileNames) { for (const QString& name : fileNames) {
const KFileItem item(QUrl::fromLocalFile(prefix + name), QString(), KFileItem::Unknown); const KFileItem item(QUrl::fromLocalFile(prefix + name), QString(), KFileItem::Unknown);
result << item; result << item;
} }

View file

@ -241,7 +241,7 @@ void KItemListControllerTest::testKeyboardNavigation_data()
groupingEnabledList.append(true); groupingEnabledList.append(true);
groupingEnabledNames[true] = "grouping enabled"; groupingEnabledNames[true] = "grouping enabled";
foreach (const KFileItemListView::ItemLayout& layout, layoutList) { for (const KFileItemListView::ItemLayout& layout : layoutList) {
// The following settings depend on the layout. // The following settings depend on the layout.
// Note that 'columns' are actually 'rows' in // Note that 'columns' are actually 'rows' in
// Compact layout. // Compact layout.
@ -279,9 +279,9 @@ void KItemListControllerTest::testKeyboardNavigation_data()
break; break;
} }
foreach (int columnCount, columnCountList) { for (int columnCount : qAsConst(columnCountList)) {
foreach (const KItemListController::SelectionBehavior& selectionBehavior, selectionBehaviorList) { for (const KItemListController::SelectionBehavior& selectionBehavior : qAsConst(selectionBehaviorList)) {
foreach (bool groupingEnabled, groupingEnabledList) { // krazy:exclude=foreach for (bool groupingEnabled : qAsConst(groupingEnabledList)) {
QList<QPair<KeyPress, ViewState> > testList; QList<QPair<KeyPress, ViewState> > testList;
// First, key presses which should have the same effect // First, key presses which should have the same effect

View file

@ -16,7 +16,7 @@ Q_DECLARE_METATYPE(KItemRangeList)
KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges) KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges)
{ {
KItemSet result; KItemSet result;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) { for (int i = range.index; i < range.index + range.count; ++i) {
result.insert(i); result.insert(i);
} }
@ -30,7 +30,7 @@ KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges)
QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges) QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges)
{ {
QSet<int> result; QSet<int> result;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) { for (int i = range.index; i < range.index + range.count; ++i) {
result.insert(i); result.insert(i);
} }
@ -44,7 +44,7 @@ QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges)
QVector<int> KItemRangeList2QVector(const KItemRangeList& itemRanges) QVector<int> KItemRangeList2QVector(const KItemRangeList& itemRanges)
{ {
QVector<int> result; QVector<int> result;
foreach (const KItemRange& range, itemRanges) { for (const KItemRange& range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) { for (int i = range.index; i < range.index + range.count; ++i) {
result.append(i); result.append(i);
} }
@ -65,11 +65,11 @@ static QSet<int> KItemSet2QSet(const KItemSet& itemSet)
// Check that the conversion was successful. // Check that the conversion was successful.
Q_ASSERT(itemSet.count() == result.count()); Q_ASSERT(itemSet.count() == result.count());
for (int i : itemSet) { for (int i : qAsConst(itemSet)) {
Q_ASSERT(result.contains(i)); Q_ASSERT(result.contains(i));
} }
foreach (int i, result) { for (int i : qAsConst(result)) {
Q_ASSERT(itemSet.contains(i)); Q_ASSERT(itemSet.contains(i));
} }

View file

@ -61,7 +61,7 @@ void TestDir::createFile(const QString& path, const QByteArray& data, const QDat
void TestDir::createFiles(const QStringList& files) void TestDir::createFiles(const QStringList& files)
{ {
foreach (const QString& path, files) { for (const QString& path : files) {
createFile(path); createFile(path);
} }
} }
@ -81,7 +81,7 @@ void TestDir::createDir(const QString& path, const QDateTime& time)
void TestDir::removeFiles(const QStringList& files) void TestDir::removeFiles(const QStringList& files)
{ {
foreach (const QString& path, files) { for (const QString& path : files) {
removeFile(path); removeFile(path);
} }
} }

View file

@ -512,7 +512,7 @@ QString DolphinView::statusBarText() const
if (m_container->controller()->selectionManager()->hasSelection()) { if (m_container->controller()->selectionManager()->hasSelection()) {
// Give a summary of the status of the selected files // Give a summary of the status of the selected files
const KFileItemList list = selectedItems(); const KFileItemList list = selectedItems();
foreach (const KFileItem& item, list) { for (const KFileItem& item : list) {
if (item.isDir()) { if (item.isDir()) {
++folderCount; ++folderCount;
} else { } else {
@ -976,7 +976,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
// Add all roles to the menu that can be shown or hidden by the user // Add all roles to the menu that can be shown or hidden by the user
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { for (const KFileItemModel::RoleInfo& info : rolesInfo) {
if (info.role == "text") { if (info.role == "text") {
// It should not be possible to hide the "text" role // It should not be possible to hide the "text" role
continue; continue;
@ -1033,8 +1033,9 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
// Apply the current column-widths as custom column-widths and turn // Apply the current column-widths as custom column-widths and turn
// off the automatic resizing of the columns // off the automatic resizing of the columns
QList<int> columnWidths; QList<int> columnWidths;
columnWidths.reserve(view->visibleRoles().count()); const auto visibleRoles = view->visibleRoles();
foreach (const QByteArray& role, view->visibleRoles()) { columnWidths.reserve(visibleRoles.count());
for (const QByteArray& role : visibleRoles) {
columnWidths.append(header->columnWidth(role)); columnWidths.append(header->columnWidth(role));
} }
props.setHeaderColumnWidths(columnWidths); props.setHeaderColumnWidths(columnWidths);
@ -1055,8 +1056,9 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
QList<int> columnWidths; QList<int> columnWidths;
if (!header->automaticColumnResizing()) { if (!header->automaticColumnResizing()) {
columnWidths.reserve(view->visibleRoles().count()); const auto visibleRoles = view->visibleRoles();
foreach (const QByteArray& role, view->visibleRoles()) { columnWidths.reserve(visibleRoles.count());
for (const QByteArray& role : visibleRoles) {
columnWidths.append(header->columnWidth(role)); columnWidths.append(header->columnWidth(role));
} }
} }
@ -1077,7 +1079,7 @@ void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray& role, qr
columnWidths.clear(); columnWidths.clear();
columnWidths.reserve(visibleRoles.count()); columnWidths.reserve(visibleRoles.count());
const KItemListHeader* header = m_view->header(); const KItemListHeader* header = m_view->header();
foreach (const QByteArray& role, visibleRoles) { for (const QByteArray& role : visibleRoles) {
const int width = header->columnWidth(role); const int width = header->columnWidth(role);
columnWidths.append(width); columnWidths.append(width);
} }
@ -1876,7 +1878,7 @@ QList<QUrl> DolphinView::simplifiedSelectedUrls() const
const KFileItemList items = selectedItems(); const KFileItemList items = selectedItems();
urls.reserve(items.count()); urls.reserve(items.count());
foreach (const KFileItem& item, items) { for (const KFileItem& item : items) {
urls.append(item.url()); urls.append(item.url());
} }

View file

@ -227,7 +227,8 @@ void DolphinViewActionHandler::createActions()
sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By")); sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
sortByActionMenu->setDelayed(false); sortByActionMenu->setDelayed(false);
foreach (QAction* action, sortByActionGroup->actions()) { const auto sortByActionGroupActions = sortByActionGroup->actions();
for (QAction* action : sortByActionGroupActions) {
sortByActionMenu->addAction(action); sortByActionMenu->addAction(action);
} }
@ -261,7 +262,8 @@ void DolphinViewActionHandler::createActions()
visibleRolesMenu->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo"))); visibleRolesMenu->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
visibleRolesMenu->setDelayed(false); visibleRolesMenu->setDelayed(false);
foreach (QAction* action, visibleRolesGroup->actions()) { const auto visibleRolesGroupActions = visibleRolesGroup->actions();
for (QAction* action : visibleRolesGroupActions) {
visibleRolesMenu->addAction(action); visibleRolesMenu->addAction(action);
} }
@ -317,7 +319,7 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
#endif #endif
const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation(); const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { for (const KFileItemModel::RoleInfo& info : rolesInfo) {
if (!isSortGroup && info.role == "text") { if (!isSortGroup && info.role == "text") {
// It should not be possible to hide the "text" role // It should not be possible to hide the "text" role
continue; continue;
@ -654,7 +656,8 @@ void DolphinViewActionHandler::slotSortTriggered(QAction* action)
for (QAction *groupAction : qAsConst(m_sortByActions)) { for (QAction *groupAction : qAsConst(m_sortByActions)) {
KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction); KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
if (actionMenu) { if (actionMenu) {
foreach (QAction* subAction, actionMenu->menu()->actions()) { const auto actions = actionMenu->menu()->actions();
for (QAction* subAction : actions) {
subAction->setChecked(false); subAction->setChecked(false);
} }
} else if (groupAction->actionGroup()) { } else if (groupAction->actionGroup()) {

View file

@ -97,7 +97,7 @@ DolphinView* VersionControlObserver::view() const
QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const
{ {
bool hasNullItems = false; bool hasNullItems = false;
foreach (const KFileItem& item, items) { for (const KFileItem& item : items) {
if (item.isNull()) { if (item.isNull()) {
qCWarning(DolphinDebug) << "Requesting version-control-actions for empty items"; qCWarning(DolphinDebug) << "Requesting version-control-actions for empty items";
hasNullItems = true; hasNullItems = true;
@ -189,7 +189,7 @@ void VersionControlObserver::slotThreadFinished()
for (; it != itemStates.constEnd(); ++it) { for (; it != itemStates.constEnd(); ++it) {
const QVector<ItemState>& items = it.value(); const QVector<ItemState>& items = it.value();
foreach (const ItemState& item, items) { for (const ItemState& item : items) {
const KFileItem& fileItem = item.first; const KFileItem& fileItem = item.first;
const KVersionControlPlugin::ItemVersion version = item.second; const KVersionControlPlugin::ItemVersion version = item.second;
QHash<QByteArray, QVariant> values; QHash<QByteArray, QVariant> values;

View file

@ -266,7 +266,7 @@ void ViewProperties::setVisibleRoles(const QList<QByteArray>& roles)
// Add the updated values for the current view-mode // Add the updated values for the current view-mode
newVisibleRoles.reserve(roles.count()); newVisibleRoles.reserve(roles.count());
foreach (const QByteArray& role, roles) { for (const QByteArray& role : roles) {
newVisibleRoles.append(prefix + role); newVisibleRoles.append(prefix + role);
} }
@ -309,7 +309,7 @@ QList<QByteArray> ViewProperties::visibleRoles() const
const int prefixLength = prefix.length(); const int prefixLength = prefix.length();
const QStringList visibleRoles = m_node->visibleRoles(); const QStringList visibleRoles = m_node->visibleRoles();
foreach (const QString& visibleRole, visibleRoles) { for (const QString& visibleRole : visibleRoles) {
if (visibleRole.startsWith(prefix)) { if (visibleRole.startsWith(prefix)) {
const QByteArray role = visibleRole.right(visibleRole.length() - prefixLength).toLatin1(); const QByteArray role = visibleRole.right(visibleRole.length() - prefixLength).toLatin1();
if (role != "text") { if (role != "text") {
@ -422,7 +422,7 @@ void ViewProperties::convertAdditionalInfo()
// the internal role. One special-case must be handled: "LinkDestination" // the internal role. One special-case must be handled: "LinkDestination"
// has been used for "destination". // has been used for "destination".
visibleRoles.reserve(additionalInfo.count()); visibleRoles.reserve(additionalInfo.count());
foreach (const QString& info, additionalInfo) { for (const QString& info : additionalInfo) {
QString visibleRole = info; QString visibleRole = info;
int index = visibleRole.indexOf('_'); int index = visibleRole.indexOf('_');
if (index >= 0 && index + 1 < visibleRole.length()) { if (index >= 0 && index + 1 < visibleRole.length()) {