Skip to content

Commit

Permalink
Replace foreach with Q_FOREACH
Browse files Browse the repository at this point in the history
For:
- consistency
- to make it immediately clear that this is a Qt macro and that it
works slightly differently to c++ for loops
  • Loading branch information
nyalldawson committed Sep 9, 2015
1 parent 7c10760 commit f628ebd
Show file tree
Hide file tree
Showing 265 changed files with 1,011 additions and 1,011 deletions.
4 changes: 2 additions & 2 deletions src/analysis/raster/qgsalignraster.cpp
Expand Up @@ -366,7 +366,7 @@ bool QgsAlignRaster::run()

//dump();

foreach ( const Item& r, mRasters )
Q_FOREACH ( const Item& r, mRasters )
{
if ( !createAndWarp( r ) )
return false;
Expand Down Expand Up @@ -401,7 +401,7 @@ int QgsAlignRaster::suggestedReferenceLayer() const
QgsCoordinateReferenceSystem destCRS( "EPSG:4326" );
QString destWkt = destCRS.toWkt();

foreach ( const Item& raster, mRasters )
Q_FOREACH ( const Item& raster, mRasters )
{
if ( !suggestedWarpOutput( RasterInfo( raster.inputFilename ), destWkt, &cs ) )
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -561,7 +561,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mPanelMenu->addAction( mItemsDock->toggleViewAction() );

QList<QDockWidget *> docks = findChildren<QDockWidget *>();
foreach ( QDockWidget* dock, docks )
Q_FOREACH ( QDockWidget* dock, docks )
{
dock->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable );
connect( dock, SIGNAL( visibilityChanged( bool ) ), this, SLOT( dockVisibilityChanged( bool ) ) );
Expand Down Expand Up @@ -729,7 +729,7 @@ void QgsComposer::setIconSizes( int size )

//Change all current icon sizes.
QList<QToolBar *> toolbars = findChildren<QToolBar *>();
foreach ( QToolBar * toolbar, toolbars )
Q_FOREACH ( QToolBar * toolbar, toolbars )
{
toolbar->setIconSize( QSize( size, size ) );
}
Expand Down Expand Up @@ -1384,14 +1384,14 @@ void QgsComposer::on_mActionHidePanels_triggered()
mPanelStatus.clear();
//record status of all docks

foreach ( QDockWidget* dock, docks )
Q_FOREACH ( QDockWidget* dock, docks )
{
mPanelStatus.insert( dock->windowTitle(), PanelStatus( dock->isVisible(), false ) );
dock->setVisible( false );
}

//record active dock tabs
foreach ( QTabBar* tabBar, tabBars )
Q_FOREACH ( QTabBar* tabBar, tabBars )
{
QString currentTabTitle = tabBar->tabText( tabBar->currentIndex() );
mPanelStatus[ currentTabTitle ].isActive = true;
Expand All @@ -1400,7 +1400,7 @@ void QgsComposer::on_mActionHidePanels_triggered()
else
{
//restore visibility of all docks
foreach ( QDockWidget* dock, docks )
Q_FOREACH ( QDockWidget* dock, docks )
{
if ( ! mPanelStatus.contains( dock->windowTitle() ) )
{
Expand All @@ -1411,7 +1411,7 @@ void QgsComposer::on_mActionHidePanels_triggered()
}

//restore previously active dock tabs
foreach ( QTabBar* tabBar, tabBars )
Q_FOREACH ( QTabBar* tabBar, tabBars )
{
//loop through all tabs in tab bar
for ( int i = 0; i < tabBar->count(); ++i )
Expand Down Expand Up @@ -3725,7 +3725,7 @@ void QgsComposer::populateHelpMenu()
void QgsComposer::populateWithOtherMenu( QMenu* thisMenu, QMenu* otherMenu )
{
thisMenu->clear();
foreach ( QAction* act, otherMenu->actions() )
Q_FOREACH ( QAction* act, otherMenu->actions() )
{
if ( act->menu() )
{
Expand All @@ -3741,7 +3741,7 @@ void QgsComposer::populateWithOtherMenu( QMenu* thisMenu, QMenu* otherMenu )
QMenu* QgsComposer::mirrorOtherMenu( QMenu* otherMenu )
{
QMenu* newMenu = new QMenu( otherMenu->title(), this );
foreach ( QAction* act, otherMenu->actions() )
Q_FOREACH ( QAction* act, otherMenu->actions() )
{
if ( act->menu() )
{
Expand Down
16 changes: 8 additions & 8 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -68,7 +68,7 @@ class QgsComposerLegendMenuProvider : public QObject, public QgsLayerTreeViewMen

QList<QgsComposerLegendStyle::Style> lst;
lst << QgsComposerLegendStyle::Hidden << QgsComposerLegendStyle::Group << QgsComposerLegendStyle::Subgroup;
foreach ( QgsComposerLegendStyle::Style style, lst )
Q_FOREACH ( QgsComposerLegendStyle::Style style, lst )
{
QAction* action = menu->addAction( QgsComposerLegendStyle::styleLabel( style ), mWidget, SLOT( setCurrentNodeStyleFromAction() ) );
action->setCheckable( true );
Expand Down Expand Up @@ -572,7 +572,7 @@ void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged( int state )
QList<QWidget*> widgets;
widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
<< mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton;
foreach ( QWidget* w, widgets )
Q_FOREACH ( QWidget* w, widgets )
w->setEnabled( state != Qt::Checked );
}

Expand Down Expand Up @@ -661,26 +661,26 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
mLegend->beginCommand( "Legend item removed" );

QList<QPersistentModelIndex> indexes;
foreach ( const QModelIndex &index, selectionModel->selectedIndexes() )
Q_FOREACH ( const QModelIndex &index, selectionModel->selectedIndexes() )
indexes << index;

// first try to remove legend nodes
QHash<QgsLayerTreeLayer*, QList<int> > nodesWithRemoval;
foreach ( const QPersistentModelIndex& index, indexes )
Q_FOREACH ( const QPersistentModelIndex& index, indexes )
{
if ( QgsLayerTreeModelLegendNode* legendNode = mItemTreeView->layerTreeModel()->index2legendNode( index ) )
{
QgsLayerTreeLayer* nodeLayer = legendNode->layerNode();
nodesWithRemoval[nodeLayer].append( index.row() );
}
}
foreach ( QgsLayerTreeLayer* nodeLayer, nodesWithRemoval.keys() )
Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, nodesWithRemoval.keys() )
{
QList<int> toDelete = nodesWithRemoval[nodeLayer];
qSort( toDelete.begin(), toDelete.end(), qGreater<int>() );
QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( nodeLayer );

foreach ( int i, toDelete )
Q_FOREACH ( int i, toDelete )
{
if ( i >= 0 && i < order.count() )
order.removeAt( i );
Expand All @@ -691,7 +691,7 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
}

// then remove layer tree nodes
foreach ( const QPersistentModelIndex& index, indexes )
Q_FOREACH ( const QPersistentModelIndex& index, indexes )
{
if ( index.isValid() && mItemTreeView->layerTreeModel()->index2node( index ) )
mLegend->modelV2()->removeRow( index.row(), index.parent() );
Expand Down Expand Up @@ -795,7 +795,7 @@ void QgsComposerLegendWidget::resetLayerNodeToDefaults()

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

foreach ( const QString& key, nodeLayer->customProperties() )
Q_FOREACH ( const QString& key, nodeLayer->customProperties() )
{
if ( key.startsWith( "legend/" ) )
nodeLayer->removeCustomProperty( key );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermanager.cpp
Expand Up @@ -528,7 +528,7 @@ void QgsComposerNameDelegate::setModelData( QWidget *editor, QAbstractItemModel

//check if name already exists
QStringList cNames;
foreach ( QgsComposer* c, QgisApp::instance()->printComposers() )
Q_FOREACH ( QgsComposer* c, QgisApp::instance()->printComposers() )
{
cNames << c->title();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -298,7 +298,7 @@ void QgsComposerMapWidget::aboutToShowVisibilityPresetsMenu()
return;

menu->clear();
foreach ( const QString& presetName, QgsProject::instance()->visibilityPresetCollection()->presets() )
Q_FOREACH ( const QString& presetName, QgsProject::instance()->visibilityPresetCollection()->presets() )
{
QAction* a = menu->addAction( presetName, this, SLOT( visibilityPresetSelected() ) );
a->setCheckable( true );
Expand Down
10 changes: 5 additions & 5 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -107,7 +107,7 @@ void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
static QgsLayerTreeGroup* _groupIndexToNode( int groupIndex, QgsLayerTreeGroup* parentGroup, int& currentIndex )
{
++currentIndex;
foreach ( QgsLayerTreeNode* child, parentGroup->children() )
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
Expand All @@ -132,7 +132,7 @@ QgsLayerTreeGroup* QgsAppLegendInterface::groupIndexToNode( int itemIndex )
static int _groupNodeToIndex( QgsLayerTreeGroup* group, QgsLayerTreeGroup* parentGroup, int& currentIndex )
{
++currentIndex;
foreach ( QgsLayerTreeNode* child, parentGroup->children() )
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
Expand Down Expand Up @@ -169,7 +169,7 @@ void QgsAppLegendInterface::setLayerExpanded( QgsMapLayer * ml, bool expand )

static void _collectGroups( QgsLayerTreeGroup* parentGroup, QStringList& list )
{
foreach ( QgsLayerTreeNode* child, parentGroup->children() )
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
Expand Down Expand Up @@ -206,7 +206,7 @@ QList< GroupLayerInfo > QgsAppLegendInterface::groupLayerRelationship()
else if ( QgsLayerTree::isGroup( currentNode ) )
{
QList<QString> layerList;
foreach ( QgsLayerTreeNode* gNode, QgsLayerTree::toGroup( currentNode )->children() )
Q_FOREACH ( QgsLayerTreeNode* gNode, QgsLayerTree::toGroup( currentNode )->children() )
{
if ( QgsLayerTree::isLayer( gNode ) )
{
Expand Down Expand Up @@ -273,7 +273,7 @@ QList<QgsMapLayer *> QgsAppLegendInterface::selectedLayers( bool inDrawOrder ) c
QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
QList<QgsMapLayer*> lst;
foreach ( QgsLayerTreeLayer* node, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
Q_FOREACH ( QgsLayerTreeLayer* node, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
{
if ( node->layer() )
lst << node->layer();
Expand Down
6 changes: 3 additions & 3 deletions src/app/main.cpp
Expand Up @@ -827,7 +827,7 @@ APP_EXPORT int main( int argc, char *argv[] )
QStringList customVarsList = mySettings.value( "qgis/customEnvVars", "" ).toStringList();
if ( !customVarsList.isEmpty() )
{
foreach ( const QString &varStr, customVarsList )
Q_FOREACH ( const QString &varStr, customVarsList )
{
int pos = varStr.indexOf( QLatin1Char( '|' ) );
if ( pos == -1 )
Expand Down Expand Up @@ -1141,7 +1141,7 @@ APP_EXPORT int main( int argc, char *argv[] )
QList< QPair<QgsVectorLayer *, int > > layers;
if ( !dxfPreset.isEmpty() )
{
foreach ( const QString& layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
Q_FOREACH ( const QString& layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer ) );
if ( !vl )
Expand All @@ -1152,7 +1152,7 @@ APP_EXPORT int main( int argc, char *argv[] )
}
else
{
foreach ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers().values() )
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers().values() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl )
Expand Down
10 changes: 5 additions & 5 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -146,7 +146,7 @@ void QgsMapToolNodeTool::canvasMapMoveEvent( QgsMapMouseEvent* e )
rbGeom->transform( *mCanvas->mapSettings().layerTransform( vlayer ) );
rb->setGeometry( rbGeom );
mMoveRubberBands.insert( mSelectedFeature->featureId(), rb );
foreach ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() )
Q_FOREACH ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() )
{
if ( vertexEntry->isSelected() )
mMoveVertices[mSelectedFeature->featureId()].append( qMakePair( vertexEntry->vertexId(), toMapCoordinates( vlayer, vertexEntry->point() ) ) );
Expand All @@ -167,10 +167,10 @@ void QgsMapToolNodeTool::canvasMapMoveEvent( QgsMapMouseEvent* e )
double diffX = curPos.x() - origPos.x();
double diffY = curPos.y() - origPos.y();

foreach ( const QgsFeatureId& fid, mMoveRubberBands.keys() )
Q_FOREACH ( const QgsFeatureId& fid, mMoveRubberBands.keys() )
{
typedef QPair<QgsVertexId, QgsPointV2> MoveVertex;
foreach ( const MoveVertex& pair, mMoveVertices[fid] )
Q_FOREACH ( const MoveVertex& pair, mMoveVertices[fid] )
{
QgsPointV2 pos = pair.second;
pos.setX( pos.x() + diffX );
Expand Down Expand Up @@ -394,7 +394,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands()
{
QgsVectorLayer* vlayer = mSelectedFeature->vlayer();

foreach ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() )
Q_FOREACH ( const QgsVertexEntry* vertexEntry, mSelectedFeature->vertexMap() )
{
if ( !vertexEntry->isSelected() )
{
Expand All @@ -404,7 +404,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands()
// Snap vertex
QMultiMap<double, QgsSnappingResult> snapResults;
vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex );
foreach ( const QgsSnappingResult& snapResult, snapResults.values() )
Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults.values() )
{
// Get geometry of snapped feature
QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry;
Expand Down
18 changes: 9 additions & 9 deletions src/app/nodetool/qgsnodeeditor.cpp
Expand Up @@ -40,7 +40,7 @@ class CoordinateItemDelegate : public QStyledItemDelegate
QString displayText( const QVariant & value, const QLocale & locale ) const override
{
return locale.toString( value.toDouble(), 'f', 4 );
}
}

protected:

Expand All @@ -49,19 +49,19 @@ class CoordinateItemDelegate : public QStyledItemDelegate
QLineEdit* lineEdit = new QLineEdit( parent );
QDoubleValidator* validator = new QDoubleValidator();
if ( !index.data( MinRadiusRole ).isNull() )
validator->setBottom( index.data( MinRadiusRole ).toDouble() );
validator->setBottom( index.data( MinRadiusRole ).toDouble() );
lineEdit->setValidator( validator );
return lineEdit;
}

void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>( editor );
if ( lineEdit->hasAcceptableInput() )
{
QStyledItemDelegate::setModelData( editor, model, index );
QLineEdit* lineEdit = qobject_cast<QLineEdit*>( editor );
if ( lineEdit->hasAcceptableInput() )
{
QStyledItemDelegate::setModelData( editor, model, index );
}
}
}
};


Expand Down Expand Up @@ -112,7 +112,7 @@ void QgsNodeEditor::rebuildTable()
mTableWidget->setRowCount( 0 );
int row = 0;
bool hasR = false;
foreach ( const QgsVertexEntry* entry, mSelectedFeature->vertexMap() )
Q_FOREACH ( const QgsVertexEntry* entry, mSelectedFeature->vertexMap() )
{
mTableWidget->insertRow( row );

Expand Down Expand Up @@ -231,7 +231,7 @@ void QgsNodeEditor::updateNodeSelection()
disconnect( mSelectedFeature, SIGNAL( selectionChanged() ), this, SLOT( updateTableSelection() ) );

mSelectedFeature->deselectAllVertexes();
foreach ( const QModelIndex& index, mTableWidget->selectionModel()->selectedRows() )
Q_FOREACH ( const QModelIndex& index, mTableWidget->selectionModel()->selectedRows() )
{
int nodeIdx = mTableWidget->item( index.row(), 0 )->data( Qt::DisplayRole ).toInt();
mSelectedFeature->selectVertex( nodeIdx );
Expand Down
8 changes: 4 additions & 4 deletions src/app/nodetool/qgsselectedfeature.cpp
Expand Up @@ -232,7 +232,7 @@ void QgsSelectedFeature::validationFinished()
void QgsSelectedFeature::deleteSelectedVertexes()
{
int nSelected = 0;
foreach ( QgsVertexEntry *entry, mVertexMap )
Q_FOREACH ( QgsVertexEntry *entry, mVertexMap )
{
if ( entry->isSelected() )
nSelected++;
Expand Down Expand Up @@ -304,7 +304,7 @@ void QgsSelectedFeature::deleteSelectedVertexes()
void QgsSelectedFeature::moveSelectedVertexes( const QgsVector &v )
{
int nUpdates = 0;
foreach ( QgsVertexEntry *entry, mVertexMap )
Q_FOREACH ( QgsVertexEntry *entry, mVertexMap )
{
if ( entry->isSelected() )
nUpdates++;
Expand Down Expand Up @@ -377,7 +377,7 @@ void QgsSelectedFeature::replaceVertexMap()

void QgsSelectedFeature::deleteVertexMap()
{
foreach ( QgsVertexEntry *entry, mVertexMap )
Q_FOREACH ( QgsVertexEntry *entry, mVertexMap )
{
delete entry;
}
Expand Down Expand Up @@ -491,7 +491,7 @@ void QgsSelectedFeature::invertVertexSelection( int vertexNr )

void QgsSelectedFeature::updateVertexMarkersPosition()
{
foreach ( QgsVertexEntry* vertexEntry, mVertexMap )
Q_FOREACH ( QgsVertexEntry* vertexEntry, mVertexMap )
{
vertexEntry->placeMarker();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -924,7 +924,7 @@ void QgsPluginManager::clearRepositoryList()
buttonRefreshRepos->setEnabled( false );
buttonEditRep->setEnabled( false );
buttonDeleteRep->setEnabled( false );
foreach ( QAction * action, treeRepositories->actions() )
Q_FOREACH ( QAction * action, treeRepositories->actions() )
{
treeRepositories->removeAction( action );
}
Expand Down

0 comments on commit f628ebd

Please sign in to comment.