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.
This commit is contained in:
parent
f7d69de030
commit
d5dafb2ae3
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<QGpgMENewCryptoConfigComponent> 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<QGpgMENewCryptoConfigComponent> &c, m_componentsByName)
|
||||
for (const std::shared_ptr<QGpgMENewCryptoConfigComponent> &c : qAsConst(m_componentsByName)) {
|
||||
c->sync(runtime);
|
||||
}
|
||||
}
|
||||
|
||||
void QGpgMENewCryptoConfig::clear()
|
||||
@ -156,7 +157,7 @@ void QGpgMENewCryptoConfigComponent::setComponent(const Component &component)
|
||||
std::shared_ptr<QGpgMENewCryptoConfigGroup> group;
|
||||
|
||||
const std::vector<Option> options = m_component.options();
|
||||
Q_FOREACH(const Option & o, options)
|
||||
for (const Option &o : options) {
|
||||
if (o.flags() & Group) {
|
||||
if (group) {
|
||||
m_groupsByName[group->name()] = group;
|
||||
@ -170,6 +171,7 @@ void QGpgMENewCryptoConfigComponent::setComponent(const Component &component)
|
||||
} else {
|
||||
qCWarning(QGPGME_LOG) << "found no group for entry" << o.name() << "of component" << name();
|
||||
}
|
||||
}
|
||||
if (group) {
|
||||
m_groupsByName[group->name()] = group;
|
||||
}
|
||||
@ -578,7 +580,7 @@ QList<QUrl> QGpgMENewCryptoConfigEntry::urlValueList() const
|
||||
const Argument arg = m_option.currentValue();
|
||||
const std::vector<const char *> values = arg.stringValues();
|
||||
QList<QUrl> ret;
|
||||
Q_FOREACH(const char *value, values)
|
||||
for (const char *value : values) {
|
||||
if (type == FilenameType) {
|
||||
QUrl url;
|
||||
url.setPath(QFile::decodeName(value));
|
||||
@ -586,6 +588,7 @@ QList<QUrl> QGpgMENewCryptoConfigEntry::urlValueList() const
|
||||
} else {
|
||||
ret << parseURL(type, QString::fromUtf8(value));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -678,12 +681,13 @@ void QGpgMENewCryptoConfigEntry::setURLValueList(const QList<QUrl> &urls)
|
||||
Q_ASSERT(isList());
|
||||
std::vector<std::string> values;
|
||||
values.reserve(urls.size());
|
||||
Q_FOREACH (const QUrl &url, urls)
|
||||
for (const QUrl &url : urls) {
|
||||
if (type == FilenameType) {
|
||||
values.push_back(QFile::encodeName(url.path()).constData());
|
||||
} else {
|
||||
values.push_back(splitURL(type, url).toUtf8().constData());
|
||||
}
|
||||
}
|
||||
const auto err = m_option.setNewValue(m_option.createStringListArgument(values));
|
||||
if (err) {
|
||||
qCWarning(QGPGME_LOG) << "setURLValueList: failed to set new value:" << err;
|
||||
|
@ -124,11 +124,13 @@ static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thr
|
||||
}
|
||||
|
||||
ctx->clearSigningKeys();
|
||||
Q_FOREACH (const Key &signer, signers)
|
||||
if (!signer.isNull())
|
||||
for (const Key &signer : signers) {
|
||||
if (!signer.isNull()) {
|
||||
if (const Error err = ctx->addSigningKey(signer)) {
|
||||
return std::make_tuple(SigningResult(err), EncryptionResult(), QByteArray(), QString(), Error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!cipherText) {
|
||||
QGpgME::QByteArrayDataProvider out;
|
||||
|
@ -87,11 +87,13 @@ static QGpgMESignJob::result_type sign(Context *ctx, QThread *thread,
|
||||
}
|
||||
|
||||
ctx->clearSigningKeys();
|
||||
Q_FOREACH (const Key &signer, signers)
|
||||
if (!signer.isNull())
|
||||
for (const Key &signer : signers) {
|
||||
if (!signer.isNull()) {
|
||||
if (const Error err = ctx->addSigningKey(signer)) {
|
||||
return std::make_tuple(SigningResult(err), QByteArray(), QString(), Error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!signature) {
|
||||
QGpgME::QByteArrayDataProvider out;
|
||||
|
@ -108,7 +108,7 @@ QString _detail::audit_log_as_html(Context *ctx, GpgME::Error &err)
|
||||
static QList<QByteArray> from_sl(const QStringList &sl)
|
||||
{
|
||||
QList<QByteArray> result;
|
||||
Q_FOREACH (const QString &str, sl) {
|
||||
for (const QString &str : sl) {
|
||||
result.append(str.toUtf8());
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ private Q_SLOTS:
|
||||
{ Subkey::AlgoEDDSA, QStringLiteral("EdDSA") },
|
||||
{ Subkey::AlgoUnknown, QString() }
|
||||
};
|
||||
Q_FOREACH (Subkey::PubkeyAlgo algo, expected.keys()) {
|
||||
for (Subkey::PubkeyAlgo algo : expected.keys()) {
|
||||
QVERIFY(QString::fromUtf8(Subkey::publicKeyAlgorithmAsString(algo)) ==
|
||||
expected.value(algo));
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ private Q_SLOTS:
|
||||
Key k = keys.front();
|
||||
QVERIFY(k.numUserIDs());
|
||||
bool found = false;
|
||||
Q_FOREACH (const UserID uid, k.userIDs()) {
|
||||
for (const UserID &uid : k.userIDs()) {
|
||||
const QString mailBox = QString::fromUtf8(uid.email());
|
||||
if (mTestpattern.toLower() == mailBox.toLower()) {
|
||||
found = true;
|
||||
@ -109,7 +109,7 @@ private Q_SLOTS:
|
||||
Key k = keys.front();
|
||||
QVERIFY(k.numUserIDs());
|
||||
bool found = false;
|
||||
Q_FOREACH (const UserID uid, k.userIDs()) {
|
||||
for (const UserID &uid : k.userIDs()) {
|
||||
const QString mailBox = QString::fromUtf8(uid.email());
|
||||
if (mTestpattern.toLower() == mailBox.toLower()) {
|
||||
found = true;
|
||||
|
Loading…
Reference in New Issue
Block a user