Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code cleanup (#9392)
* Make auth a Q_FOREACH free zone

* Code cleanup

* Add const

* Indentation

* Indentation
  • Loading branch information
m-kuhn authored and 3nids committed Mar 6, 2019
1 parent 53a717a commit 825c240
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/auth/basic/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (basicauthmethod
qgis_core
qgis_gui
)
TARGET_COMPILE_DEFINITIONS(basicauthmethod PRIVATE "-DQT_NO_FOREACH")

INSTALL(TARGETS basicauthmethod
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
Expand Down
1 change: 1 addition & 0 deletions src/auth/esritoken/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (esritokenauthmethod
qgis_core
qgis_gui
)
TARGET_COMPILE_DEFINITIONS(esritokenauthmethod PRIVATE "-DQT_NO_FOREACH")

INSTALL(TARGETS esritokenauthmethod
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
Expand Down
1 change: 1 addition & 0 deletions src/auth/identcert/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (identcertauthmethod
qgis_core
qgis_gui
)
TARGET_COMPILE_DEFINITIONS(identcertauthmethod PRIVATE "-DQT_NO_FOREACH")

INSTALL(TARGETS identcertauthmethod
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
Expand Down
4 changes: 2 additions & 2 deletions src/auth/identcert/qgsauthidentcertedit.cpp
Expand Up @@ -75,12 +75,12 @@ void QgsAuthIdentCertEdit::populateIdentityComboBox()
{
cmbIdentityCert->addItem( tr( "Select identity…" ), "" );

QList<QSslCertificate> certs( QgsApplication::authManager()->certIdentities() );
const QList<QSslCertificate> certs( QgsApplication::authManager()->certIdentities() );
if ( !certs.isEmpty() )
{
cmbIdentityCert->setIconSize( QSize( 26, 22 ) );
QgsStringMap idents;
Q_FOREACH ( const QSslCertificate &cert, certs )
for ( const QSslCertificate &cert : certs )
{
QString org( SSL_SUBJECT_INFO( cert, QSslCertificate::Organization ) );
if ( org.isEmpty() )
Expand Down
8 changes: 4 additions & 4 deletions src/auth/oauth2/qgsauthoauth2edit.cpp
Expand Up @@ -633,11 +633,11 @@ void QgsAuthOAuth2Edit::removeTokenCacheFile()
return;
}

QStringList cachefiles;
cachefiles << QgsAuthOAuth2Config::tokenCachePath( authcfg, false )
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, true );
const QStringList cachefiles = QStringList()
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, false )
<< QgsAuthOAuth2Config::tokenCachePath( authcfg, true );

Q_FOREACH ( const QString &cachefile, cachefiles )
for ( const QString &cachefile : cachefiles )
{
if ( QFile::exists( cachefile ) && !QFile::remove( cachefile ) )
{
Expand Down
20 changes: 11 additions & 9 deletions src/auth/oauth2/qgsauthoauth2method.cpp
Expand Up @@ -54,11 +54,11 @@ QgsAuthOAuth2Method::QgsAuthOAuth2Method()
<< QStringLiteral( "wcs" )
<< QStringLiteral( "wms" ) );

QStringList cachedirpaths;
cachedirpaths << QgsAuthOAuth2Config::tokenCacheDirectory()
<< QgsAuthOAuth2Config::tokenCacheDirectory( true );
const QStringList cachedirpaths = QStringList()
<< QgsAuthOAuth2Config::tokenCacheDirectory()
<< QgsAuthOAuth2Config::tokenCacheDirectory( true );

Q_FOREACH ( const QString &cachedirpath, cachedirpaths )
for ( const QString &cachedirpath : cachedirpaths )
{
QDir cachedir( cachedirpath );
if ( !cachedir.mkpath( cachedirpath ) )
Expand All @@ -71,10 +71,10 @@ QgsAuthOAuth2Method::QgsAuthOAuth2Method()
QgsAuthOAuth2Method::~QgsAuthOAuth2Method()
{
QDir tempdir( QgsAuthOAuth2Config::tokenCacheDirectory( true ) );
QStringList dirlist = tempdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
Q_FOREACH ( const QString &f, dirlist )
const QStringList dirlist = tempdir.entryList( QDir::Files | QDir::NoDotAndDotDot );
for ( const QString &f : dirlist )
{
QString tempfile( tempdir.path() + QStringLiteral( "/" ) + f );
QString tempfile( tempdir.path() + '/' + f );
if ( !QFile::remove( tempfile ) )
{
QgsDebugMsg( QStringLiteral( "FAILED to delete temp token cache file: %1" ).arg( tempfile ) );
Expand Down Expand Up @@ -343,7 +343,8 @@ void QgsAuthOAuth2Method::onLinkingSucceeded()
if ( !extraTokens.isEmpty() )
{
QString msg = QStringLiteral( "Extra tokens in response:\n" );
Q_FOREACH ( const QString &key, extraTokens.keys() )
const QStringList extraTokenKeys = extraTokens.keys();
for ( const QString &key : extraTokenKeys )
{
// don't expose the values in a log (unless they are only 3 chars long, of course)
msg += QStringLiteral( " %1:%2…\n" ).arg( key, extraTokens.value( key ).toString().left( 3 ) );
Expand Down Expand Up @@ -371,7 +372,8 @@ void QgsAuthOAuth2Method::onCloseBrowser()
// Bring focus back to QGIS app
if ( qobject_cast<QApplication *>( qApp ) )
{
Q_FOREACH ( QWidget *topwdgt, QgsApplication::topLevelWidgets() )
const QList<QWidget *> widgets = QgsApplication::topLevelWidgets();
for ( QWidget *topwdgt : widgets )
{
if ( topwdgt->objectName() == QStringLiteral( "MainWindow" ) )
{
Expand Down
1 change: 1 addition & 0 deletions src/auth/pkipaths/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (pkipathsauthmethod
qgis_core
qgis_gui
)
TARGET_COMPILE_DEFINITIONS(pkipathsauthmethod PRIVATE "-DQT_NO_FOREACH")

INSTALL(TARGETS pkipathsauthmethod
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
Expand Down
1 change: 1 addition & 0 deletions src/auth/pkipkcs12/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ TARGET_LINK_LIBRARIES (pkcs12authmethod
qgis_core
qgis_gui
)
TARGET_COMPILE_DEFINITIONS(pkcs12authmethod PRIVATE "-DQT_NO_FOREACH")

INSTALL(TARGETS pkcs12authmethod
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp
Expand Up @@ -107,7 +107,7 @@ QgsEditorWidgetSetup QgsEditorWidgetAutoConf::editorWidgetSetup( const QgsVector
}

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

void QgsEditorWidgetAutoConf::registerPlugin( QgsEditorWidgetAutoConfPlugin *plugin )
{
plugins.append( std::shared_ptr<QgsEditorWidgetAutoConfPlugin>( plugin ) );
mPlugins.append( std::shared_ptr<QgsEditorWidgetAutoConfPlugin>( plugin ) );
}
///@endcond
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetautoconf.h
Expand Up @@ -90,7 +90,7 @@ class GUI_EXPORT QgsEditorWidgetAutoConf SIP_SKIP
void registerPlugin( QgsEditorWidgetAutoConfPlugin *plugin );

private:
QList<std::shared_ptr<QgsEditorWidgetAutoConfPlugin> > plugins;
QList<std::shared_ptr<QgsEditorWidgetAutoConfPlugin> > mPlugins;
};
///@endcond

Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -105,7 +105,7 @@ void QgsRelationWidgetWrapper::setShowLabel( bool showLabel )

void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
{
QgsRelationEditorWidget *w = dynamic_cast<QgsRelationEditorWidget *>( editor );
QgsRelationEditorWidget *w = qobject_cast<QgsRelationEditorWidget *>( editor );

// if the editor cannot be cast to relation editor, insert a new one
if ( !w )
Expand Down
7 changes: 4 additions & 3 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -1374,11 +1374,12 @@ void QgsAttributeForm::init()
}
}

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

QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
Expand Down

0 comments on commit 825c240

Please sign in to comment.