Commit 6e265458 authored by Andrius Štikonas's avatar Andrius Štikonas

Port away from most cases of Q_FOREACH to C++11 ranged for loop.

In order to avoid deep copies, Qt containers over which we iterate must be const
The remaining unported cases require qAsConst (Qt 5.7) or std::as_const (C++17)
parent aa39c9fd
......@@ -326,7 +326,7 @@ void KgpgTextEdit::slotVerifyDone(int result)
return;
QStringList msglist;
foreach (QString rawmsg, messages) // krazy:exclude=foreach
for (QString rawmsg : messages)
msglist << rawmsg.replace(QLatin1Char('<'), QLatin1String("&lt;"));
(void) new KgpgDetailedInfo(this, KGpgVerify::getReport(messages, m_model),
......
......@@ -108,7 +108,7 @@ FolderCompressJob::doWork()
return;
}
foreach (const QUrl &url, d->m_sources)
for (const QUrl &url : d->m_sources)
arch->addLocalDirectory(url.path(), url.fileName());
arch->close();
delete arch;
......
......@@ -336,7 +336,8 @@ GPGProc::getGpgPubkeyAlgorithms(const QString &binary)
{
QStringList ret;
foreach (const QString &s, getGpgStatusLine(binary, QLatin1String("Pubkey:")).split(QLatin1Char(','))) {
const auto algorithms = getGpgStatusLine(binary, QLatin1String("Pubkey:")).split(QLatin1Char(','));
for (const QString &s : algorithms) {
QString t = s.trimmed();
if (t == QLatin1String("?"))
continue;
......
......@@ -303,7 +303,8 @@ void KeyServer::transferKeyID()
{
QSet<QString> ids;
foreach (const QModelIndex &index, m_listpop->kLVsearch->selectionModel()->selectedIndexes())
const QModelIndexList indexes = m_listpop->kLVsearch->selectionModel()->selectedIndexes();
for (const QModelIndex &index : indexes)
ids << m_resultmodel.idForIndex(index);
const QStringList idlist(ids.toList());
......
......@@ -733,13 +733,13 @@ void KeysManager::slotGotoDefaultKey()
void KeysManager::refreshKeyFromServer()
{
QList<KGpgNode *> keysList(iview->selectedNodes());
const QList<KGpgNode *> keysList(iview->selectedNodes());
if (keysList.isEmpty())
return;
QStringList keyIDS;
foreach (KGpgNode *item, keysList) {
for (KGpgNode *item : keysList) {
if (item->getType() == ITYPE_GROUP)
{
for (int j = 0; j < item->getChildCount(); j++)
......@@ -1254,7 +1254,7 @@ KeysManager::slotMenu(const QPoint &pos)
// find out if an item has unknown signatures. Only check if the item has been
// expanded before as expansion is very expensive and can take several seconds
// that will freeze the UI meanwhile.
foreach (KGpgNode *nd, ndlist) {
for (KGpgNode *nd : ndlist) {
if (!nd->hasChildren())
continue;
......@@ -1277,7 +1277,7 @@ KeysManager::slotMenu(const QPoint &pos)
if (itype == ITYPE_SIGN) {
bool allunksig = true;
foreach (KGpgNode *nd, ndlist) {
for (KGpgNode *nd : ndlist) {
allunksig = nd->toSignNode()->isUnknown();
if (!allunksig)
break;
......@@ -1417,7 +1417,7 @@ void KeysManager::slotexport()
bool same;
KgpgItemType tp;
QList<KGpgNode *> ndlist(iview->selectedNodes(&same, &tp));
const QList<KGpgNode *> ndlist(iview->selectedNodes(&same, &tp));
if (ndlist.isEmpty())
return;
if (!(tp & ITYPE_PUBLIC) || (tp & ~ITYPE_GPAIR))
......@@ -1720,7 +1720,7 @@ void KeysManager::createNewGroup()
QStringList badkeys;
KGpgKeyNode::List keysList;
KgpgItemType tp;
KGpgNode::List ndlist(iview->selectedNodes(Q_NULLPTR, &tp));
const KGpgNode::List ndlist(iview->selectedNodes(Q_NULLPTR, &tp));
if (ndlist.isEmpty())
return;
......@@ -1736,7 +1736,7 @@ void KeysManager::createNewGroup()
mintrust = KgpgCore::TRUST_FULL;
}
foreach (KGpgNode *nd, ndlist) {
for (KGpgNode *nd : ndlist) {
if (nd->getTrust() >= mintrust) {
keysList.append(nd->toKeyNode());
} else {
......@@ -1800,7 +1800,7 @@ void KeysManager::signkey()
return;
KgpgItemType tp;
QList<KGpgNode *> tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
const QList<KGpgNode *> tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
if (tmplist.isEmpty())
return;
......@@ -1830,7 +1830,7 @@ void KeysManager::signkey()
signList.append(nd);
} else {
QStringList signKeyList;
foreach (KGpgNode *n, tmplist) {
for (KGpgNode *n : tmplist) {
const KGpgKeyNode *nd = n->toKeyNode();
if (nd->getEmail().isEmpty())
......@@ -1879,7 +1879,7 @@ void KeysManager::signuid()
return;
KgpgItemType tp;
KGpgNode::List tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
const KGpgNode::List tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
if (tmplist.isEmpty())
return;
......@@ -1913,7 +1913,7 @@ void KeysManager::signuid()
} else {
QStringList signKeyList;
foreach (KGpgNode *nd, tmplist) {
for (KGpgNode *nd : tmplist) {
const KGpgKeyNode *pnd = (nd->getType() & (ITYPE_UID | ITYPE_UAT)) ?
nd->getParentKeyNode()->toKeyNode() : nd->toKeyNode();
......@@ -2026,7 +2026,7 @@ void KeysManager::signatureResult(int success)
void KeysManager::caff()
{
KgpgItemType tp;
KGpgNode::List tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
const KGpgNode::List tmplist = iview->selectedNodes(Q_NULLPTR, &tp);
KGpgSignableNode::List slist;
if (tmplist.isEmpty())
return;
......@@ -2036,7 +2036,7 @@ void KeysManager::caff()
return;
}
foreach (KGpgNode *nd, tmplist) {
for (KGpgNode *nd : tmplist) {
switch (nd->getType()) {
case KgpgCore::ITYPE_PAIR:
case KgpgCore::ITYPE_PUBLIC: {
......@@ -2093,7 +2093,7 @@ void KeysManager::signKeyOpenConsole(const QString &signer, const QString &keyid
void KeysManager::getMissingSigs(QSet<QString> &missingKeys, const KGpgExpandableNode *nd)
{
foreach (const KGpgNode *ch, nd->getChildren()) {
for (const KGpgNode *ch : nd->getChildren()) {
if (ch->hasChildren()) {
getMissingSigs(missingKeys, ch->toExpandableNode());
continue;
......@@ -2112,7 +2112,7 @@ void KeysManager::importallsignkey()
if (sel.isEmpty())
return;
foreach (const KGpgNode *nd, sel) {
for (const KGpgNode *nd : sel) {
if (nd->hasChildren()) {
getMissingSigs(missingKeys, nd->toExpandableNode());
} else if (nd->getType() == ITYPE_SIGN) {
......@@ -2141,7 +2141,7 @@ void KeysManager::preimportsignkey()
if (exportList.empty())
return;
foreach (const KGpgNode *nd, exportList)
for (const KGpgNode *nd : exportList)
idlist << nd->getId();
importRemoteKeys(idlist);
......@@ -2254,7 +2254,8 @@ void KeysManager::slotSendEmail()
{
QStringList maillist;
foreach (const KGpgNode *nd, iview->selectedNodes()) {
const auto nodes = iview->selectedNodes();
for (const KGpgNode *nd : nodes) {
if (nd->getEmail().isEmpty())
continue;
......@@ -2322,7 +2323,8 @@ void KeysManager::removeFromGroups(KGpgKeyNode *node)
{
QStringList groupNames;
foreach (const KGpgGroupNode *gnd, node->getGroups())
const auto groups = node->getGroups();
for (const KGpgGroupNode *gnd : groups)
groupNames << gnd->getName();
if (groupNames.isEmpty())
......@@ -2337,7 +2339,8 @@ void KeysManager::removeFromGroups(KGpgKeyNode *node)
bool groupDeleted = false;
foreach (KGpgGroupMemberNode *gref, node->getGroupRefs()) {
const auto grefs = node->getGroupRefs();
for (KGpgGroupMemberNode *gref : grefs) {
KGpgGroupNode *group = gref->getParentKeyNode();
bool deleteWholeGroup = (group->getChildCount() == 1) &&
......@@ -2436,7 +2439,7 @@ void KeysManager::confirmdeletekey()
return;
} else if ((pt & ITYPE_GROUP) && !(pt & ~ITYPE_GPAIR)) {
bool invalidDelete = false;
foreach (const KGpgNode *nd, ndlist)
for (const KGpgNode *nd : ndlist)
if (nd->getType() == ITYPE_GROUP) {
invalidDelete = true;
break;
......@@ -2445,7 +2448,7 @@ void KeysManager::confirmdeletekey()
// only allow removing group members if they belong to the same group
if (!invalidDelete) {
const KGpgNode * const group = ndlist.first()->getParentKeyNode();
foreach (const KGpgNode *nd, ndlist)
for (const KGpgNode *nd : ndlist)
if (nd->getParentKeyNode() != group) {
invalidDelete = true;
break;
......@@ -2457,7 +2460,7 @@ void KeysManager::confirmdeletekey()
QList<KGpgNode *> members = gnd->getChildren();
foreach (KGpgNode *nd, ndlist) {
for (KGpgNode *nd : ndlist) {
int r = members.removeAll(nd);
Q_ASSERT(r == 1);
Q_UNUSED(r);
......@@ -2481,7 +2484,7 @@ void KeysManager::confirmdeletekey()
KGpgKeyNode::List delkeys;
bool secretKeyInside = (pt & ITYPE_SECRET);
foreach (KGpgNode *nd, ndlist) {
for (KGpgNode *nd : ndlist) {
KGpgKeyNode *ki = nd->toKeyNode();
if (ki->getType() & ITYPE_SECRET) {
......@@ -2512,7 +2515,7 @@ void KeysManager::confirmdeletekey()
if (result != KMessageBox::Continue)
return;
foreach (KGpgNode *nd, ndlist)
for (KGpgNode *nd : ndlist)
removeFromGroups(nd->toKeyNode());
m_delkey = new KGpgDelKey(this, delkeys);
......@@ -2523,7 +2526,8 @@ void KeysManager::confirmdeletekey()
void KeysManager::slotDelKeyDone(int res)
{
if (res == 0) {
foreach (KGpgKeyNode *kn, m_delkey->keys())
const auto keys = m_delkey->keys();
for (KGpgKeyNode *kn : keys)
imodel->delNode(kn);
}
......
......@@ -113,7 +113,8 @@ int KGpgApp::newInstance(QCommandLineParser& parser)
} else {
QList<QUrl> urlList;
foreach (const auto &arg, parser.positionalArguments())
const QStringList positionalArguments = parser.positionalArguments();
for (const QString &arg : positionalArguments)
urlList.append(QUrl::fromLocalFile(arg));
bool directoryInside = false;
......
......@@ -283,7 +283,7 @@ void KGpgExternalActions::slotVerificationDone(int result)
return;
QStringList msglist;
foreach (QString rawmsg, messages) // krazy:exclude=foreach
for (QString rawmsg : messages)
msglist << rawmsg.replace(QLatin1Char('<'), QLatin1String("&lt;"));
(void) new KgpgDetailedInfo(m_keysmanager, KGpgVerify::getReport(messages, m_model),
......
......@@ -272,14 +272,14 @@ KGpgFirstAssistant::findConfigPath()
return;
}
KgpgKeyList publiclist = KgpgInterface::readPublicKeys(secids);
const KgpgKeyList publiclist = KgpgInterface::readPublicKeys(secids);
generateCB->setChecked(false);
setAppropriate(page_defaultkey, true);
CBdefault->clear();
foreach (const KgpgKey &k, publiclist) {
for (const KgpgKey &k : publiclist) {
QString s;
if (k.email().isEmpty())
......
......@@ -312,7 +312,7 @@ KGpgItemModel::changeGroup(KGpgGroupNode *node, const QList<KGpgNode *> &keys)
for (int i = node->getChildCount() - 1; i >= 0; i--) {
bool found = false;
foreach (const KGpgNode *nd, keys) {
for (const KGpgNode *nd : keys) {
found = (node->getChild(i)->getId() == nd->getId());
if (found)
break;
......@@ -330,7 +330,7 @@ KGpgItemModel::changeGroup(KGpgGroupNode *node, const QList<KGpgNode *> &keys)
for (int i = 0; i < keys.count(); i++) {
bool found = false;
foreach (const KGpgNode *nd, node->getChildren()) {
for (const KGpgNode *nd : node->getChildren()) {
found = (nd->getId() == keys.at(i)->getId());
if (found)
break;
......@@ -523,7 +523,8 @@ KGpgItemModel::isDefaultKey(const KGpgNode *node) const
void
KGpgItemModel::invalidateIndexes(KGpgNode *nd)
{
foreach (const QModelIndex &idx, persistentIndexList()) {
const auto indexList = persistentIndexList();
for (const QModelIndex &idx : indexList) {
KGpgNode *n = nodeForIndex(idx);
if (n != nd)
......
......@@ -188,7 +188,8 @@ QStringList KgpgSelectPublicKeyDlg::selectedKeys() const
QStringList selectedKeys;
foreach (const QModelIndex &idx, m_keyslist->selectionModel()->selectedIndexes()) {
const QModelIndexList indexes = m_keyslist->selectionModel()->selectedIndexes();
for (const QModelIndex &idx : indexes) {
if (idx.column() != 0)
continue;
KGpgNode *nd = iproxy->nodeForIndex(idx);
......
......@@ -65,7 +65,7 @@ KGpgDecrypt::decryptedText() const
QStringList result;
int txtlength = 0;
foreach (const QString &line, getMessages())
for (const QString &line : getMessages())
if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
result.append(line);
txtlength += line.length() + 1;
......
......@@ -39,7 +39,7 @@ KGpgDelSign::KGpgDelSign(QObject *parent, const KGpgSignNode::List &signids)
setUid(signids.at(0)->getParentKeyNode()->getId());
#ifndef QT_NO_DEBUG
foreach (const KGpgSignNode *snode, signids) {
for (const KGpgSignNode *snode : signids) {
Q_ASSERT(signids.at(0)->getParentKeyNode() == snode->getParentKeyNode());
}
#endif
......
......@@ -83,7 +83,7 @@ KGpgEncrypt::encryptedText() const
QStringList result;
int txtlength = 0;
foreach (const QString &line, getMessages())
for (const QString &line : getMessages())
if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
result.append(line);
txtlength += line.length() + 1;
......
......@@ -48,7 +48,7 @@ KGpgImport::getImportedKeys() const
{
QStringList res;
foreach (const QString &str, getMessages())
for (const QString &str : getMessages())
if (str.startsWith(QLatin1String("[GNUPG:] IMPORTED ")))
res << str.mid(18);
......@@ -60,7 +60,7 @@ KGpgImport::getImportedIds(const QStringList &log, const int reason)
{
QStringList res;
foreach (const QString &str, log) {
for (const QString &str : log) {
if (!str.startsWith(QLatin1String("[GNUPG:] IMPORT_OK ")))
continue;
......@@ -109,7 +109,7 @@ KGpgImport::getImportMessage(const QStringList &log)
memset(rcode, 0, sizeof(rcode));
foreach (const QString &str, log) {
for (const QString &str : log) {
line++;
if (!str.startsWith(QLatin1String("[GNUPG:] IMPORT_RES ")))
continue;
......@@ -177,7 +177,7 @@ beautifyKeyList(const QStringList &keyIds, const KGpgItemModel *model)
if (model == Q_NULLPTR) {
result.append(QLatin1String(" ") + keyIds.join(QLatin1String("\n ")));
} else {
foreach (const QString &changed, keyIds) {
for (const QString &changed : keyIds) {
const KGpgKeyNode *node = model->findKeyNode(changed);
QString line;
......@@ -203,7 +203,7 @@ KGpgImport::getDetailedImportMessage(const QStringList &log, const KGpgItemModel
QString result;
QMap<QString, unsigned int> resultcodes;
foreach (const QString &keyresult, log) {
for (const QString &keyresult : log) {
if (!keyresult.startsWith(QLatin1String("[GNUPG:] IMPORT_OK ")))
continue;
......
......@@ -75,7 +75,7 @@ KGpgSignText::signedText() const
{
QStringList result;
foreach (const QString &line, getMessages())
for (const QString &line : getMessages())
if (!line.startsWith(QLatin1String("[GNUPG:] "))) {
result.append(line);
}
......
......@@ -254,7 +254,7 @@ KGpgTransaction::insertArguments(const int pos, const QStringList &args)
QStringList tmp(d->m_process->program());
int tmppos = pos;
foreach (const QString &s, args) {
for (const QString &s : args) {
tmp.insert(tmppos++, s);
}
d->m_process->setProgram(tmp);
......
......@@ -169,7 +169,7 @@ KGpgTransactionPrivate::slotReadReady()
// all known hints
int i = 0;
bool matched = false;
foreach (const QString &hintName, hintNames()) {
for (const QString &hintName : hintNames()) {
const KGpgTransaction::ts_hintType h = static_cast<KGpgTransaction::ts_hintType>(i++);
if (!line.startsWith(hintName))
continue;
......
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