Skip to content

Commit

Permalink
Fix clazy qstring-arg warnings
Browse files Browse the repository at this point in the history
Avoid chained QString::arg() calls and instead use the multi-arg
overload to save memory allocations
  • Loading branch information
nyalldawson committed Oct 22, 2016
1 parent f267215 commit fae8071
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsbookmarks.cpp
Expand Up @@ -442,10 +442,10 @@ bool QgsProjectBookmarksTableModel::setData( const QModelIndex& index, const QVa
switch ( index.column() )
{
case 1:
QgsProject::instance()->writeEntry( "Bookmarks", QString( "/Row-%1/Name" ).arg( index.row() ), value.value<QString>() );
QgsProject::instance()->writeEntry( "Bookmarks", QString( "/Row-%1/Name" ).arg( index.row() ), value.toString() );
return true;
case 2:
QgsProject::instance()->writeEntry( "Bookmarks", QString( "/Row-%1/Project" ).arg( index.row() ), value.value<QString>() );
QgsProject::instance()->writeEntry( "Bookmarks", QString( "/Row-%1/Project" ).arg( index.row() ), value.toString() );
return true;
case 3:
QgsProject::instance()->writeEntry( "Bookmarks", QString( "/Row-%1/MinX" ).arg( index.row() ), value.toDouble() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgml.cpp
Expand Up @@ -387,7 +387,7 @@ QgsGmlStreamingParser::QgsGmlStreamingParser( const QList<LayerProperties>& laye
if ( alreadyFoundGeometry )
{
QgsDebugMsg( QString( "Will ignore geometry field %1 from typename %2" ).
arg( mLayerProperties[i].mGeometryAttribute ).arg( mLayerProperties[i].mName ) );
arg( mLayerProperties[i].mGeometryAttribute, mLayerProperties[i].mName ) );
mLayerProperties[i].mGeometryAttribute.clear();
}
alreadyFoundGeometry = true;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -291,12 +291,12 @@ QVariantList QgsJSONUtils::parseArray( const QString& json, QVariant::Type type
QVariantList result;
if ( error.error != QJsonParseError::NoError )
{
QgsLogger::warning( QString( "Cannot parse json (%1): %2" ).arg( error.errorString() ).arg( json ) );
QgsLogger::warning( QString( "Cannot parse json (%1): %2" ).arg( error.errorString(), json ) );
return result;
}
if ( !jsonDoc.isArray() )
{
QgsLogger::warning( QString( "Cannot parse json (%1) as array: %2" ).arg( error.errorString() ).arg( json ) );
QgsLogger::warning( QString( "Cannot parse json (%1) as array: %2" ).arg( error.errorString(), json ) );
return result;
}
Q_FOREACH ( const QJsonValue cur, jsonDoc.array() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgssqlstatement.cpp
Expand Up @@ -237,7 +237,7 @@ bool QgsSQLStatement::doBasicValidationChecks( QString& errorMsgOut ) const
{
if ( !errorMsgOut.isEmpty() )
errorMsgOut += " ";
errorMsgOut += QString( tr( "Table %1 is referenced by column %2, but not selected in FROM / JOIN." ) ).arg( pair.first ).arg( pair.second );
errorMsgOut += QString( tr( "Table %1 is referenced by column %2, but not selected in FROM / JOIN." ) ).arg( pair.first, pair.second );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsstringutils.cpp
Expand Up @@ -362,7 +362,7 @@ QString QgsStringUtils::insertLinks( const QString& string, bool *foundLinks )
{
protoUrl.prepend( "http://" );
}
QString anchor = QString( "<a href=\"%1\">%2</a>" ).arg( Qt::escape( protoUrl ) ).arg( Qt::escape( url ) );
QString anchor = QString( "<a href=\"%1\">%2</a>" ).arg( Qt::escape( protoUrl ), Qt::escape( url ) );
converted.replace( urlRegEx.pos( 1 ), url.length(), anchor );
offset = urlRegEx.pos( 1 ) + anchor.length();
}
Expand All @@ -371,7 +371,7 @@ QString QgsStringUtils::insertLinks( const QString& string, bool *foundLinks )
{
found = true;
QString email = emailRegEx.cap( 1 );
QString anchor = QString( "<a href=\"mailto:%1\">%1</a>" ).arg( Qt::escape( email ) ).arg( Qt::escape( email ) );
QString anchor = QString( "<a href=\"mailto:%1\">%1</a>" ).arg( Qt::escape( email ), Qt::escape( email ) );
converted.replace( emailRegEx.pos( 1 ), email.length(), anchor );
offset = emailRegEx.pos( 1 ) + anchor.length();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -281,7 +281,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
{
if ( fileEncoding.compare( metadata.compulsoryEncoding, Qt::CaseInsensitive ) != 0 )
{
QgsDebugMsg( QString( "forced %1 encoding for %2" ).arg( metadata.compulsoryEncoding ).arg( driverName ) );
QgsDebugMsg( QString( "forced %1 encoding for %2" ).arg( metadata.compulsoryEncoding, driverName ) );
fileEncoding = metadata.compulsoryEncoding;
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -793,9 +793,9 @@ void QgsAttributeForm::displayInvalidConstraintMessage( const QStringList& f,
int size = f.size() > max ? max : f.size();
QString descriptions;
for ( int i = 0; i < size; i++ )
descriptions += QString( "<li>%1: <i>%2</i></li>" ).arg( f[i] ).arg( d[i] );
descriptions += QString( "<li>%1: <i>%2</i></li>" ).arg( f[i], d[i] );

QString msg = QString( "<b>%1</b><ul>%2</ul>" ).arg( tr( "Invalid fields" ) ).arg( descriptions ) ;
QString msg = QString( "<b>%1</b><ul>%2</ul>" ).arg( tr( "Invalid fields" ), descriptions ) ;

mInvalidConstraintMessage->setText( msg );
mTopMessageWidget->show();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgscolorbutton.cpp
Expand Up @@ -171,8 +171,8 @@ bool QgsColorButton::event( QEvent *e )
int saturation = this->color().saturation();
QString info = QString( "HEX: %1 \n"
"RGB: %2 \n"
"HSV: %3,%4,%5" ).arg( name )
.arg( QgsSymbolLayerUtils::encodeColor( this->color() ) )
"HSV: %3,%4,%5" ).arg( name,
QgsSymbolLayerUtils::encodeColor( this->color() ) )
.arg( hue ).arg( saturation ).arg( value );
setToolTip( info );
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsdataitems.cpp
Expand Up @@ -150,7 +150,7 @@ void QgsAfsConnectionItem::deleteConnection()
QgsAfsLayerItem::QgsAfsLayerItem( QgsDataItem* parent, const QString &name, const QString &url, const QString &title, const QString& authid )
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Vector, "arcgisfeatureserver" )
{
mUri = QString( "crs='%1' url='%2'" ).arg( authid ).arg( url );
mUri = QString( "crs='%1' url='%2'" ).arg( authid, url );
setState( Populated );
mIconName = "mIconConnect.png";
}
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsprovider.cpp
Expand Up @@ -118,7 +118,7 @@ QgsAfsProvider::QgsAfsProvider( const QString& uri )
QVariantMap objectIdData = QgsArcGisRestUtils::getObjectIds( mDataSource.param( "url" ), errorTitle, errorMessage );
if ( objectIdData.isEmpty() )
{
appendError( QgsErrorMessage( tr( "getObjectIds failed: %1 - %2" ).arg( errorTitle ).arg( errorMessage ), "AFSProvider" ) );
appendError( QgsErrorMessage( tr( "getObjectIds failed: %1 - %2" ).arg( errorTitle, errorMessage ), "AFSProvider" ) );
return;
}
if ( !objectIdData["objectIdFieldName"].isValid() || !objectIdData["objectIds"].isValid() )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsafssourceselect.cpp
Expand Up @@ -41,7 +41,7 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( "url" ), errorTitle, errorMessage );
if ( serviceInfoMap.isEmpty() )
{
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle ).arg( errorMessage ) );
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle, errorMessage ) );
return false;
}

Expand All @@ -58,7 +58,7 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( "url" ) + "/" + layerInfoMap["id"].toString(), errorTitle, errorMessage );
if ( layerData.isEmpty() )
{
layerErrors.append( tr( "Layer %1: %2 - %3" ).arg( layerInfoMap["id"].toString() ).arg( errorTitle ).arg( errorMessage ) );
layerErrors.append( tr( "Layer %1: %2 - %3" ).arg( layerInfoMap["id"].toString(), errorTitle, errorMessage ) );
continue;
}
// insert the typenames, titles and abstracts into the tree view
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsamsdataitems.cpp
Expand Up @@ -165,7 +165,7 @@ void QgsAmsConnectionItem::deleteConnection()
QgsAmsLayerItem::QgsAmsLayerItem( QgsDataItem* parent, const QString& name, const QString &url, const QString& id, const QString& title, const QString& authid, const QString& format )
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Raster, "arcgismapserver" )
{
mUri = QString( "crs='%1' format='%2' layer='%3' url='%4'" ).arg( authid ).arg( format ).arg( id ).arg( url );
mUri = QString( "crs='%1' format='%2' layer='%3' url='%4'" ).arg( authid, format, id, url );
setState( Populated );
mIconName = "mIconAms.svg";
}
6 changes: 3 additions & 3 deletions src/providers/arcgisrest/qgsamsprovider.cpp
Expand Up @@ -222,11 +222,11 @@ static inline QString dumpVariantMap( const QVariantMap& variantMap, const QStri
QVariantMap childMap = variantMap[key].toMap();
if ( childMap.isEmpty() )
{
result += QString( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key ).arg( variantMap[key].toString() );
result += QString( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key, variantMap[key].toString() );
}
else
{
result += QString( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key ).arg( dumpVariantMap( childMap ) );
result += QString( "<tr><td>%1</td><td>%2</td></tr>" ).arg( key, dumpVariantMap( childMap ) );
}
}
result += "</table>";
Expand Down Expand Up @@ -400,7 +400,7 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPoint & thePoint, Qgs
QString valueStr;
foreach ( const QString& attribute, attributesMap.keys() )
{
valueStr += QString( "%1 = %2\n" ).arg( attribute ).arg( attributesMap[attribute].toString() );
valueStr += QString( "%1 = %2\n" ).arg( attribute, attributesMap[attribute].toString() );
}
entries.insert( entries.size(), valueStr );
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsamssourceselect.cpp
Expand Up @@ -40,7 +40,7 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( "url" ), errorTitle, errorMessage );
if ( serviceInfoMap.isEmpty() )
{
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle ).arg( errorMessage ) );
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle, errorMessage ) );
return false;
}

Expand All @@ -59,7 +59,7 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( "url" ) + "/" + layerInfoMap["id"].toString(), errorTitle, errorMessage );
if ( layerData.isEmpty() )
{
layerErrors.append( QString( "Layer %1: %2 - %3" ).arg( layerInfoMap["id"].toString() ).arg( errorTitle ).arg( errorMessage ) );
layerErrors.append( QString( "Layer %1: %2 - %3" ).arg( layerInfoMap["id"].toString(), errorTitle, errorMessage ) );
continue;
}
// insert the typenames, titles and abstracts into the tree view
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2expressioncompiler.cpp
Expand Up @@ -118,7 +118,7 @@ QgsSqlExpressionCompiler::Result QgsDb2ExpressionCompiler::compileNode( const Qg
}

result = "NOT " + result;
QgsDebugMsg( QString( "NOT; result: %1; right: %2" ).arg( resultType( rr ) ).arg( result ) );
QgsDebugMsg( QString( "NOT; result: %1; right: %2" ).arg( resultType( rr ), result ) );
return rr;

case QgsExpression::uoMinus:
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2provider.cpp
Expand Up @@ -1529,7 +1529,7 @@ QgsVectorLayerImport::ImportError QgsDb2Provider::createEmptyLayer( const QStrin
for ( int i = 0; i < list.size(); ++i )
{
QgsDebugMsg( QString( "i: %1; value: %2; type: %3" )
.arg( i ).arg( list.at( i ).toString().toLatin1().data() ).arg( list.at( i ).typeName() ) );
.arg( i ).arg( list.at( i ).toString().toLatin1().data(), list.at( i ).typeName() ) );
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrass.cpp
Expand Up @@ -1579,7 +1579,7 @@ QStringList QgsGrass::grassObjects( const QgsGrassObject& mapsetObject, QgsGrass
catch ( QgsGrass::Exception &e )
{
// TODO: notify somehow user
QgsDebugMsg( QString( "Cannot run %1: %2" ).arg( cmd ).arg( e.what() ) );
QgsDebugMsg( QString( "Cannot run %1: %2" ).arg( cmd, e.what() ) );
}
}
#endif
Expand Down
16 changes: 8 additions & 8 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -422,7 +422,7 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg, QS
concatenatedTypenames ) )
{
errorMsg = tr( "DescribeFeatureType failed for url %1: %2" ).
arg( dataSourceUri() ).arg( describeFeatureType.errorMessage() );
arg( dataSourceUri(), describeFeatureType.errorMessage() );
return false;
}

Expand All @@ -434,7 +434,7 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg, QS
{
QgsDebugMsg( response );
errorMsg = tr( "DescribeFeatureType failed for url %1: %2" ).
arg( dataSourceUri() ).arg( errorMsg );
arg( dataSourceUri(), errorMsg );
return false;
}

Expand All @@ -451,7 +451,7 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg, QS
geometryAttribute, fields, geomType, errorMsg ) )
{
errorMsg = tr( "Analysis of DescribeFeatureType response failed for url %1, typeName %2: %3" ).
arg( dataSourceUri() ).arg( typeName ).arg( errorMsg );
arg( dataSourceUri(), typeName, errorMsg );
return false;
}

Expand Down Expand Up @@ -1109,7 +1109,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
mShared->mURI.typeName() ) )
{
QgsMessageLog::logMessage( tr( "DescribeFeatureType failed for url %1: %2" ).
arg( dataSourceUri() ).arg( describeFeatureType.errorMessage() ), tr( "WFS" ) );
arg( dataSourceUri(), describeFeatureType.errorMessage() ), tr( "WFS" ) );
return false;
}

Expand All @@ -1121,7 +1121,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
{
QgsDebugMsg( response );
QgsMessageLog::logMessage( tr( "DescribeFeatureType failed for url %1: %2" ).
arg( dataSourceUri() ).arg( errorMsg ), tr( "WFS" ) );
arg( dataSourceUri(), errorMsg ), tr( "WFS" ) );
return false;
}

Expand All @@ -1130,7 +1130,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
geometryAttribute, fields, geomType, errorMsg ) )
{
QgsMessageLog::logMessage( tr( "Analysis of DescribeFeatureType response failed for url %1: %2" ).
arg( dataSourceUri() ).arg( errorMsg ), tr( "WFS" ) );
arg( dataSourceUri(), errorMsg ), tr( "WFS" ) );
return false;
}

Expand Down Expand Up @@ -1449,7 +1449,7 @@ bool QgsWFSProvider::getCapabilities()
if ( !getCapabilities.requestCapabilities( synchronous, forceRefresh ) )
{
QgsMessageLog::logMessage( tr( "GetCapabilities failed for url %1: %2" ).
arg( dataSourceUri() ).arg( getCapabilities.errorMessage() ), tr( "WFS" ) );
arg( dataSourceUri(), getCapabilities.errorMessage() ), tr( "WFS" ) );
return false;
}

Expand Down Expand Up @@ -1524,7 +1524,7 @@ bool QgsWFSProvider::getCapabilities()
if ( !foundLayer )
{
QgsMessageLog::logMessage( tr( "Could not find typename %1 in capabilities for url %2" ).
arg( thisLayerName ).arg( dataSourceUri() ), tr( "WFS" ) );
arg( thisLayerName, dataSourceUri() ), tr( "WFS" ) );
}

return foundLayer;
Expand Down
8 changes: 4 additions & 4 deletions src/providers/wfs/qgswfsshareddata.cpp
Expand Up @@ -382,7 +382,7 @@ bool QgsWFSSharedData::createCache()
if ( !ogrWaySuccessful )
{
mCacheTablename = "features";
sql = QString( "CREATE TABLE %1 (%2 INTEGER PRIMARY KEY" ).arg( mCacheTablename ).arg( fidName );
sql = QString( "CREATE TABLE %1 (%2 INTEGER PRIMARY KEY" ).arg( mCacheTablename, fidName );
Q_FOREACH ( QgsField field, cacheFields )
{
QString type( "VARCHAR" );
Expand Down Expand Up @@ -421,7 +421,7 @@ bool QgsWFSSharedData::createCache()

// We need an index on the gmlid, since we will check for duplicates, particularly
// useful in the case we do overlapping BBOX requests
sql = QString( "CREATE INDEX idx_%2 ON %1(%2)" ).arg( mCacheTablename ).arg( QgsWFSConstants::FIELD_GMLID );
sql = QString( "CREATE INDEX idx_%2 ON %1(%2)" ).arg( mCacheTablename, QgsWFSConstants::FIELD_GMLID );
rc = sqlite3_exec( db, sql.toUtf8(), nullptr, nullptr, nullptr );
if ( rc != SQLITE_OK )
{
Expand All @@ -431,7 +431,7 @@ bool QgsWFSSharedData::createCache()

if ( mDistinctSelect )
{
sql = QString( "CREATE INDEX idx_%2 ON %1(%2)" ).arg( mCacheTablename ).arg( QgsWFSConstants::FIELD_MD5 );
sql = QString( "CREATE INDEX idx_%2 ON %1(%2)" ).arg( mCacheTablename, QgsWFSConstants::FIELD_MD5 );
rc = sqlite3_exec( db, sql.toUtf8(), nullptr, nullptr, nullptr );
if ( rc != SQLITE_OK )
{
Expand Down Expand Up @@ -985,7 +985,7 @@ void QgsWFSSharedData::endOfDownload( bool success, int featureCount,

if ( !success && !interrupted )
{
QString errorMsgOut( tr( "Download of features for layer %1 failed or partially failed: %2. You may attempt reloading the layer with F5" ).arg( mURI.typeName() ).arg( errorMsg ) );
QString errorMsgOut( tr( "Download of features for layer %1 failed or partially failed: %2. You may attempt reloading the layer with F5" ).arg( mURI.typeName(), errorMsg ) );
pushError( errorMsgOut );
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsutils.cpp
Expand Up @@ -61,7 +61,7 @@ QString QgsWFSUtils::getCacheDirectory( bool createIfNotExisting )
QMutexLocker locker( &gmMutex );
if ( !QDir( baseDirectory ).exists( processPath ) )
{
QgsDebugMsg( QString( "Creating our cache dir %1/%2" ).arg( baseDirectory ).arg( processPath ) );
QgsDebugMsg( QString( "Creating our cache dir %1/%2" ).arg( baseDirectory, processPath ) );
QDir( baseDirectory ).mkpath( processPath );
}
if ( gmCounter == 0 && gmKeepAliveWorks )
Expand Down
3 changes: 1 addition & 2 deletions src/server/qgsconfigcache.cpp
Expand Up @@ -75,8 +75,7 @@ QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& file
}
QgsMessageLog::logMessage(
QString( "QGIS server version %1, project version %2" )
.arg( thisVersion.text() )
.arg( fileVersion.text() ),
.arg( thisVersion.text(), fileVersion.text() ),
"Server", QgsMessageLog::INFO
);
return new QgsServerProjectParser( doc, filePath );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgscomposergroup.cpp
Expand Up @@ -69,8 +69,8 @@ void TestQgsComposerGroup::dumpUndoStack( const QUndoStack& us, QString prefix )
for ( int i = 0; i < us.count(); ++i )
{
QgsDebugMsg( QString( "%4US %1: %2%3" )
.arg( i ). arg( i >= us.index() ? "-" : "" )
.arg( us.text( i ) ) .arg( prefix ) );
.arg( i ). arg( i >= us.index() ? "-" : "",
us.text( i ), prefix ) );
}
}

Expand Down

0 comments on commit fae8071

Please sign in to comment.