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

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;
......
Supports Markdown
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