Skip to content
Permalink
Browse files

Merge pull request #9786 from m-kuhn/app_no_qforeach

No more Q_FOREACH in app
  • Loading branch information
m-kuhn committed Apr 15, 2019
2 parents f86d8de + 2f3646a commit 04409ac725582b9122d6aff91ce0cabbebe2bfec
Showing with 680 additions and 637 deletions.
  1. +4 −2 src/app/3d/qgspoint3dsymbolwidget.cpp
  2. +4 −2 src/app/3d/qgsrulebased3drendererwidget.cpp
  3. +2 −0 src/app/CMakeLists.txt
  4. +4 −2 src/app/dwg/qgsdwgimportdialog.cpp
  5. +153 −334 src/app/dwg/qgsdwgimporter.cpp
  6. +2 −1 src/app/layout/qgslayoutaddpagesdialog.cpp
  7. +8 −4 src/app/layout/qgslayoutdesignerdialog.cpp
  8. +12 −6 src/app/layout/qgslayoutguidewidget.cpp
  9. +8 −5 src/app/layout/qgslayoutlegendwidget.cpp
  10. +2 −1 src/app/layout/qgslayoutmanagerdialog.cpp
  11. +2 −1 src/app/layout/qgslayoutmapwidget.cpp
  12. +2 −1 src/app/layout/qgslayoutpagepropertieswidget.cpp
  13. +2 −1 src/app/locator/qgsinbuiltlocatorfilters.cpp
  14. +8 −4 src/app/main.cpp
  15. +2 −1 src/app/pluginmanager/qgspluginmanager.cpp
  16. +151 −77 src/app/qgisapp.cpp
  17. +2 −1 src/app/qgsaddtaborgroup.cpp
  18. +6 −3 src/app/qgsalignrasterdialog.cpp
  19. +4 −2 src/app/qgsapplayertreeviewmenuprovider.cpp
  20. +2 −1 src/app/qgsattributeactiondialog.cpp
  21. +8 −4 src/app/qgsattributeactionpropertiesdialog.cpp
  22. +4 −2 src/app/qgsattributesformproperties.cpp
  23. +6 −3 src/app/qgsattributetabledialog.cpp
  24. +2 −1 src/app/qgsbookmarks.cpp
  25. +4 −2 src/app/qgsclipboard.cpp
  26. +45 −54 src/app/qgscustomization.cpp
  27. +4 −2 src/app/qgsdiagramproperties.cpp
  28. +4 −4 src/app/qgsdiscoverrelationsdlg.cpp
  29. +14 −7 src/app/qgsdxfexportdialog.cpp
  30. +2 −1 src/app/qgsfeatureaction.cpp
  31. +4 −2 src/app/qgshandlebadlayers.cpp
  32. +14 −7 src/app/qgsidentifyresultsdialog.cpp
  33. +6 −3 src/app/qgslabelpropertydialog.cpp
  34. +2 −1 src/app/qgslayercapabilitiesmodel.cpp
  35. +2 −1 src/app/qgslayerstylingwidget.cpp
  36. +2 −1 src/app/qgsmapcanvasdockwidget.cpp
  37. +4 −2 src/app/qgsmaplayerstyleguiutils.cpp
  38. +2 −1 src/app/qgsmapsavedialog.cpp
  39. +4 −2 src/app/qgsmapthemes.cpp
  40. +2 −1 src/app/qgsmaptooladdfeature.cpp
  41. +4 −2 src/app/qgsmaptoolannotation.cpp
  42. +2 −1 src/app/qgsmaptoolidentifyaction.cpp
  43. +8 −4 src/app/qgsmaptoollabel.cpp
  44. +1 −1 src/app/qgsmaptoolmovefeature.cpp
  45. +4 −2 src/app/qgsmaptooloffsetpointsymbol.cpp
  46. +2 −1 src/app/qgsmaptoolpinlabels.cpp
  47. +2 −1 src/app/qgsmaptoolpointsymbol.cpp
  48. +2 −1 src/app/qgsmaptoolrotatefeature.cpp
  49. +6 −3 src/app/qgsmaptoolsimplify.cpp
  50. +2 −1 src/app/qgsmeasuretool.cpp
  51. +1 −1 src/app/qgsmergeattributesdialog.cpp
  52. +13 −8 src/app/qgsoptions.cpp
  53. +8 −4 src/app/qgspluginregistry.cpp
  54. +12 −6 src/app/qgsprojectlayergroupdialog.cpp
  55. +21 −11 src/app/qgsprojectproperties.cpp
  56. +5 −3 src/app/qgsrasterlayerproperties.cpp
  57. +6 −4 src/app/qgsrelationmanagerdialog.cpp
  58. +4 −2 src/app/qgsrulebasedlabelingwidget.cpp
  59. +4 −2 src/app/qgssettingstree.cpp
  60. +6 −3 src/app/qgssnappinglayertreemodel.cpp
  61. +4 −2 src/app/qgssnappingwidget.cpp
  62. +6 −3 src/app/qgssourcefieldsproperties.cpp
  63. +20 −10 src/app/qgsstatisticalsummarydockwidget.cpp
  64. +14 −7 src/app/qgsvectorlayerproperties.cpp
  65. +4 −2 src/app/qgsversionmigration.cpp
  66. +4 −2 src/app/vertextool/qgslockedfeature.cpp
@@ -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 );
@@ -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 ) );
}
@@ -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() );
@@ -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 )
@@ -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)
@@ -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( "''" ) ) ) );
}
@@ -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] );
}

Large diffs are not rendered by default.

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

0 comments on commit 04409ac

Please sign in to comment.
You can’t perform that action at this time.