Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flip some QStrings to QLatin1String where they may be faster
  • Loading branch information
nyalldawson committed Oct 12, 2015
1 parent 52f0b5b commit 160f172
Show file tree
Hide file tree
Showing 39 changed files with 114 additions and 114 deletions.
2 changes: 1 addition & 1 deletion src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -414,7 +414,7 @@ void QgsGPSInformationWidget::connectGps()
}
else if ( mRadInternal->isChecked() )
{
port = QString( "internalGPS" );
port = QLatin1String( "internalGPS" );
}

mGPSPlainTextEdit->appendPlainText( tr( "Connecting..." ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -1003,7 +1003,7 @@ int main( int argc, char *argv[] )

//set up splash screen
QString mySplashPath( QgsCustomization::instance()->splashPath() );
QPixmap myPixmap( mySplashPath + QString( "splash.png" ) );
QPixmap myPixmap( mySplashPath + QLatin1String( "splash.png" ) );
QSplashScreen *mypSplash = new QSplashScreen( myPixmap );
if ( mySettings.value( "/qgis/hideSplash" ).toBool() || myHideSplash )
{
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -3948,7 +3948,7 @@ bool QgisApp::fileNewFromTemplate( const QString& fileName )

void QgisApp::fileNewFromDefaultTemplate()
{
QString projectTemplate = QgsApplication::qgisSettingsDirPath() + QString( "project_default.qgs" );
QString projectTemplate = QgsApplication::qgisSettingsDirPath() + QLatin1String( "project_default.qgs" );
QString msgTxt;
if ( !projectTemplate.isEmpty() && QFile::exists( projectTemplate ) )
{
Expand Down Expand Up @@ -4043,7 +4043,7 @@ void QgisApp::fileOpenAfterLaunch()
return;
}

if ( !projPath.endsWith( QString( "qgs" ), Qt::CaseInsensitive ) )
if ( !projPath.endsWith( QLatin1String( "qgs" ), Qt::CaseInsensitive ) )
{
messageBar()->pushMessage( autoOpenMsgTitle,
tr( "Not valid project file: %1" ).arg( projPath ),
Expand All @@ -4063,7 +4063,7 @@ void QgisApp::fileOpenAfterLaunch()
QgsMessageBar::WARNING );
}

if ( projPath.endsWith( QString( "project_default.qgs" ) ) )
if ( projPath.endsWith( QLatin1String( "project_default.qgs" ) ) )
{
messageBar()->pushMessage( autoOpenMsgTitle,
tr( "Default template has been reopened: %1" ).arg( projPath ),
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgscustomization.cpp
Expand Up @@ -55,7 +55,7 @@ QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent, QSettings* sett
myHeaders << tr( "Object name" ) << tr( "Label" ) << tr( "Description" );
treeWidget->setHeaderLabels( myHeaders );

mLastDirSettingsName = QString( "/UI/lastCustomizationDir" );
mLastDirSettingsName = QLatin1String( "/UI/lastCustomizationDir" );
//treeWidget->hideColumn(0)
connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), this, SLOT( ok() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
Expand Down
22 changes: 11 additions & 11 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -952,8 +952,8 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )

mFontCaseDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::FontCase ),
QgsDataDefinedButton::String,
trString + QString( "[<b>NoChange</b>|<b>Upper</b>|<br>"
"<b>Lower</b>|<b>Capitalize</b>]" ) );
trString + QLatin1String( "[<b>NoChange</b>|<b>Upper</b>|<br>"
"<b>Lower</b>|<b>Capitalize</b>]" ) );

mFontLetterSpacingDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::FontLetterSpacing ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
Expand Down Expand Up @@ -1016,8 +1016,8 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
mShapeDrawDDBtn->registerCheckedWidget( mShapeDrawChkBx );
mShapeTypeDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShapeKind ),
QgsDataDefinedButton::String,
trString + QString( "[<b>Rectangle</b>|<b>Square</b>|<br>"
"<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ) );
trString + QLatin1String( "[<b>Rectangle</b>|<b>Square</b>|<br>"
"<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ) );
mShapeSVGPathDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShapeSVGFile ),
QgsDataDefinedButton::String, QgsDataDefinedButton::svgPathDesc() );
mShapeSizeTypeDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShapeSizeType ),
Expand Down Expand Up @@ -1063,8 +1063,8 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
mShadowDrawDDBtn->registerCheckedWidget( mShadowDrawChkBx );
mShadowUnderDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShadowUnder ),
QgsDataDefinedButton::String,
trString + QString( "[<b>Lowest</b>|<b>Text</b>|<br>"
"<b>Buffer</b>|<b>Background</b>]" ) );
trString + QLatin1String( "[<b>Lowest</b>|<b>Text</b>|<br>"
"<b>Buffer</b>|<b>Background</b>]" ) );
mShadowOffsetAngleDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShadowOffsetAngle ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::double180RotDesc() );
mShadowOffsetDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ShadowOffsetDist ),
Expand All @@ -1090,9 +1090,9 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
trString + "[<b>Visible</b>|<b>Whole</b>]" );
mPointQuadOffsetDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::OffsetQuad ),
QgsDataDefinedButton::AnyType,
tr( "int<br>" ) + QString( "[<b>0</b>=Above Left|<b>1</b>=Above|<b>2</b>=Above Right|<br>"
"<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
"<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ) );
tr( "int<br>" ) + QLatin1String( "[<b>0</b>=Above Left|<b>1</b>=Above|<b>2</b>=Above Right|<br>"
"<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
"<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ) );
mPointOffsetDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::OffsetXY ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleXYDesc() );
mPointOffsetUnitsDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::OffsetUnits ),
Expand Down Expand Up @@ -1130,8 +1130,8 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
mCoordAlignmentHDDBtn->setUsageInfo( ddPlaceInfo );
mCoordAlignmentVDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::Vali ),
QgsDataDefinedButton::String,
trString + QString( "[<b>Bottom</b>|<b>Base</b>|<br>"
"<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ) );
trString + QLatin1String( "[<b>Bottom</b>|<b>Base</b>|<br>"
"<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ) );
mCoordAlignmentVDDBtn->setUsageInfo( ddPlaceInfo );
mCoordRotationDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::Rotation ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::double180RotDesc() );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsoptions.cpp
Expand Up @@ -883,7 +883,7 @@ void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
{
if ( checked )
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "project_default.qgs" );
QString fileName = QgsApplication::qgisSettingsDirPath() + QLatin1String( "project_default.qgs" );
if ( ! QFile::exists( fileName ) )
{
QMessageBox::information( 0, tr( "Save default project" ), tr( "You must set a default project" ) );
Expand All @@ -894,7 +894,7 @@ void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )

void QgsOptions::on_pbnProjectDefaultSetCurrent_clicked()
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "project_default.qgs" );
QString fileName = QgsApplication::qgisSettingsDirPath() + QLatin1String( "project_default.qgs" );
if ( QgsProject::instance()->write( QFileInfo( fileName ) ) )
{
QMessageBox::information( 0, tr( "Save default project" ), tr( "Current project saved as default" ) );
Expand All @@ -907,7 +907,7 @@ void QgsOptions::on_pbnProjectDefaultSetCurrent_clicked()

void QgsOptions::on_pbnProjectDefaultReset_clicked()
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "project_default.qgs" );
QString fileName = QgsApplication::qgisSettingsDirPath() + QLatin1String( "project_default.qgs" );
if ( QFile::exists( fileName ) )
{
QFile::remove( fileName );
Expand All @@ -927,7 +927,7 @@ void QgsOptions::on_pbnTemplateFolderBrowse_pressed()

void QgsOptions::on_pbnTemplateFolderReset_pressed()
{
leTemplateFolder->setText( QgsApplication::qgisSettingsDirPath() + QString( "project_templates" ) );
leTemplateFolder->setText( QgsApplication::qgisSettingsDirPath() + QLatin1String( "project_templates" ) );
}

void QgsOptions::iconSizeChanged( const QString &iconSize )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -1508,7 +1508,7 @@ void QgsProjectProperties::populateEllipsoidList()
myItem.semiMinor = 0.0;
mEllipsoidList.append( myItem );

myItem.acronym = QString( "PARAMETER:6370997:6370997" );
myItem.acronym = QLatin1String( "PARAMETER:6370997:6370997" );
myItem.description = tr( "Parameters:" );
myItem.semiMajor = 6370997.0;
myItem.semiMinor = 6370997.0;
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -193,13 +193,13 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
if ( myRasterPyramidIterator->exists )
{
lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
QString::number( myRasterPyramidIterator->xDim ) + QString( " x " ) +
QString::number( myRasterPyramidIterator->xDim ) + QLatin1String( " x " ) +
QString::number( myRasterPyramidIterator->yDim ) ) );
}
else
{
lbxPyramidResolutions->addItem( new QListWidgetItem( myNoPyramidPixmap,
QString::number( myRasterPyramidIterator->xDim ) + QString( " x " ) +
QString::number( myRasterPyramidIterator->xDim ) + QLatin1String( " x " ) +
QString::number( myRasterPyramidIterator->yDim ) ) );
}
}
Expand Down Expand Up @@ -1038,13 +1038,13 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
if ( myRasterPyramidIterator->exists )
{
lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap,
QString::number( myRasterPyramidIterator->xDim ) + QString( " x " ) +
QString::number( myRasterPyramidIterator->xDim ) + QLatin1String( " x " ) +
QString::number( myRasterPyramidIterator->yDim ) ) );
}
else
{
lbxPyramidResolutions->addItem( new QListWidgetItem( myNoPyramidPixmap,
QString::number( myRasterPyramidIterator->xDim ) + QString( " x " ) +
QString::number( myRasterPyramidIterator->xDim ) + QLatin1String( " x " ) +
QString::number( myRasterPyramidIterator->yDim ) ) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/identcert/qgsauthidentcertmethod.cpp
Expand Up @@ -73,7 +73,7 @@ bool QgsAuthIdentCertMethod::updateNetworkRequest( QNetworkRequest &request, con
Q_UNUSED( dataprovider )

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QString( "https" ) )
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
{
QgsDebugMsg( QString( "Update request SSL config SKIPPED for authcfg %1: not HTTPS" ).arg( authcfg ) );
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/pkipaths/qgsauthpkipathsmethod.cpp
Expand Up @@ -73,7 +73,7 @@ bool QgsAuthPkiPathsMethod::updateNetworkRequest( QNetworkRequest &request, cons
Q_UNUSED( dataprovider )

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QString( "https" ) )
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
{
QgsDebugMsg( QString( "Update request SSL config SKIPPED for authcfg %1: not HTTPS" ).arg( authcfg ) );
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/pkipkcs12/qgsauthpkcs12method.cpp
Expand Up @@ -73,7 +73,7 @@ bool QgsAuthPkcs12Method::updateNetworkRequest( QNetworkRequest &request, const
Q_UNUSED( dataprovider )

// TODO: is this too restrictive, to intercept only HTTPS connections?
if ( request.url().scheme().toLower() != QString( "https" ) )
if ( request.url().scheme().toLower() != QLatin1String( "https" ) )
{
QgsDebugMsg( QString( "Update request SSL config SKIPPED for authcfg %1: not HTTPS" ).arg( authcfg ) );
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/browser/main.cpp
Expand Up @@ -41,7 +41,7 @@ int main( int argc, char ** argv )
|| theme == "classic"
|| theme == "nkids" )
{
theme = QString( "default" );
theme = QLatin1String( "default" );
}
a.setThemeName( theme );
a.initQgis();
Expand Down
6 changes: 3 additions & 3 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -129,7 +129,7 @@ bool QgsAuthManager::init( const QString& pluginPath )
{
QString pn = p->name();
int pr = 0;
if ( pn != QString( "qca-ossl" ) )
if ( pn != QLatin1String( "qca-ossl" ) )
{
pr = QCA::providerPriority( pn ) + 1;
}
Expand Down Expand Up @@ -632,7 +632,7 @@ bool QgsAuthManager::resetMasterPassword( const QString& newpass, const QString
// backup database of failed attempt, for inspection
authDbConnection().close();
QString errdbbackup( dbbackup );
errdbbackup.replace( QString( ".db" ), QString( "_ERROR.db" ) );
errdbbackup.replace( QLatin1String( ".db" ), QLatin1String( "_ERROR.db" ) );
QFile::rename( authenticationDbPath(), errdbbackup );
QgsDebugMsg( QString( "Master password reset FAILED: backed up failed db at %1" ).arg( errdbbackup ) );

Expand Down Expand Up @@ -1204,7 +1204,7 @@ bool QgsAuthManager::backupAuthenticationDatabase( QString *backuppath )
// duplicate current db file to 'qgis-auth_YYYY-MM-DD-HHMMSS.db' backup
QString datestamp( QDateTime::currentDateTime().toString( "yyyy-MM-dd-hhmmss" ) );
QString dbbackup( authenticationDbPath() );
dbbackup.replace( QString( ".db" ), QString( "_%1.db" ).arg( datestamp ) );
dbbackup.replace( QLatin1String( ".db" ), QString( "_%1.db" ).arg( datestamp ) );

if ( !QFile::copy( authenticationDbPath(), dbbackup ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -426,7 +426,7 @@ void QgsComposerPicture::loadPicture( const QString &path )
{
//trying to load an invalid file or bad expression, show cross picture
mMode = SVG;
QString badFile = QString( ":/images/composer/missing_image.svg" );
QString badFile( ":/images/composer/missing_image.svg" );
mSVG.load( badFile );
if ( mSVG.isValid() )
{
Expand Down

2 comments on commit 160f172

@jef-n
Copy link
Member

@jef-n jef-n commented on 160f172 Oct 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply "foo" instead of QLatin1String("foo") ?

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of reasons:

  • QLatin1String docs suggest that it's the safest + fastest approach
  • For Qt5 builds QLatin1String is faster than the char* overloads as the char* overloads use slower utf8 decoding but QLatin1String doesn't (see http://woboq.com/blog/qstringliteral.html)
  • it will make it much easier to identify strings which we can flip to QStringLiteral when we kick Qt4 to the kerb.

Please sign in to comment.