Skip to content
Permalink
Browse files

More efficient use of QStrings

- use .isEmpty() instead of == QLatin1String( "" ) to check for
empty strings
- use .clear() instead of = QLatin1String( "" ) to empty a string
- remove unnecessary QString initializations
  • Loading branch information
nyalldawson committed Sep 27, 2017
1 parent 036646f commit 8c3939e756a929c629f42ffc7af005862d62b96f
Showing with 282 additions and 305 deletions.
  1. +1 −1 src/app/composer/qgscomposermapgridwidget.cpp
  2. +1 −1 src/app/composer/qgscomposermapwidget.cpp
  3. +1 −1 src/app/composer/qgscomposerpicturewidget.cpp
  4. +5 −5 src/app/main.cpp
  5. +14 −15 src/app/pluginmanager/qgspluginmanager.cpp
  6. +2 −2 src/app/qgisapp.cpp
  7. +1 −1 src/app/qgsabout.cpp
  8. +11 −11 src/app/qgscustomprojectiondialog.cpp
  9. +4 −4 src/app/qgsdecorationgrid.cpp
  10. +1 −1 src/app/qgsmapsavedialog.cpp
  11. +1 −1 src/app/qgsnewspatialitelayerdialog.cpp
  12. +2 −2 src/app/qgsprojectproperties.cpp
  13. +1 −1 src/app/qgsrelationmanagerdialog.cpp
  14. +1 −1 src/app/qgsversioninfo.cpp
  15. +1 −1 src/app/qgswelcomepageitemsmodel.cpp
  16. +0 −3 src/auth/pkipaths/qgsauthpkipathsedit.cpp
  17. +0 −3 src/auth/pkipkcs12/qgsauthpkcs12edit.cpp
  18. +1 −1 src/core/annotations/qgshtmlannotation.cpp
  19. +2 −2 src/core/auth/qgsauthmanager.cpp
  20. +4 −4 src/core/providers/memory/qgsmemoryprovider.cpp
  21. +1 −1 src/core/qgscolorramp.cpp
  22. +9 −9 src/core/qgsdatasourceuri.cpp
  23. +1 −1 src/core/qgsmimedatautils.cpp
  24. +3 −3 src/core/qgsofflineediting.cpp
  25. +0 −1 src/core/qgspallabeling.cpp
  26. +1 −1 src/core/qgsproject.cpp
  27. +2 −2 src/core/qgsvectorlayer.cpp
  28. +1 −1 src/core/raster/qgsrasterlayer.cpp
  29. +10 −10 src/core/symbology/qgscptcityarchive.cpp
  30. +1 −1 src/core/symbology/qgsgraduatedsymbolrenderer.cpp
  31. +2 −3 src/core/symbology/qgssymbol.cpp
  32. +0 −2 src/gui/auth/qgsauthimportidentitydialog.cpp
  33. +2 −2 src/gui/auth/qgsauthsslconfigwidget.cpp
  34. +1 −1 src/gui/editorwidgets/qgsrangeconfigdlg.cpp
  35. +1 −1 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
  36. +2 −2 src/gui/ogr/qgsogrhelperfunctions.cpp
  37. +0 −2 src/gui/qgscollapsiblegroupbox.cpp
  38. +2 −2 src/gui/qgsdatumtransformdialog.cpp
  39. +4 −4 src/gui/qgsdetaileditemdelegate.cpp
  40. +3 −3 src/gui/qgsexpressionbuilderwidget.cpp
  41. +1 −1 src/gui/qgsfilewidget.cpp
  42. +1 −1 src/gui/qgsmanageconnectionsdialog.cpp
  43. +0 −2 src/gui/qgsmessageviewer.cpp
  44. +1 −1 src/gui/qgsnewgeopackagelayerdialog.cpp
  45. +2 −2 src/gui/qgsowssourceselect.cpp
  46. +6 −6 src/gui/qgsprojectionselectiontreewidget.cpp
  47. +7 −7 src/gui/qgsrasterformatsaveoptionswidget.cpp
  48. +1 −1 src/gui/qgsrasterlayersaveasdialog.cpp
  49. +1 −1 src/gui/qgsrasterpyramidsoptionswidget.cpp
  50. +4 −4 src/gui/raster/qgsrasterhistogramwidget.cpp
  51. +1 −1 src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
  52. +10 −10 src/gui/symbology/qgscptcitycolorrampdialog.cpp
  53. +1 −1 src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
  54. +4 −5 src/gui/symbology/qgsstyleexportimportdialog.cpp
  55. +1 −1 src/gui/symbology/qgssymbolslistwidget.cpp
  56. +1 −1 src/gui/symbology/qgsvectorfieldsymbollayerwidget.cpp
  57. +13 −13 src/plugins/evis/databaseconnection/evisdatabaseconnectiongui.cpp
  58. +2 −2 src/plugins/evis/databaseconnection/evisdatabaselayerfieldselectiongui.cpp
  59. +0 −8 src/plugins/evis/databaseconnection/evisquerydefinition.cpp
  60. +2 −2 src/plugins/evis/databaseconnection/evisquerydefinition.h
  61. +2 −2 src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp
  62. +1 −1 src/plugins/geometry_checker/ui/qgsgeometrycheckfixdialog.cpp
  63. +5 −5 src/plugins/georeferencer/qgsgeorefplugingui.cpp
  64. +1 −1 src/plugins/georeferencer/qgstransformsettingsdialog.cpp
  65. +2 −2 src/plugins/gps_importer/qgsgpsdevicedialog.cpp
  66. +8 −8 src/plugins/gps_importer/qgsgpsplugingui.cpp
  67. +1 −1 src/plugins/offline_editing/offline_editing_plugin.cpp
  68. +1 −1 src/providers/db2/qgsdb2expressioncompiler.cpp
  69. +1 −1 src/providers/db2/qgsdb2featureiterator.cpp
  70. +2 −2 src/providers/db2/qgsdb2geometrycolumns.cpp
  71. +4 −4 src/providers/db2/qgsdb2provider.cpp
  72. +3 −3 src/providers/db2/qgsdb2sourceselect.cpp
  73. +2 −2 src/providers/db2/qgsdb2tablemodel.cpp
  74. +4 −4 src/providers/delimitedtext/qgsdelimitedtextfile.cpp
  75. +1 −1 src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
  76. +2 −2 src/providers/gdal/qgsgdaldataitems.cpp
  77. +6 −5 src/providers/gdal/qgsgdalprovider.cpp
  78. +12 −12 src/providers/gpx/gpsdata.cpp
  79. +2 −2 src/providers/mssql/qgsmssqlgeomcolumntypethread.cpp
  80. +2 −2 src/providers/mssql/qgsmssqlnewconnection.cpp
  81. +2 −2 src/providers/mssql/qgsmssqlprovider.cpp
  82. +3 −3 src/providers/mssql/qgsmssqlsourceselect.cpp
  83. +2 −2 src/providers/mssql/qgsmssqltablemodel.cpp
  84. +2 −2 src/providers/ogr/qgsogrdataitems.cpp
  85. +2 −2 src/providers/ogr/qgsogrprovider.cpp
  86. +2 −2 src/providers/postgres/qgspgsourceselect.cpp
  87. +3 −3 src/providers/postgres/qgspostgresconn.cpp
  88. +16 −16 src/providers/postgres/qgspostgresprovider.cpp
  89. +1 −1 src/providers/spatialite/qgsspatialiteprovider.cpp
  90. +1 −1 src/providers/spatialite/qgsspatialitesourceselect.cpp
  91. +1 −1 src/providers/virtual/qgsvirtuallayerprovider.h
  92. +1 −1 src/providers/wcs/qgswcscapabilities.cpp
  93. +2 −2 src/providers/wcs/qgswcsprovider.cpp
  94. +1 −1 src/providers/wfs/qgswfscapabilities.cpp
  95. +1 −1 src/providers/wfs/qgswfsprovider.cpp
  96. +2 −2 src/providers/wms/qgswmsprovider.cpp
  97. +3 −3 src/providers/wms/qgswmssourceselect.cpp
  98. +8 −8 tests/bench/main.cpp
  99. +1 −1 tests/src/app/testqgisappclipboard.cpp
  100. +1 −1 tests/src/core/testqgscoordinatereferencesystem.cpp
  101. +5 −5 tests/src/core/testziplayer.cpp
  102. +1 −1 tests/src/gui/testqgsscalecombobox.cpp
@@ -438,7 +438,7 @@ bool QgsComposerMapGridWidget::hasPredefinedScales() const
QgsSettings settings;
QString scalesStr( settings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString() );
QStringList myScalesList = scalesStr.split( ',' );
return !myScalesList.isEmpty() && myScalesList[0] != QLatin1String( "" );
return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
}
return true;
}
@@ -1051,7 +1051,7 @@ bool QgsComposerMapWidget::hasPredefinedScales() const
QgsSettings settings;
QString scalesStr( settings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString() );
QStringList myScalesList = scalesStr.split( ',' );
return !myScalesList.isEmpty() && myScalesList[0] != QLatin1String( "" );
return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
}
return true;
}
@@ -564,7 +564,7 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString &path )
listItem->setIcon( icon );
}

listItem->setText( QLatin1String( "" ) );
listItem->setText( QString() );
//store the absolute icon file path as user data
listItem->setData( Qt::UserRole, fileIt->absoluteFilePath() );
++counter;
@@ -168,7 +168,7 @@ void usage( const QString &appName )
// AppleEvent handler as well as by the main routine argv processing

// This behavior will cause QGIS to autoload a project
static QString sProjectFileName = QLatin1String( "" );
static QString sProjectFileName;

// This is the 'leftover' arguments collection
static QStringList sFileList;
@@ -492,8 +492,8 @@ int main( int argc, char *argv[] )

// This behavior is used to load the app, snapshot the map,
// save the image to disk and then exit
QString mySnapshotFileName = QLatin1String( "" );
QString configLocalStorageLocation = QLatin1String( "" );
QString mySnapshotFileName;
QString configLocalStorageLocation;
QString profileName;
int mySnapshotWidth = 800;
int mySnapshotHeight = 600;
@@ -520,7 +520,7 @@ int main( int argc, char *argv[] )
// there are no command line arguments. This gives a usable map
// extent when qgis starts with no layers loaded. When layers are
// loaded, we let the layers define the initial extent.
QString myInitialExtent = QLatin1String( "" );
QString myInitialExtent;
if ( argc == 1 )
myInitialExtent = QStringLiteral( "-1,-1,1,1" );

@@ -1238,7 +1238,7 @@ int main( int argc, char *argv[] )
/////////////////////////////////`////////////////////////////////////
// Take a snapshot of the map view then exit if snapshot mode requested
/////////////////////////////////////////////////////////////////////
if ( mySnapshotFileName != QLatin1String( "" ) )
if ( !mySnapshotFileName.isEmpty() )
{
/*You must have at least one paintEvent() delivered for the window to be
rendered properly.
@@ -622,20 +622,19 @@ void QgsPluginManager::showPluginDetails( QStandardItem *item )
return;
}

QString html = QLatin1String( "" );
html += "<style>"
" body, table {"
" padding:0px;"
" margin:0px;"
" font-family:verdana;"
" font-size: 10pt;"
" }"
" div#votes {"
" width:360px;"
" margin-left:98px;"
" padding-top:3px;"
" }"
"</style>";
QString html = "<style>"
" body, table {"
" padding:0px;"
" margin:0px;"
" font-family:verdana;"
" font-size: 10pt;"
" }"
" div#votes {"
" width:360px;"
" margin-left:98px;"
" padding-top:3px;"
" }"
"</style>";

if ( !metadata->value( QStringLiteral( "plugin_id" ) ).isEmpty() )
{
@@ -1135,7 +1134,7 @@ void QgsPluginManager::setCurrentTab( int idx )
mModelProxy->setAcceptedStatuses( acceptedStatuses );

// load tab description HTML to the detail browser
QString tabInfoHTML = QLatin1String( "" );
QString tabInfoHTML;
QMap<QString, QString>::const_iterator it = mTabDescriptions.constFind( tabTitle );
if ( it != mTabDescriptions.constEnd() )
{
@@ -5792,7 +5792,7 @@ void QgisApp::saveMapAsPdf()
//overloaded version of the above function
void QgisApp::saveMapAsImage( const QString &imageFileNameQString, QPixmap *theQPixmap )
{
if ( imageFileNameQString == QLatin1String( "" ) )
if ( imageFileNameQString.isEmpty() )
{
//no fileName chosen
return;
@@ -9913,7 +9913,7 @@ void QgisApp::setExtent( const QgsRectangle &rect )
*/
bool QgisApp::saveDirty()
{
QString whyDirty = QLatin1String( "" );
QString whyDirty;
bool hasUnsavedEdits = false;
// extra check to see if there are any vector layers with unsaved provider edits
// to ensure user has opportunity to save any editing
@@ -186,7 +186,7 @@ void QgsAbout::init()
#endif
if ( translatorFile.open( QIODevice::ReadOnly ) )
{
QString translatorHTML = QLatin1String( "" );
QString translatorHTML;
QTextStream translatorStream( &translatorFile );
// Always use UTF-8
translatorStream.setCodec( "UTF-8" );
@@ -308,7 +308,7 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem myCRS, con
void QgsCustomProjectionDialog::on_pbnAdd_clicked()
{
QString name = tr( "new CRS" );
QString id = QLatin1String( "" );
QString id;
QgsCoordinateReferenceSystem parameters;

QTreeWidgetItem *newItem = new QTreeWidgetItem( leNameList, QStringList() );
@@ -331,7 +331,7 @@ void QgsCustomProjectionDialog::on_pbnRemove_clicked()
}
QTreeWidgetItem *item = leNameList->takeTopLevelItem( i );
delete item;
if ( customCRSids[i] != QLatin1String( "" ) )
if ( !customCRSids[i].isEmpty() )
{
deletedCRSs.push_back( customCRSids[i] );
}
@@ -361,8 +361,8 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte
else
{
//Can happen that current is null, for example if we just deleted the last element
leName->setText( QLatin1String( "" ) );
teParameters->setPlainText( QLatin1String( "" ) );
leName->clear();
teParameters->clear();
return;
}
}
@@ -415,7 +415,7 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
{
CRS.createFromProj4( customCRSparameters[i] );
//Test if we just added this CRS (if it has no existing ID)
if ( customCRSids[i] == QLatin1String( "" ) )
if ( !customCRSids[i].isEmpty() )
{
save_success &= saveCrs( CRS, customCRSnames[i], QLatin1String( "" ), true );
}
@@ -462,8 +462,8 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
{
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
tr( "This proj4 projection definition is not valid." ) );
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
projectedX->clear();
projectedY->clear();
pj_free( myProj );
pj_ctx_free( pContext );
return;
@@ -478,8 +478,8 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
{
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
tr( "Northing and Easthing must be in decimal form." ) );
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
projectedX->clear();
projectedY->clear();
pj_free( myProj );
pj_ctx_free( pContext );
return;
@@ -491,8 +491,8 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
{
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
tr( "Internal Error (source projection invalid?)" ) );
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
projectedX->clear();
projectedY->clear();
pj_free( wgs84Proj );
pj_ctx_free( pContext );
return;
@@ -110,8 +110,8 @@ void QgsDecorationGrid::projectRead()
mGridAnnotationPosition = InsideMapFrame; // don't allow outside frame, doesn't make sense
mGridAnnotationDirection = static_cast< GridAnnotationDirection >( QgsProject::instance()->readNumEntry( mNameConfig,
QStringLiteral( "/AnnotationDirection" ), 0 ) );
QString fontStr = QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/AnnotationFont" ), QLatin1String( "" ) );
if ( fontStr != QLatin1String( "" ) )
QString fontStr = QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/AnnotationFont" ), QString() );
if ( !fontStr.isEmpty() )
{
mGridAnnotationFont.fromString( fontStr );
}
@@ -134,7 +134,7 @@ void QgsDecorationGrid::projectRead()
if ( mLineSymbol )
setLineSymbol( nullptr );
xml = QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/LineSymbol" ) );
if ( xml != QLatin1String( "" ) )
if ( !xml.isEmpty() )
{
doc.setContent( xml );
elem = doc.documentElement();
@@ -146,7 +146,7 @@ void QgsDecorationGrid::projectRead()
if ( mMarkerSymbol )
setMarkerSymbol( nullptr );
xml = QgsProject::instance()->readEntry( mNameConfig, QStringLiteral( "/MarkerSymbol" ) );
if ( xml != QLatin1String( "" ) )
if ( !xml.isEmpty() )
{
doc.setContent( xml );
elem = doc.documentElement();
@@ -380,7 +380,7 @@ void QgsMapSaveDialog::onAccepted()
if ( mDialogType == Image )
{
QPair< QString, QString> fileNameAndFilter = QgsGuiUtils::getSaveAsImageName( QgisApp::instance(), tr( "Choose a file name to save the map image as" ) );
if ( fileNameAndFilter.first != QLatin1String( "" ) )
if ( !fileNameAndFilter.first.isEmpty() )
{
QgsMapSettings ms = QgsMapSettings();
applyMapSettings( ms );
@@ -340,7 +340,7 @@ bool QgsNewSpatialiteLayerDialog::apply()
{
// Build up the sql statement for creating the table
QString sql = QStringLiteral( "create table %1(" ).arg( quotedIdentifier( leLayerName->text() ) );
QString delim = QLatin1String( "" );
QString delim;

if ( checkBoxPrimaryKey->isChecked() )
{
@@ -1867,8 +1867,8 @@ void QgsProjectProperties::updateEllipsoidUI( int newIndex )
mEllipsoidIndex = newIndex;
leSemiMajor->setEnabled( false );
leSemiMinor->setEnabled( false );
leSemiMajor->setText( QLatin1String( "" ) );
leSemiMinor->setText( QLatin1String( "" ) );
leSemiMajor->clear();
leSemiMinor->clear();

cmbEllipsoid->setEnabled( projectionSelector->crs().isValid() );
cmbEllipsoid->setToolTip( QLatin1String( "" ) );
@@ -88,7 +88,7 @@ void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
relation.setReferencingLayer( addDlg.referencingLayerId() );
relation.setReferencedLayer( addDlg.referencedLayerId() );
QString relationId = addDlg.relationId();
if ( addDlg.relationId() == QLatin1String( "" ) )
if ( addDlg.relationId().isEmpty() )
relationId = QStringLiteral( "%1_%2_%3_%4" )
.arg( addDlg.referencingLayerId(),
addDlg.references().at( 0 ).first,
@@ -79,7 +79,7 @@ void QgsVersionInfo::versionReplyFinished()
mErrorString = tr( "The host name %1 could not be resolved. Check your DNS settings or contact your system administrator." ).arg( reply->request().url().host() );
break;
case QNetworkReply::NoError:
mErrorString = QLatin1String( "" );
mErrorString.clear();
break;
default:
mErrorString = reply->errorString();
@@ -150,7 +150,7 @@ QVariant QgsWelcomePageItemsModel::data( const QModelIndex &index, int role ) co
case PathRole:
return QDir::toNativeSeparators( mRecentProjects.at( index.row() ).path );
case CrsRole:
if ( mRecentProjects.at( index.row() ).crs != QLatin1String( "" ) )
if ( !mRecentProjects.at( index.row() ).crs.isEmpty() )
{
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mRecentProjects.at( index.row() ).crs );
return QStringLiteral( "%1 (%2)" ).arg( mRecentProjects.at( index.row() ).crs, crs.description() );
@@ -162,10 +162,7 @@ void QgsAuthPkiPathsEdit::writePkiMessage( QLineEdit *lineedit, const QString &m
txt = tr( "Invalid: %1" ).arg( msg );
break;
case Unknown:
ss = QLatin1String( "" );
break;
default:
ss = QLatin1String( "" );
}
lineedit->setStyleSheet( ss );
lineedit->setText( txt );
@@ -167,10 +167,7 @@ void QgsAuthPkcs12Edit::writePkiMessage( QLineEdit *lineedit, const QString &msg
txt = tr( "Invalid: %1" ).arg( msg );
break;
case Unknown:
ss = QLatin1String( "" );
break;
default:
ss = QLatin1String( "" );
}
lineedit->setStyleSheet( ss );
lineedit->setText( txt );
@@ -61,7 +61,7 @@ void QgsHtmlAnnotation::setSourceFile( const QString &htmlFile )
mHtmlFile = htmlFile;
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
mHtmlSource = QLatin1String( "" );
mHtmlSource.clear();
}
else
{
@@ -804,7 +804,7 @@ const QString QgsAuthManager::uniqueConfigId() const

while ( true )
{
id = QLatin1String( "" );
id.clear();
for ( int i = 0; i < len; i++ )
{
switch ( qrand() % 2 )
@@ -3051,7 +3051,7 @@ void QgsAuthManager::setPasswordHelperLoggingEnabled( const bool enabled )
void QgsAuthManager::passwordHelperClearErrors()
{
mPasswordHelperErrorCode = QKeychain::NoError;
mPasswordHelperErrorMessage = QLatin1String( "" );
mPasswordHelperErrorMessage.clear();
}

void QgsAuthManager::passwordHelperProcessError()
@@ -158,22 +158,22 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri )
length = -1;
}

if ( reFieldDef.cap( 2 ) != QLatin1String( "" ) )
if ( !reFieldDef.cap( 2 ).isEmpty() )
{
length = reFieldDef.cap( 2 ).toInt();
}
if ( reFieldDef.cap( 3 ) != QLatin1String( "" ) )
if ( !reFieldDef.cap( 3 ).isEmpty() )
{
precision = reFieldDef.cap( 3 ).toInt();
}
if ( reFieldDef.cap( 4 ) != QLatin1String( "" ) )
if ( !reFieldDef.cap( 4 ).isEmpty() )
{
//array
subType = type;
type = ( subType == QVariant::String ? QVariant::StringList : QVariant::List );
}
}
if ( name != QLatin1String( "" ) )
if ( !name.isEmpty() )
attributes.append( QgsField( name, type, typeName, length, precision, QLatin1String( "" ), subType ) );
}
addAttributes( attributes );
@@ -691,7 +691,7 @@ QgsStringMap QgsCptCityColorRamp::properties() const

QString QgsCptCityColorRamp::fileName() const
{
if ( mSchemeName == QLatin1String( "" ) )
if ( mSchemeName.isEmpty() )
return QString();
else
{

0 comments on commit 8c3939e

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