Skip to content

Commit 702804f

Browse files
authored
Merge pull request #9739 from m-kuhn/kill_qforeach
No more Q_FOREACH in gui
2 parents ea4ea1f + 2f8b9c7 commit 702804f

File tree

113 files changed

+674
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+674
-353
lines changed

src/gui/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,8 @@ IF(ENABLE_MODELTEST)
10641064
TARGET_LINK_LIBRARIES(qgis_gui ${Qt5Test_LIBRARIES})
10651065
ENDIF(ENABLE_MODELTEST)
10661066

1067+
TARGET_COMPILE_DEFINITIONS(qgis_gui PRIVATE "-DQT_NO_FOREACH")
1068+
10671069
IF(WIN32)
10681070
ADD_DEFINITIONS(-DQWT_DLL)
10691071
ADD_DEFINITIONS(-DQSCINTILLA_DLL)

src/gui/attributetable/qgsattributetablefiltermodel.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTa
141141
}
142142

143143
QVector<int> newColumnMapping;
144-
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
144+
const auto constColumns = mConfig.columns();
145+
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
145146
{
146147
// Hidden? Forget about this column
147148
if ( columnConfig.hidden )
@@ -504,7 +505,8 @@ QModelIndex QgsAttributeTableFilterModel::fidToIndex( QgsFeatureId fid )
504505
QModelIndexList QgsAttributeTableFilterModel::fidToIndexList( QgsFeatureId fid )
505506
{
506507
QModelIndexList indexes;
507-
Q_FOREACH ( const QModelIndex &idx, masterModel()->idToIndexList( fid ) )
508+
const auto constIdToIndexList = masterModel()->idToIndexList( fid );
509+
for ( const QModelIndex &idx : constIdToIndexList )
508510
{
509511
indexes.append( mapFromMaster( idx ) );
510512
}

src/gui/attributetable/qgsattributetablemodel.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ void QgsAttributeTableModel::featuresDeleted( const QgsFeatureIds &fids )
105105
{
106106
QList<int> rows;
107107

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

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

125-
Q_FOREACH ( int row, rows )
126+
const auto constRows = rows;
127+
for ( int row : constRows )
126128
{
127129
#if 0
128130
qDebug() << "Row: " << row << ", begin " << beginRow << ", last " << lastRow << ", current " << currentRowCount << ", removed " << removedRows;

src/gui/attributetable/qgsattributetableview.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ bool QgsAttributeTableView::eventFilter( QObject *object, QEvent *event )
8989
void QgsAttributeTableView::setAttributeTableConfig( const QgsAttributeTableConfig &config )
9090
{
9191
int i = 0;
92-
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, config.columns() )
92+
const auto constColumns = config.columns();
93+
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
9394
{
9495
if ( columnConfig.hidden )
9596
continue;
@@ -201,7 +202,8 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
201202

202203
// first add user created layer actions
203204
QList<QgsAction> actions = mFilterModel->layer()->actions()->actions( QStringLiteral( "Feature" ) );
204-
Q_FOREACH ( const QgsAction &action, actions )
205+
const auto constActions = actions;
206+
for ( const QgsAction &action : constActions )
205207
{
206208
if ( !mFilterModel->layer()->isEditable() && action.isEnabledOnlyWhenEditable() )
207209
continue;
@@ -219,10 +221,9 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
219221
defaultAction = act;
220222
}
221223

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

243-
Q_FOREACH ( QAction *act, actionList )
244+
const auto constActionList = actionList;
245+
for ( QAction *act : constActionList )
244246
{
245247
if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown )
246248
{
@@ -325,7 +327,8 @@ void QgsAttributeTableView::keyPressEvent( QKeyEvent *event )
325327

326328
void QgsAttributeTableView::repaintRequested( const QModelIndexList &indexes )
327329
{
328-
Q_FOREACH ( const QModelIndex &index, indexes )
330+
const auto constIndexes = indexes;
331+
for ( const QModelIndex &index : constIndexes )
329332
{
330333
update( index );
331334
}

src/gui/attributetable/qgsdualview.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ void QgsDualView::columnBoxInit()
131131
mFeatureListPreviewButton->addAction( mActionExpressionPreview );
132132
mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
133133

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

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

587-
Q_FOREACH ( QgsMapLayerAction *action, registeredActions )
589+
const auto constRegisteredActions = registeredActions;
590+
for ( QgsMapLayerAction *action : constRegisteredActions )
588591
{
589592
QgsAttributeTableMapLayerAction *a = new QgsAttributeTableMapLayerAction( action->text(), this, action, sourceIndex );
590593
menu->addAction( action->text(), a, &QgsAttributeTableMapLayerAction::execute );

src/gui/attributetable/qgsfeaturelistview.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
185185
{
186186
QItemSelection selection;
187187

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

214215
void QgsFeatureListView::repaintRequested( const QModelIndexList &indexes )
215216
{
216-
Q_FOREACH ( const QModelIndex &index, indexes )
217+
const auto constIndexes = indexes;
218+
for ( const QModelIndex &index : constIndexes )
217219
{
218220
update( index );
219221
}

src/gui/attributetable/qgsfeatureselectionmodel.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
7575

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

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

@@ -89,7 +90,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
8990
if ( !mSyncEnabled )
9091
{
9192
mClearAndSelectBuffer = true;
92-
Q_FOREACH ( QgsFeatureId id, ids )
93+
const auto constIds = ids;
94+
for ( QgsFeatureId id : constIds )
9395
{
9496
if ( !mDeselectedBuffer.remove( id ) )
9597
{
@@ -106,7 +108,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
106108
{
107109
if ( !mSyncEnabled )
108110
{
109-
Q_FOREACH ( QgsFeatureId id, ids )
111+
const auto constIds = ids;
112+
for ( QgsFeatureId id : constIds )
110113
{
111114
if ( !mDeselectedBuffer.remove( id ) )
112115
{
@@ -123,7 +126,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
123126
{
124127
if ( !mSyncEnabled )
125128
{
126-
Q_FOREACH ( QgsFeatureId id, ids )
129+
const auto constIds = ids;
130+
for ( QgsFeatureId id : constIds )
127131
{
128132
if ( !mSelectedBuffer.remove( id ) )
129133
{
@@ -140,7 +144,8 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
140144
connect( mFeatureSelectionManager, &QgsIFeatureSelectionManager::selectionChanged, this, &QgsFeatureSelectionModel::layerSelectionChanged );
141145

142146
QModelIndexList updatedIndexes;
143-
Q_FOREACH ( const QModelIndex &idx, selection.indexes() )
147+
const auto indexes = selection.indexes();
148+
for ( const QModelIndex &idx : indexes )
144149
{
145150
updatedIndexes.append( expandIndexToRow( idx ) );
146151
}
@@ -164,12 +169,14 @@ void QgsFeatureSelectionModel::layerSelectionChanged( const QgsFeatureIds &selec
164169
else
165170
{
166171
QModelIndexList updatedIndexes;
167-
Q_FOREACH ( QgsFeatureId fid, selected )
172+
const auto constSelected = selected;
173+
for ( QgsFeatureId fid : constSelected )
168174
{
169175
updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
170176
}
171177

172-
Q_FOREACH ( QgsFeatureId fid, deselected )
178+
const auto constDeselected = deselected;
179+
for ( QgsFeatureId fid : constDeselected )
173180
{
174181
updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
175182
}

src/gui/attributetable/qgsfieldconditionalformatwidget.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ void QgsFieldConditionalFormatWidget::setPresets( const QList<QgsConditionalStyl
202202
{
203203
mPresets.clear();
204204
mPresetsModel->clear();
205-
Q_FOREACH ( const QgsConditionalStyle &style, styles )
205+
const auto constStyles = styles;
206+
for ( const QgsConditionalStyle &style : constStyles )
206207
{
207208
if ( style.isValid() )
208209
{
@@ -302,7 +303,8 @@ void QgsFieldConditionalFormatWidget::reloadStyles()
302303
{
303304
mModel->clear();
304305

305-
Q_FOREACH ( const QgsConditionalStyle &style, getStyles() )
306+
const auto constGetStyles = getStyles();
307+
for ( const QgsConditionalStyle &style : constGetStyles )
306308
{
307309
QStandardItem *item = new QStandardItem( style.displayText() );
308310
item->setIcon( QIcon( style.renderPreview() ) );

src/gui/attributetable/qgsorganizetablecolumnsdialog.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog( const QgsVectorLay
5858

5959
mFieldsList->clear();
6060

61-
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
61+
const auto constColumns = mConfig.columns();
62+
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
6263
{
6364
QListWidgetItem *item = nullptr;
6465
if ( columnConfig.type == QgsAttributeTableConfig::Action )

src/gui/auth/qgsauthauthoritieseditor.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ void QgsAuthAuthoritiesEditor::refreshCaCertsView()
160160

161161
static void removeChildren_( QTreeWidgetItem *item )
162162
{
163-
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
163+
const auto constTakeChildren = item->takeChildren();
164+
for ( QTreeWidgetItem *child : constTakeChildren )
164165
{
165166
delete child;
166167
}
@@ -270,7 +271,8 @@ void QgsAuthAuthoritiesEditor::appendCertsToItem( const QList<QSslCertificate> &
270271
QStringList untrustedids = mCertTrustCache.value( QgsAuthCertUtils::Untrusted );
271272

272273
// Columns: Common Name, Serial #, Expiry Date
273-
Q_FOREACH ( const QSslCertificate &cert, certs )
274+
const auto constCerts = certs;
275+
for ( const QSslCertificate &cert : constCerts )
274276
{
275277
QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
276278

@@ -452,7 +454,8 @@ void QgsAuthAuthoritiesEditor::btnAddCa_clicked()
452454

453455
if ( dlg->certTrustPolicy() != QgsAuthCertUtils::DefaultTrust )
454456
{
455-
Q_FOREACH ( const QSslCertificate &cert, certs )
457+
const auto constCerts = certs;
458+
for ( const QSslCertificate &cert : constCerts )
456459
{
457460
if ( !QgsApplication::authManager()->storeCertTrustPolicy( cert, dlg->certTrustPolicy() ) )
458461
{
@@ -688,7 +691,8 @@ void QgsAuthAuthoritiesEditor::btnCaFile_clicked()
688691
if ( dlg->certTrustPolicy() != QgsAuthCertUtils::DefaultTrust )
689692
{
690693
QList<QSslCertificate> certs( QgsApplication::authManager()->extraFileCAs() );
691-
Q_FOREACH ( const QSslCertificate &cert, certs )
694+
const auto constCerts = certs;
695+
for ( const QSslCertificate &cert : constCerts )
692696
{
693697
if ( !QgsApplication::authManager()->storeCertTrustPolicy( cert, dlg->certTrustPolicy() ) )
694698
{

src/gui/auth/qgsauthcertificateinfo.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ static void setItemBold_( QTreeWidgetItem *item )
4242

4343
static void removeChildren_( QTreeWidgetItem *item )
4444
{
45-
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
45+
const auto constTakeChildren = item->takeChildren();
46+
for ( QTreeWidgetItem *child : constTakeChildren )
4647
{
4748
delete child;
4849
}
@@ -144,7 +145,8 @@ bool QgsAuthCertInfo::populateQcaCertCollection()
144145
}
145146
if ( !mConnectionCAs.isEmpty() )
146147
{
147-
Q_FOREACH ( const QSslCertificate &cert, mConnectionCAs )
148+
const auto constMConnectionCAs = mConnectionCAs;
149+
for ( const QSslCertificate &cert : constMConnectionCAs )
148150
{
149151
QCA::ConvertResult res;
150152
QCA::Certificate acert = QCA::Certificate::fromPEM( cert.toPem(), &res, QStringLiteral( "qca-ossl" ) );
@@ -201,7 +203,8 @@ bool QgsAuthCertInfo::populateCertChain()
201203
}
202204

203205
// mirror chain to QSslCertificate
204-
Q_FOREACH ( QCA::Certificate cert, mACertChain )
206+
const auto constMACertChain = mACertChain;
207+
for ( QCA::Certificate cert : constMACertChain )
205208
{
206209
QSslCertificate qcert;
207210
if ( !cert.isNull() )
@@ -777,7 +780,8 @@ void QgsAuthCertInfo::populateInfoDetailsSection()
777780
QStringList keyusage;
778781
QStringList extkeyusage;
779782
QList<QCA::ConstraintType> certconsts = mCurrentACert.constraints();
780-
Q_FOREACH ( const QCA::ConstraintType &certconst, certconsts )
783+
const auto constCertconsts = certconsts;
784+
for ( const QCA::ConstraintType &certconst : constCertconsts )
781785
{
782786
if ( certconst.section() == QCA::ConstraintType::KeyUsage )
783787
{

src/gui/auth/qgsauthconfigedit.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void QgsAuthConfigEdit::populateAuthMethods()
102102

103103
// sort by auth method description attribute, then populate
104104
QMap<QString, QgsAuthMethod *> descmap;
105-
Q_FOREACH ( const QString &authMethodKey, authMethodKeys )
105+
const auto constAuthMethodKeys = authMethodKeys;
106+
for ( const QString &authMethodKey : constAuthMethodKeys )
106107
{
107108
QgsAuthMethod *authmethod = QgsApplication::authManager()->authMethod( authMethodKey );
108109
if ( !authmethod )

src/gui/auth/qgsauthidentitieseditor.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ void QgsAuthIdentitiesEditor::setupIdentitiesTree()
106106

107107
static void removeChildren_( QTreeWidgetItem *item )
108108
{
109-
Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
109+
const auto constTakeChildren = item->takeChildren();
110+
for ( QTreeWidgetItem *child : constTakeChildren )
110111
{
111112
delete child;
112113
}
@@ -193,7 +194,8 @@ void QgsAuthIdentitiesEditor::appendIdentitiesToItem( const QList<QSslCertificat
193194
QBrush redb( QgsAuthGuiUtils::redColor() );
194195

195196
// Columns: Common Name, Serial #, Expiry Date
196-
Q_FOREACH ( const QSslCertificate &cert, certs )
197+
const auto constCerts = certs;
198+
for ( const QSslCertificate &cert : constCerts )
197199
{
198200
QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
199201

src/gui/auth/qgsauthimportcertdialog.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void QgsAuthImportCertDialog::validateCertificates()
168168

169169
int certssize = certs.size();
170170

171-
Q_FOREACH ( const QSslCertificate &cert, certs )
171+
const auto constCerts = certs;
172+
for ( const QSslCertificate &cert : constCerts )
172173
{
173174
if ( QgsAuthCertUtils::certIsViable( cert ) )
174175
++validcerts;
@@ -192,7 +193,8 @@ void QgsAuthImportCertDialog::validateCertificates()
192193

193194
if ( !nixcerts.isEmpty() )
194195
{
195-
Q_FOREACH ( const QSslCertificate &nixcert, nixcerts )
196+
const auto constNixcerts = nixcerts;
197+
for ( const QSslCertificate &nixcert : constNixcerts )
196198
{
197199
certs.removeOne( nixcert );
198200
}

src/gui/auth/qgsauthimportidentitydialog.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ bool QgsAuthImportIdentityDialog::validatePkiPkcs12()
406406
QList<QSslCertificate> ca_certs;
407407
if ( cert_chain.size() > 1 )
408408
{
409-
Q_FOREACH ( const QCA::Certificate &ca_cert, cert_chain )
409+
const auto constCert_chain = cert_chain;
410+
for ( const QCA::Certificate &ca_cert : constCert_chain )
410411
{
411412
if ( ca_cert != cert_chain.primary() )
412413
{

0 commit comments

Comments
 (0)