Skip to content

Commit

Permalink
Merge pull request #9786 from m-kuhn/app_no_qforeach
Browse files Browse the repository at this point in the history
No more Q_FOREACH in app
  • Loading branch information
m-kuhn committed Apr 15, 2019
2 parents f86d8de + 2f3646a commit 04409ac
Show file tree
Hide file tree
Showing 66 changed files with 680 additions and 637 deletions.
6 changes: 4 additions & 2 deletions src/app/3d/qgspoint3dsymbolwidget.cpp
Expand Up @@ -51,7 +51,8 @@ QgsPoint3DSymbolWidget::QgsPoint3DSymbolWidget( QWidget *parent )
QList<QDoubleSpinBox *> spinWidgets;
spinWidgets << spinRadius << spinTopRadius << spinBottomRadius << spinMinorRadius << spinSize << spinLength;
spinWidgets << spinTX << spinTY << spinTZ << spinSX << spinSY << spinSZ << spinRX << spinRY << spinRZ;
Q_FOREACH ( QDoubleSpinBox *spinBox, spinWidgets )
const auto constSpinWidgets = spinWidgets;
for ( QDoubleSpinBox *spinBox : constSpinWidgets )
connect( spinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPoint3DSymbolWidget::changed );
connect( lineEditModel, static_cast<void ( QLineEdit::* )( const QString & )>( &QLineEdit::textChanged ), this, &QgsPoint3DSymbolWidget::changed );
connect( btnModel, static_cast<void ( QToolButton::* )( bool )>( &QToolButton::clicked ), this, &QgsPoint3DSymbolWidget::onChooseModelClicked );
Expand Down Expand Up @@ -254,7 +255,8 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
break;
}

Q_FOREACH ( QWidget *w, allWidgets )
const auto constAllWidgets = allWidgets;
for ( QWidget *w : constAllWidgets )
{
w->setVisible( activeWidgets.contains( w ) );
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/3d/qgsrulebased3drendererwidget.cpp
Expand Up @@ -150,7 +150,8 @@ void QgsRuleBased3DRendererWidget::editRule( const QModelIndex &index )
void QgsRuleBased3DRendererWidget::removeRule()
{
QItemSelection sel = viewRules->selectionModel()->selection();
Q_FOREACH ( const QItemSelectionRange &range, sel )
const auto constSel = sel;
for ( const QItemSelectionRange &range : constSel )
{
if ( range.isValid() )
mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
Expand Down Expand Up @@ -405,7 +406,8 @@ QMimeData *QgsRuleBased3DRendererModel::mimeData( const QModelIndexList &indexes

QDataStream stream( &encodedData, QIODevice::WriteOnly );

Q_FOREACH ( const QModelIndex &index, indexes )
const auto constIndexes = indexes;
for ( const QModelIndex &index : constIndexes )
{
// each item consists of several columns - let's add it with just first one
if ( !index.isValid() || index.column() != 0 )
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -828,6 +828,8 @@ TARGET_LINK_LIBRARIES(qgis_app
libdxfrw
)

TARGET_COMPILE_DEFINITIONS(qgis_app PRIVATE "-DQT_NO_FOREACH")

IF(ENABLE_MODELTEST)
TARGET_LINK_LIBRARIES(qgis_app ${Qt5Test_LIBRARIES})
ENDIF(ENABLE_MODELTEST)
Expand Down
6 changes: 4 additions & 2 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -289,7 +289,8 @@ void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, const QString &n
if ( !layers.isEmpty() )
{
QStringList exprlist;
Q_FOREACH ( QString layer, layers )
const auto constLayers = layers;
for ( QString layer : constLayers )
{
exprlist.append( QStringLiteral( "'%1'" ).arg( layer.replace( QLatin1String( "'" ), QLatin1String( "''" ) ) ) );
}
Expand Down Expand Up @@ -506,7 +507,8 @@ void QgsDwgImportDialog::buttonBox_accepted()
QgsLayerTreeGroup *dwgGroup = QgisApp::instance()->layerTreeView()->layerTreeModel()->rootGroup()->addGroup( leLayerGroup->text() );
Q_ASSERT( dwgGroup );

Q_FOREACH ( const QString &layer, layers.keys() )
const auto constKeys = layers.keys();
for ( const QString &layer : constKeys )
{
createGroup( dwgGroup, layer, QStringList( layer ), layers[layer] );
}
Expand Down
487 changes: 153 additions & 334 deletions src/app/dwg/qgsdwgimporter.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/app/layout/qgslayoutaddpagesdialog.cpp
Expand Up @@ -29,7 +29,8 @@ QgsLayoutAddPagesDialog::QgsLayoutAddPagesDialog( QWidget *parent, Qt::WindowFla
mPageOrientationComboBox->addItem( tr( "Landscape" ), QgsLayoutItemPage::Landscape );
mPageOrientationComboBox->setCurrentIndex( 1 );

Q_FOREACH ( const QgsPageSize &size, QgsApplication::pageSizeRegistry()->entries() )
const auto constEntries = QgsApplication::pageSizeRegistry()->entries();
for ( const QgsPageSize &size : constEntries )
{
mPageSizeComboBox->addItem( size.displayName, size.name );
}
Expand Down
12 changes: 8 additions & 4 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -705,7 +705,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
QValidator *zoomValidator = new QRegularExpressionValidator( zoomRx, mStatusZoomCombo );
mStatusZoomCombo->lineEdit()->setValidator( zoomValidator );

Q_FOREACH ( double level, sStatusZoomLevelsList )
const auto constSStatusZoomLevelsList = sStatusZoomLevelsList;
for ( double level : constSStatusZoomLevelsList )
{
mStatusZoomCombo->insertItem( 0, tr( "%1%" ).arg( level * 100.0, 0, 'f', 1 ), level );
}
Expand Down Expand Up @@ -912,7 +913,8 @@ QMenu *QgsLayoutDesignerDialog::createPopupMenu()
plabel->setAlignment( Qt::AlignHCenter );
panelstitle->setDefaultWidget( plabel );
menu->addAction( panelstitle );
Q_FOREACH ( QAction *a, panels )
const auto constPanels = panels;
for ( QAction *a : constPanels )
{
if ( ( a == mAtlasDock->toggleViewAction() && !dynamic_cast< QgsPrintLayout * >( mMasterLayout ) ) ||
( a == mReportDock->toggleViewAction() && !dynamic_cast< QgsReport * >( mMasterLayout ) ) )
Expand All @@ -938,7 +940,8 @@ QMenu *QgsLayoutDesignerDialog::createPopupMenu()
toolbarstitle->setDefaultWidget( tlabel );
menu->addAction( toolbarstitle );
std::sort( toolbars.begin(), toolbars.end(), cmpByText_ );
Q_FOREACH ( QAction *a, toolbars )
const auto constToolbars = toolbars;
for ( QAction *a : constToolbars )
{
if ( ( a == mAtlasToolbar->toggleViewAction() && !dynamic_cast< QgsPrintLayout * >( mMasterLayout ) ) ||
( a == mReportToolbar->toggleViewAction() && !dynamic_cast< QgsReport * >( mMasterLayout ) ) )
Expand Down Expand Up @@ -1080,7 +1083,8 @@ void QgsLayoutDesignerDialog::setIconSizes( int size )

//Change all current icon sizes.
QList<QToolBar *> toolbars = findChildren<QToolBar *>();
Q_FOREACH ( QToolBar *toolbar, toolbars )
const auto constToolbars = toolbars;
for ( QToolBar *toolbar : constToolbars )
{
toolbar->setIconSize( QSize( size, size ) );
}
Expand Down
18 changes: 12 additions & 6 deletions src/app/layout/qgslayoutguidewidget.cpp
Expand Up @@ -74,7 +74,8 @@ void QgsLayoutGuideWidget::addVerticalGuide()
void QgsLayoutGuideWidget::deleteHorizontalGuide()
{
mLayout->undoStack()->beginMacro( tr( "Remove Horizontal Guides" ) );
Q_FOREACH ( const QModelIndex &index, mHozGuidesTableView->selectionModel()->selectedIndexes() )
const auto constSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : constSelectedIndexes )
{
mHozGuidesTableView->closePersistentEditor( index );
if ( index.column() == 0 )
Expand All @@ -86,7 +87,8 @@ void QgsLayoutGuideWidget::deleteHorizontalGuide()
void QgsLayoutGuideWidget::deleteVerticalGuide()
{
mLayout->undoStack()->beginMacro( tr( "Remove Vertical Guides" ) );
Q_FOREACH ( const QModelIndex &index, mVertGuidesTableView->selectionModel()->selectedIndexes() )
const auto constSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : constSelectedIndexes )
{
mVertGuidesTableView->closePersistentEditor( index );
if ( index.column() == 0 )
Expand All @@ -102,11 +104,13 @@ void QgsLayoutGuideWidget::pageChanged( int page )
// have to close any open editors - or we'll get a crash

// qt - y u no do this for me?
Q_FOREACH ( const QModelIndex &index, mHozGuidesTableView->selectionModel()->selectedIndexes() )
const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : horizontalSelectedIndexes )
{
mHozGuidesTableView->closePersistentEditor( index );
}
Q_FOREACH ( const QModelIndex &index, mVertGuidesTableView->selectionModel()->selectedIndexes() )
const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : verticalSelectedIndexes )
{
mVertGuidesTableView->closePersistentEditor( index );
}
Expand All @@ -119,11 +123,13 @@ void QgsLayoutGuideWidget::pageChanged( int page )
void QgsLayoutGuideWidget::clearAll()
{
// qt - y u no do this for me?
Q_FOREACH ( const QModelIndex &index, mHozGuidesTableView->selectionModel()->selectedIndexes() )
const auto horizontalSelectedIndexes = mHozGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : horizontalSelectedIndexes )
{
mHozGuidesTableView->closePersistentEditor( index );
}
Q_FOREACH ( const QModelIndex &index, mVertGuidesTableView->selectionModel()->selectedIndexes() )
const auto verticalSelectedIndexes = mVertGuidesTableView->selectionModel()->selectedIndexes();
for ( const QModelIndex &index : verticalSelectedIndexes )
{
mVertGuidesTableView->closePersistentEditor( index );
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -744,12 +744,13 @@ void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
mLegend->beginCommand( tr( "Remove Legend Item" ) );

QList<QPersistentModelIndex> indexes;
Q_FOREACH ( const QModelIndex &index, selectionModel->selectedIndexes() )
const auto constSelectedIndexes = selectionModel->selectedIndexes();
for ( const QModelIndex &index : constSelectedIndexes )
indexes << index;

// first try to remove legend nodes
QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
Q_FOREACH ( const QPersistentModelIndex &index, indexes )
for ( const QPersistentModelIndex &index : qgis::as_const( indexes ) )
{
if ( QgsLayerTreeModelLegendNode *legendNode = mItemTreeView->layerTreeModel()->index2legendNode( index ) )
{
Expand All @@ -763,7 +764,8 @@ void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( it.key() );

Q_FOREACH ( int i, toDelete )
const auto constToDelete = toDelete;
for ( int i : constToDelete )
{
if ( i >= 0 && i < order.count() )
order.removeAt( i );
Expand All @@ -774,7 +776,7 @@ void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
}

// then remove layer tree nodes
Q_FOREACH ( const QPersistentModelIndex &index, indexes )
for ( const QPersistentModelIndex &index : qgis::as_const( indexes ) )
{
if ( index.isValid() && mItemTreeView->layerTreeModel()->index2node( index ) )
mLegend->model()->removeRow( index.row(), index.parent() );
Expand Down Expand Up @@ -825,7 +827,8 @@ void QgsLayoutLegendWidget::resetLayerNodeToDefaults()

mLegend->beginCommand( tr( "Update Legend" ) );

Q_FOREACH ( const QString &key, nodeLayer->customProperties() )
const auto constCustomProperties = nodeLayer->customProperties();
for ( const QString &key : constCustomProperties )
{
if ( key.startsWith( QLatin1String( "legend/" ) ) )
nodeLayer->removeCustomProperty( key );
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout/qgslayoutmanagerdialog.cpp
Expand Up @@ -164,7 +164,8 @@ QMap<QString, QString> QgsLayoutManagerDialog::otherTemplates() const
{
QMap<QString, QString> templateMap;
QStringList paths = QgsApplication::layoutTemplatePaths();
Q_FOREACH ( const QString &path, paths )
const auto constPaths = paths;
for ( const QString &path : constPaths )
{
QMap<QString, QString> templates = templatesFromPath( path );
QMap<QString, QString>::const_iterator templateIt = templates.constBegin();
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout/qgslayoutmapwidget.cpp
Expand Up @@ -246,7 +246,8 @@ void QgsLayoutMapWidget::aboutToShowKeepLayersVisibilityPresetsMenu()
return;

menu->clear();
Q_FOREACH ( const QString &presetName, QgsProject::instance()->mapThemeCollection()->mapThemes() )
const auto constMapThemes = QgsProject::instance()->mapThemeCollection()->mapThemes();
for ( const QString &presetName : constMapThemes )
{
menu->addAction( presetName, this, &QgsLayoutMapWidget::keepLayersVisibilityPresetSelected );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout/qgslayoutpagepropertieswidget.cpp
Expand Up @@ -31,7 +31,8 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
mPageOrientationComboBox->addItem( tr( "Portrait" ), QgsLayoutItemPage::Portrait );
mPageOrientationComboBox->addItem( tr( "Landscape" ), QgsLayoutItemPage::Landscape );

Q_FOREACH ( const QgsPageSize &size, QgsApplication::pageSizeRegistry()->entries() )
const auto constEntries = QgsApplication::pageSizeRegistry()->entries();
for ( const QgsPageSize &size : constEntries )
{
mPageSizeComboBox->addItem( size.displayName, size.name );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -152,7 +152,8 @@ void QgsActionLocatorFilter::searchActions( const QString &string, QWidget *pare
QRegularExpression extractFromTooltip( QStringLiteral( "<b>(.*)</b>" ) );
QRegularExpression newLineToSpace( QStringLiteral( "[\\s\\n\\r]+" ) );

Q_FOREACH ( QAction *action, parent->actions() )
const auto constActions = parent->actions();
for ( QAction *action : constActions )
{
if ( action->menu() )
{
Expand Down
12 changes: 8 additions & 4 deletions src/app/main.cpp
Expand Up @@ -1156,7 +1156,8 @@ int main( int argc, char *argv[] )
gdalShares << QCoreApplication::applicationDirPath().append( "/share/gdal" )
<< appResources.append( "/share/gdal" )
<< appResources.append( "/gdal" );
Q_FOREACH ( const QString &gdalShare, gdalShares )
const auto constGdalShares = gdalShares;
for ( const QString &gdalShare : constGdalShares )
{
if ( QFile::exists( gdalShare ) )
{
Expand All @@ -1175,7 +1176,8 @@ int main( int argc, char *argv[] )
QStringList customVarsList = settings.value( QStringLiteral( "qgis/customEnvVars" ), "" ).toStringList();
if ( !customVarsList.isEmpty() )
{
Q_FOREACH ( const QString &varStr, customVarsList )
const auto constCustomVarsList = customVarsList;
for ( const QString &varStr : constCustomVarsList )
{
int pos = varStr.indexOf( QLatin1Char( '|' ) );
if ( pos == -1 )
Expand Down Expand Up @@ -1431,7 +1433,8 @@ int main( int argc, char *argv[] )
QList< QgsDxfExport::DxfLayer > layers;
if ( !dxfMapTheme.isEmpty() )
{
Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayers( dxfMapTheme ) )
const auto constMapThemeVisibleLayers = QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayers( dxfMapTheme );
for ( QgsMapLayer *layer : constMapThemeVisibleLayers )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( !vl )
Expand All @@ -1442,7 +1445,8 @@ int main( int argc, char *argv[] )
}
else
{
Q_FOREACH ( QgsMapLayer *ml, QgsProject::instance()->mapLayers() )
const auto constMapLayers = QgsProject::instance()->mapLayers();
for ( QgsMapLayer *ml : constMapLayers )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl )
Expand Down
3 changes: 2 additions & 1 deletion src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -1089,7 +1089,8 @@ void QgsPluginManager::clearRepositoryList()
buttonRefreshRepos->setEnabled( false );
buttonEditRep->setEnabled( false );
buttonDeleteRep->setEnabled( false );
Q_FOREACH ( QAction *action, treeRepositories->actions() )
const auto constActions = treeRepositories->actions();
for ( QAction *action : constActions )
{
treeRepositories->removeAction( action );
}
Expand Down

0 comments on commit 04409ac

Please sign in to comment.