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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>() );