summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrius Štikonas <andrius@stikonas.eu>2016-09-01 14:36:43 (GMT)
committerAndrius Štikonas <andrius@stikonas.eu>2016-09-01 14:36:43 (GMT)
commit6e2654585568ec9528008022d83669996b6676c2 (patch)
tree1a062191f741777f37bb9adc663f9a6eb0d3a1ec
parentaa39c9fdecec09d621f5ee38f48b71c8421aa74f (diff)
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)
-rw-r--r--editor/kgpgtextedit.cpp2
-rw-r--r--foldercompressjob.cpp2
-rw-r--r--gpgproc.cpp3
-rw-r--r--keyservers.cpp3
-rw-r--r--keysmanager.cpp54
-rw-r--r--kgpg.cpp3
-rw-r--r--kgpgexternalactions.cpp2
-rw-r--r--kgpgfirstassistant.cpp4
-rw-r--r--model/kgpgitemmodel.cpp7
-rw-r--r--selectpublickeydialog.cpp3
-rw-r--r--transactions/kgpgdecrypt.cpp2
-rw-r--r--transactions/kgpgdelsign.cpp2
-rw-r--r--transactions/kgpgencrypt.cpp2
-rw-r--r--transactions/kgpgimport.cpp10
-rw-r--r--transactions/kgpgsigntext.cpp2
-rw-r--r--transactions/kgpgtransaction.cpp2
-rw-r--r--transactions/kgpgtransactionprivate.cpp2
17 files changed, 57 insertions, 48 deletions
diff --git a/editor/kgpgtextedit.cpp b/editor/kgpgtextedit.cpp
index 99603d5..dc5ba1f 100644
--- a/editor/kgpgtextedit.cpp
+++ b/editor/kgpgtextedit.cpp
@@ -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),
diff --git a/foldercompressjob.cpp b/foldercompressjob.cpp
index ad0f2ed..0ae21ee 100644
--- a/foldercompressjob.cpp
+++ b/foldercompressjob.cpp
@@ -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;
diff --git a/gpgproc.cpp b/gpgproc.cpp
index bc31a9a..7ee2683 100644
--- a/gpgproc.cpp
+++ b/gpgproc.cpp
@@ -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;
diff --git a/keyservers.cpp b/keyservers.cpp
index 081d00f..5df5b95 100644
--- a/keyservers.cpp
+++ b/keyservers.cpp
@@ -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());
diff --git a/keysmanager.cpp b/keysmanager.cpp
index ff248d2..23e1c89 100644
--- a/keysmanager.cpp
+++ b/keysmanager.cpp
@@ -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);
}
diff --git a/kgpg.cpp b/kgpg.cpp
index 2433d1d..ae24f9b 100644
--- a/kgpg.cpp
+++ b/kgpg.cpp
@@ -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;
diff --git a/kgpgexternalactions.cpp b/kgpgexternalactions.cpp
index ea3aafb..0b25d4c 100644
--- a/kgpgexternalactions.cpp
+++ b/kgpgexternalactions.cpp
@@ -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),
diff --git a/kgpgfirstassistant.cpp b/kgpgfirstassistant.cpp
index 0edd3dc..06468e2 100644
--- a/kgpgfirstassistant.cpp
+++ b/kgpgfirstassistant.cpp
@@ -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())
diff --git a/model/kgpgitemmodel.cpp b/model/kgpgitemmodel.cpp
index 3d531ec..88d7eb0 100644
--- a/model/kgpgitemmodel.cpp
+++ b/model/kgpgitemmodel.cpp
@@ -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)
diff --git a/selectpublickeydialog.cpp b/selectpublickeydialog.cpp
index ecd8f99..ec922dc 100644
--- a/selectpublickeydialog.cpp
+++ b/selectpublickeydialog.cpp
@@ -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);
diff --git a/transactions/kgpgdecrypt.cpp b/transactions/kgpgdecrypt.cpp
index 7ebffa2..d489e10 100644
--- a/transactions/kgpgdecrypt.cpp
+++ b/transactions/kgpgdecrypt.cpp
@@ -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;
diff --git a/transactions/kgpgdelsign.cpp b/transactions/kgpgdelsign.cpp
index e358376..c51eefe 100644
--- a/transactions/kgpgdelsign.cpp
+++ b/transactions/kgpgdelsign.cpp
@@ -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
diff --git a/transactions/kgpgencrypt.cpp b/transactions/kgpgencrypt.cpp
index 11ae480..f54b5df 100644
--- a/transactions/kgpgencrypt.cpp
+++ b/transactions/kgpgencrypt.cpp
@@ -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;
diff --git a/transactions/kgpgimport.cpp b/transactions/kgpgimport.cpp
index 2faf80f..2ebe056 100644
--- a/transactions/kgpgimport.cpp
+++ b/transactions/kgpgimport.cpp
@@ -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;
diff --git a/transactions/kgpgsigntext.cpp b/transactions/kgpgsigntext.cpp
index ef43732..6699a33 100644
--- a/transactions/kgpgsigntext.cpp
+++ b/transactions/kgpgsigntext.cpp
@@ -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);
}
diff --git a/transactions/kgpgtransaction.cpp b/transactions/kgpgtransaction.cpp
index 74bb880..0495ce5 100644
--- a/transactions/kgpgtransaction.cpp
+++ b/transactions/kgpgtransaction.cpp
@@ -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);
diff --git a/transactions/kgpgtransactionprivate.cpp b/transactions/kgpgtransactionprivate.cpp
index 38dfaa4..c5bb366 100644
--- a/transactions/kgpgtransactionprivate.cpp
+++ b/transactions/kgpgtransactionprivate.cpp
@@ -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;