Commit e31b3036 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port more foreach

parent cd6126b5
Pipeline #82072 canceled with stage
......@@ -62,7 +62,7 @@ template<> char *toString(const KCalendarCore::Attendee &at)
template<> char *toString(const QList<int> &l)
{
QByteArray ba = "QList<int>(";
foreach (int i, l) {
for (int i : l) {
ba += QByteArray::number(i) + ", ";
}
ba += ")";
......@@ -72,7 +72,7 @@ template<> char *toString(const QList<int> &l)
template<> char *toString(const QList<KCalendarCore::RecurrenceRule::WDayPos> &l)
{
QByteArray ba = "QList<int>(";
foreach (const KCalendarCore::RecurrenceRule::WDayPos &i, l) {
for (const KCalendarCore::RecurrenceRule::WDayPos &i : l) {
ba += QByteArray::number(i.pos()) + " ";
ba += QByteArray::number(i.day()) + ", ";
}
......@@ -93,7 +93,7 @@ template<> char *toString(const KCalendarCore::DateList &l)
template<> char *toString(const KCalendarCore::DateTimeList &l)
{
QByteArray ba = "KCalendarCore::DateTimeList(";
foreach (const QDateTime &i, l) {
for (const QDateTime &i : l) {
ba += toString(i);
}
ba += ")";
......
......@@ -315,7 +315,7 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
d->mDictionary.clear();
const std::vector<std::string> entries = dictionary.entries();
d->mDictionary.reserve(entries.size());
foreach (const std::string &entry, entries) {
for (const std::string &entry : entries) {
d->mDictionary.append(Conversion::fromStdString(entry));
}
d->mDictionaryLanguage = Conversion::fromStdString(dictionary.language());
......@@ -553,7 +553,7 @@ KMime::Message::Ptr KolabObjectWriter::writeDictionary(const QStringList &entrie
Kolab::Dictionary dictionary(Conversion::toStdString(lang));
std::vector<std::string> ent;
ent.reserve(entries.count());
foreach (const QString &e, entries) {
for (const QString &e : entries) {
ent.push_back(Conversion::toStdString(e));
}
dictionary.setEntries(ent);
......@@ -592,7 +592,7 @@ KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const Q
Kolab::Relation relation(Conversion::toStdString(tag.name()), "tag");
std::vector<std::string> m;
m.reserve(members.count());
foreach (const QString &member, members) {
for (const QString &member : members) {
m.push_back(Conversion::toStdString(member));
}
relation.setMembers(m);
......
......@@ -228,7 +228,7 @@ public:
static std::vector<Kolab::Attachment> getAttachments(const std::vector<Kolab::Attachment> &attachments, const KMime::Message::Ptr &msg)
{
std::vector<Kolab::Attachment> allAttachments;
foreach (const Kolab::Attachment &attachment, attachments) {
for (const Kolab::Attachment &attachment : attachments) {
if (!attachment.uri().empty()) {
const Kolab::Attachment extracted = Mime::getAttachment(attachment.uri(), msg);
if (extracted.isValid()) {
......@@ -244,7 +244,7 @@ static std::vector<Kolab::Attachment> getAttachments(const std::vector<Kolab::At
static std::vector<Kolab::Attachment> getAttachments(const QStringList &attachmentNames, const KMime::Message::Ptr &msg)
{
std::vector<Kolab::Attachment> allAttachments;
foreach (const QString &name, attachmentNames) {
for (const QString &name : attachmentNames) {
const Kolab::Attachment extracted = Mime::getAttachmentByName(name, msg);
if (extracted.isValid()) {
allAttachments.push_back(extracted);
......@@ -499,7 +499,7 @@ static std::string createCid()
std::vector<Kolab::Attachment> convertToReferences(const std::vector<Kolab::Attachment> &attachments, std::vector<std::string> &attachmentCids)
{
std::vector<Kolab::Attachment> attachmentsWithReferences;
Q_FOREACH (const Kolab::Attachment &a, attachments) {
for (const Kolab::Attachment &a : attachments) {
Kolab::Attachment attachment;
attachment.setLabel(a.label());
const std::string cid = a.uri().empty() ? createCid() : a.uri();
......@@ -520,7 +520,7 @@ template<class T> static T convertAttachmentsToReferences(const T &incidence, st
static void addAttachments(KMime::Message::Ptr msg, const std::vector<Attachment> &attachments, std::vector<std::string> &attachmentCids)
{
int index = 0;
foreach (const Attachment &attachment, attachments) {
for (const Attachment &attachment : attachments) {
const std::string data = attachment.data();
const std::string cid = attachmentCids.empty() ? attachment.uri() : attachmentCids.at(index);
msg->addContent(Mime::createAttachmentPart(Mime::fromCid(QString::fromStdString(cid.c_str())).toLatin1(),
......
......@@ -281,7 +281,7 @@ void CollectionFetchTest::testMixedTree()
QCOMPARE(collections.count(), firstLevelNames.count());
QCOMPARE(job->collections(), collections);
Q_FOREACH (const Collection &collection, collections) {
for (const Collection &collection : std::as_const(collections)) {
QVERIFY(!collection.remoteId().isEmpty());
QCOMPARE(collection.remoteId(), collection.name());
QCOMPARE(collection.contentMimeTypes(), QStringList() << Collection::mimeType() << KMime::Message::mimeType());
......@@ -307,7 +307,7 @@ void CollectionFetchTest::testMixedTree()
QCOMPARE(collections.count(), firstLevelNames.count() + secondLevelNames.count() + thirdLevelNames.count());
QCOMPARE(job->collections(), collections);
Q_FOREACH (const Collection &collection, collections) {
for (const Collection &collection : std::as_const(collections)) {
QVERIFY(!collection.remoteId().isEmpty());
QCOMPARE(collection.remoteId(), collection.name());
QCOMPARE(collection.contentMimeTypes(), QStringList() << Collection::mimeType() << KMime::Message::mimeType());
......@@ -328,7 +328,7 @@ void CollectionFetchTest::testMixedTree()
}
// test base fetching all collections
Q_FOREACH (const Collection &collection, collections) {
for (const Collection &collection : std::as_const(collections)) {
job = mStore->fetchCollections(collection, FileStore::CollectionFetchJob::Base);
spy = new QSignalSpy(job, &FileStore::CollectionFetchJob::collectionsReceived);
......@@ -353,7 +353,7 @@ void CollectionFetchTest::testMixedTree()
}
// test first level fetching all collections
Q_FOREACH (const Collection &collection, collections) {
for (const Collection &collection : std::as_const(collections)) {
job = mStore->fetchCollections(collection, FileStore::CollectionFetchJob::FirstLevel);
spy = new QSignalSpy(job, &FileStore::CollectionFetchJob::collectionsReceived);
......@@ -364,7 +364,7 @@ void CollectionFetchTest::testMixedTree()
const Collection::List list = collectionsFromSpy(spy);
QCOMPARE(job->collections(), list);
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QCOMPARE(childCollection.parentCollection(), collection);
QVERIFY(!childCollection.remoteId().isEmpty());
......@@ -377,11 +377,11 @@ void CollectionFetchTest::testMixedTree()
}
if (firstLevelNames.contains(collection.name())) {
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QVERIFY(secondLevelNames.contains(childCollection.name()));
}
} else if (secondLevelNames.contains(collection.name())) {
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QVERIFY(thirdLevelNames.contains(childCollection.name()));
}
if (collection.name() == md1_2.name()) {
......@@ -396,7 +396,7 @@ void CollectionFetchTest::testMixedTree()
}
// test recursive fetching all collections
Q_FOREACH (const Collection &collection, collections) {
for (const Collection &collection : std::as_const(collections)) {
job = mStore->fetchCollections(collection, FileStore::CollectionFetchJob::Recursive);
spy = new QSignalSpy(job, &FileStore::CollectionFetchJob::collectionsReceived);
......@@ -407,7 +407,7 @@ void CollectionFetchTest::testMixedTree()
const Collection::List list = collectionsFromSpy(spy);
QCOMPARE(job->collections(), list);
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QVERIFY(childCollection.parentCollection() == collection || childCollection.parentCollection().parentCollection() == collection);
QVERIFY(!childCollection.remoteId().isEmpty());
QCOMPARE(childCollection.remoteId(), childCollection.name());
......@@ -419,11 +419,11 @@ void CollectionFetchTest::testMixedTree()
}
if (firstLevelNames.contains(collection.name())) {
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QVERIFY(secondLevelNames.contains(childCollection.name()) || thirdLevelNames.contains(childCollection.name()));
}
} else if (secondLevelNames.contains(collection.name())) {
Q_FOREACH (const Collection &childCollection, list) {
for (const Collection &childCollection : list) {
QVERIFY(thirdLevelNames.contains(childCollection.name()));
}
if (collection.name() == md1_2.name()) {
......
......@@ -398,7 +398,8 @@ void CollectionModifyTest::testIndexPreservation()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
for (const Item &item : std::as_const(items)) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......
......@@ -408,8 +408,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -523,8 +524,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -563,8 +565,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -654,8 +657,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -893,8 +897,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -936,8 +941,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -983,8 +989,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1030,8 +1037,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1074,8 +1082,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1118,8 +1127,9 @@ void CollectionMoveTest::testMoveToMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1228,8 +1238,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1275,8 +1286,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1329,8 +1341,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1397,8 +1410,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1419,8 +1433,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1436,8 +1451,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1503,8 +1519,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1525,8 +1542,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1542,8 +1560,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1589,8 +1608,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1631,8 +1651,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1673,8 +1694,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1715,8 +1737,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1759,8 +1782,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1802,8 +1826,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1849,8 +1874,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1896,8 +1922,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1940,8 +1967,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -1984,8 +2012,9 @@ void CollectionMoveTest::testMoveToMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 4);
Q_FOREACH (const Item &item, items) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
for (const Item &item : std::as_const(items)) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......
......@@ -257,7 +257,8 @@ void ItemCreateTest::testMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 5);
for (const Item &item : std::as_const(items)) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -301,7 +302,8 @@ void ItemCreateTest::testMBox()
items = itemFetch->items();
QCOMPARE((int)items.count(), 6);
for (const Item &item : std::as_const(items)) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -466,7 +468,8 @@ void ItemCreateTest::testMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 5);
for (const Item &item : std::as_const(items)) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......@@ -514,7 +517,8 @@ void ItemCreateTest::testMaildir()
items = itemFetch->items();
QCOMPARE((int)items.count(), 6);
for (const Item &item : std::as_const(items)) {
Q_FOREACH (const QByteArray &flag, item.flags()) {
const auto flags{item.flags()};
for (const QByteArray &flag : flags) {
++flagCounts[flag];
}
}
......
......@@ -760,7 +760,7 @@ void POP3Resource::deleteJobResult(KJob *job)
QList<QString> seenUIDs = mSettings.seenUidList();
QList<int> timeOfSeenUids = mSettings.seenUidTimeList();
Q_ASSERT(seenUIDs.size() == timeOfSeenUids.size());
foreach (int deletedId, mDeletedIDs) {
for (int deletedId : std::as_const(mDeletedIDs)) {
const QString deletedUID = mIdsToUidsMap.value(deletedId);
if (!deletedUID.isEmpty()) {
int index = seenUIDs.indexOf(deletedUID);
......@@ -842,11 +842,11 @@ void POP3Resource::saveSeenUIDList()
// Those messages, we have to remember, so we don't download them again.
//
QList<int> idsOfMessagesDownloadedButNotDeleted = mIDsStored;
foreach (int deletedId, mDeletedIDs) {