Commit 869ccf43 authored by Laurent Montel's avatar Laurent Montel 😁

Port for(...:...)

parent 94bd3ea4
......@@ -24,6 +24,7 @@
#include "job/contactgroupexpandjob.h"
#include "standardcontactgroupformatter.h"
#include "textbrowser_p.h"
#include "helper_p.h"
#include <collectionfetchjob.h>
#include <entitydisplayattribute.h>
......@@ -72,7 +73,7 @@ public:
KContacts::ContactGroup group;
group.setName(mCurrentGroupName);
foreach (const KContacts::Addressee &contact, mCurrentContacts) {
for (const KContacts::Addressee &contact : qAsConst(mCurrentContacts)) {
group.append(KContacts::ContactGroup::Data(contact.realName(), contact.preferredEmail()));
}
......
......@@ -26,6 +26,7 @@
#include "customfieldmanager_p.h"
#include "standardcontactformatter.h"
#include "textbrowser_p.h"
#include "helper_p.h"
#include "editor/im/improtocols.h"
#include <KIOCore/kio/transferjob.h>
#include <collection.h>
......@@ -170,11 +171,11 @@ public:
QVector<QVariantMap> customFieldDescriptions;
const CustomField::List globalCustomFields = CustomFieldManager::globalCustomFieldDescriptions();
customFieldDescriptions.reserve(localCustomFieldDescriptions.count() + globalCustomFields.count());
foreach (const QVariant &entry, localCustomFieldDescriptions) {
for (const QVariant &entry : qAsConst(localCustomFieldDescriptions)) {
customFieldDescriptions << entry.toMap();
}
foreach (const CustomField &field, globalCustomFields) {
for (const CustomField &field : qAsConst(globalCustomFields)) {
QVariantMap description;
description.insert(QStringLiteral("key"), field.key());
description.insert(QStringLiteral("title"), field.title());
......
......@@ -32,7 +32,7 @@ void CustomFieldManager::setGlobalCustomFieldDescriptions(const CustomField::Lis
KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
group.deleteGroup();
foreach (const CustomField &field, customFields) {
for (const CustomField &field : customFields) {
const QString key = field.key();
const QString value = CustomField::typeToString(field.type()) + QLatin1Char(':') + field.title();
......@@ -49,7 +49,7 @@ CustomField::List CustomFieldManager::globalCustomFieldDescriptions()
const QStringList keys = group.keyList();
customFields.reserve(keys.count());
foreach (const QString &key, keys) {
for (const QString &key : keys) {
CustomField field;
field.setKey(key);
field.setScope(CustomField::GlobalScope);
......
......@@ -182,7 +182,7 @@ void AddressLocationWidget::fillCountryCombo()
QStringList countries;
const QList<QLocale> localeList = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
countries.reserve(localeList.count());
foreach (const QLocale &locale, localeList) {
for (const QLocale &locale : localeList) {
const QString localeStr = QLocale::countryToString(locale.country());
if (countries.contains(localeStr)) {
continue;
......
......@@ -25,6 +25,7 @@
#include "personaleditor/personaleditorwidget.h"
#include "contacteditorpageplugin.h"
#include "contactmetadata_p.h"
#include "helper_p.h"
#include <kconfig.h>
#include <kconfiggroup.h>
......@@ -169,7 +170,7 @@ void ContactEditorWidget::Private::loadCustomPages()
mCustomPages.append(plugin);
}
foreach (Akonadi::ContactEditorPagePlugin *plugin, mCustomPages) {
for (Akonadi::ContactEditorPagePlugin *plugin : qAsConst(mCustomPages)) {
mTabWidget->addTab(plugin, plugin->title());
}
}
......@@ -227,7 +228,7 @@ void ContactEditorWidget::loadContact(const KContacts::Addressee &contact, const
d->mCustomFieldsWidget->loadContact(contact);
// custom pages
foreach (Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages) {
for (Akonadi::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) {
plugin->loadContact(contact);
}
}
......@@ -255,7 +256,7 @@ void ContactEditorWidget::storeContact(KContacts::Addressee &contact, Akonadi::C
metaData.setDisplayNameMode(d->mGeneralInfoWidget->displayType());
// custom pages
foreach (Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages) {
for (Akonadi::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) {
plugin->storeContact(contact);
}
}
......@@ -279,7 +280,7 @@ void ContactEditorWidget::setReadOnly(bool readOnly)
d->mCustomFieldsWidget->setReadOnly(readOnly);
// custom pages
foreach (Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages) {
for (Akonadi::ContactEditorPagePlugin *plugin : qAsConst(d->mCustomPages)) {
plugin->setReadOnly(readOnly);
}
}
......
......@@ -22,6 +22,7 @@
#include "customfieldslistwidget.h"
#include "../utils/utils.h"
#include "helper_p.h"
#include "customfieldmanager_p.h"
#include "customfieldslistdelegate.h"
#include <QSortFilterProxyModel>
......@@ -64,7 +65,7 @@ void CustomFieldsListWidget::loadContact(const KContacts::Addressee &contact)
CustomField::List globalCustomFields = CustomFieldManager::globalCustomFieldDescriptions();
const QStringList customs = contact.customs();
foreach (const QString &custom, customs) {
for (const QString &custom : customs) {
QString app, name, value;
Akonadi::Utils::splitCustomField(custom, app, name, value);
......@@ -163,11 +164,11 @@ void CustomFieldsListWidget::storeContact(KContacts::Addressee &contact) const
// Now remove all fields that were available in loadContact (these are stored in mLocalCustomFields)
// but are not part of customFields now, which means they have been removed or renamed by the user
// in the editor dialog.
foreach (const CustomField &oldCustomField, mLocalCustomFields) {
for (const CustomField &oldCustomField : qAsConst(mLocalCustomFields)) {
if (oldCustomField.scope() != CustomField::ExternalScope) {
bool fieldStillExists = false;
foreach (const CustomField &newCustomField, customFields) {
for (const CustomField &newCustomField : qAsConst(customFields)) {
if (newCustomField.scope() != CustomField::ExternalScope) {
if (newCustomField.key() == oldCustomField.key()) {
fieldStillExists = true;
......@@ -184,7 +185,7 @@ void CustomFieldsListWidget::storeContact(KContacts::Addressee &contact) const
// And store the global custom fields descriptions as well
CustomField::List globalCustomFields;
foreach (const CustomField &customField, customFields) {
for (const CustomField &customField : qAsConst(customFields)) {
if (customField.scope() == CustomField::GlobalScope) {
globalCustomFields << customField;
}
......
......@@ -52,7 +52,7 @@ void CategoriesEditWidget::loadContact(const KContacts::Addressee &contact)
const QStringList categories = contact.categories();
tags.reserve(categories.count());
foreach (const QString &category, categories) {
for (const QString &category : categories) {
tags.append(Akonadi::Tag::fromUrl(QUrl(category)));
}
......@@ -65,7 +65,7 @@ void CategoriesEditWidget::storeContact(KContacts::Addressee &contact) const
const Akonadi::Tag::List tags = mTagWidget->selection();
categories.reserve(tags.count());
foreach (const Akonadi::Tag &tag, tags) {
for (const Akonadi::Tag &tag : tags) {
categories.append(tag.url().url());
}
......
......@@ -20,6 +20,7 @@
*/
#include "displaynameeditwidget.h"
#include "helper_p.h"
#include <QtCore/QEvent>
#include <QAbstractItemView>
......@@ -68,7 +69,7 @@ public:
QFont font = view->font();
font.setStyle(QFont::StyleItalic);
QFontMetrics metrics(font);
foreach (const QString &description, mDescriptions) {
for (const QString &description : qAsConst(mDescriptions)) {
mMaxDescriptionWidth = qMax(mMaxDescriptionWidth, metrics.width(description));
}
......
......@@ -52,7 +52,7 @@ MessagingWidget::MessagingWidget(QWidget *parent)
layout->addWidget(mProtocolCombo);
const QStringList protocols = IMProtocols::self()->protocols();
foreach (const QString &protocol, protocols) {
for (const QString &protocol : protocols) {
mProtocolCombo->addItem(QIcon::fromTheme(IMProtocols::self()->icon(protocol)),
IMProtocols::self()->name(protocol),
protocol);
......
......@@ -25,6 +25,7 @@
#include "../../im/imaddress.h"
#include "../../im/improtocols.h"
#include "../../utils/utils.h"
#include "helper_p.h"
#include <KContacts/Addressee>
using namespace Akonadi;
......@@ -47,7 +48,7 @@ void MessagingWidgetLister::loadContact(const KContacts::Addressee &contact)
IMAddress::List imaddresses;
const QStringList customs = contact.customs();
foreach (const QString &custom, customs) {
for (const QString &custom : customs) {
QString app, name, value;
Akonadi::Utils::splitCustomField(custom, app, name, value);
......@@ -56,7 +57,7 @@ void MessagingWidgetLister::loadContact(const KContacts::Addressee &contact)
const QString protocol = app;
const QStringList names = value.split(QChar(0xE000), QString::SkipEmptyParts);
foreach (const QString &name, names) {
for (const QString &name : names) {
//TODO preferred support ?
imaddresses << IMAddress(protocol, name, false);
}
......@@ -90,12 +91,13 @@ void MessagingWidgetLister::storeContact(KContacts::Addressee &contact) const
QMap<QString, QStringList> protocolMap;
// fill map with all known protocols
foreach (const QString &protocol, IMProtocols::self()->protocols()) {
const QStringList lstProtocols = IMProtocols::self()->protocols();
for (const QString &protocol : lstProtocols) {
protocolMap.insert(protocol, QStringList());
}
// add the configured addresses
foreach (const IMAddress &address, imaddresses) {
for (const IMAddress &address : qAsConst(imaddresses)) {
protocolMap[address.protocol()].append(address.name());
}
......
......@@ -31,7 +31,7 @@
*/
#include "kwidgetlister_p.h"
#include "helper_p.h"
#include <QHBoxLayout>
#include <QPushButton>
......@@ -116,7 +116,7 @@ void KWidgetLister::slotClear()
setNumberOfShownWidgetsTo(d->mMinWidgets);
// clear remaining widgets
foreach (QWidget *widget, d->mWidgetList) {
for (QWidget *widget : qAsConst(d->mWidgetList)) {
clearWidget(widget);
}
......
......@@ -206,7 +206,7 @@ EmailAddressSelection::List EmailAddressSelectionWidget::selectedAddresses() con
}
const QModelIndexList selectedRows = d->mView->selectionModel()->selectedRows(0);
foreach (const QModelIndex &index, selectedRows) {
for (const QModelIndex &index : selectedRows) {
EmailAddressSelection selection;
selection.d->mName = index.data(EmailAddressSelectionProxyModel::NameRole).toString();
selection.d->mEmailAddress = index.data(EmailAddressSelectionProxyModel::EmailAddressRole).toString();
......
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef _HELPER_H
#define _HELPER_H
#include <qglobal.h>
#if QT_VERSION < QT_VERSION_CHECK(5,7,0)
namespace QtPrivate
{
template <typename T> struct QAddConst {
typedef const T Type;
};
}
// this adds const to non-const objects (like std::as_const)
template <typename T>
Q_DECL_CONSTEXPR typename QtPrivate::QAddConst<T>::Type &qAsConst(T &t) Q_DECL_NOTHROW { return t; }
// prevent rvalue arguments:
template <typename T>
void qAsConst(const T &&) Q_DECL_EQ_DELETE;
#endif
#endif
......@@ -92,8 +92,8 @@ void ContactGroupSearchJob::setLimit(int limit)
KContacts::ContactGroup::List ContactGroupSearchJob::contactGroups() const
{
KContacts::ContactGroup::List contactGroups;
foreach (const Item &item, items()) {
const Akonadi::Item::List lstItems = items();
for (const Item &item : lstItems) {
if (item.hasPayload<KContacts::ContactGroup>()) {
contactGroups.append(item.payload<KContacts::ContactGroup>());
}
......
......@@ -96,7 +96,8 @@ KContacts::Addressee::List ContactSearchJob::contacts() const
{
KContacts::Addressee::List contacts;
foreach (const Item &item, items()) {
const Akonadi::Item::List lstItems = items();
for (const Item &item : lstItems) {
if (item.hasPayload<KContacts::Addressee>()) {
contacts.append(item.payload<KContacts::Addressee>());
}
......
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