Skip to content

Commit c50033b

Browse files
committed
Misc optimisations suggested by clazy
- avoid Q_FOREACH( ..., QMap.values() ) as it allocates an unnecessary list - use .endsWith( ... , Qt::CaseInsensitive) instead of .lower().endsWith( ... ) as it avoids an extra QString allocation
1 parent d0e595f commit c50033b

23 files changed

+34
-34
lines changed

src/app/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ int main( int argc, char *argv[] )
11721172
}
11731173
else
11741174
{
1175-
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers().values() )
1175+
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers() )
11761176
{
11771177
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
11781178
if ( !vl )

src/app/nodetool/qgsmaptoolnodetool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void QgsMapToolNodeTool::createTopologyRubberBands()
6767
// Snap vertex
6868
QMultiMap<double, QgsSnappingResult> snapResults;
6969
vlayer->snapWithContext( vertexEntry->pointV1(), ZERO_TOLERANCE, snapResults, QgsSnapper::SnapToVertex );
70-
Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults.values() )
70+
Q_FOREACH ( const QgsSnappingResult& snapResult, snapResults )
7171
{
7272
// Get geometry of snapped feature
7373
QgsFeatureId snapFeatureId = snapResult.snappedAtGeometry;

src/app/qgisapp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4798,7 +4798,7 @@ bool QgisApp::openLayer( const QString & fileName, bool allowInteractive )
47984798
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
47994799
{
48004800
// open .adf as a directory
4801-
if ( fileName.toLower().endsWith( ".adf" ) )
4801+
if ( fileName.endsWith( ".adf", Qt::CaseInsensitive ) )
48024802
{
48034803
QString dirName = fileInfo.path();
48044804
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
@@ -10337,7 +10337,7 @@ QgsRasterLayer* QgisApp::addRasterLayerPrivate(
1033710337
// XXX ya know QgsRasterLayer can snip out the basename on its own;
1033810338
// XXX why do we have to pass it in for it?
1033910339
// ET : we may not be getting "normal" files here, so we still need the baseName argument
10340-
if ( !providerKey.isEmpty() && uri.toLower().endsWith( ".adf" ) )
10340+
if ( !providerKey.isEmpty() && uri.endsWith( ".adf", Qt::CaseInsensitive ) )
1034110341
{
1034210342
QFileInfo fileInfo( uri );
1034310343
QString dirName = fileInfo.path();

src/app/qgsalignrasterdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
static QgsMapLayer* _rasterLayer( const QString& filename )
3737
{
3838
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
39-
Q_FOREACH ( QgsMapLayer* layer, layers.values() )
39+
Q_FOREACH ( QgsMapLayer* layer, layers )
4040
{
4141
if ( layer->type() == QgsMapLayer::RasterLayer && layer->source() == filename )
4242
return layer;
@@ -457,7 +457,7 @@ void QgsAlignRasterLayerConfigDialog::browseOutputFilename()
457457
if ( !fileName.isEmpty() )
458458
{
459459
// ensure the user never ommited the extension from the file name
460-
if ( !fileName.toLower().endsWith( ".tif" ) && !fileName.toLower().endsWith( ".tiff" ) )
460+
if ( !fileName.endsWith( ".tif", Qt::CaseInsensitive ) && !fileName.endsWith( ".tiff", Qt::CaseInsensitive ) )
461461
{
462462
fileName += ".tif";
463463
}

src/app/qgsbookmarks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void QgsBookmarks::exportToXML()
326326
}
327327

328328
// ensure the user never ommited the extension from the file name
329-
if ( !fileName.toLower().endsWith( ".xml" ) )
329+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
330330
{
331331
fileName += ".xml";
332332
}

src/app/qgsconfigureshortcutsdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts()
107107
return;
108108

109109
// ensure the user never omitted the extension from the file name
110-
if ( !fileName.toLower().endsWith( ".xml" ) )
110+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
111111
{
112112
fileName += ".xml";
113113
}

src/app/qgsnewspatialitelayerdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void QgsNewSpatialiteLayerDialog::on_toolButtonNewDatabase_clicked()
117117
if ( fileName.isEmpty() )
118118
return;
119119

120-
if ( !fileName.toLower().endsWith( ".sqlite" ) && !fileName.toLower().endsWith( ".db" ) )
120+
if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) && !fileName.endsWith( ".db", Qt::CaseInsensitive ) )
121121
{
122122
fileName += ".sqlite";
123123
}

src/app/qgsoptions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ void QgsOptions::on_pbnExportScales_clicked()
20012001
}
20022002

20032003
// ensure the user never ommited the extension from the file name
2004-
if ( !fileName.toLower().endsWith( ".xml" ) )
2004+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
20052005
{
20062006
fileName += ".xml";
20072007
}
@@ -2160,7 +2160,7 @@ void QgsOptions::on_mButtonExportColors_clicked()
21602160
}
21612161

21622162
// ensure filename contains extension
2163-
if ( !fileName.toLower().endsWith( ".gpl" ) )
2163+
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
21642164
{
21652165
fileName += ".gpl";
21662166
}

src/app/qgsprojectproperties.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
643643
mTabRelations->layout()->addWidget( mRelationManagerDlg );
644644

645645
QList<QgsVectorLayer*> vectorLayers;
646-
Q_FOREACH ( QgsMapLayer* mapLayer, mapLayers.values() )
646+
Q_FOREACH ( QgsMapLayer* mapLayer, mapLayers )
647647
{
648648
if ( QgsMapLayer::VectorLayer == mapLayer->type() )
649649
{
@@ -1482,7 +1482,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
14821482

14831483
QStringList duplicateNames, regExpMessages;
14841484
QRegExp snRegExp = QgsApplication::shortNameRegExp();
1485-
Q_FOREACH ( QString name, owsNames )
1485+
Q_FOREACH ( const QString& name, owsNames )
14861486
{
14871487
if ( !snRegExp.exactMatch( name ) )
14881488
regExpMessages << tr( "Use short name for \"%1\"" ).arg( name );
@@ -1583,7 +1583,7 @@ void QgsProjectProperties::on_pbnExportScales_clicked()
15831583
}
15841584

15851585
// ensure the user never ommited the extension from the file name
1586-
if ( !fileName.toLower().endsWith( ".xml" ) )
1586+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
15871587
{
15881588
fileName += ".xml";
15891589
}
@@ -2015,7 +2015,7 @@ void QgsProjectProperties::on_mButtonExportColors_clicked()
20152015
}
20162016

20172017
// ensure filename contains extension
2018-
if ( !fileName.toLower().endsWith( ".gpl" ) )
2018+
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
20192019
{
20202020
fileName += ".gpl";
20212021
}

src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void QgsValueMapConfigDlg::removeSelectedButtonPushed()
111111
}
112112
}
113113
}
114-
for ( i = 0; i < rowsToRemove.values().size(); i++ )
114+
for ( i = 0; i < rowsToRemove.size(); i++ )
115115
{
116116
tableWidget->removeRow( rowsToRemove.values().at( i ) - removed );
117117
removed++;

src/gui/qgisgui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace QgisGui
168168
#endif
169169

170170
// Add the file type suffix to the fileName if required
171-
if ( !ext.isNull() && !outputFileName.toLower().endsWith( '.' + ext.toLower() ) )
171+
if ( !ext.isNull() && !outputFileName.endsWith( '.' + ext.toLower(), Qt::CaseInsensitive ) )
172172
{
173173
outputFileName += '.' + ext;
174174
}

src/gui/qgscolordialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void QgsColorDialogV2::exportColors()
572572
}
573573

574574
// ensure filename contains extension
575-
if ( !fileName.toLower().endsWith( ".gpl" ) )
575+
if ( !fileName.endsWith( ".gpl", Qt::CaseInsensitive ) )
576576
{
577577
fileName += ".gpl";
578578
}

src/gui/qgsmanageconnectionsdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void QgsManageConnectionsDialog::doExportImport()
9999
}
100100

101101
// ensure the user never ommited the extension from the file name
102-
if ( !fileName.toLower().endsWith( ".xml" ) )
102+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
103103
{
104104
fileName += ".xml";
105105
}

src/gui/qgsprojectionselector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet<QString> * c
172172

173173
// iterate through all incoming CRSs
174174

175-
Q_FOREACH ( const QString& auth_id, crsFilter->values() )
175+
Q_FOREACH ( const QString& auth_id, *crsFilter )
176176
{
177177
QStringList parts = auth_id.split( ':' );
178178

src/gui/qgsrasterlayersaveasdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void QgsRasterLayerSaveAsDialog::on_mBrowseButton_clicked()
204204
if ( !fileName.isEmpty() )
205205
{
206206
// ensure the user never ommited the extension from the file name
207-
if ( !fileName.toLower().endsWith( ".tif" ) && !fileName.toLower().endsWith( ".tiff" ) )
207+
if ( !fileName.endsWith( ".tif", Qt::CaseInsensitive ) && !fileName.endsWith( ".tiff", Qt::CaseInsensitive ) )
208208
{
209209
fileName += ".tif";
210210
}

src/gui/symbology-ng/qgssmartgroupeditordialog.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void QgsSmartGroupEditorDialog::addCondition()
106106
// enable the remove buttons when 2nd condition is added
107107
if ( mConditionMap.count() == 1 )
108108
{
109-
Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap.values() )
109+
Q_FOREACH ( QgsSmartGroupCondition *condition, mConditionMap )
110110
{
111111
condition->hideRemoveButton( false );
112112
}
@@ -128,7 +128,7 @@ void QgsSmartGroupEditorDialog::removeCondition( int id )
128128
// hide the remove button of the last condition when 2nd last is removed
129129
if ( mConditionMap.count() == 2 )
130130
{
131-
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() )
131+
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
132132
{
133133
condition->hideRemoveButton( true );
134134
}
@@ -142,7 +142,7 @@ QgsSmartConditionMap QgsSmartGroupEditorDialog::conditionMap()
142142
{
143143
QgsSmartConditionMap conditions;
144144

145-
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap.values() )
145+
Q_FOREACH ( QgsSmartGroupCondition* condition, mConditionMap )
146146
{
147147
conditions.insert( condition->constraint(), condition->parameter() );
148148
}

src/gui/symbology-ng/qgsstylev2exportimportdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void QgsStyleV2ExportImportDialog::doExportImport()
134134
}
135135

136136
// ensure the user never ommited the extension from the file name
137-
if ( !fileName.toLower().endsWith( ".xml" ) )
137+
if ( !fileName.endsWith( ".xml", Qt::CaseInsensitive ) )
138138
{
139139
fileName += ".xml";
140140
}

src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void dxf2shpConverterGui::getOutputDir()
163163

164164
if ( !s.isEmpty() )
165165
{
166-
if ( !s.toLower().endsWith( ".shp" ) )
166+
if ( !s.endsWith( ".shp", Qt::CaseInsensitive ) )
167167
{
168168
s += ".shp";
169169
}

src/plugins/gps_importer/qgsgpsplugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void QgsGPSPlugin::createGPX()
174174
tr( "GPS eXchange file" ) + " (*.gpx)" );
175175
if ( !fileName.isEmpty() )
176176
{
177-
if ( !fileName.toLower().endsWith( ".gpx" ) )
177+
if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
178178
{
179179
fileName += ".gpx";
180180
}

src/plugins/gps_importer/qgsgpsplugingui.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
116116
int featureType = cmbDLFeatureType->currentIndex();
117117

118118
QString fileName = leDLOutput->text();
119-
if ( !fileName.toLower().endsWith( ".gpx" ) )
119+
if ( !fileName.endsWith( ".gpx", Qt::CaseInsensitive ) )
120120
{
121121
fileName += ".gpx";
122122
}
@@ -166,7 +166,7 @@ void QgsGPSPluginGui::on_pbnDLOutput_clicked()
166166
tr( "GPS eXchange format" ) + " (*.gpx)" );
167167
if ( !myFileNameQString.isEmpty() )
168168
{
169-
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
169+
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
170170
{
171171
myFileNameQString += ".gpx";
172172
}
@@ -316,7 +316,7 @@ void QgsGPSPluginGui::on_pbnIMPOutput_clicked()
316316
tr( "GPS eXchange format" ) + " (*.gpx)" );
317317
if ( !myFileNameQString.isEmpty() )
318318
{
319-
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
319+
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
320320
{
321321
myFileNameQString += ".gpx";
322322
}
@@ -423,7 +423,7 @@ void QgsGPSPluginGui::on_pbnCONVOutput_clicked()
423423
tr( "GPS eXchange format" ) + " (*.gpx)" );
424424
if ( !myFileNameQString.isEmpty() )
425425
{
426-
if ( !myFileNameQString.toLower().endsWith( ".gpx" ) )
426+
if ( !myFileNameQString.endsWith( ".gpx", Qt::CaseInsensitive ) )
427427
{
428428
myFileNameQString += ".gpx";
429429
}

src/plugins/offline_editing/offline_editing_plugin_gui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void QgsOfflineEditingPluginGui::on_mBrowseButton_clicked()
117117

118118
if ( !fileName.isEmpty() )
119119
{
120-
if ( !fileName.toLower().endsWith( ".sqlite" ) )
120+
if ( !fileName.endsWith( ".sqlite", Qt::CaseInsensitive ) )
121121
{
122122
fileName += ".sqlite";
123123
}

src/providers/virtual/qgsvirtuallayersourceselect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::W
8787
}
8888

8989
// configure auto completion with table and column names
90-
Q_FOREACH ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers().values() )
90+
Q_FOREACH ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers() )
9191
{
9292
if ( l->type() == QgsMapLayer::VectorLayer )
9393
{

tests/src/gui/testprojectionissues.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void TestProjectionIssues::initTestCase()
6868

6969
// Add all layers in registry to the canvas
7070
QList<QgsMapCanvasLayer> canvasLayers;
71-
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
71+
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
7272
{
7373
canvasLayers.append( QgsMapCanvasLayer( layer ) );
7474
}

0 commit comments

Comments
 (0)