Skip to content
Permalink
Browse files

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 825c240be3d2adba3dc34613946f69a913339d44
@@ -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}
@@ -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}
@@ -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}
@@ -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() )
@@ -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 ) )
{
@@ -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 ) )
@@ -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 ) );
@@ -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 ) );
@@ -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" ) )
{
@@ -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}
@@ -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}
@@ -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 );
@@ -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
@@ -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

@@ -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 )
@@ -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 );

0 comments on commit 825c240

Please sign in to comment.
You can’t perform that action at this time.