Commit d3f58b05 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Port a bunch of foreach usages

parent 053b187c
......@@ -178,7 +178,7 @@ void TimeZoneModel::update()
}
cities.sort(Qt::CaseInsensitive);
Q_FOREACH (const QString &key, cities) {
for (const QString &key : qAsConst(cities)) {
const QTimeZone timeZone = zonesByCity.value(key);
QString comment = timeZone.comment();
......
......@@ -91,12 +91,12 @@ QVariantList createActionListForFileItem(const KFileItem &fileItem)
{
QVariantList list;
KService::List services = KApplicationTrader::queryByMimeType(fileItem.mimetype());
const KService::List services = KApplicationTrader::queryByMimeType(fileItem.mimetype());
if (!services.isEmpty()) {
list << createTitleActionItem(i18n("Open with:"));
foreach (const KService::Ptr service, services) {
for (const KService::Ptr service : services) {
const QString text = service->name().replace(QLatin1Char('&'), QStringLiteral("&&"));
QVariantMap item = createActionItem(text, service->icon(), QStringLiteral("_kicker_fileItem_openWith"), service->entryPath());
......@@ -225,7 +225,7 @@ QVariantList jumpListActions(KService::Ptr service)
}
const auto &actions = service->actions();
foreach (const KServiceAction &action, actions) {
for (const KServiceAction &action : actions) {
if (action.text().isEmpty() || action.exec().isEmpty()) {
continue;
}
......
......@@ -77,7 +77,7 @@ AppsModel::AppsModel(const QList<AbstractEntry *> entryList, bool deleteEntriesO
foreach(AbstractEntry *suggestedEntry, entryList) {
bool found = false;
foreach (const AbstractEntry *entry, m_entryList) {
for (const AbstractEntry *entry : qAsConst(m_entryList)) {
if (entry->type() == AbstractEntry::RunnableType
&& static_cast<const AppEntry *>(entry)->service()->storageId()
== static_cast<const AppEntry *>(suggestedEntry)->service()->storageId()) {
......@@ -520,7 +520,7 @@ void AppsModel::refreshInternal()
bool found = false;
foreach (const AbstractEntry *entry, m_entryList) {
for (const AbstractEntry *entry : qAsConst(m_entryList)) {
if (entry->type() == AbstractEntry::RunnableType
&& static_cast<const AppEntry *>(entry)->service()->storageId() == service->storageId()) {
found = true;
......@@ -658,7 +658,7 @@ void AppsModel::processServiceGroup(KServiceGroup::Ptr group)
bool found = false;
foreach (const AbstractEntry *entry, m_entryList) {
for (const AbstractEntry *entry : qAsConst(m_entryList)) {
if (entry->type() == AbstractEntry::RunnableType
&& static_cast<const AppEntry *>(entry)->service()->storageId() == service->storageId()) {
found = true;
......
......@@ -114,7 +114,7 @@ bool RecentContactsModel::trigger(int row, const QString &actionId, const QVaria
if (!actionList.isEmpty()) {
QAction *chat = nullptr;
foreach (QAction *action, actionList) {
for (QAction *action : actionList) {
const QVariant &actionType = action->property("actionType");
if (!actionType.isNull() && actionType.toInt() == KPeople::ActionType::TextChatAction) {
......
......@@ -93,8 +93,8 @@ QVariant RunnerMatchesModel::data(const QModelIndex &index, int role) const
return match.runner()->id() == QLatin1String("services") || !runner->actions().isEmpty();
} else if (role == Kicker::ActionListRole) {
QVariantList actionList;
foreach (QAction *action, m_runnerManager->actionsForMatch(match)) {
const QList<QAction *> actions = m_runnerManager->actionsForMatch(match);
for (QAction *action : actions) {
QVariantMap item = Kicker::createActionItem(action->text(), action->icon().name(), QStringLiteral("runnerAction"),
QVariant::fromValue<QObject *>(action));
......
......@@ -215,7 +215,7 @@ void RunnerModel::matchesChanged(const QList<Plasma::QueryMatch> &matches)
// We do not use a QMultiHash here because it keeps values in LIFO order, while we want FIFO.
QHash<QString, QList<Plasma::QueryMatch> > matchesForRunner;
foreach (const Plasma::QueryMatch &match, matches) {
for (const Plasma::QueryMatch &match : matches) {
auto it = matchesForRunner.find(match.runner()->id());
if (it == matchesForRunner.end()) {
......
......@@ -129,7 +129,7 @@ InteractiveConsole::InteractiveConsole(QWidget *parent)
editorLayout->addWidget(toolBar);
const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KTextEditor/Document"));
foreach (const KService::Ptr &service, offers) {
for (const KService::Ptr &service : offers) {
m_editorPart = service->createInstance<KTextEditor::Document>(widget);
if (m_editorPart) {
m_editorPart->setHighlightingMode(QStringLiteral("JavaScript/PlasmaDesktop"));
......
......@@ -311,7 +311,7 @@ void PlasmaAppletItemModel::populateModel(const QStringList &whatChanged)
void PlasmaAppletItemModel::setRunningApplets(const QHash<QString, int> &apps)
{
//foreach item, find that string and set the count
//for each item, find that string and set the count
for (int r = 0; r < rowCount(); ++r) {
QStandardItem *i = item(r);
PlasmaAppletItem *p = dynamic_cast<PlasmaAppletItem *>(i);
......@@ -373,7 +373,7 @@ QMimeData *PlasmaAppletItemModel::mimeData(const QModelIndexList &indexes) const
QByteArray appletNames;
int lastRow = -1;
foreach (const QModelIndex &index, indexes) {
for (const QModelIndex &index : indexes) {
if (index.row() == lastRow) {
continue;
}
......
......@@ -138,7 +138,6 @@ void WidgetExplorerPrivate::initFilters()
typedef QPair<QString, QString> catPair;
QMap<QString, catPair > categories;
QSet<QString> existingCategories = itemModel.categories();
//foreach (const QString &category, Plasma::Applet::listCategories(application)) {
QStringList cats;
const QList<KPluginMetaData> list = PluginLoader::self()->listAppletMetaData(QString());
......@@ -157,7 +156,7 @@ void WidgetExplorerPrivate::initFilters()
}
}
qWarning() << "TODO: port listCategories()";
foreach (const QString &category, cats) {
for (const QString &category : qAsConst(cats)) {
const QString lowerCaseCat = category.toLower();
if (existingCategories.contains(lowerCaseCat)) {
const QString trans = i18nd("libplasma5", category.toLocal8Bit());
......@@ -165,7 +164,7 @@ void WidgetExplorerPrivate::initFilters()
}
}
foreach (const catPair &category, categories) {
for (const catPair &category : qAsConst(categories)) {
filterModel.addFilter(category.first,
KCategorizedItemsViewModels::Filter(QStringLiteral("category"), category.second));
}
......@@ -525,10 +524,10 @@ void WidgetExplorer::uninstall(const QString &pluginName)
if (corona()) {
const auto &containments = corona()->containments();
foreach (Containment *c, containments) {
for(Containment *c : containments) {
const auto &applets = c->applets();
foreach (Applet *applet, applets) {
for (Applet *applet : applets) {
const auto &appletInfo = applet->pluginMetaData();
if (appletInfo.isValid() && appletInfo.pluginId() == pluginName) {
......
......@@ -49,7 +49,8 @@ QList<QAction*> AppLauncher::contextualActions()
void AppLauncher::makeMenu(QMenu *menu, const KServiceGroup::Ptr group)
{
foreach (KSycocaEntry::Ptr p, group->entries(true, true, true)) {
const auto entries = group->entries(true, true, true);
for (const KSycocaEntry::Ptr &p : entries ) {
if (p->isType(KST_KService)) {
const KService::Ptr service(static_cast<KService*>(p.data()));
......
......@@ -93,7 +93,7 @@ void ContextMenu::restore(const KConfigGroup &config)
disabled.insert(QStringLiteral("configure shortcuts"));
}
foreach (const QString &name, m_actionOrder) {
for (const QString &name : qAsConst(m_actionOrder)) {
actions.insert(name, !disabled.contains(name));
}
......
......@@ -44,9 +44,9 @@ void ActivityEngine::init()
} else {
m_activityController = new KActivities::Controller(this);
m_currentActivity = m_activityController->currentActivity();
QStringList activities = m_activityController->activities();
const QStringList activities = m_activityController->activities();
//setData("allActivities", activities);
foreach (const QString &id, activities) {
for (const QString &id : activities) {
insertActivity(id);
}
......@@ -160,7 +160,7 @@ void ActivityEngine::setActivityScores(const ActivityDataList &activities)
QSet<QString> presentActivities;
m_activityScores.clear();
foreach (const ActivityData &activity, activities) {
for (const ActivityData &activity : activities) {
if (m_activities.contains(activity.id)) {
setData(activity.id, QStringLiteral("Score"), activity.score);
}
......@@ -168,7 +168,8 @@ void ActivityEngine::setActivityScores(const ActivityDataList &activities)
m_activityScores[activity.id] = activity.score;
}
foreach (const QString &activityId, m_activityController->activities()) {
const auto controllerActivities = m_activityController->activities();
for (const QString &activityId : controllerActivities) {
if (!presentActivities.contains(activityId) && m_activities.contains(activityId)) {
setData(activityId, QStringLiteral("Score"), 0);
}
......
......@@ -71,7 +71,8 @@ void AppSource::updateGroup()
setData(QStringLiteral("display"), !m_group->noDisplay());
QStringList entries;
foreach (KSycocaEntry::Ptr p, m_group->entries(true, false, true)) {
const auto groupEntries = m_group->entries(true, false, true);
for (const KSycocaEntry::Ptr &p : groupEntries) {
if (p->isType(KST_KService)) {
const KService::Ptr service(static_cast<KService*>(p.data()));
entries << service->storageId();
......
......@@ -189,7 +189,7 @@ void KSolidNotify::onSolidReply(SolidReplyType type, Solid::ErrorType error, con
if (type == SolidReplyType::Eject) {
QString discUdi;
foreach (Solid::Device device, m_devices) {
for (Solid::Device device : qAsConst(m_devices)) {
if (device.parentUdi() == udi) {
discUdi = device.udi();
}
......
......@@ -52,7 +52,7 @@ void Geolocation::init()
const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/GeolocationProvider"));
QVariantList args;
Q_FOREACH (const KService::Ptr &service, offers) {
for (const KService::Ptr &service : offers) {
QString error;
GeolocationProvider *plugin = service->createInstance<GeolocationProvider>(nullptr, args, &error);
if (plugin) {
......@@ -91,7 +91,7 @@ bool Geolocation::updatePlugins(GeolocationProvider::UpdateTriggers triggers)
{
bool changed = false;
Q_FOREACH (GeolocationProvider *plugin, m_plugins) {
for (GeolocationProvider *plugin : qAsConst(m_plugins)) {
changed = plugin->requestUpdate(triggers) || changed;
}
......@@ -130,7 +130,7 @@ void Geolocation::pluginAvailabilityChanged(GeolocationProvider *provider)
provider->requestUpdate(GeolocationProvider::ForcedUpdate);
bool changed = false;
Q_FOREACH (GeolocationProvider *plugin, m_plugins) {
for (GeolocationProvider *plugin : qAsConst(m_plugins)) {
changed = plugin->populateSharedData() || changed;
}
......
......@@ -48,7 +48,7 @@ HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& args)
{
const QStringList folders = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("solid/actions"), QStandardPaths::LocateDirectory);
foreach (const QString &folder, folders) {
for (const QString &folder : folders) {
m_dirWatch->addDir(folder, KDirWatch::WatchFiles);
}
connect(m_dirWatch, &KDirWatch::created, this, &HotplugEngine::updatePredicates);
......@@ -73,8 +73,8 @@ void HotplugEngine::init()
p |= Solid::Predicate(Solid::DeviceInterface::OpticalDisc);
p |= Solid::Predicate(Solid::DeviceInterface::PortableMediaPlayer);
p |= Solid::Predicate(Solid::DeviceInterface::Camera);
QList<Solid::Device> devices = Solid::Device::listFromQuery(p);
foreach (const Solid::Device &dev, devices) {
const QList<Solid::Device> devices = Solid::Device::listFromQuery(p);
for (const Solid::Device &dev : devices) {
m_startList.insert(dev.udi(), dev);
}
......@@ -114,14 +114,14 @@ void HotplugEngine::findPredicates()
m_predicates.clear();
QStringList files;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("solid/actions"), QStandardPaths::LocateDirectory);
Q_FOREACH (const QString& dir, dirs) {
for (const QString& dir : dirs) {
QDirIterator it(dir, QStringList() << QStringLiteral("*.desktop"));
while (it.hasNext()) {
files.prepend(it.next());
}
}
//qDebug() << files;
foreach (const QString &path, files) {
for (const QString &path : qAsConst(files)) {
KDesktopFile cfg(path);
const QString string_predicate = cfg.desktopGroup().readEntry("X-KDE-Solid-Predicate");
//qDebug() << path << string_predicate;
......
......@@ -64,9 +64,8 @@ SetPreviewWidget::SetPreviewWidget(QWidget *parent) : QFrame(parent)
labelSelection7->setBackgroundRole(QPalette::Highlight);
*/
QList<QWidget*> widgets = findChildren<QWidget*>();
foreach (QWidget* widget, widgets)
{
const QList<QWidget*> widgets = findChildren<QWidget*>();
for (QWidget* widget : widgets) {
widget->installEventFilter(this);
widget->setFocusPolicy(Qt::NoFocus);
}
......
......@@ -274,8 +274,8 @@ bool CursorThemeModel::isCursorTheme(const QString &theme, const int depth)
// Recurse through the list of inherited themes, to check if one of them
// is a cursor theme.
QStringList inherits = cg.readEntry("Inherits", QStringList());
foreach (const QString &inherit, inherits)
const QStringList inherits = cg.readEntry("Inherits", QStringList());
for (const QString &inherit : inherits)
{
// Avoid possible DoS
if (inherit == theme)
......
......@@ -581,8 +581,8 @@ QDir KCMLookandFeel::cursorThemeDir(const QString &theme, const int depth)
// Recurse through the list of inherited themes, to check if one of them
// is a cursor theme.
QStringList inherits = cg.readEntry("Inherits", QStringList());
foreach (const QString &inherit, inherits) {
const QStringList inherits = cg.readEntry("Inherits", QStringList());
for(const QString &inherit : inherits) {
// Avoid possible DoS
if (inherit == theme) {
continue;
......
......@@ -88,7 +88,7 @@ void ActionsWidget::setActionList(const ActionList& list)
qDeleteAll( m_actionList );
m_actionList.clear();
foreach (ClipAction* action, list) {
for (ClipAction* action : list) {
if (!action) {
qCDebug(KLIPPER_LOG) << "action is null!";
continue;
......
......@@ -671,16 +671,17 @@ QString defaultApplication(const QUrl &url)
return service->storageId();
} else {
// Try the files in share/apps/kcm_componentchooser/*.desktop.
QStringList directories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory);
const QStringList directories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory);
QStringList services;
foreach(const QString& directory, directories) {
for (const QString& directory : directories) {
QDir dir(directory);
foreach(const QString& f, dir.entryList(QStringList("*.desktop")))
const QStringList desktopFiles = dir.entryList(QStringList("*.desktop"));
for (const QString& f : desktopFiles)
services += dir.absoluteFilePath(f);
}
foreach (const QString & service, services) {
for (const QString &service : qAsConst(services)) {
KConfig config(service, KConfig::SimpleConfig);
KConfigGroup cg = config.group(QByteArray());
const QString type = cg.readEntry("valueName", QString());
......
......@@ -641,14 +641,15 @@ void WaylandTasksModel::requestVirtualDesktops(const QModelIndex &index, const Q
KWayland::Client::PlasmaWindow *window = d->windows.at(index.row());
if (desktops.isEmpty()) {
foreach (const QVariant &desktop, window->plasmaVirtualDesktops()) {
window->requestLeaveVirtualDesktop(desktop.toString());
const QStringList virtualDesktops = window->plasmaVirtualDesktops();
for (const QString &desktop : virtualDesktops) {
window->requestLeaveVirtualDesktop(desktop);
}
} else {
const QStringList &now = window->plasmaVirtualDesktops();
QStringList next;
foreach (const QVariant &desktop, desktops) {
for (const QVariant &desktop : desktops) {
const QString &desktopId = desktop.toString();
if (!desktopId.isEmpty()) {
......@@ -660,7 +661,7 @@ void WaylandTasksModel::requestVirtualDesktops(const QModelIndex &index, const Q
}
}
foreach (const QString &desktop, now) {
for (const QString &desktop : now) {
if (!next.contains(desktop)) {
window->requestLeaveVirtualDesktop(desktop);
}
......
......@@ -36,7 +36,7 @@ HolidaysEventsPlugin::HolidaysEventsPlugin(QObject *parent)
regionCodes << KHolidays::HolidayRegion::defaultRegionCode();
}
Q_FOREACH (const QString &region, regionCodes) {
for (const QString &region : qAsConst(regionCodes)) {
m_regions << new KHolidays::HolidayRegion(region);
}
}
......@@ -56,10 +56,10 @@ void HolidaysEventsPlugin::loadEventsForDateRange(const QDate &startDate, const
m_lastData.clear();
QMultiHash<QDate, CalendarEvents::EventData> data;
Q_FOREACH (KHolidays::HolidayRegion *region, m_regions) {
KHolidays::Holiday::List holidays = region->holidays(startDate, endDate);
for (KHolidays::HolidayRegion *region : qAsConst(m_regions)) {
const KHolidays::Holiday::List holidays = region->holidays(startDate, endDate);
Q_FOREACH (const KHolidays::Holiday &holiday, holidays) {
for (const KHolidays::Holiday &holiday : holidays) {
CalendarEvents::EventData eventData;
eventData.setStartDateTime(holiday.observedStartDate().startOfDay());
eventData.setEndDateTime(holiday.observedEndDate().endOfDay());
......
......@@ -137,9 +137,8 @@ PlasmaQuick::ConfigModel *ContainmentConfigView::containmentPluginsConfigModel()
if (!m_containmentPluginsConfigModel) {
m_containmentPluginsConfigModel = new PlasmaQuick::ConfigModel(this);
KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentsOfType(QStringLiteral("Desktop"));
foreach (const KPluginInfo &info, actions) {
const KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentsOfType(QStringLiteral("Desktop"));
for (const KPluginInfo &info : actions) {
m_containmentPluginsConfigModel->appendCategory(info.icon(), info.name(), QString(), info.pluginName());
}
......
......@@ -219,7 +219,7 @@ QStringList AppInterface::knownContainmentTypes(const QString &type) const
const KPluginInfo::List infoLs = Plasma::PluginLoader::listContainmentsOfType(type);
containments.reserve(infoLs.count());
foreach (const KPluginInfo &info, infoLs) {
for (const KPluginInfo &info : infoLs) {
containments.append(info.pluginName());
}
......
......@@ -75,7 +75,7 @@ void Applet::setCurrentConfigGroup(const QStringList &groupNames)
d->configGroup = app->config();
d->configGroupPath = groupNames;
foreach (const QString &groupName, groupNames) {
for (const QString &groupName : groupNames) {
d->configGroup = KConfigGroup(&d->configGroup, groupName);
}
......@@ -156,7 +156,7 @@ void Applet::setCurrentGlobalConfigGroup(const QStringList &groupNames)
d->globalConfigGroup = app->globalConfig();
d->globalConfigGroupPath = groupNames;
foreach (const QString &groupName, groupNames) {
for (const QString &groupName : groupNames) {
d->globalConfigGroup = KConfigGroup(&d->globalConfigGroup, groupName);
}
}
......
......@@ -30,7 +30,7 @@ SolidAutoEject::SolidAutoEject(QObject* parent, const QList<QVariant>&)
: KDEDModule(parent)
{
const QList<Solid::Device> drives = Solid::Device::listFromType(Solid::DeviceInterface::OpticalDrive);
foreach (const Solid::Device &drive, drives) {
for (const Solid::Device &drive : drives) {
connectDevice(drive);
}
......
......@@ -68,11 +68,11 @@ AutoStart::loadAutoStartList()
// Make unique list of relative paths
QHash<QString, QString> files;
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QStringLiteral("autostart"), QStandardPaths::LocateDirectory);
Q_FOREACH (const QString &dir, dirs) {
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QStringLiteral("autostart"), QStandardPaths::LocateDirectory);
for (const QString &dir : dirs) {
const QDir d(dir);
const QStringList fileNames = d.entryList(QStringList() << QStringLiteral("*.desktop"));
Q_FOREACH (const QString &file, fileNames) {
for (const QString &file : fileNames) {
if (!files.contains(file)) {
files.insert(file, d.absoluteFilePath(file));
}
......
......@@ -142,7 +142,7 @@ void BackgroundListModel::processPaths(const QStringList &paths)
QList<KPackage::Package> newPackages;
newPackages.reserve(paths.count());
Q_FOREACH (QString file, paths) {
for (QString file : paths) {
// check if the path is a symlink and if it is,
// work with the target rather than the symlink
QFileInfo info(file);
......@@ -184,7 +184,7 @@ void BackgroundListModel::processPaths(const QStringList &paths)
}
// add new files to dirwatch
Q_FOREACH (const KPackage::Package &b, newPackages) {
for (const KPackage::Package &b : qAsConst(newPackages)) {
if (!m_dirwatch.contains(b.path())) {
m_dirwatch.addDir(b.path());
}
......@@ -498,9 +498,11 @@ QStringList BackgroundFinder::suffixes()
QSet<QString> suffixes;
QMimeDatabase db;
Q_FOREACH (const QByteArray &mimeType, QImageReader::supportedMimeTypes()) {
const auto supportedMimeTypes = QImageReader::supportedMimeTypes();
for (const QByteArray &mimeType : supportedMimeTypes) {
QMimeType mime(db.mimeTypeForName(mimeType));
Q_FOREACH (const QString &pattern, mime.globPatterns()) {
const QStringList globPatterns = mime.globPatterns();
for (const QString &pattern : globPatterns) {
suffixes.insert(pattern);
}
}
......@@ -536,7 +538,7 @@ void BackgroundFinder::run()
const QString path = m_paths.at(i);
dir.setPath(path);
const QFileInfoList files = dir.entryInfoList();
Q_FOREACH (const QFileInfo &wp, files) {
for (const QFileInfo &wp : files) {
if (wp.isDir()) {
//qCDebug(IMAGEWALLPAPER) << "scanning directory" << wp.fileName();
......
......@@ -217,7 +217,7 @@ QString Image::findPreferedImage(const QStringList &images)
float best = FLT_MAX;
QString bestImage;
foreach (const QString &entry, images) {
for (const QString &entry : images) {
QSize candidate = resSize(QFileInfo(entry).baseName());
if (candidate == QSize()) {
continue;
......@@ -557,7 +557,7 @@ void Image::setSingleImage()
void Image::addUrls(const QList<QUrl> &urls)
{
bool first = true;
Q_FOREACH (const QUrl &url, urls) {
for (const QUrl &url : urls) {
// set the first drop as the current paper, just add the rest to the roll
addUrl(url, first);
first = false;
......
......@@ -57,7 +57,7 @@ void SlideModel::removeDir(const QString &path)
void SlideModel::removeBackgrounds(const QStringList &paths, const QString &token)
{
Q_FOREACH (const QString &file, paths) {
for (const QString &file : paths) {
removeBackground(file);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment