Skip to content

Commit 825c240

Browse files
m-kuhn3nids
authored andcommitted
Code cleanup (#9392)
* Make auth a Q_FOREACH free zone * Code cleanup * Add const * Indentation * Indentation
1 parent 53a717a commit 825c240

12 files changed

+30
-22
lines changed

src/auth/basic/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (basicauthmethod
4343
qgis_core
4444
qgis_gui
4545
)
46+
TARGET_COMPILE_DEFINITIONS(basicauthmethod PRIVATE "-DQT_NO_FOREACH")
4647

4748
INSTALL(TARGETS basicauthmethod
4849
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}

src/auth/esritoken/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (esritokenauthmethod
4343
qgis_core
4444
qgis_gui
4545
)
46+
TARGET_COMPILE_DEFINITIONS(esritokenauthmethod PRIVATE "-DQT_NO_FOREACH")
4647

4748
INSTALL(TARGETS esritokenauthmethod
4849
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}

src/auth/identcert/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (identcertauthmethod
4343
qgis_core
4444
qgis_gui
4545
)
46+
TARGET_COMPILE_DEFINITIONS(identcertauthmethod PRIVATE "-DQT_NO_FOREACH")
4647

4748
INSTALL(TARGETS identcertauthmethod
4849
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}

src/auth/identcert/qgsauthidentcertedit.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ void QgsAuthIdentCertEdit::populateIdentityComboBox()
7575
{
7676
cmbIdentityCert->addItem( tr( "Select identity…" ), "" );
7777

78-
QList<QSslCertificate> certs( QgsApplication::authManager()->certIdentities() );
78+
const QList<QSslCertificate> certs( QgsApplication::authManager()->certIdentities() );
7979
if ( !certs.isEmpty() )
8080
{
8181
cmbIdentityCert->setIconSize( QSize( 26, 22 ) );
8282
QgsStringMap idents;
83-
Q_FOREACH ( const QSslCertificate &cert, certs )
83+
for ( const QSslCertificate &cert : certs )
8484
{
8585
QString org( SSL_SUBJECT_INFO( cert, QSslCertificate::Organization ) );
8686
if ( org.isEmpty() )

src/auth/oauth2/qgsauthoauth2edit.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,11 @@ void QgsAuthOAuth2Edit::removeTokenCacheFile()
633633
return;
634634
}
635635

636-
QStringList cachefiles;
637-
cachefiles << QgsAuthOAuth2Config::tokenCachePath( authcfg, false )
638-
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, true );
636+
const QStringList cachefiles = QStringList()
637+
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, false )
638+
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, true );
639639

640-
Q_FOREACH ( const QString &cachefile, cachefiles )
640+
for ( const QString &cachefile : cachefiles )
641641
{
642642
if ( QFile::exists( cachefile ) && !QFile::remove( cachefile ) )
643643
{

src/auth/oauth2/qgsauthoauth2method.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ QgsAuthOAuth2Method::QgsAuthOAuth2Method()
5454
<< QStringLiteral( "wcs" )
5555
<< QStringLiteral( "wms" ) );
5656

57-
QStringList cachedirpaths;
58-
cachedirpaths << QgsAuthOAuth2Config::tokenCacheDirectory()
59-
<< QgsAuthOAuth2Config::tokenCacheDirectory( true );
57+
const QStringList cachedirpaths = QStringList()
58+
<< QgsAuthOAuth2Config::tokenCacheDirectory()
59+
<< QgsAuthOAuth2Config::tokenCacheDirectory( true );
6060

61-
Q_FOREACH ( const QString &cachedirpath, cachedirpaths )
61+
for ( const QString &cachedirpath : cachedirpaths )
6262
{
6363
QDir cachedir( cachedirpath );
6464
if ( !cachedir.mkpath( cachedirpath ) )
@@ -71,10 +71,10 @@ QgsAuthOAuth2Method::QgsAuthOAuth2Method()
7171
QgsAuthOAuth2Method::~QgsAuthOAuth2Method()
7272
{
7373
QDir tempdir( QgsAuthOAuth2Config::tokenCacheDirectory( true ) );
74-
QStringList dirlist = tempdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
75-
Q_FOREACH ( const QString &f, dirlist )
74+
const QStringList dirlist = tempdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
75+
for ( const QString &f : dirlist )
7676
{
77-
QString tempfile( tempdir.path() + QStringLiteral( "/" ) + f );
77+
QString tempfile( tempdir.path() + '/' + f );
7878
if ( !QFile::remove( tempfile ) )
7979
{
8080
QgsDebugMsg( QStringLiteral( "FAILED to delete temp token cache file: %1" ).arg( tempfile ) );
@@ -343,7 +343,8 @@ void QgsAuthOAuth2Method::onLinkingSucceeded()
343343
if ( !extraTokens.isEmpty() )
344344
{
345345
QString msg = QStringLiteral( "Extra tokens in response:\n" );
346-
Q_FOREACH ( const QString &key, extraTokens.keys() )
346+
const QStringList extraTokenKeys = extraTokens.keys();
347+
for ( const QString &key : extraTokenKeys )
347348
{
348349
// don't expose the values in a log (unless they are only 3 chars long, of course)
349350
msg += QStringLiteral( " %1:%2…\n" ).arg( key, extraTokens.value( key ).toString().left( 3 ) );
@@ -371,7 +372,8 @@ void QgsAuthOAuth2Method::onCloseBrowser()
371372
// Bring focus back to QGIS app
372373
if ( qobject_cast<QApplication *>( qApp ) )
373374
{
374-
Q_FOREACH ( QWidget *topwdgt, QgsApplication::topLevelWidgets() )
375+
const QList<QWidget *> widgets = QgsApplication::topLevelWidgets();
376+
for ( QWidget *topwdgt : widgets )
375377
{
376378
if ( topwdgt->objectName() == QStringLiteral( "MainWindow" ) )
377379
{

src/auth/pkipaths/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (pkipathsauthmethod
4343
qgis_core
4444
qgis_gui
4545
)
46+
TARGET_COMPILE_DEFINITIONS(pkipathsauthmethod PRIVATE "-DQT_NO_FOREACH")
4647

4748
INSTALL(TARGETS pkipathsauthmethod
4849
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}

src/auth/pkipkcs12/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (pkcs12authmethod
4343
qgis_core
4444
qgis_gui
4545
)
46+
TARGET_COMPILE_DEFINITIONS(pkcs12authmethod PRIVATE "-DQT_NO_FOREACH")
4647

4748
INSTALL(TARGETS pkcs12authmethod
4849
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}

src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ QgsEditorWidgetSetup QgsEditorWidgetAutoConf::editorWidgetSetup( const QgsVector
107107
}
108108

109109
int bestScore = 0;
110-
Q_FOREACH ( std::shared_ptr<QgsEditorWidgetAutoConfPlugin> cur, plugins )
110+
for ( const std::shared_ptr<QgsEditorWidgetAutoConfPlugin> &cur : mPlugins )
111111
{
112112
int score = 0;
113113
const QgsEditorWidgetSetup curResult = cur->editorWidgetSetup( vl, fieldName, score );
@@ -124,6 +124,6 @@ QgsEditorWidgetSetup QgsEditorWidgetAutoConf::editorWidgetSetup( const QgsVector
124124

125125
void QgsEditorWidgetAutoConf::registerPlugin( QgsEditorWidgetAutoConfPlugin *plugin )
126126
{
127-
plugins.append( std::shared_ptr<QgsEditorWidgetAutoConfPlugin>( plugin ) );
127+
mPlugins.append( std::shared_ptr<QgsEditorWidgetAutoConfPlugin>( plugin ) );
128128
}
129129
///@endcond

src/gui/editorwidgets/core/qgseditorwidgetautoconf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class GUI_EXPORT QgsEditorWidgetAutoConf SIP_SKIP
9090
void registerPlugin( QgsEditorWidgetAutoConfPlugin *plugin );
9191

9292
private:
93-
QList<std::shared_ptr<QgsEditorWidgetAutoConfPlugin> > plugins;
93+
QList<std::shared_ptr<QgsEditorWidgetAutoConfPlugin> > mPlugins;
9494
};
9595
///@endcond
9696

src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void QgsRelationWidgetWrapper::setShowLabel( bool showLabel )
105105

106106
void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
107107
{
108-
QgsRelationEditorWidget *w = dynamic_cast<QgsRelationEditorWidget *>( editor );
108+
QgsRelationEditorWidget *w = qobject_cast<QgsRelationEditorWidget *>( editor );
109109

110110
// if the editor cannot be cast to relation editor, insert a new one
111111
if ( !w )

src/gui/qgsattributeform.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1374,11 +1374,12 @@ void QgsAttributeForm::init()
13741374
}
13751375
}
13761376

1377-
Q_FOREACH ( const QgsRelation &rel, QgsProject::instance()->relationManager()->referencedRelations( mLayer ) )
1377+
const QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer );
1378+
for ( const QgsRelation &rel : relations )
13781379
{
13791380
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1380-
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, rel.id() );
1381-
rww->setConfig( setup.config() );
1381+
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
1382+
rww->setConfig( config );
13821383
rww->setContext( mContext );
13831384

13841385
QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );

0 commit comments

Comments
 (0)