Skip to content
Permalink
Browse files

Merge pull request #9722 from m-kuhn/code_modernization

Make QGIS core library a Q_FOREACH free zone
  • Loading branch information
m-kuhn committed Apr 7, 2019
2 parents 4a87cc9 + 4852bac commit 736e8cbbc34ef8ea4ec935851766dd295a365b1a
Showing with 1,747 additions and 921 deletions.
  1. +2 −0 src/core/CMakeLists.txt
  2. +7 −6 src/core/expression/qgsexpressioncontextutils.cpp
  3. +7 −6 src/core/layertree/qgslayertree.cpp
  4. +13 −12 src/core/layertree/qgslayertreegroup.cpp
  5. +40 −25 src/core/layertree/qgslayertreemodel.cpp
  6. +10 −5 src/core/layertree/qgslayertreenode.cpp
  7. +6 −3 src/core/layertree/qgslayertreeregistrybridge.cpp
  8. +22 −11 src/core/layertree/qgslayertreeutils.cpp
  9. +2 −1 src/core/layout/qgslayout.cpp
  10. +13 −7 src/core/layout/qgslayoutguidecollection.cpp
  11. +2 −1 src/core/layout/qgslayoutitemlegend.cpp
  12. +16 −8 src/core/layout/qgslayoutpagecollection.cpp
  13. +2 −1 src/core/layout/qgslayoutsnapper.cpp
  14. +10 −5 src/core/layout/qgslayouttable.cpp
  15. +2 −1 src/core/layout/qgspagesizeregistry.cpp
  16. +6 −3 src/core/metadata/qgslayermetadatavalidator.cpp
  17. +3 −2 src/core/pal/feature.cpp
  18. +2 −1 src/core/pal/layer.cpp
  19. +6 −3 src/core/pal/pal.cpp
  20. +38 −20 src/core/processing/models/qgsprocessingmodelalgorithm.cpp
  21. +4 −2 src/core/processing/models/qgsprocessingmodelchildalgorithm.cpp
  22. +2 −1 src/core/processing/qgsprocessingalgorithm.cpp
  23. +58 −29 src/core/processing/qgsprocessingparameters.cpp
  24. +4 −2 src/core/processing/qgsprocessingregistry.cpp
  25. +2 −1 src/core/providers/memory/qgsmemoryprovider.cpp
  26. +2 −1 src/core/qgsaction.cpp
  27. +2 −1 src/core/qgsactionscoperegistry.cpp
  28. +13 −7 src/core/qgsapplication.cpp
  29. +2 −1 src/core/qgsarchive.cpp
  30. +2 −1 src/core/qgsattributeeditorelement.cpp
  31. +4 −2 src/core/qgsattributetableconfig.cpp
  32. +2 −1 src/core/qgsblockingnetworkrequest.cpp
  33. +12 −6 src/core/qgsbrowsermodel.cpp
  34. +4 −2 src/core/qgscolorramp.cpp
  35. +2 −1 src/core/qgscolorscheme.cpp
  36. +10 −5 src/core/qgsconditionalstyle.cpp
  37. +8 −4 src/core/qgscoordinatereferencesystem.cpp
  38. +11 −9 src/core/qgsdatadefinedsizelegend.cpp
  39. +36 −18 src/core/qgsdataitem.cpp
  40. +2 −1 src/core/qgsdataitemproviderregistry.cpp
  41. +5 −3 src/core/qgsdatasourceuri.cpp
  42. +2 −1 src/core/qgsdatetimestatisticalsummary.cpp
  43. +12 −6 src/core/qgsdiagramrenderer.cpp
  44. +2 −1 src/core/qgseditformconfig.cpp
  45. +2 −1 src/core/qgsellipsoidutils.cpp
  46. +2 −1 src/core/qgserror.cpp
  47. +22 −12 src/core/qgsexpressioncontext.cpp
  48. +4 −2 src/core/qgsexpressionfieldbuffer.cpp
  49. +2 −1 src/core/qgsfeature.cpp
  50. +2 −1 src/core/qgsfeaturefiltermodel.cpp
  51. +2 −1 src/core/qgsfeatureiterator.cpp
  52. +6 −3 src/core/qgsfeaturerequest.cpp
  53. +6 −3 src/core/qgsfontutils.cpp
  54. +8 −4 src/core/qgsgml.cpp
  55. +8 −4 src/core/qgsgmlschema.cpp
  56. +4 −2 src/core/qgsinterval.cpp
  57. +6 −3 src/core/qgsjsonutils.cpp
  58. +4 −2 src/core/qgslabelingengine.cpp
  59. +18 −9 src/core/qgslayerdefinition.cpp
  60. +9 −5 src/core/qgslegendrenderer.cpp
  61. +6 −3 src/core/qgsmaphittest.cpp
  62. +10 −5 src/core/qgsmaplayer.cpp
  63. +12 −6 src/core/qgsmaplayerlegend.cpp
  64. +6 −3 src/core/qgsmaplayermodel.cpp
  65. +4 −2 src/core/qgsmaplayerproxymodel.cpp
  66. +10 −5 src/core/qgsmaplayerstore.cpp
  67. +2 −1 src/core/qgsmaplayerstylemanager.cpp
  68. +8 −4 src/core/qgsmaprenderercache.cpp
  69. +6 −3 src/core/qgsmaprendererjob.cpp
  70. +6 −3 src/core/qgsmaprenderertask.cpp
  71. +2 −1 src/core/qgsmapsettings.cpp
  72. +2 −1 src/core/qgsmapsettingsutils.cpp
  73. +38 −21 src/core/qgsmapthemecollection.cpp
  74. +10 −5 src/core/qgsmimedatautils.cpp
  75. +4 −2 src/core/qgsmultirenderchecker.cpp
  76. +4 −2 src/core/qgsnetworkaccessmanager.cpp
  77. +4 −2 src/core/qgsnetworkreplyparser.cpp
  78. +2 −1 src/core/qgsobjectcustomproperties.cpp
  79. +25 −13 src/core/qgsogcutils.cpp
  80. +2 −1 src/core/qgspluginlayerregistry.cpp
  81. +2 −1 src/core/qgspointlocator.cpp
  82. +18 −9 src/core/qgsproject.cpp
  83. +2 −1 src/core/qgsprojectbadlayerhandler.cpp
  84. +20 −11 src/core/qgspropertycollection.cpp
  85. +6 −3 src/core/qgspropertytransformer.cpp
  86. +4 −2 src/core/qgsproviderregistry.cpp
  87. +20 −10 src/core/qgsrelationmanager.cpp
  88. +6 −3 src/core/qgssnappingconfig.cpp
  89. +23 −13 src/core/qgssnappingutils.cpp
  90. +4 −2 src/core/qgssqlexpressioncompiler.cpp
  91. +32 −16 src/core/qgssqlstatement.cpp
  92. +2 −1 src/core/qgsstatisticalsummary.cpp
  93. +4 −2 src/core/qgsstringstatisticalsummary.cpp
  94. +4 −2 src/core/qgsstringutils.cpp
  95. +25 −13 src/core/qgstaskmanager.cpp
  96. +5 −3 src/core/qgstextrenderer.cpp
  97. +23 −11 src/core/qgstracer.cpp
  98. +2 −1 src/core/qgstransaction.cpp
  99. +10 −5 src/core/qgstransactiongroup.cpp
  100. +4 −2 src/core/qgsvectordataprovider.cpp
  101. +10 −5 src/core/qgsvectorfilewriter.cpp
  102. +28 −18 src/core/qgsvectorlayer.cpp
  103. +12 −6 src/core/qgsvectorlayercache.cpp
  104. +22 −11 src/core/qgsvectorlayereditbuffer.cpp
  105. +2 −1 src/core/qgsvectorlayerexporter.cpp
  106. +2 −1 src/core/qgsvectorlayerfeaturecounter.cpp
  107. +10 −7 src/core/qgsvectorlayerfeatureiterator.cpp
  108. +18 −9 src/core/qgsvectorlayerjoinbuffer.cpp
  109. +2 −1 src/core/qgsvectorlayerlabelprovider.cpp
  110. +2 −1 src/core/qgsvectorlayerutils.cpp
  111. +8 −4 src/core/qgsvirtuallayerdefinition.cpp
  112. +4 −2 src/core/qgsvirtuallayerdefinitionutils.cpp
  113. +4 −2 src/core/qgsxmlutils.cpp
  114. +6 −3 src/core/raster/qgspalettedrasterrenderer.cpp
  115. +2 −1 src/core/raster/qgsrasterfilewriter.cpp
  116. +8 −4 src/core/raster/qgsrasterinterface.cpp
  117. +4 −2 src/core/raster/qgsrasterlayer.cpp
  118. +2 −1 src/core/raster/qgsrasterpipe.cpp
  119. +33 −17 src/core/symbology/qgscptcityarchive.cpp
  120. +24 −13 src/core/symbology/qgsgraduatedsymbolrenderer.cpp
  121. +7 −4 src/core/symbology/qgsinvertedpolygonrenderer.cpp
  122. +6 −3 src/core/symbology/qgspointdistancerenderer.cpp
  123. +8 −4 src/core/symbology/qgsrenderer.cpp
  124. +2 −1 src/core/symbology/qgsrendererregistry.cpp
  125. +49 −25 src/core/symbology/qgsrulebasedrenderer.cpp
  126. +4 −2 src/core/symbology/qgsstyle.cpp
  127. +70 −36 src/core/symbology/qgssymbol.cpp
  128. +8 −4 src/core/symbology/qgssymbollayerutils.cpp
  129. +12 −6 src/providers/db2/qgsdb2dataitems.cpp
  130. +6 −3 src/providers/db2/qgsdb2featureiterator.cpp
  131. +2 −0 src/providers/delimitedtext/CMakeLists.txt
  132. +2 −1 src/providers/delimitedtext/qgsdelimitedtextfile.cpp
  133. +6 −3 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  134. +2 −1 src/providers/gdal/qgsgdaldataitems.cpp
  135. +12 −6 src/providers/gdal/qgsgdalprovider.cpp
  136. +2 −0 src/providers/geonode/CMakeLists.txt
  137. +16 −8 src/providers/grass/qgis.v.in.cpp
  138. +8 −4 src/providers/grass/qgsgrass.cpp
  139. +2 −1 src/providers/grass/qgsgrassfeatureiterator.cpp
  140. +10 −5 src/providers/grass/qgsgrassprovider.cpp
  141. +22 −11 src/providers/grass/qgsgrassprovidermodule.cpp
  142. +4 −2 src/providers/grass/qgsgrassrasterprovider.cpp
  143. +4 −2 src/providers/grass/qgsgrassvector.cpp
  144. +10 −5 src/providers/grass/qgsgrassvectormap.cpp
  145. +14 −7 src/providers/grass/qgsgrassvectormaplayer.cpp
  146. +24 −12 src/providers/mssql/qgsmssqldataitems.cpp
  147. +4 −2 src/providers/mssql/qgsmssqlfeatureiterator.cpp
  148. +2 −1 src/providers/mssql/qgsmssqlprovider.cpp
  149. +4 −2 src/providers/mssql/qgsmssqltablemodel.cpp
  150. +4 −2 src/providers/ogr/qgsogrdataitems.cpp
  151. +14 −7 src/providers/ogr/qgsogrprovider.cpp
  152. +4 −2 src/providers/oracle/qgsoracleconn.h
  153. +8 −4 src/providers/oracle/qgsoracledataitems.cpp
  154. +6 −3 src/providers/oracle/qgsoraclefeatureiterator.cpp
  155. +18 −9 src/providers/oracle/qgsoracleprovider.cpp
  156. +4 −2 src/providers/oracle/qgsoraclesourceselect.cpp
  157. +6 −3 src/providers/oracle/qgsoracletablecache.cpp
  158. +2 −1 src/providers/oracle/qgsoracletablemodel.cpp
  159. +6 −3 src/providers/ows/qgsowsdataitems.cpp
  160. +6 −3 src/providers/postgres/qgspgsourceselect.cpp
  161. +4 −2 src/providers/postgres/qgspgtablemodel.cpp
  162. +4 −2 src/providers/postgres/qgspostgresconn.cpp
  163. +4 −2 src/providers/postgres/qgspostgresconn.h
  164. +8 −4 src/providers/postgres/qgspostgresdataitems.cpp
  165. +6 −3 src/providers/postgres/qgspostgresfeatureiterator.cpp
  166. +23 −13 src/providers/postgres/qgspostgresprovider.cpp
  167. +4 −2 src/providers/spatialite/qgsspatialitedataitems.cpp
  168. +4 −2 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  169. +2 −1 src/providers/spatialite/qgsspatialitesourceselect.cpp
  170. +2 −1 src/providers/virtual/qgsembeddedlayerselectdialog.cpp
  171. +8 −4 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
  172. +10 −5 src/providers/virtual/qgsvirtuallayerprovider.cpp
  173. +10 −5 src/providers/virtual/qgsvirtuallayersourceselect.cpp
  174. +2 −1 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  175. +16 −8 src/providers/wcs/qgswcscapabilities.cpp
  176. +2 −1 src/providers/wcs/qgswcsdataitems.cpp
  177. +2 −1 src/providers/wcs/qgswcsprovider.cpp
  178. +4 −2 src/providers/wfs/qgswfsdatasourceuri.cpp
  179. +4 −2 src/providers/wfs/qgswfsfeatureiterator.cpp
  180. +18 −10 src/providers/wfs/qgswfsprovider.cpp
  181. +2 −1 src/providers/wfs/qgswfsrequest.cpp
  182. +8 −4 src/providers/wfs/qgswfsshareddata.cpp
  183. +4 −2 src/providers/wfs/qgswfssourceselect.cpp
  184. +4 −2 src/providers/wfs/qgswfsutils.cpp
  185. +2 −0 src/providers/wms/CMakeLists.txt
  186. +2 −1 src/providers/wms/qgstilescalewidget.cpp
  187. +10 −6 src/providers/wms/qgswmscapabilities.cpp
  188. +14 −10 src/providers/wms/qgswmsdataitems.cpp
  189. +48 −27 src/providers/wms/qgswmsprovider.cpp
  190. +15 −10 src/providers/wms/qgswmssourceselect.cpp
  191. +2 −2 tests/qt_modeltest/dynamictreemodel.cpp
@@ -1406,6 +1406,8 @@ IF (Qt5Positioning_FOUND)
)
ENDIF (Qt5Positioning_FOUND)

TARGET_COMPILE_DEFINITIONS(qgis_core PRIVATE "-DQT_NO_FOREACH")

# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(
@@ -321,11 +321,11 @@ QgsExpressionContextScope *QgsExpressionContextUtils::layerScope( const QgsMapLa
return scope;

//add variables defined in layer properties
QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
const QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
const QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();

int varIndex = 0;
Q_FOREACH ( const QString &variableName, variableNames )
for ( const QString &variableName : variableNames )
{
if ( varIndex >= variableValues.length() )
{
@@ -525,11 +525,12 @@ QgsExpressionContextScope *QgsExpressionContextUtils::layoutScope( const QgsLayo
return scope.release();

//add variables defined in layout properties
QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
const QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
const QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();

int varIndex = 0;
Q_FOREACH ( const QString &variableName, variableNames )

for ( const QString &variableName : variableNames )
{
if ( varIndex >= variableValues.length() )
{
@@ -129,14 +129,14 @@ void QgsLayerTree::writeXml( QDomElement &parentElement, const QgsReadWriteConte

writeCommonXml( elem );

Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->writeXml( elem, context );

QDomElement customOrderElem = doc.createElement( QStringLiteral( "custom-order" ) );
customOrderElem.setAttribute( QStringLiteral( "enabled" ), mHasCustomLayerOrder ? 1 : 0 );
elem.appendChild( customOrderElem );

Q_FOREACH ( QgsMapLayer *layer, mCustomLayerOrder )
for ( QgsMapLayer *layer : qgis::as_const( mCustomLayerOrder ) )
{
// Safety belt, see https://issues.qgis.org/issues/19145
// Crash when deleting an item from the layout legend
@@ -181,12 +181,13 @@ void QgsLayerTree::nodeAddedChildren( QgsLayerTreeNode *node, int indexFrom, int
}
else if ( QgsLayerTree::isGroup( child ) )
{
Q_FOREACH ( QgsLayerTreeLayer *nodeL, QgsLayerTree::toGroup( child )->findLayers() )
const auto nodeLayers = QgsLayerTree::toGroup( child )->findLayers();
for ( QgsLayerTreeLayer *nodeL : nodeLayers )
layers << nodeL->layer();
}
}

Q_FOREACH ( QgsMapLayer *layer, layers )
for ( QgsMapLayer *layer : qgis::as_const( layers ) )
{
if ( !mCustomLayerOrder.contains( layer ) && layer )
mCustomLayerOrder.append( layer );
@@ -217,8 +218,8 @@ void QgsLayerTree::addMissingLayers()
{
bool changed = false;

const QList< QgsLayerTreeLayer * > foundLayers = findLayers();
for ( const auto layer : foundLayers )
const QList< QgsLayerTreeLayer * > layers = findLayers();
for ( const auto layer : layers )
{
if ( !mCustomLayerOrder.contains( layer->layer() ) &&
layer->layer() && layer->layer()->isSpatial() )
@@ -138,7 +138,7 @@ void QgsLayerTreeGroup::removeChildNode( QgsLayerTreeNode *node )

void QgsLayerTreeGroup::removeLayer( QgsMapLayer *layer )
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -173,7 +173,8 @@ void QgsLayerTreeGroup::removeChildren( int from, int count )
void QgsLayerTreeGroup::removeChildrenGroupWithoutLayers()
{
// clean the layer tree by removing empty group
Q_FOREACH ( QgsLayerTreeNode *treeNode, children() )
const auto childNodes = children();
for ( QgsLayerTreeNode *treeNode : childNodes )
{
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
{
@@ -201,7 +202,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( QgsMapLayer *layer ) const

QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
{
@@ -222,7 +223,7 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( const QString &layerId ) const
QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const
{
QList<QgsLayerTreeLayer *> list;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isLayer( child ) )
list << QgsLayerTree::toLayer( child );
@@ -234,7 +235,7 @@ QList<QgsLayerTreeLayer *> QgsLayerTreeGroup::findLayers() const

QgsLayerTreeGroup *QgsLayerTreeGroup::findGroup( const QString &name )
{
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
{
@@ -310,7 +311,7 @@ void QgsLayerTreeGroup::writeXml( QDomElement &parentElement, const QgsReadWrite

writeCommonXml( elem );

Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->writeXml( elem, context );

parentElement.appendChild( elem );
@@ -336,7 +337,7 @@ QString QgsLayerTreeGroup::dump() const
{
QString header = QStringLiteral( "GROUP: %1 checked=%2 expanded=%3\n" ).arg( name() ).arg( mChecked ).arg( mExpanded );
QStringList childrenDump;
Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
childrenDump << node->dump().split( '\n' );
for ( int i = 0; i < childrenDump.count(); ++i )
childrenDump[i].prepend( " " );
@@ -350,7 +351,7 @@ QgsLayerTreeGroup *QgsLayerTreeGroup::clone() const

void QgsLayerTreeGroup::resolveReferences( const QgsProject *project, bool looseMatching )
{
Q_FOREACH ( QgsLayerTreeNode *node, mChildren )
for ( QgsLayerTreeNode *node : qgis::as_const( mChildren ) )
node->resolveReferences( project, looseMatching );
}

@@ -379,7 +380,7 @@ void QgsLayerTreeGroup::setIsMutuallyExclusive( bool enabled, int initialChildIn
{
// try to use first checked index
int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( _nodeIsChecked( child ) )
{
@@ -396,7 +397,7 @@ void QgsLayerTreeGroup::setIsMutuallyExclusive( bool enabled, int initialChildIn
QStringList QgsLayerTreeGroup::findLayerIds() const
{
QStringList lst;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
if ( QgsLayerTree::isGroup( child ) )
lst << QgsLayerTree::toGroup( child )->findLayerIds();
@@ -432,7 +433,7 @@ void QgsLayerTreeGroup::updateChildVisibilityMutuallyExclusive()
mChangingChildVisibility = true; // guard against running again setVisible() triggered from children

int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
child->setItemVisibilityChecked( index == mMutuallyExclusiveChildIndex );
++index;
@@ -448,7 +449,7 @@ void QgsLayerTreeGroup::setItemVisibilityCheckedRecursive( bool checked )
mChangingChildVisibility = true; // guard against running again setVisible() triggered from children

int index = 0;
Q_FOREACH ( QgsLayerTreeNode *child, mChildren )
for ( QgsLayerTreeNode *child : qgis::as_const( mChildren ) )
{
child->setItemVisibilityCheckedRecursive( checked && ( mMutuallyExclusiveChildIndex < 0 || index == mMutuallyExclusiveChildIndex ) );
++index;

0 comments on commit 736e8cb

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