From d5dafb2ae332fb6ad463c363e6c2c527bcf66656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 13 Dec 2023 11:45:26 +0100 Subject: [PATCH] qt: Replace Q_FOREACH with range-for * lang/qt/src/qgpgmekeyformailboxjob.cpp (do_work): Replace Q_FOREACH with range-for. * lang/qt/src/qgpgmekeylistjob.cpp (QGpgMEKeyListJob::resultHook): Ditto. * lang/qt/src/threadedjobmixin.cpp (_detail::audit_log_as_html): Ditto. * lang/qt/tests/t-keylist.cpp (KeyListTest::testPubkeyAlgoAsString): Ditto. * lang/qt/tests/t-keylocate.cpp (KeyLocateTest::testDaneKeyLocate, KeyLocateTest::testKeyLocateSingle): Ditto. * lang/qt/src/qgpgmesignencryptjob.cpp (sign_encrypt): Replace Q_FOREACH with range-for. Add braces around single statement blocks. * lang/qt/src/qgpgmesignjob.cpp (sign): Ditto. * lang/qt/src/qgpgmenewcryptoconfig.cpp (QGpgMENewCryptoConfig::reloadConfiguration, QGpgMENewCryptoConfig::sync, QGpgMENewCryptoConfigComponent::setComponent, QGpgMENewCryptoConfigEntry::urlValueList, QGpgMENewCryptoConfigEntry::setURLValueList): Replace Q_FOREACH with range-for. Fix indentation. Add braces around single statement blocks. -- Where necessary the iterated object is wrapped with qAsConst to avoid deep copies of the iterated object. --- lang/qt/src/qgpgmekeyformailboxjob.cpp | 8 ++--- lang/qt/src/qgpgmekeylistjob.cpp | 2 +- lang/qt/src/qgpgmenewcryptoconfig.cpp | 50 ++++++++++++++------------ lang/qt/src/qgpgmesignencryptjob.cpp | 6 ++-- lang/qt/src/qgpgmesignjob.cpp | 6 ++-- lang/qt/src/threadedjobmixin.cpp | 2 +- lang/qt/tests/t-keylist.cpp | 2 +- lang/qt/tests/t-keylocate.cpp | 4 +-- 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/lang/qt/src/qgpgmekeyformailboxjob.cpp b/lang/qt/src/qgpgmekeyformailboxjob.cpp index b6ab3db6..8a6651ba 100644 --- a/lang/qt/src/qgpgmekeyformailboxjob.cpp +++ b/lang/qt/src/qgpgmekeyformailboxjob.cpp @@ -86,12 +86,12 @@ static QGpgMEKeyForMailboxJob::result_type do_work(Context *ctx, const QString & // See: https://bugs.gnupg.org/gnupg/issue2359 Key keyC; UserID uidC; - Q_FOREACH (const Key k, keys) { + for (const Key &k : keys) { if (canEncrypt && !k.canEncrypt()) { continue; } /* First get the uid that matches the mailbox */ - Q_FOREACH (const UserID u, k.userIDs()) { + for (const UserID &u : k.userIDs()) { if (QString::fromUtf8(u.email()).toLower() == mailbox.toLower()) { if (uidC.isNull()) { keyC = k; @@ -103,13 +103,13 @@ static QGpgMEKeyForMailboxJob::result_type do_work(Context *ctx, const QString & } else if (uidC.validity() == u.validity() && uidIsOk(u)) { /* Both are the same check which one is newer. */ time_t oldTime = 0; - Q_FOREACH (const Subkey s, keyC.subkeys()) { + for (const Subkey &s : keyC.subkeys()) { if ((canEncrypt && s.canEncrypt()) && subkeyIsOk(s)) { oldTime = s.creationTime(); } } time_t newTime = 0; - Q_FOREACH (const Subkey s, k.subkeys()) { + for (const Subkey &s : k.subkeys()) { if ((canEncrypt && s.canEncrypt()) && subkeyIsOk(s)) { newTime = s.creationTime(); } diff --git a/lang/qt/src/qgpgmekeylistjob.cpp b/lang/qt/src/qgpgmekeylistjob.cpp index 295e612d..706d2575 100644 --- a/lang/qt/src/qgpgmekeylistjob.cpp +++ b/lang/qt/src/qgpgmekeylistjob.cpp @@ -152,7 +152,7 @@ KeyListResult QGpgMEKeyListJob::exec(const QStringList &patterns, bool secretOnl void QGpgMEKeyListJob::resultHook(const result_type &tuple) { mResult = std::get<0>(tuple); - Q_FOREACH (const Key &key, std::get<1>(tuple)) { + for (const Key &key : std::get<1>(tuple)) { Q_EMIT nextKey(key); } } diff --git a/lang/qt/src/qgpgmenewcryptoconfig.cpp b/lang/qt/src/qgpgmenewcryptoconfig.cpp index 94e3fb2b..15d50b4a 100644 --- a/lang/qt/src/qgpgmenewcryptoconfig.cpp +++ b/lang/qt/src/qgpgmenewcryptoconfig.cpp @@ -97,7 +97,7 @@ void QGpgMENewCryptoConfig::reloadConfiguration(bool) KMessageBox::error(0, wmsg); } #endif - Q_FOREACH(const Component & c, components) { + for (const Component &c : components) { const std::shared_ptr comp(new QGpgMENewCryptoConfigComponent); comp->setComponent(c); m_componentsByName[ comp->name() ] = comp; @@ -127,8 +127,9 @@ QGpgMENewCryptoConfigComponent *QGpgMENewCryptoConfig::component(const QString & void QGpgMENewCryptoConfig::sync(bool runtime) { - Q_FOREACH(const std::shared_ptr &c, m_componentsByName) - c->sync(runtime); + for (const std::shared_ptr &c : qAsConst(m_componentsByName)) { + c->sync(runtime); + } } void QGpgMENewCryptoConfig::clear() @@ -156,19 +157,20 @@ void QGpgMENewCryptoConfigComponent::setComponent(const Component &component) std::shared_ptr group; const std::vector