Skip to content

Commit

Permalink
Merge pull request #9739 from m-kuhn/kill_qforeach
Browse files Browse the repository at this point in the history
No more Q_FOREACH in gui
  • Loading branch information
m-kuhn committed Apr 7, 2019
2 parents ea4ea1f + 2f8b9c7 commit 702804f
Show file tree
Hide file tree
Showing 113 changed files with 674 additions and 353 deletions.
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -1064,6 +1064,8 @@ IF(ENABLE_MODELTEST)
TARGET_LINK_LIBRARIES(qgis_gui ${Qt5Test_LIBRARIES})
ENDIF(ENABLE_MODELTEST)

TARGET_COMPILE_DEFINITIONS(qgis_gui PRIVATE "-DQT_NO_FOREACH")

IF(WIN32)
ADD_DEFINITIONS(-DQWT_DLL)
ADD_DEFINITIONS(-DQSCINTILLA_DLL)
Expand Down
6 changes: 4 additions & 2 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Expand Up @@ -141,7 +141,8 @@ void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTa
}

QVector<int> newColumnMapping;
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
const auto constColumns = mConfig.columns();
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
{
// Hidden? Forget about this column
if ( columnConfig.hidden )
Expand Down Expand Up @@ -504,7 +505,8 @@ QModelIndex QgsAttributeTableFilterModel::fidToIndex( QgsFeatureId fid )
QModelIndexList QgsAttributeTableFilterModel::fidToIndexList( QgsFeatureId fid )
{
QModelIndexList indexes;
Q_FOREACH ( const QModelIndex &idx, masterModel()->idToIndexList( fid ) )
const auto constIdToIndexList = masterModel()->idToIndexList( fid );
for ( const QModelIndex &idx : constIdToIndexList )
{
indexes.append( mapFromMaster( idx ) );
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -105,7 +105,8 @@ void QgsAttributeTableModel::featuresDeleted( const QgsFeatureIds &fids )
{
QList<int> rows;

Q_FOREACH ( QgsFeatureId fid, fids )
const auto constFids = fids;
for ( QgsFeatureId fid : constFids )
{
QgsDebugMsgLevel( QStringLiteral( "(%2) fid: %1, size: %3" ).arg( fid ).arg( mFeatureRequest.filterType() ).arg( mIdRowMap.size() ), 4 );

Expand All @@ -122,7 +123,8 @@ void QgsAttributeTableModel::featuresDeleted( const QgsFeatureIds &fids )
int removedRows = 0;
bool reset = false;

Q_FOREACH ( int row, rows )
const auto constRows = rows;
for ( int row : constRows )
{
#if 0
qDebug() << "Row: " << row << ", begin " << beginRow << ", last " << lastRow << ", current " << currentRowCount << ", removed " << removedRows;
Expand Down
17 changes: 10 additions & 7 deletions src/gui/attributetable/qgsattributetableview.cpp
Expand Up @@ -89,7 +89,8 @@ bool QgsAttributeTableView::eventFilter( QObject *object, QEvent *event )
void QgsAttributeTableView::setAttributeTableConfig( const QgsAttributeTableConfig &config )
{
int i = 0;
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, config.columns() )
const auto constColumns = config.columns();
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
{
if ( columnConfig.hidden )
continue;
Expand Down Expand Up @@ -201,7 +202,8 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )

// first add user created layer actions
QList<QgsAction> actions = mFilterModel->layer()->actions()->actions( QStringLiteral( "Feature" ) );
Q_FOREACH ( const QgsAction &action, actions )
const auto constActions = actions;
for ( const QgsAction &action : constActions )
{
if ( !mFilterModel->layer()->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;
Expand All @@ -219,10 +221,9 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
defaultAction = act;
}

const auto mapLayerActions {QgsGui::mapLayerActionRegistry()->mapLayerActions( mFilterModel->layer(), QgsMapLayerAction::SingleFeature ) };
// next add any registered actions for this layer
Q_FOREACH ( QgsMapLayerAction *mapLayerAction,
QgsGui::mapLayerActionRegistry()->mapLayerActions( mFilterModel->layer(),
QgsMapLayerAction::SingleFeature ) )
for ( QgsMapLayerAction *mapLayerAction : mapLayerActions )
{
QAction *action = new QAction( mapLayerAction->icon(), mapLayerAction->text(), container );
action->setData( "map_layer_action" );
Expand All @@ -240,7 +241,8 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
if ( !defaultAction && !actionList.isEmpty() )
defaultAction = actionList.at( 0 );

Q_FOREACH ( QAction *act, actionList )
const auto constActionList = actionList;
for ( QAction *act : constActionList )
{
if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown )
{
Expand Down Expand Up @@ -325,7 +327,8 @@ void QgsAttributeTableView::keyPressEvent( QKeyEvent *event )

void QgsAttributeTableView::repaintRequested( const QModelIndexList &indexes )
{
Q_FOREACH ( const QModelIndex &index, indexes )
const auto constIndexes = indexes;
for ( const QModelIndex &index : constIndexes )
{
update( index );
}
Expand Down
9 changes: 6 additions & 3 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -131,7 +131,8 @@ void QgsDualView::columnBoxInit()
mFeatureListPreviewButton->addAction( mActionExpressionPreview );
mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );

Q_FOREACH ( const QgsField &field, fields )
const auto constFields = fields;
for ( const QgsField &field : constFields )
{
int fieldIndex = mLayer->fields().lookupField( field.name() );
if ( fieldIndex == -1 )
Expand Down Expand Up @@ -564,7 +565,8 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
QAction *a = menu->addAction( tr( "Run Layer Action" ) );
a->setEnabled( false );

Q_FOREACH ( const QgsAction &action, actions )
const auto constActions = actions;
for ( const QgsAction &action : constActions )
{
if ( !action.runable() )
continue;
Expand All @@ -584,7 +586,8 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
//add a separator between user defined and standard actions
menu->addSeparator();

Q_FOREACH ( QgsMapLayerAction *action, registeredActions )
const auto constRegisteredActions = registeredActions;
for ( QgsMapLayerAction *action : constRegisteredActions )
{
QgsAttributeTableMapLayerAction *a = new QgsAttributeTableMapLayerAction( action->text(), this, action, sourceIndex );
menu->addAction( action->text(), a, &QgsAttributeTableMapLayerAction::execute );
Expand Down
6 changes: 4 additions & 2 deletions src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -185,7 +185,8 @@ void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
{
QItemSelection selection;

Q_FOREACH ( QgsFeatureId fid, fids )
const auto constFids = fids;
for ( QgsFeatureId fid : constFids )
{
selection.append( QItemSelectionRange( mModel->mapToMaster( mModel->fidToIdx( fid ) ) ) );
}
Expand Down Expand Up @@ -213,7 +214,8 @@ void QgsFeatureListView::setEditSelection( const QModelIndex &index, QItemSelect

void QgsFeatureListView::repaintRequested( const QModelIndexList &indexes )
{
Q_FOREACH ( const QModelIndex &index, indexes )
const auto constIndexes = indexes;
for ( const QModelIndex &index : constIndexes )
{
update( index );
}
Expand Down
21 changes: 14 additions & 7 deletions src/gui/attributetable/qgsfeatureselectionmodel.cpp
Expand Up @@ -75,7 +75,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,

QgsDebugMsg( QStringLiteral( "Index count: %1" ).arg( selection.indexes().size() ) );

Q_FOREACH ( const QModelIndex &index, selection.indexes() )
const auto constIndexes = selection.indexes();
for ( const QModelIndex &index : constIndexes )
{
QgsFeatureId id = index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();

Expand All @@ -89,7 +90,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
if ( !mSyncEnabled )
{
mClearAndSelectBuffer = true;
Q_FOREACH ( QgsFeatureId id, ids )
const auto constIds = ids;
for ( QgsFeatureId id : constIds )
{
if ( !mDeselectedBuffer.remove( id ) )
{
Expand All @@ -106,7 +108,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
{
if ( !mSyncEnabled )
{
Q_FOREACH ( QgsFeatureId id, ids )
const auto constIds = ids;
for ( QgsFeatureId id : constIds )
{
if ( !mDeselectedBuffer.remove( id ) )
{
Expand All @@ -123,7 +126,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
{
if ( !mSyncEnabled )
{
Q_FOREACH ( QgsFeatureId id, ids )
const auto constIds = ids;
for ( QgsFeatureId id : constIds )
{
if ( !mSelectedBuffer.remove( id ) )
{
Expand All @@ -140,7 +144,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
connect( mFeatureSelectionManager, &QgsIFeatureSelectionManager::selectionChanged, this, &QgsFeatureSelectionModel::layerSelectionChanged );

QModelIndexList updatedIndexes;
Q_FOREACH ( const QModelIndex &idx, selection.indexes() )
const auto indexes = selection.indexes();
for ( const QModelIndex &idx : indexes )
{
updatedIndexes.append( expandIndexToRow( idx ) );
}
Expand All @@ -164,12 +169,14 @@ void QgsFeatureSelectionModel::layerSelectionChanged( const QgsFeatureIds &selec
else
{
QModelIndexList updatedIndexes;
Q_FOREACH ( QgsFeatureId fid, selected )
const auto constSelected = selected;
for ( QgsFeatureId fid : constSelected )
{
updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
}

Q_FOREACH ( QgsFeatureId fid, deselected )
const auto constDeselected = deselected;
for ( QgsFeatureId fid : constDeselected )
{
updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Expand Up @@ -202,7 +202,8 @@ void QgsFieldConditionalFormatWidget::setPresets( const QList<QgsConditionalStyl
{
mPresets.clear();
mPresetsModel->clear();
Q_FOREACH ( const QgsConditionalStyle &style, styles )
const auto constStyles = styles;
for ( const QgsConditionalStyle &style : constStyles )
{
if ( style.isValid() )
{
Expand Down Expand Up @@ -302,7 +303,8 @@ void QgsFieldConditionalFormatWidget::reloadStyles()
{
mModel->clear();

Q_FOREACH ( const QgsConditionalStyle &style, getStyles() )
const auto constGetStyles = getStyles();
for ( const QgsConditionalStyle &style : constGetStyles )
{
QStandardItem *item = new QStandardItem( style.displayText() );
item->setIcon( QIcon( style.renderPreview() ) );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/attributetable/qgsorganizetablecolumnsdialog.cpp
Expand Up @@ -58,7 +58,8 @@ QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog( const QgsVectorLay

mFieldsList->clear();

Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
const auto constColumns = mConfig.columns();
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
{
QListWidgetItem *item = nullptr;
if ( columnConfig.type == QgsAttributeTableConfig::Action )
Expand Down
12 changes: 8 additions & 4 deletions src/gui/auth/qgsauthauthoritieseditor.cpp
Expand Up @@ -160,7 +160,8 @@ void QgsAuthAuthoritiesEditor::refreshCaCertsView()

static void removeChildren_( QTreeWidgetItem *item )
{
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
const auto constTakeChildren = item->takeChildren();
for ( QTreeWidgetItem *child : constTakeChildren )
{
delete child;
}
Expand Down Expand Up @@ -270,7 +271,8 @@ void QgsAuthAuthoritiesEditor::appendCertsToItem( const QList<QSslCertificate> &
QStringList untrustedids = mCertTrustCache.value( QgsAuthCertUtils::Untrusted );

// Columns: Common Name, Serial #, Expiry Date
Q_FOREACH ( const QSslCertificate &cert, certs )
const auto constCerts = certs;
for ( const QSslCertificate &cert : constCerts )
{
QString id( QgsAuthCertUtils::shaHexForCert( cert ) );

Expand Down Expand Up @@ -452,7 +454,8 @@ void QgsAuthAuthoritiesEditor::btnAddCa_clicked()

if ( dlg->certTrustPolicy() != QgsAuthCertUtils::DefaultTrust )
{
Q_FOREACH ( const QSslCertificate &cert, certs )
const auto constCerts = certs;
for ( const QSslCertificate &cert : constCerts )
{
if ( !QgsApplication::authManager()->storeCertTrustPolicy( cert, dlg->certTrustPolicy() ) )
{
Expand Down Expand Up @@ -688,7 +691,8 @@ void QgsAuthAuthoritiesEditor::btnCaFile_clicked()
if ( dlg->certTrustPolicy() != QgsAuthCertUtils::DefaultTrust )
{
QList<QSslCertificate> certs( QgsApplication::authManager()->extraFileCAs() );
Q_FOREACH ( const QSslCertificate &cert, certs )
const auto constCerts = certs;
for ( const QSslCertificate &cert : constCerts )
{
if ( !QgsApplication::authManager()->storeCertTrustPolicy( cert, dlg->certTrustPolicy() ) )
{
Expand Down
12 changes: 8 additions & 4 deletions src/gui/auth/qgsauthcertificateinfo.cpp
Expand Up @@ -42,7 +42,8 @@ static void setItemBold_( QTreeWidgetItem *item )

static void removeChildren_( QTreeWidgetItem *item )
{
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
const auto constTakeChildren = item->takeChildren();
for ( QTreeWidgetItem *child : constTakeChildren )
{
delete child;
}
Expand Down Expand Up @@ -144,7 +145,8 @@ bool QgsAuthCertInfo::populateQcaCertCollection()
}
if ( !mConnectionCAs.isEmpty() )
{
Q_FOREACH ( const QSslCertificate &cert, mConnectionCAs )
const auto constMConnectionCAs = mConnectionCAs;
for ( const QSslCertificate &cert : constMConnectionCAs )
{
QCA::ConvertResult res;
QCA::Certificate acert = QCA::Certificate::fromPEM( cert.toPem(), &res, QStringLiteral( "qca-ossl" ) );
Expand Down Expand Up @@ -201,7 +203,8 @@ bool QgsAuthCertInfo::populateCertChain()
}

// mirror chain to QSslCertificate
Q_FOREACH ( QCA::Certificate cert, mACertChain )
const auto constMACertChain = mACertChain;
for ( QCA::Certificate cert : constMACertChain )
{
QSslCertificate qcert;
if ( !cert.isNull() )
Expand Down Expand Up @@ -777,7 +780,8 @@ void QgsAuthCertInfo::populateInfoDetailsSection()
QStringList keyusage;
QStringList extkeyusage;
QList<QCA::ConstraintType> certconsts = mCurrentACert.constraints();
Q_FOREACH ( const QCA::ConstraintType &certconst, certconsts )
const auto constCertconsts = certconsts;
for ( const QCA::ConstraintType &certconst : constCertconsts )
{
if ( certconst.section() == QCA::ConstraintType::KeyUsage )
{
Expand Down
3 changes: 2 additions & 1 deletion src/gui/auth/qgsauthconfigedit.cpp
Expand Up @@ -102,7 +102,8 @@ void QgsAuthConfigEdit::populateAuthMethods()

// sort by auth method description attribute, then populate
QMap<QString, QgsAuthMethod *> descmap;
Q_FOREACH ( const QString &authMethodKey, authMethodKeys )
const auto constAuthMethodKeys = authMethodKeys;
for ( const QString &authMethodKey : constAuthMethodKeys )
{
QgsAuthMethod *authmethod = QgsApplication::authManager()->authMethod( authMethodKey );
if ( !authmethod )
Expand Down
6 changes: 4 additions & 2 deletions src/gui/auth/qgsauthidentitieseditor.cpp
Expand Up @@ -106,7 +106,8 @@ void QgsAuthIdentitiesEditor::setupIdentitiesTree()

static void removeChildren_( QTreeWidgetItem *item )
{
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
const auto constTakeChildren = item->takeChildren();
for ( QTreeWidgetItem *child : constTakeChildren )
{
delete child;
}
Expand Down Expand Up @@ -193,7 +194,8 @@ void QgsAuthIdentitiesEditor::appendIdentitiesToItem( const QList<QSslCertificat
QBrush redb( QgsAuthGuiUtils::redColor() );

// Columns: Common Name, Serial #, Expiry Date
Q_FOREACH ( const QSslCertificate &cert, certs )
const auto constCerts = certs;
for ( const QSslCertificate &cert : constCerts )
{
QString id( QgsAuthCertUtils::shaHexForCert( cert ) );

Expand Down
6 changes: 4 additions & 2 deletions src/gui/auth/qgsauthimportcertdialog.cpp
Expand Up @@ -168,7 +168,8 @@ void QgsAuthImportCertDialog::validateCertificates()

int certssize = certs.size();

Q_FOREACH ( const QSslCertificate &cert, certs )
const auto constCerts = certs;
for ( const QSslCertificate &cert : constCerts )
{
if ( QgsAuthCertUtils::certIsViable( cert ) )
++validcerts;
Expand All @@ -192,7 +193,8 @@ void QgsAuthImportCertDialog::validateCertificates()

if ( !nixcerts.isEmpty() )
{
Q_FOREACH ( const QSslCertificate &nixcert, nixcerts )
const auto constNixcerts = nixcerts;
for ( const QSslCertificate &nixcert : constNixcerts )
{
certs.removeOne( nixcert );
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/auth/qgsauthimportidentitydialog.cpp
Expand Up @@ -406,7 +406,8 @@ bool QgsAuthImportIdentityDialog::validatePkiPkcs12()
QList<QSslCertificate> ca_certs;
if ( cert_chain.size() > 1 )
{
Q_FOREACH ( const QCA::Certificate &ca_cert, cert_chain )
const auto constCert_chain = cert_chain;
for ( const QCA::Certificate &ca_cert : constCert_chain )
{
if ( ca_cert != cert_chain.primary() )
{
Expand Down

0 comments on commit 702804f

Please sign in to comment.