Skip to content

Commit 9ac511d

Browse files
committed
Flip a couple of Q_FOREACHs to c++11 for loops
... just to check how bad the Q_FOREACH deprecation will be. And yep, it's horrendous. Each one takes around 10 seconds or so to port, and we've got some 2500+ remaining uses.
1 parent 0cb52f6 commit 9ac511d

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

src/core/annotations/qgsannotationmanager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool QgsAnnotationManager::removeAnnotation( QgsAnnotation *annotation )
6262

6363
void QgsAnnotationManager::clear()
6464
{
65-
Q_FOREACH ( QgsAnnotation *a, mAnnotations )
65+
for ( auto *a : qgsAsConst( mAnnotations ) )
6666
{
6767
removeAnnotation( a );
6868
}
@@ -76,7 +76,7 @@ QList<QgsAnnotation *> QgsAnnotationManager::annotations() const
7676
QList<QgsAnnotation *> QgsAnnotationManager::cloneAnnotations() const
7777
{
7878
QList<QgsAnnotation *> results;
79-
Q_FOREACH ( const QgsAnnotation *a, mAnnotations )
79+
for ( const auto *a : qgsAsConst( mAnnotations ) )
8080
{
8181
results << a->clone();
8282
}

src/core/auth/qgsauthcertutils.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QString QgsAuthCertUtils::getSslProtocolName( QSsl::SslProtocol protocol )
4848
QMap<QString, QSslCertificate> QgsAuthCertUtils::mapDigestToCerts( const QList<QSslCertificate> &certs )
4949
{
5050
QMap<QString, QSslCertificate> digestmap;
51-
Q_FOREACH ( const QSslCertificate &cert, certs )
51+
for ( const auto &cert : certs )
5252
{
5353
digestmap.insert( shaHexForCert( cert ), cert );
5454
}
@@ -58,7 +58,7 @@ QMap<QString, QSslCertificate> QgsAuthCertUtils::mapDigestToCerts( const QList<Q
5858
QMap<QString, QList<QSslCertificate> > QgsAuthCertUtils::certsGroupedByOrg( const QList<QSslCertificate> &certs )
5959
{
6060
QMap< QString, QList<QSslCertificate> > orgcerts;
61-
Q_FOREACH ( const QSslCertificate &cert, certs )
61+
for ( const auto &cert : certs )
6262
{
6363
QString org( SSL_SUBJECT_INFO( cert, QSslCertificate::Organization ) );
6464
if ( org.isEmpty() )
@@ -72,7 +72,7 @@ QMap<QString, QList<QSslCertificate> > QgsAuthCertUtils::certsGroupedByOrg( cons
7272
QMap<QString, QgsAuthConfigSslServer> QgsAuthCertUtils::mapDigestToSslConfigs( const QList<QgsAuthConfigSslServer> &configs )
7373
{
7474
QMap<QString, QgsAuthConfigSslServer> digestmap;
75-
Q_FOREACH ( const QgsAuthConfigSslServer &config, configs )
75+
for ( const auto &config : configs )
7676
{
7777
digestmap.insert( shaHexForCert( config.sslCertificate() ), config );
7878
}
@@ -82,7 +82,7 @@ QMap<QString, QgsAuthConfigSslServer> QgsAuthCertUtils::mapDigestToSslConfigs( c
8282
QMap<QString, QList<QgsAuthConfigSslServer> > QgsAuthCertUtils::sslConfigsGroupedByOrg( const QList<QgsAuthConfigSslServer> &configs )
8383
{
8484
QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs;
85-
Q_FOREACH ( const QgsAuthConfigSslServer &config, configs )
85+
for ( const auto &config : configs )
8686
{
8787
QString org( SSL_SUBJECT_INFO( config.sslCertificate(), QSslCertificate::Organization ) );
8888

@@ -439,7 +439,7 @@ QCA::CertificateCollection QgsAuthCertUtils::qtCertsToQcaCollection( const QList
439439
if ( QgsAuthManager::instance()->isDisabled() )
440440
return qcacoll;
441441

442-
Q_FOREACH ( const QSslCertificate &cert, certs )
442+
for ( const auto &cert : certs )
443443
{
444444
QCA::Certificate qcacert( qtCertToQcaCert( cert ) );
445445
if ( !qcacert.isNull() )
@@ -622,8 +622,8 @@ QList<QgsAuthCertUtils::CertUsageType> QgsAuthCertUtils::certificateUsageTypes(
622622
usages << QgsAuthCertUtils::CertAuthorityUsage;
623623
}
624624

625-
QList<QCA::ConstraintType> certconsts = qcacert.constraints();
626-
Q_FOREACH ( const QCA::ConstraintType &certconst, certconsts )
625+
const QList<QCA::ConstraintType> certconsts = qcacert.constraints();
626+
for ( const auto &certconst : certconsts )
627627
{
628628
if ( certconst.known() == QCA::KeyCertificateSign )
629629
{
@@ -722,8 +722,8 @@ bool QgsAuthCertUtils::certificateIsSslServer( const QSslCertificate &cert )
722722
return false;
723723
}
724724

725-
QList<QCA::ConstraintType> certconsts = qcacert.constraints();
726-
Q_FOREACH ( QCA::ConstraintType certconst, certconsts )
725+
const QList<QCA::ConstraintType> certconsts = qcacert.constraints();
726+
for ( const auto & certconst, certconsts )
727727
{
728728
if ( certconst.known() == QCA::KeyCertificateSign )
729729
{
@@ -737,7 +737,7 @@ bool QgsAuthCertUtils::certificateIsSslServer( const QSslCertificate &cert )
737737
bool serverauth = false;
738738
bool dsignature = false;
739739
bool keyencrypt = false;
740-
Q_FOREACH ( QCA::ConstraintType certconst, certconsts )
740+
for ( const auto &certconst : certconsts )
741741
{
742742
if ( certconst.known() == QCA::DigitalSignature )
743743
{
@@ -791,7 +791,7 @@ bool QgsAuthCertUtils::certificateIsSslServer( const QSslCertificate &cert )
791791
{
792792
return false;
793793
}
794-
Q_FOREACH ( QCA::ConstraintType certconst, certconsts )
794+
for ( const auto &certconst : certconsts )
795795
{
796796
if ( certconst.known() == QCA::EncipherOnly )
797797
{

src/core/auth/qgsauthconfig.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void QgsAuthMethodConfig::loadConfigString( const QString &configstr )
9191
return;
9292
}
9393

94-
QStringList confs( configstr.split( CONFIG_SEP ) );
94+
const QStringList confs( configstr.split( CONFIG_SEP ) );
9595

96-
Q_FOREACH ( const QString &conf, confs )
96+
for ( const auto &conf : confs )
9797
{
9898
if ( conf.contains( CONFIG_KEY_SEP ) )
9999
{
@@ -255,7 +255,7 @@ const QgsPkiBundle QgsPkiBundle::fromPkcs12Paths( const QString &bundlepath,
255255
QCA::KeyBundle bundle( QCA::KeyBundle::fromFile( bundlepath, passarray, &res, QStringLiteral( "qca-ossl" ) ) );
256256
if ( res == QCA::ConvertGood && !bundle.isNull() )
257257
{
258-
QCA::CertificateChain cert_chain( bundle.certificateChain() );
258+
const QCA::CertificateChain cert_chain( bundle.certificateChain() );
259259
QSslCertificate cert( cert_chain.primary().toPEM().toLatin1() );
260260
if ( !cert.isNull() )
261261
{
@@ -270,7 +270,7 @@ const QgsPkiBundle QgsPkiBundle::fromPkcs12Paths( const QString &bundlepath,
270270
if ( cert_chain.size() > 1 )
271271
{
272272
QList<QSslCertificate> ca_chain;
273-
Q_FOREACH ( const QCA::Certificate &ca_cert, cert_chain )
273+
for ( const auto &ca_cert : cert_chain )
274274
{
275275
if ( ca_cert != cert_chain.primary() )
276276
{
@@ -366,7 +366,8 @@ QgsAuthConfigSslServer::QgsAuthConfigSslServer()
366366
const QList<QSslError> QgsAuthConfigSslServer::sslIgnoredErrors() const
367367
{
368368
QList<QSslError> errors;
369-
Q_FOREACH ( QSslError::SslError errenum, sslIgnoredErrorEnums() )
369+
const QList<QSslError::SslError> ignoredErrors = sslIgnoredErrorEnums();
370+
for ( QSslError::SslError errenum : ignoredErrors )
370371
{
371372
errors << QSslError( errenum );
372373
}
@@ -381,7 +382,7 @@ const QString QgsAuthConfigSslServer::configString() const
381382
configlist << QString::number( static_cast< int >( mSslProtocol ) );
382383

383384
QStringList errs;
384-
Q_FOREACH ( const QSslError::SslError &err, mSslIgnoredErrors )
385+
for ( auto err : mSslIgnoredErrors )
385386
{
386387
errs << QString::number( static_cast< int >( err ) );
387388
}
@@ -408,8 +409,8 @@ void QgsAuthConfigSslServer::loadConfigString( const QString &config )
408409
mSslProtocol = static_cast< QSsl::SslProtocol >( configlist.at( 2 ).toInt() );
409410

410411
mSslIgnoredErrors.clear();
411-
QStringList errs( configlist.at( 3 ).split( QStringLiteral( "~~" ) ) );
412-
Q_FOREACH ( const QString &err, errs )
412+
const QStringList errs( configlist.at( 3 ).split( QStringLiteral( "~~" ) ) );
413+
for ( const auto &err : errs )
413414
{
414415
mSslIgnoredErrors.append( static_cast< QSslError::SslError >( err.toInt() ) );
415416
}

src/core/auth/qgsauthmanager.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ bool QgsAuthManager::init( const QString &pluginPath )
148148
}
149149

150150
QgsDebugMsg( "Prioritizing qca-ossl over all other QCA providers..." );
151-
QCA::ProviderList provds = QCA::providers();
151+
const QCA::ProviderList provds = QCA::providers();
152152
QStringList prlist;
153-
Q_FOREACH ( QCA::Provider *p, provds )
153+
for ( QCA::Provider *p : provds )
154154
{
155155
QString pn = p->name();
156156
int pr = 0;
@@ -780,7 +780,8 @@ bool QgsAuthManager::registerCoreAuthMethods()
780780

781781
qDeleteAll( mAuthMethods );
782782
mAuthMethods.clear();
783-
Q_FOREACH ( const QString &authMethodKey, QgsAuthMethodRegistry::instance()->authMethodList() )
783+
const QStringList methods = QgsAuthMethodRegistry::instance()->authMethodList();
784+
for ( const auto &authMethodKey : methods )
784785
{
785786
mAuthMethods.insert( authMethodKey, QgsAuthMethodRegistry::instance()->authMethod( authMethodKey ).release() );
786787
}
@@ -2086,7 +2087,7 @@ void QgsAuthManager::dumpIgnoredSslErrorsCache_()
20862087
while ( i != mIgnoredSslErrorsCache.constEnd() )
20872088
{
20882089
QStringList errs;
2089-
Q_FOREACH ( QSslError::SslError err, i.value() )
2090+
for ( auto err : i.value() )
20902091
{
20912092
errs << QgsAuthCertUtils::sslErrorEnumString( err );
20922093
}
@@ -2150,7 +2151,7 @@ bool QgsAuthManager::updateIgnoredSslErrorsCache( const QString &shahostport, co
21502151
}
21512152

21522153
QSet<QSslError::SslError> errs;
2153-
Q_FOREACH ( const QSslError &error, errors )
2154+
for ( const auto &error : errors )
21542155
{
21552156
if ( error.error() == QSslError::NoError )
21562157
continue;
@@ -2240,7 +2241,7 @@ bool QgsAuthManager::storeCertAuthorities( const QList<QSslCertificate> &certs )
22402241
return false;
22412242
}
22422243

2243-
Q_FOREACH ( const QSslCertificate &cert, certs )
2244+
for ( const auto &cert : certs )
22442245
{
22452246
if ( !storeCertAuthority( cert ) )
22462247
return false;
@@ -2410,7 +2411,7 @@ const QList<QSslCertificate> QgsAuthManager::getExtraFileCAs()
24102411
filecerts = QgsAuthCertUtils::certsFromFile( cafile );
24112412
}
24122413
// only CAs or certs capable of signing other certs are allowed
2413-
Q_FOREACH ( const QSslCertificate &cert, filecerts )
2414+
for ( const auto &cert : qgsAsConst( filecerts ) )
24142415
{
24152416
if ( !allowinvalid.toBool() && !cert.isValid() )
24162417
{
@@ -2547,7 +2548,7 @@ bool QgsAuthManager::removeCertTrustPolicies( const QList<QSslCertificate> &cert
25472548
return false;
25482549
}
25492550

2550-
Q_FOREACH ( const QSslCertificate &cert, certs )
2551+
for ( const auto &cert : certs )
25512552
{
25522553
if ( !removeCertTrustPolicy( cert ) )
25532554
return false;
@@ -2730,11 +2731,11 @@ bool QgsAuthManager::rebuildTrustedCaCertsCache()
27302731
const QByteArray QgsAuthManager::getTrustedCaCertsPemText()
27312732
{
27322733
QByteArray capem;
2733-
QList<QSslCertificate> certs( getTrustedCaCertsCache() );
2734+
const QList<QSslCertificate> certs( getTrustedCaCertsCache() );
27342735
if ( !certs.isEmpty() )
27352736
{
27362737
QStringList certslist;
2737-
Q_FOREACH ( const QSslCertificate &cert, certs )
2738+
for ( const auto &cert : certs )
27382739
{
27392740
certslist << cert.toPem();
27402741
}
@@ -2762,7 +2763,8 @@ void QgsAuthManager::clearAllCachedConfigs()
27622763
if ( isDisabled() )
27632764
return;
27642765

2765-
Q_FOREACH ( QString authcfg, configIds() )
2766+
const QStringList ids = configIds();
2767+
for ( const auto &authcfg : ids )
27662768
{
27672769
clearCachedConfig( authcfg );
27682770
}
@@ -3307,7 +3309,8 @@ bool QgsAuthManager::reencryptAllAuthenticationConfigs( const QString &prevpass,
33073309
return false;
33083310

33093311
bool res = true;
3310-
Q_FOREACH ( QString configid, configIds() )
3312+
const QStringList ids = configIds();
3313+
for ( const auto &configid : ids )
33113314
{
33123315
res = res && reencryptAuthenticationConfig( configid, prevpass, prevciv );
33133316
}
@@ -3395,7 +3398,7 @@ bool QgsAuthManager::reencryptAllAuthenticationSettings( const QString &prevpass
33953398
QStringList encryptedsettings;
33963399
encryptedsettings << "";
33973400

3398-
Q_FOREACH ( const QString &sett, encryptedsettings )
3401+
for ( const auto & sett, qgsAsConst( encryptedsettings ) )
33993402
{
34003403
if ( sett.isEmpty() || !existsAuthSetting( sett ) )
34013404
continue;
@@ -3468,7 +3471,8 @@ bool QgsAuthManager::reencryptAllAuthenticationIdentities( const QString &prevpa
34683471
return false;
34693472

34703473
bool res = true;
3471-
Q_FOREACH ( const QString &identid, getCertIdentityIds() )
3474+
const QStringList ids = getCertIdentityIds();
3475+
for ( const auto &identid : ids )
34723476
{
34733477
res = res && reencryptAuthenticationIdentity( identid, prevpass, prevciv );
34743478
}
@@ -3649,7 +3653,7 @@ bool QgsAuthManager::authDbTransactionQuery( QSqlQuery *query ) const
36493653

36503654
void QgsAuthManager::insertCaCertInCache( QgsAuthCertUtils::CaCertSource source, const QList<QSslCertificate> &certs )
36513655
{
3652-
Q_FOREACH ( const QSslCertificate &cert, certs )
3656+
for ( const auto &cert : certs )
36533657
{
36543658
mCaCertsCache.insert( QgsAuthCertUtils::shaHexForCert( cert ),
36553659
QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>( source, cert ) );

0 commit comments

Comments
 (0)