Skip to content
Permalink
Browse files

Modernize some code

  • Loading branch information
nyalldawson committed Oct 17, 2018
1 parent ac4f7b5 commit ffdf39eb6e811aae1d1e6b0f6e1a45bc21ecd277
@@ -122,7 +122,8 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
QString objectIdFieldName;

// Read fields
foreach ( const QVariant &fieldData, layerData["fields"].toList() )
const QVariantList fields = layerData.value( QStringLiteral( "fields" ) ).toList();
for ( const QVariant &fieldData : fields )
{
const QVariantMap fieldDataMap = fieldData.toMap();
const QString fieldName = fieldDataMap[QStringLiteral( "name" )].toString();
@@ -189,7 +190,8 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
break;
}
}
foreach ( const QVariant &objectId, objectIdData["objectIds"].toList() )
const QVariantList objectIds = objectIdData.value( QStringLiteral( "objectIds" ) ).toList();
for ( const QVariant &objectId : objectIds )
{
mSharedData->mObjectIds.append( objectId.toInt() );
}
@@ -100,7 +100,7 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, const QgsRect
const QVariantMap attributesData = featureData[QStringLiteral( "attributes" )].toMap();
feature.setFields( mFields );
QgsAttributes attributes( mFields.size() );
foreach ( int idx, fetchAttribIdx )
for ( int idx : qgis::as_const( fetchAttribIdx ) )
{
QVariant attribute = attributesData[mFields.at( idx ).name()];
if ( attribute.isNull() )
@@ -45,7 +45,8 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
}

QStringList layerErrors;
foreach ( const QVariant &layerInfo, serviceInfoMap["layers"].toList() )
const QVariantList layers = serviceInfoMap.value( QStringLiteral( "layers" ) ).toList();
for ( const QVariant &layerInfo : layers )
{
const QVariantMap layerInfoMap = layerInfo.toMap();
if ( !layerInfoMap[QStringLiteral( "id" )].isValid() )
@@ -26,7 +26,7 @@

#include <QImageReader>

QgsAmsRootItem::QgsAmsRootItem( QgsDataItem *parent, QString name, QString path )
QgsAmsRootItem::QgsAmsRootItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
{
mCapabilities |= Fast | Collapse;
@@ -38,7 +38,8 @@ QVector<QgsDataItem *> QgsAmsRootItem::createChildren()
{
QVector<QgsDataItem *> connections;

Q_FOREACH ( const QString &connName, QgsOwsConnection::connectionList( "arcgismapserver" ) )
const QStringList connectionList = QgsOwsConnection::connectionList( QStringLiteral( "arcgismapserver" ) );
for ( const QString &connName : connectionList )
{
QgsOwsConnection connection( QStringLiteral( "arcgismapserver" ), connName );
QString path = "ams:/" + connName;
@@ -82,7 +83,7 @@ void QgsAmsRootItem::newConnection()

///////////////////////////////////////////////////////////////////////////////

QgsAmsConnectionItem::QgsAmsConnectionItem( QgsDataItem *parent, QString name, QString path, QString url )
QgsAmsConnectionItem::QgsAmsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &url )
: QgsDataCollectionItem( parent, name, path )
, mUrl( url )
{
@@ -102,10 +103,11 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()
QString authid = QgsArcGisRestUtils::parseSpatialReference( serviceData[QStringLiteral( "spatialReference" )].toMap() ).authid();
QString format = QStringLiteral( "jpg" );
bool found = false;
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach ( const QString &encoding, serviceData["supportedImageFormatTypes"].toString().split( ',' ) )
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
const QStringList supportedImageFormatTypes = serviceData.value( QStringLiteral( "supportedImageFormatTypes" ) ).toString().split( ',' );
for ( const QString &encoding : supportedImageFormatTypes )
{
foreach ( const QByteArray &fmt, supportedFormats )
for ( const QByteArray &fmt : supportedFormats )
{
if ( encoding.startsWith( fmt, Qt::CaseInsensitive ) )
{
@@ -118,7 +120,8 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()
break;
}

foreach ( const QVariant &layerInfo, serviceData["layers"].toList() )
const QVariantList layersList = serviceData.value( QStringLiteral( "layers" ) ).toList();
for ( const QVariant &layerInfo : layersList )
{
QVariantMap layerInfoMap = layerInfo.toMap();
QString id = layerInfoMap[QStringLiteral( "id" )].toString();
@@ -131,7 +134,7 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()

bool QgsAmsConnectionItem::equal( const QgsDataItem *other )
{
const QgsAmsConnectionItem *o = dynamic_cast<const QgsAmsConnectionItem *>( other );
const QgsAmsConnectionItem *o = qobject_cast<const QgsAmsConnectionItem *>( other );
return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
}

@@ -26,7 +26,7 @@ class QgsAmsRootItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsAmsRootItem( QgsDataItem *parent, QString name, QString path );
QgsAmsRootItem( QgsDataItem *parent, const QString &name, const QString &path );

QVector<QgsDataItem *> createChildren() override;

@@ -49,7 +49,7 @@ class QgsAmsConnectionItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsAmsConnectionItem( QgsDataItem *parent, QString name, QString path, QString url );
QgsAmsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &url );
QVector<QgsDataItem *> createChildren() override;
bool equal( const QgsDataItem *other ) override;
#ifdef HAVE_GUI
@@ -71,16 +71,17 @@ void QgsAmsLegendFetcher::handleFinished()
QVariantMap queryResults = doc.object().toVariantMap();
QgsDataSourceUri dataSource( mProvider->dataSourceUri() );
QVector< QPair<QString, QImage> > legendEntries;
foreach ( const QVariant &result, queryResults["layers"].toList() )
const QVariantList layersList = queryResults.value( QStringLiteral( "layers" ) ).toList();
for ( const QVariant &result : layersList )
{
QVariantMap queryResultMap = result.toMap();
QString layerId = queryResultMap[QStringLiteral( "layerId" )].toString();
if ( layerId != dataSource.param( QStringLiteral( "layer" ) ) && !mProvider->subLayers().contains( layerId ) )
{
continue;
}
QVariantList legendSymbols = queryResultMap[QStringLiteral( "legend" )].toList();
foreach ( const QVariant &legendEntry, legendSymbols )
const QVariantList legendSymbols = queryResultMap[QStringLiteral( "legend" )].toList();
for ( const QVariant &legendEntry : legendSymbols )
{
QVariantMap legendEntryMap = legendEntry.toMap();
QString label = legendEntryMap[QStringLiteral( "label" )].toString();
@@ -99,7 +100,7 @@ void QgsAmsLegendFetcher::handleFinished()

typedef QPair<QString, QImage> LegendEntry_t;
QSize maxImageSize( 0, 0 );
foreach ( const LegendEntry_t &legendEntry, legendEntries )
for ( const LegendEntry_t &legendEntry : qgis::as_const( legendEntries ) )
{
maxImageSize.setWidth( std::max( maxImageSize.width(), legendEntry.second.width() ) );
maxImageSize.setHeight( std::max( maxImageSize.height(), legendEntry.second.height() ) );
@@ -111,7 +112,7 @@ void QgsAmsLegendFetcher::handleFinished()
mLegendImage.fill( Qt::transparent );
QPainter painter( &mLegendImage );
int i = 0;
foreach ( const LegendEntry_t &legendEntry, legendEntries )
for ( const LegendEntry_t &legendEntry : qgis::as_const( legendEntries ) )
{
QImage symbol = legendEntry.second.scaled( legendEntry.second.width() * scaleFactor, legendEntry.second.height() * scaleFactor, Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter.drawImage( 0, vpadding + i * ( imageSize + vpadding ) + ( imageSize - symbol.height() ), symbol );
@@ -144,7 +145,9 @@ QgsAmsProvider::QgsAmsProvider( const QString &uri, const ProviderOptions &optio
appendError( QgsErrorMessage( tr( "Could not parse spatial reference" ), QStringLiteral( "AMSProvider" ) ) );
return;
}
foreach ( const QVariant &sublayer, mLayerInfo["subLayers"].toList() )
const QVariantList subLayersList = mLayerInfo.value( QStringLiteral( "subLayers" ) ).toList();
mSubLayers.reserve( subLayersList.size() );
for ( const QVariant &sublayer : subLayersList )
{
mSubLayers.append( sublayer.toMap()[QStringLiteral( "id" )].toString() );
mSubLayerVisibilities.append( true );
@@ -157,6 +160,7 @@ QgsAmsProvider::QgsAmsProvider( const QString &uri, const ProviderOptions &optio
QStringList QgsAmsProvider::subLayerStyles() const
{
QStringList styles;
styles.reserve( mSubLayers.size() );
for ( int i = 0, n = mSubLayers.size(); i < n; ++i )
{
styles.append( QString() );
@@ -170,7 +174,7 @@ void QgsAmsProvider::setLayerOrder( const QStringList &layers )
QList<bool> oldSubLayerVisibilities = mSubLayerVisibilities;
mSubLayers.clear();
mSubLayerVisibilities.clear();
foreach ( const QString &layer, layers )
for ( const QString &layer : layers )
{
// Search for match
for ( int i = 0, n = oldSubLayers.size(); i < n; ++i )
@@ -273,7 +277,7 @@ void QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int p
double oy = origin[QStringLiteral( "y" )].toDouble();

// Search matching resolution (tile resolution <= targetRes)
QList<QVariant> lodEntries = tileInfo[QStringLiteral( "lods" )].toList();
const QList<QVariant> lodEntries = tileInfo[QStringLiteral( "lods" )].toList();
if ( lodEntries.isEmpty() )
{
mCachedImage = QImage();
@@ -282,7 +286,7 @@ void QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int p
}
int level = 0;
double resolution = lodEntries.front().toMap()[QStringLiteral( "resolution" )].toDouble();
foreach ( const QVariant &lodEntry, lodEntries )
for ( const QVariant &lodEntry : lodEntries )
{
QVariantMap lodEntryMap = lodEntry.toMap();
level = lodEntryMap[QStringLiteral( "level" )].toInt();
@@ -47,7 +47,8 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
populateImageEncodings( serviceInfoMap[QStringLiteral( "supportedImageFormatTypes" )].toString().split( ',' ) );

QStringList layerErrors;
foreach ( const QVariant &layerInfo, serviceInfoMap["layers"].toList() )
const QVariantList layersList = serviceInfoMap[QStringLiteral( "layers" )].toList();
for ( const QVariant &layerInfo : layersList )
{
QVariantMap layerInfoMap = layerInfo.toMap();
if ( !layerInfoMap[QStringLiteral( "id" )].isValid() )
@@ -125,12 +125,12 @@ static std::unique_ptr< QgsPoint > parsePoint( const QVariantList &coordList, Qg

static std::unique_ptr< QgsCircularString > parseCircularString( const QVariantMap &curveData, QgsWkbTypes::Type pointType, const QgsPoint &startPoint )
{
QVariantList coordsList = curveData[QStringLiteral( "c" )].toList();
const QVariantList coordsList = curveData[QStringLiteral( "c" )].toList();
if ( coordsList.isEmpty() )
return nullptr;
QVector<QgsPoint> points;
points.append( startPoint );
foreach ( const QVariant &coordData, coordsList )
for ( const QVariant &coordData : coordsList )
{
std::unique_ptr< QgsPoint > point = parsePoint( coordData.toList(), pointType );
if ( !point )
@@ -150,7 +150,7 @@ static std::unique_ptr< QgsCompoundCurve > parseCompoundCurve( const QVariantLis
std::unique_ptr< QgsCompoundCurve > compoundCurve = qgis::make_unique< QgsCompoundCurve >();
QgsLineString *lineString = new QgsLineString();
compoundCurve->addCurve( lineString );
foreach ( const QVariant &curveData, curvesList )
for ( const QVariant &curveData : curvesList )
{
if ( curveData.type() == QVariant::List )
{
@@ -230,7 +230,7 @@ static std::unique_ptr< QgsMultiCurve > parseEsriGeometryPolyline( const QVarian
if ( pathsList.isEmpty() )
return nullptr;
std::unique_ptr< QgsMultiCurve > multiCurve = qgis::make_unique< QgsMultiCurve >();
foreach ( const QVariant &pathData, pathsList )
for ( const QVariant &pathData : qgis::as_const( pathsList ) )
{
std::unique_ptr< QgsCompoundCurve > curve = parseCompoundCurve( pathData.toList(), pointType );
if ( !curve )
@@ -392,7 +392,7 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
QString &errorTitle, QString &errorText, QgsFeedback *feedback )
{
QStringList ids;
foreach ( int id, objectIds )
for ( int id : objectIds )
{
ids.append( QString::number( id ) );
}
@@ -413,8 +413,8 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
queryUrl.addQueryItem( QStringLiteral( "returnGeometry" ), QStringLiteral( "false" ) );
queryUrl.addQueryItem( QStringLiteral( "outFields" ), outFields );
}
queryUrl.addQueryItem( QStringLiteral( "returnM" ), fetchM ? "true" : "false" );
queryUrl.addQueryItem( QStringLiteral( "returnZ" ), fetchZ ? "true" : "false" );
queryUrl.addQueryItem( QStringLiteral( "returnM" ), fetchM ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
queryUrl.addQueryItem( QStringLiteral( "returnZ" ), fetchZ ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
if ( !filterRect.isNull() )
{
queryUrl.addQueryItem( QStringLiteral( "geometry" ), QStringLiteral( "%1,%2,%3,%4" )
@@ -118,11 +118,11 @@ void QgsArcGisServiceSourceSelect::populateImageEncodings( const QStringList &av
delete item;
}
bool first = true;
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach ( const QString &encoding, availableEncodings )
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
for ( const QString &encoding : availableEncodings )
{
bool supported = false;
foreach ( const QByteArray &fmt, supportedFormats )
for ( const QByteArray &fmt : supportedFormats )
{
if ( encoding.startsWith( fmt, Qt::CaseInsensitive ) )
{
@@ -149,9 +149,9 @@ QString QgsArcGisServiceSourceSelect::getSelectedImageEncoding() const

void QgsArcGisServiceSourceSelect::populateConnectionList()
{
QStringList conns = QgsOwsConnection::connectionList( mServiceName );
const QStringList conns = QgsOwsConnection::connectionList( mServiceName );
cmbConnections->clear();
foreach ( const QString &item, conns )
for ( const QString &item : conns )
{
cmbConnections->addItem( item );
}
@@ -383,7 +383,8 @@ void QgsArcGisServiceSourceSelect::changeCrsFilter()
if ( crsIterator != mAvailableCRS.constEnd() )
{
QSet<QString> crsNames;
foreach ( const QString &crsName, crsIterator.value() )
const QStringList crsNamesList = crsIterator.value();
for ( const QString &crsName : crsNamesList )
{
crsNames.insert( crsName );
}

0 comments on commit ffdf39e

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