Skip to content

Commit

Permalink
Enable -DQT_USE_QSTRINGBUILDER and fix related build errors
Browse files Browse the repository at this point in the history
Background:
https://www.qt.io/blog/2011/06/13/string-concatenation-with-qstringbuilder

When enabling -DQT_USE_QSTRINGBUILDER, QString() concatenation with operator +
are done in a more efficient way, especially with repeated + operators.

Qt and creator themselves are built with that enabled.
  • Loading branch information
rouault authored and nyalldawson committed Oct 11, 2020
1 parent e29f17c commit 5e4707f
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 131 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -624,6 +624,9 @@ ADD_DEFINITIONS(-DQT_DEPRECATED_WARNINGS)
# Unfortunately Qwt uses deprecated QString::null in headers, preventing this being raised above 5.8
ADD_DEFINITIONS(-DQT_DISABLE_DEPRECATED_BEFORE=0x050800)

# For fast string concatenation
ADD_DEFINITIONS(-DQT_USE_QSTRINGBUILDER)

IF (WITH_GEOREFERENCER)
FIND_PACKAGE(GSL REQUIRED)
SET(HAVE_GEOREFERENCER TRUE)
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmlayouttoimage.cpp
Expand Up @@ -92,7 +92,7 @@ void QgsLayoutToImageAlgorithm::initAlgorithm( const QVariantMap & )
continue;

QString longName = format.toUpper() + QObject::tr( " format" );
QString glob = "*." + format;
QString glob = QStringLiteral( "*." ) + format;

if ( format == "png" && !imageFilters.empty() )
imageFilters.insert( 0, QStringLiteral( "%1 (%2 %3)" ).arg( longName, glob.toLower(), glob.toUpper() ) );
Expand Down
Expand Up @@ -72,7 +72,7 @@ QVariantMap QgsStringConcatenationAlgorithm::processAlgorithm( const QVariantMap
QString input_2 = parameterAsString( parameters, QStringLiteral( "INPUT_2" ), context );

QVariantMap outputs;
outputs.insert( QStringLiteral( "CONCATENATION" ), input_1 + input_2 );
outputs.insert( QStringLiteral( "CONCATENATION" ), QString( input_1 + input_2 ) );
return outputs;
}

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsprojectstylealgorithms.cpp
Expand Up @@ -34,7 +34,7 @@ bool QgsSaveToStyleVisitor::visit( const QgsStyleEntityVisitorInterface::StyleLe
{
if ( mObjects.empty() || mObjects.contains( entity.entity->type() ) )
{
const QString name = ( mParentNames.join( ' ' ) + ' ' + entity.description ).trimmed();
const QString name = QString( mParentNames.join( ' ' ) + ' ' + entity.description ).trimmed();
QString candidate = name;
int i = 1;
bool exists = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/options/qgsoptions.cpp
Expand Up @@ -793,7 +793,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
// templates
cbxProjectDefaultNew->setChecked( mSettings->value( QStringLiteral( "/qgis/newProjectDefault" ), QVariant( false ) ).toBool() );
QString templateDirName = mSettings->value( QStringLiteral( "/qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();
// make dir if it doesn't exist - should just be called once
QDir templateDir;
if ( ! templateDir.exists( templateDirName ) )
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -1117,7 +1117,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mSaveRollbackInProgress = false;

QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();
if ( !QFileInfo::exists( templateDirName ) )
{
// create default template directory
Expand Down Expand Up @@ -5049,7 +5049,7 @@ void QgisApp::saveRecentProjectPath( bool savePreviewImage, const QIcon &iconOve
QgsRecentProjectItemsModel::RecentProjectData projectData;
projectData.path = QgsProject::instance()->absoluteFilePath();
QString templateDirName = QgsSettings().value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();

// We don't want the template path to appear in the recent projects list. Never.
if ( projectData.path.startsWith( templateDirName ) )
Expand Down Expand Up @@ -5160,7 +5160,7 @@ void QgisApp::updateProjectFromTemplates()
// get list of project files in template dir
QgsSettings settings;
QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();
QDir templateDir( templateDirName );
QStringList filters( QStringLiteral( "*.qgs" ) );
filters << QStringLiteral( "*.qgz" );
Expand Down Expand Up @@ -6672,7 +6672,7 @@ void QgisApp::fileNewFromTemplateAction( QAction *qAction )
{
QgsSettings settings;
QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();
fileNewFromTemplate( templateDirName + QDir::separator() + qAction->text() );
}
}
Expand Down Expand Up @@ -7243,7 +7243,7 @@ void QgisApp::fileSaveAs()
// Retrieve last used project dir from persistent settings
QgsSettings settings;
defaultPath = settings.value( QStringLiteral( "UI/lastProjectDir" ), QDir::homePath() ).toString();
defaultPath += + '/' + QgsProject::instance()->title();
defaultPath += QString( '/' + QgsProject::instance()->title() );
}

const QString qgsExt = tr( "QGIS files" ) + " (*.qgs *.QGS)";
Expand Down Expand Up @@ -16484,7 +16484,7 @@ void QgisApp::populateProjectStorageMenu( QMenu *menu, const bool saving )
{
QgsSettings settings;
QString templateDirName = settings.value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
QString( QgsApplication::qgisSettingsDirPath() + "project_templates" ) ).toString();

const QString originalFilename = QgsProject::instance()->fileName();
QString templateName = QFileInfo( originalFilename ).baseName();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsabout.cpp
Expand Up @@ -233,7 +233,7 @@ void QgsAbout::setWhatsNew()
if ( !QFile::exists( QgsApplication::pkgDataPath() + "/doc/NEWS.html" ) )
return;

txtWhatsNew->setSource( "file:///" + QgsApplication::pkgDataPath() + "/doc/NEWS.html" );
txtWhatsNew->setSource( QString( "file:///" + QgsApplication::pkgDataPath() + "/doc/NEWS.html" ) );
}

void QgsAbout::setPluginInfo()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -574,7 +574,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat

item = new QTableWidgetItem( QString::number( i ) );
if ( fields.at( i ).name() == vlayer->displayField() )
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) + " *" );
item->setData( Qt::DisplayRole, QString( vlayer->attributeDisplayName( i ) + " *" ) );
else
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
item->setData( Qt::UserRole, fields.at( i ).name() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgstemplateprojectsmodel.cpp
Expand Up @@ -34,7 +34,7 @@ QgsTemplateProjectsModel::QgsTemplateProjectsModel( QObject *parent )
{
const QStringList paths = QStandardPaths::standardLocations( QStandardPaths::AppDataLocation );
QString templateDirName = QgsSettings().value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + QStringLiteral( "project_templates" ) ).toString();
QString( QgsApplication::qgisSettingsDirPath() + QStringLiteral( "project_templates" ) ) ).toString();

for ( const QString &templatePath : paths )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemhtml.cpp
Expand Up @@ -198,7 +198,7 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
{
QByteArray ba;
ba.append( mUserStylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
QUrl cssFileURL = QUrl( QString( "data:text/css;charset=utf-8;base64," + ba.toBase64() ) );
settings->setUserStyleSheetUrl( cssFileURL );
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemlabel.cpp
Expand Up @@ -611,7 +611,7 @@ QUrl QgsLayoutItemLabel::createStylesheetUrl() const

QByteArray ba;
ba.append( stylesheet.toUtf8() );
QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
QUrl cssFileURL = QUrl( QString( "data:text/css;charset=utf-8;base64," + ba.toBase64() ) );

return cssFileURL;
}
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -908,14 +908,14 @@ QVariant QgsProcessingUtils::generateIteratingDestination( const QVariant &input
}
else if ( res.startsWith( QLatin1String( "memory:" ) ) )
{
return res + '_' + id.toString();
return QString( res + '_' + id.toString() );
}
else
{
// assume a filename type output for now
// TODO - uris?
int lastIndex = res.lastIndexOf( '.' );
return res.left( lastIndex ) + '_' + id.toString() + res.mid( lastIndex );
return QString( res.left( lastIndex ) + '_' + id.toString() + res.mid( lastIndex ) );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsnetworkaccessmanager.h
Expand Up @@ -38,8 +38,8 @@ class QgsFeedback;
#include "qgsconfig.h"
constexpr int sFilePrefixLength = CMAKE_SOURCE_DIR[sizeof( CMAKE_SOURCE_DIR ) - 1] == '/' ? sizeof( CMAKE_SOURCE_DIR ) + 1 : sizeof( CMAKE_SOURCE_DIR );

#define QgsSetRequestInitiatorClass(request, _class) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorClass ), _class ); request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + ")" );
#define QgsSetRequestInitiatorId(request, str) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + "): " + str );
#define QgsSetRequestInitiatorClass(request, _class) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorClass ), _class ); request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString(QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + ")") );
#define QgsSetRequestInitiatorId(request, str) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString(QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + "): " + str) );
#endif

/**
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology/qgscptcityarchive.cpp
Expand Up @@ -138,7 +138,7 @@ QString QgsCptCityArchive::defaultBaseDir()

// use CptCity/baseDir setting if set, default is user dir
baseDir = settings.value( QStringLiteral( "CptCity/baseDir" ),
QgsApplication::pkgDataPath() + "/resources" ).toString();
QString( QgsApplication::pkgDataPath() + "/resources" ) ).toString();
// sub-dir defaults to cpt-city
archiveName = settings.value( QStringLiteral( "CptCity/archiveName" ), DEFAULT_CPTCITY_ARCHIVE ).toString();

Expand Down Expand Up @@ -447,7 +447,7 @@ void QgsCptCityArchive::initDefaultArchive()
QgsSettings settings;
// use CptCity/baseDir setting if set, default is user dir
QString baseDir = settings.value( QStringLiteral( "CptCity/baseDir" ),
QgsApplication::pkgDataPath() + "/resources" ).toString();
QString( QgsApplication::pkgDataPath() + "/resources" ) ).toString();
// sub-dir defaults to
QString defArchiveName = settings.value( QStringLiteral( "CptCity/archiveName" ), DEFAULT_CPTCITY_ARCHIVE ).toString();

Expand All @@ -463,7 +463,7 @@ void QgsCptCityArchive::initArchives( bool loadAll )

// use CptCity/baseDir setting if set, default is user dir
baseDir = settings.value( QStringLiteral( "CptCity/baseDir" ),
QgsApplication::pkgDataPath() + "/resources" ).toString();
QString( QgsApplication::pkgDataPath() + "/resources" ) ).toString();
// sub-dir defaults to
defArchiveName = settings.value( QStringLiteral( "CptCity/archiveName" ), DEFAULT_CPTCITY_ARCHIVE ).toString();

Expand Down Expand Up @@ -1312,7 +1312,7 @@ QgsCptCityBrowserModel::QgsCptCityBrowserModel( QObject *parent,
, mViewType( viewType )
{
Q_ASSERT( mArchive );
QgsDebugMsg( "archiveName = " + archive->archiveName() + " viewType=" + static_cast< int >( viewType ) );
QgsDebugMsg( QLatin1String( "archiveName = " ) + archive->archiveName() + " viewType=" + QString::number( static_cast< int >( viewType ) ) );
// keep iconsize for now, but not effectively used
mIconSize = QSize( 100, 15 );
addRootItems();
Expand Down Expand Up @@ -1381,7 +1381,7 @@ QVariant QgsCptCityBrowserModel::data( const QModelIndex &index, int role ) cons
{
if ( item->type() == QgsCptCityDataItem::ColorRamp &&
mViewType == List )
return item->path() + '\n' + item->info();
return QString( item->path() + '\n' + item->info() );
return item->toolTip();
}
else if ( role == Qt::DecorationRole && index.column() == 1 &&
Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -2303,7 +2303,7 @@ QString QgsMapBoxGlStyleConverter::parseExpression( const QVariantList &expressi
{
// ! inverts next expression's meaning
QVariantList contraJsonExpr = expression.value( 1 ).toList();
contraJsonExpr[0] = op + contraJsonExpr[0].toString();
contraJsonExpr[0] = QString( op + contraJsonExpr[0].toString() );
// ['!', ['has', 'level']] -> ['!has', 'level']
return parseKey( contraJsonExpr );
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/locator/qgslocatorwidget.cpp
Expand Up @@ -439,7 +439,7 @@ void QgsLocatorFilterFilter::fetchResults( const QString &string, const QgsLocat
QgsLocatorResult result;
result.displayString = filter->activePrefix();
result.description = filter->displayName();
result.userData = filter->activePrefix() + ' ';
result.userData = QString( filter->activePrefix() + ' ' );
result.icon = QgsApplication::getThemeIcon( QStringLiteral( "/search.svg" ) );
emit resultFetched( result );
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
Expand Up @@ -165,7 +165,7 @@ QVariant QgsGraduatedSymbolRendererModel::data( const QModelIndex &index, int ro
{
int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
if ( decimalPlaces < 0 ) decimalPlaces = 0;
return QLocale().toString( range.lowerValue(), 'f', decimalPlaces ) + " - " + QLocale().toString( range.upperValue(), 'f', decimalPlaces );
return QString( QLocale().toString( range.lowerValue(), 'f', decimalPlaces ) + " - " + QLocale().toString( range.upperValue(), 'f', decimalPlaces ) );
}
case 2:
return range.label();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmoduleinput.cpp
Expand Up @@ -332,7 +332,7 @@ QVariant QgsGrassModuleInputModel::data( const QModelIndex &index, int role ) co
QString mapset = QStandardItemModel::data( index, QgsGrassModuleInputModel::MapsetRole ).toString();
if ( mapset != QgsGrass::getDefaultMapset() )
{
data = data.toString() + "@" + mapset;
data = QString( data.toString() + "@" + mapset );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -4935,9 +4935,9 @@ QList<QgsRelation> QgsPostgresProvider::discoverRelations( const QgsVectorLayer
" FROM pg_constraint c "
" WHERE contype = 'f' "
" AND c.conrelid::regclass = " +
QgsPostgresConn::quotedValue( QgsPostgresConn::quotedIdentifier( mSchemaName ) +
QgsPostgresConn::quotedValue( QString( QgsPostgresConn::quotedIdentifier( mSchemaName ) +
'.' +
QgsPostgresConn::quotedIdentifier( mTableName ) ) +
QgsPostgresConn::quotedIdentifier( mTableName ) ) ) +
"::regclass ) "
"SELECT fk.conname as constraint_name, "
" a.attname as column_name, "
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -185,7 +185,7 @@ void QgsWFSProviderSQLFunctionValidator::visit( const QgsSQLStatement::NodeFunct
for ( const QgsWfsCapabilities::Function &f : constMSpatialPredicatesList )
{
if ( n.name().compare( f.name, Qt::CaseInsensitive ) == 0 ||
( "ST_" + n.name() ).compare( f.name, Qt::CaseInsensitive ) == 0 )
QString( "ST_" + n.name() ).compare( f.name, Qt::CaseInsensitive ) == 0 )
{
foundMatch = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsserverogcapihandler.cpp
Expand Up @@ -287,7 +287,7 @@ void QgsServerOgcApiHandler::htmlDump( const json &data, const QgsServerApiConte
{
// Get the template directory and the file name
QFileInfo pathInfo { path };
Environment env { ( pathInfo.dir().path() + QDir::separator() ).toStdString() };
Environment env { QString( pathInfo.dir().path() + QDir::separator() ).toStdString() };

// For template debugging:
env.add_callback( "json_dump", 0, [ = ]( Arguments & )
Expand Down

0 comments on commit 5e4707f

Please sign in to comment.