Skip to content
Permalink
Browse files

Remove Q_FOREACH, fix inefficient loops

  • Loading branch information
nyalldawson committed Sep 10, 2017
1 parent 944cb8c commit af03d2f4762a614b471f5df5271128c7bf595303
@@ -137,7 +137,7 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()

QVector<QgsDataItem *> items;
QList<QgsDataItemProvider *> *providerList = dataItemProvidersFn();
Q_FOREACH ( QgsDataItemProvider *pr, *providerList )
for ( QgsDataItemProvider *pr : qgsAsConst( *providerList ) )
{
if ( !pr->name().startsWith( mServiceName ) )
continue;
@@ -160,7 +160,7 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
return items;
}

Q_FOREACH ( QgsDataItem *item, items )
for ( QgsDataItem *item : qgsAsConst( items ) )
{
item->populate( true ); // populate in foreground - this is already run in a thread

@@ -178,12 +178,15 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
skipProvider = true;
}

Q_FOREACH ( QgsDataItem *item, serviceItems.keys() )
auto serviceItemIt = serviceItems.constBegin();
for ( ; serviceItemIt != serviceItems.constEnd(); ++serviceItemIt )
{
QString providerKey = serviceItems.value( item );
QgsDataItem *item = serviceItemIt.key();
QString providerKey = serviceItemIt.value();

// Add layers directly to service item
Q_FOREACH ( QgsDataItem *subItem, item->children() )
const QVector< QgsDataItem * > serviceChildItems = item->children();
for ( QgsDataItem *subItem : serviceChildItems )
{
if ( subItem->path().endsWith( QStringLiteral( "error" ) ) )
{
@@ -205,7 +208,8 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
void QgsGeoNodeServiceItem::replacePath( QgsDataItem *item, QString before, QString after )
{
item->setPath( item->path().replace( before, after ) );
Q_FOREACH ( QgsDataItem *subItem, item->children() )
const QVector< QgsDataItem * > children = item->children();
for ( QgsDataItem *subItem : children )
{
replacePath( subItem, before, after );
}
@@ -224,7 +228,8 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()
{
QVector<QgsDataItem *> connections;

Q_FOREACH ( const QString &connName, QgsGeoNodeConnectionUtils::connectionList() )
const QStringList names = QgsGeoNodeConnectionUtils::connectionList();
for ( const QString &connName : names )
{
std::unique_ptr< QgsGeoNodeConnection > connection( new QgsGeoNodeConnection( connName ) );
QString path = mPath + '/' + connName;
@@ -209,7 +209,8 @@ void QgsGeoNodeRequest::replyFinished()
QNetworkCacheMetaData cmd = nam->cache()->metaData( mGeoNodeReply->request().url() );

QNetworkCacheMetaData::RawHeaderList hl;
Q_FOREACH ( const QNetworkCacheMetaData::RawHeader &h, cmd.rawHeaders() )
const QNetworkCacheMetaData::RawHeaderList cmdHeaders = cmd.rawHeaders();
for ( const QNetworkCacheMetaData::RawHeader &h : cmdHeaders )
{
if ( h.first != QStringLiteral( "Cache-Control" ) )
hl.append( h );
@@ -251,14 +251,14 @@ QVector<QgsDataItem *> QgsWfsDataItemProvider::createDataItems( const QString &p
QString url = connection.uri().param( "url" );
QgsGeoNodeRequest geonodeRequest( url, true );

QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WFS" ) ) );
const QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WFS" ) ) );

if ( !encodedUris.isEmpty() )
{
Q_FOREACH ( QString encodedUri, encodedUris )
for ( const QString &encodedUri : encodedUris )
{
QgsWFSDataSourceURI uri( encodedUri );
QgsDebugMsg( QString( "WFS full uri: '%1'." ).arg( QString( uri.uri() ) ) );
QgsDebugMsg( QStringLiteral( "WFS full uri: '%1'." ).arg( uri.uri() ) );

QgsDataItem *item = new QgsWfsConnectionItem( parentItem, QStringLiteral( "WFS" ), path, uri.uri() );
if ( item )
@@ -566,11 +566,11 @@ QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &p
QString url = connection.uri().param( "url" );
QgsGeoNodeRequest geonodeRequest( url, true );

QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WMS" ) ) );
const QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WMS" ) ) );

if ( !encodedUris.isEmpty() )
{
Q_FOREACH ( QString encodedUri, encodedUris )
for ( const QString &encodedUri : encodedUris )
{
QgsDebugMsg( encodedUri );
QgsDataSourceUri uri;
@@ -612,16 +612,18 @@ QVector<QgsDataItem *> QgsXyzTileDataItemProvider::createDataItems( const QStrin
QString url = connection.uri().param( "url" );
QgsGeoNodeRequest geonodeRequest( url, true );

QgsStringMap urlData( geonodeRequest.fetchServiceUrlDataBlocking( QStringLiteral( "XYZ" ) ) );
const QgsStringMap urlData( geonodeRequest.fetchServiceUrlDataBlocking( QStringLiteral( "XYZ" ) ) );

if ( !urlData.isEmpty() )
{
Q_FOREACH ( QString layerName, urlData.keys() )
auto urlDataIt = urlData.constBegin();
for ( ; urlDataIt != urlData.constEnd(); ++urlDataIt )
{
QgsDebugMsg( urlData[ layerName] );
const QString layerName = urlDataIt.key();
QgsDebugMsg( urlDataIt.value() );
QgsDataSourceUri uri;
uri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) );
uri.setParam( QStringLiteral( "url" ), urlData[ layerName ] );
uri.setParam( QStringLiteral( "url" ), urlDataIt.value() );

QgsDataItem *item = new QgsXyzLayerItem( parentItem, layerName, path, uri.encodedUri() );
if ( item )

0 comments on commit af03d2f

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