Skip to content
Permalink
Browse files
Merge pull request #9739 from m-kuhn/kill_qforeach
No more Q_FOREACH in gui
  • Loading branch information
m-kuhn committed Apr 7, 2019
2 parents ea4ea1f + 2f8b9c7 commit 702804f6f956e7bf31993924f0eb19d6d97251c9
Show file tree
Hide file tree
Showing 113 changed files with 674 additions and 353 deletions.
@@ -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)
@@ -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 )
@@ -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 ) );
}
@@ -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 );

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

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

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

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

0 comments on commit 702804f

Please sign in to comment.