Skip to content
Permalink
Browse files

Enable -DQT_USE_QSTRINGBUILDER and fix related build errors

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 5e4707fcbf779ce660a47cdc1f362753d1565d1f
@@ -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)
@@ -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() ) );
@@ -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;
}

@@ -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;
@@ -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 ) )
@@ -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
@@ -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 ) )
@@ -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" );
@@ -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() );
}
}
@@ -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)";
{
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();
@@ -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()
@@ -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() );
@@ -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 )
{
@@ -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
@@ -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;
}
@@ -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 ) );
}
}
}
@@ -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

/**
@@ -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();

@@ -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();

@@ -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();

@@ -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();
@@ -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 &&
@@ -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 );
}
@@ -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 );
}
@@ -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();
@@ -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 );
}
}
}
@@ -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, "
@@ -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;
}
@@ -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 & )

0 comments on commit 5e4707f

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