Skip to content

Commit 4166a3e

Browse files
committed
Fix most clazy qstring-unneeded-heap-allocations warnings
By flipping string literals to QStringLiteral/QLatin1String see https://woboq.com/blog/qstringliteral.html
1 parent f6a344c commit 4166a3e

File tree

1,041 files changed

+25464
-25413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,041 files changed

+25464
-25413
lines changed

src/analysis/interpolation/DualEdgeTriangulation.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -3090,12 +3090,12 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
30903090
QString shapeFileName = fileName;
30913091

30923092
QgsFields fields;
3093-
fields.append( QgsField( "type", QVariant::String, "String" ) );
3093+
fields.append( QgsField( QStringLiteral( "type" ), QVariant::String, QStringLiteral( "String" ) ) );
30943094

30953095
// add the extension if not present
3096-
if ( shapeFileName.indexOf( ".shp" ) == -1 )
3096+
if ( shapeFileName.indexOf( QLatin1String( ".shp" ) ) == -1 )
30973097
{
3098-
shapeFileName += ".shp";
3098+
shapeFileName += QLatin1String( ".shp" );
30993099
}
31003100

31013101
//delete already existing files
@@ -3107,7 +3107,7 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
31073107
}
31083108
}
31093109

3110-
QgsVectorFileWriter writer( shapeFileName, "Utf-8", fields, QgsWkbTypes::LineString );
3110+
QgsVectorFileWriter writer( shapeFileName, QStringLiteral( "Utf-8" ), fields, QgsWkbTypes::LineString );
31113111
if ( writer.hasError() != QgsVectorFileWriter::NoError )
31123112
{
31133113
return false;
@@ -3147,11 +3147,11 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
31473147
{
31483148
if ( currentEdge->getBreak() )
31493149
{
3150-
attributeString = "break line";
3150+
attributeString = QStringLiteral( "break line" );
31513151
}
31523152
else
31533153
{
3154-
attributeString = "structure line";
3154+
attributeString = QStringLiteral( "structure line" );
31553155
}
31563156
}
31573157
edgeLineFeature.setAttribute( 0, attributeString );

src/analysis/network/qgsgraphbuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ANALYSIS_EXPORT QgsGraphBuilder : public QgsGraphBuilderInterface
3939
/**
4040
* default constructor
4141
*/
42-
QgsGraphBuilder( const QgsCoordinateReferenceSystem& crs, bool otfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" );
42+
QgsGraphBuilder( const QgsCoordinateReferenceSystem& crs, bool otfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = QStringLiteral( "WGS84" ) );
4343

4444
~QgsGraphBuilder();
4545

src/analysis/network/qgsgraphbuilderintr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
4141
* @param topologyTolerance sqrt distance between source point as one graph vertex
4242
* @param ellipsoidID ellipsoid for edge measurement
4343
*/
44-
QgsGraphBuilderInterface( const QgsCoordinateReferenceSystem& crs, bool ctfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = "WGS84" )
44+
QgsGraphBuilderInterface( const QgsCoordinateReferenceSystem& crs, bool ctfEnabled = true, double topologyTolerance = 0.0, const QString& ellipsoidID = QStringLiteral( "WGS84" ) )
4545
: mCrs( crs )
4646
, mCtfEnabled( ctfEnabled )
4747
, mTopologyTolerance( topologyTolerance )

src/analysis/network/qgslinevectorlayerdirector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ QgsLineVectorLayerDirector::~QgsLineVectorLayerDirector()
123123

124124
QString QgsLineVectorLayerDirector::name() const
125125
{
126-
return QString( "Vector line" );
126+
return QStringLiteral( "Vector line" );
127127
}
128128

129129
void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,

src/analysis/openstreetmap/qgsosmdatabase.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool QgsOSMDatabase::open()
4949
int res = QgsSLConnect::sqlite3_open_v2( mDbFileName.toUtf8().data(), &mDatabase, SQLITE_OPEN_READWRITE, nullptr );
5050
if ( res != SQLITE_OK )
5151
{
52-
mError = QString( "Failed to open database [%1]: %2" ).arg( res ).arg( mDbFileName );
52+
mError = QStringLiteral( "Failed to open database [%1]: %2" ).arg( res ).arg( mDbFileName );
5353
close();
5454
return false;
5555
}
@@ -180,7 +180,7 @@ QList<QgsOSMTagCountPair> QgsOSMDatabase::usedTags( bool ways ) const
180180
{
181181
QList<QgsOSMTagCountPair> pairs;
182182

183-
QString sql = QString( "SELECT k, count(k) FROM %1_tags GROUP BY k" ).arg( ways ? "ways" : "nodes" );
183+
QString sql = QStringLiteral( "SELECT k, count(k) FROM %1_tags GROUP BY k" ).arg( ways ? "ways" : "nodes" );
184184

185185
sqlite3_stmt* stmt;
186186
if ( sqlite3_prepare_v2( mDatabase, sql.toUtf8().data(), -1, &stmt, nullptr ) != SQLITE_OK )
@@ -281,7 +281,7 @@ bool QgsOSMDatabase::prepareStatements()
281281
if ( sqlite3_prepare_v2( mDatabase, sql[i], -1, sqlite[i], nullptr ) != SQLITE_OK )
282282
{
283283
const char* errMsg = sqlite3_errmsg( mDatabase ); // does not require free
284-
mError = QString( "Error preparing SQL command:\n%1\nSQL:\n%2" )
284+
mError = QStringLiteral( "Error preparing SQL command:\n%1\nSQL:\n%2" )
285285
.arg( QString::fromUtf8( errMsg ), QString::fromUtf8( sql[i] ) );
286286
return false;
287287
}
@@ -299,9 +299,9 @@ bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName
299299
// create SpatiaLite table
300300

301301
QString geometryType;
302-
if ( type == Point ) geometryType = "POINT";
303-
else if ( type == Polyline ) geometryType = "LINESTRING";
304-
else if ( type == Polygon ) geometryType = "POLYGON";
302+
if ( type == Point ) geometryType = QStringLiteral( "POINT" );
303+
else if ( type == Polyline ) geometryType = QStringLiteral( "LINESTRING" );
304+
else if ( type == Polygon ) geometryType = QStringLiteral( "POLYGON" );
305305
else Q_ASSERT( false && "Unknown export type" );
306306

307307
if ( !createSpatialTable( tableName, geometryType, tagKeys ) )
@@ -333,9 +333,9 @@ bool QgsOSMDatabase::exportSpatiaLite( ExportType type, const QString& tableName
333333

334334
bool QgsOSMDatabase::createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys )
335335
{
336-
QString sqlCreateTable = QString( "CREATE TABLE %1 (id INTEGER PRIMARY KEY" ).arg( quotedIdentifier( tableName ) );
336+
QString sqlCreateTable = QStringLiteral( "CREATE TABLE %1 (id INTEGER PRIMARY KEY" ).arg( quotedIdentifier( tableName ) );
337337
for ( int i = 0; i < tagKeys.count(); ++i )
338-
sqlCreateTable += QString( ", %1 TEXT" ).arg( quotedIdentifier( tagKeys[i] ) );
338+
sqlCreateTable += QStringLiteral( ", %1 TEXT" ).arg( quotedIdentifier( tagKeys[i] ) );
339339
sqlCreateTable += ')';
340340

341341
char *errMsg = nullptr;
@@ -347,7 +347,7 @@ bool QgsOSMDatabase::createSpatialTable( const QString& tableName, const QString
347347
return false;
348348
}
349349

350-
QString sqlAddGeomColumn = QString( "SELECT AddGeometryColumn(%1, 'geometry', 4326, %2, 'XY')" )
350+
QString sqlAddGeomColumn = QStringLiteral( "SELECT AddGeometryColumn(%1, 'geometry', 4326, %2, 'XY')" )
351351
.arg( quotedValue( tableName ),
352352
quotedValue( geometryType ) );
353353
ret = sqlite3_exec( mDatabase, sqlAddGeomColumn.toUtf8().constData(), nullptr, nullptr, &errMsg );
@@ -364,7 +364,7 @@ bool QgsOSMDatabase::createSpatialTable( const QString& tableName, const QString
364364

365365
bool QgsOSMDatabase::createSpatialIndex( const QString& tableName )
366366
{
367-
QString sqlSpatialIndex = QString( "SELECT CreateSpatialIndex(%1, 'geometry')" ).arg( quotedValue( tableName ) );
367+
QString sqlSpatialIndex = QStringLiteral( "SELECT CreateSpatialIndex(%1, 'geometry')" ).arg( quotedValue( tableName ) );
368368
char *errMsg = nullptr;
369369
int ret = sqlite3_exec( mDatabase, sqlSpatialIndex.toUtf8().constData(), nullptr, nullptr, &errMsg );
370370
if ( ret != SQLITE_OK )
@@ -380,14 +380,14 @@ bool QgsOSMDatabase::createSpatialIndex( const QString& tableName )
380380

381381
void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys )
382382
{
383-
QString sqlInsertPoint = QString( "INSERT INTO %1 VALUES (?" ).arg( quotedIdentifier( tableName ) );
383+
QString sqlInsertPoint = QStringLiteral( "INSERT INTO %1 VALUES (?" ).arg( quotedIdentifier( tableName ) );
384384
for ( int i = 0; i < tagKeys.count(); ++i )
385-
sqlInsertPoint += QString( ",?" );
386-
sqlInsertPoint += ", GeomFromWKB(?, 4326))";
385+
sqlInsertPoint += QStringLiteral( ",?" );
386+
sqlInsertPoint += QLatin1String( ", GeomFromWKB(?, 4326))" );
387387
sqlite3_stmt* stmtInsert;
388388
if ( sqlite3_prepare_v2( mDatabase, sqlInsertPoint.toUtf8().constData(), -1, &stmtInsert, nullptr ) != SQLITE_OK )
389389
{
390-
mError = "Prepare SELECT FROM nodes failed.";
390+
mError = QStringLiteral( "Prepare SELECT FROM nodes failed." );
391391
return;
392392
}
393393

@@ -428,7 +428,7 @@ void QgsOSMDatabase::exportSpatiaLiteNodes( const QString& tableName, const QStr
428428
int insertRes = sqlite3_step( stmtInsert );
429429
if ( insertRes != SQLITE_DONE )
430430
{
431-
mError = QString( "Error inserting node %1 [%2]" ).arg( n.id() ).arg( insertRes );
431+
mError = QStringLiteral( "Error inserting node %1 [%2]" ).arg( n.id() ).arg( insertRes );
432432
break;
433433
}
434434

@@ -446,14 +446,14 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
446446
{
447447
Q_UNUSED( tagKeys );
448448

449-
QString sqlInsertLine = QString( "INSERT INTO %1 VALUES (?" ).arg( quotedIdentifier( tableName ) );
449+
QString sqlInsertLine = QStringLiteral( "INSERT INTO %1 VALUES (?" ).arg( quotedIdentifier( tableName ) );
450450
for ( int i = 0; i < tagKeys.count(); ++i )
451-
sqlInsertLine += QString( ",?" );
452-
sqlInsertLine += ", GeomFromWKB(?, 4326))";
451+
sqlInsertLine += QStringLiteral( ",?" );
452+
sqlInsertLine += QLatin1String( ", GeomFromWKB(?, 4326))" );
453453
sqlite3_stmt* stmtInsert;
454454
if ( sqlite3_prepare_v2( mDatabase, sqlInsertLine.toUtf8().constData(), -1, &stmtInsert, nullptr ) != SQLITE_OK )
455455
{
456-
mError = "Prepare SELECT FROM ways failed.";
456+
mError = QStringLiteral( "Prepare SELECT FROM ways failed." );
457457
return;
458458
}
459459

@@ -470,11 +470,11 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
470470

471471
bool isArea = ( polyline.first() == polyline.last() ); // closed way?
472472
// filter out closed way that are not areas through tags
473-
if ( isArea && ( t.contains( "highway" ) || t.contains( "barrier" ) ) )
473+
if ( isArea && ( t.contains( QStringLiteral( "highway" ) ) || t.contains( QStringLiteral( "barrier" ) ) ) )
474474
{
475475
// make sure tags that indicate areas are taken into consideration when deciding on a closed way is or isn't an area
476476
// and allow for a closed way to be exported both as a polygon and a line in case both area and non-area tags are present
477-
if (( t.value( "area" ) != "yes" && !t.contains( "amenity" ) && !t.contains( "landuse" ) && !t.contains( "building" ) && !t.contains( "natural" ) && !t.contains( "leisure" ) && !t.contains( "aeroway" ) ) || !closed )
477+
if (( t.value( QStringLiteral( "area" ) ) != QLatin1String( "yes" ) && !t.contains( QStringLiteral( "amenity" ) ) && !t.contains( QStringLiteral( "landuse" ) ) && !t.contains( QStringLiteral( "building" ) ) && !t.contains( QStringLiteral( "natural" ) ) && !t.contains( QStringLiteral( "leisure" ) ) && !t.contains( QStringLiteral( "aeroway" ) ) ) || !closed )
478478
isArea = false;
479479
}
480480

@@ -511,7 +511,7 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
511511
int insertRes = sqlite3_step( stmtInsert );
512512
if ( insertRes != SQLITE_DONE )
513513
{
514-
mError = QString( "Error inserting way %1 [%2]" ).arg( w.id() ).arg( insertRes );
514+
mError = QStringLiteral( "Error inserting way %1 [%2]" ).arg( w.id() ).arg( insertRes );
515515
break;
516516
}
517517

@@ -526,17 +526,17 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
526526

527527
QString QgsOSMDatabase::quotedIdentifier( QString id )
528528
{
529-
id.replace( '\"', "\"\"" );
530-
return QString( "\"%1\"" ).arg( id );
529+
id.replace( '\"', QLatin1String( "\"\"" ) );
530+
return QStringLiteral( "\"%1\"" ).arg( id );
531531
}
532532

533533
QString QgsOSMDatabase::quotedValue( QString value )
534534
{
535535
if ( value.isNull() )
536-
return "NULL";
536+
return QStringLiteral( "NULL" );
537537

538-
value.replace( '\'', "''" );
539-
return QString( "'%1'" ).arg( value );
538+
value.replace( '\'', QLatin1String( "''" ) );
539+
return QStringLiteral( "'%1'" ).arg( value );
540540
}
541541

542542
///////////////////////////////////

src/analysis/openstreetmap/qgsosmdownload.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
QString QgsOSMDownload::defaultServiceUrl()
2626
{
27-
return "http://overpass-api.de/api/interpreter";
27+
return QStringLiteral( "http://overpass-api.de/api/interpreter" );
2828
}
2929

3030

3131
QString QgsOSMDownload::queryFromRect( const QgsRectangle& rect )
3232
{
33-
return QString( "(node(%1,%2,%3,%4);<;);out;" ).arg( rect.yMinimum() ).arg( rect.xMinimum() )
33+
return QStringLiteral( "(node(%1,%2,%3,%4);<;);out;" ).arg( rect.yMinimum() ).arg( rect.xMinimum() )
3434
.arg( rect.yMaximum() ).arg( rect.xMaximum() );
3535
}
3636

@@ -77,7 +77,7 @@ bool QgsOSMDownload::start()
7777
QgsNetworkAccessManager* nwam = QgsNetworkAccessManager::instance();
7878

7979
QUrl url( mServiceUrl );
80-
url.addQueryItem( "data", mQuery );
80+
url.addQueryItem( QStringLiteral( "data" ), mQuery );
8181

8282
QNetworkRequest request( url );
8383
request.setRawHeader( "User-Agent", "QGIS" );

0 commit comments

Comments
 (0)