Skip to content

Commit c179780

Browse files
committed
Use .empty() instead of .size() > 0/.size() >=1/etc
Possibly faster, and clearer to read
1 parent 2a33844 commit c179780

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+98
-96
lines changed

src/analysis/interpolation/qgsinterpolator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QgsInterpolator::QgsInterpolator()
3737

3838
int QgsInterpolator::cacheBaseData()
3939
{
40-
if ( mLayerData.size() < 1 )
40+
if ( mLayerData.empty() )
4141
{
4242
return 0;
4343
}

src/analysis/openstreetmap/qgsosmimport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool QgsOSMXmlImport::createDatabase()
136136
{
137137
QString version = QString::fromUtf8( results[1] );
138138
QStringList parts = version.split( ' ', QString::SkipEmptyParts );
139-
if ( parts.size() >= 1 )
139+
if ( !parts.empty() )
140140
{
141141
QStringList verparts = parts[0].split( '.', QString::SkipEmptyParts );
142142
above41 = verparts.size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );

src/app/composer/qgsattributeselectiondialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void QgsAttributeSelectionDialog::on_mColumnUpPushButton_clicked()
340340
{
341341
//move selected row up
342342
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
343-
if ( viewSelection.size() > 0 )
343+
if ( !viewSelection.empty() )
344344
{
345345
int selectedRow = viewSelection.indexes().at( 0 ).row();
346346
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftUp );
@@ -351,7 +351,7 @@ void QgsAttributeSelectionDialog::on_mColumnDownPushButton_clicked()
351351
{
352352
//move selected row down
353353
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
354-
if ( viewSelection.size() > 0 )
354+
if ( !viewSelection.empty() )
355355
{
356356
int selectedRow = viewSelection.indexes().at( 0 ).row();
357357
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftDown );

src/app/composer/qgscomposer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21362136
return;
21372137
}
21382138
QStringList s = dlg.selectedFiles();
2139-
if ( s.size() < 1 || s.at( 0 ).isEmpty() )
2139+
if ( s.empty() || s.at( 0 ).isEmpty() )
21402140
{
21412141
return;
21422142
}

src/app/dwg/qgsdwgimporter.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ void QgsDwgImporter::addLType( const DRW_LType &data )
811811
}
812812

813813
QString typeName( data.name.c_str() ), dash( "" );
814-
if ( upath.size() > 0 )
814+
if ( !upath.empty() )
815815
{
816816
QStringList l;
817817
if ( upath[0] < 0 )
@@ -1486,7 +1486,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
14861486
.arg( p1.asWkt() ), 5
14871487
);
14881488

1489-
if ( s.size() > 0 && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
1489+
if ( !s.empty() && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
14901490
{
14911491
if ( hadBulge )
14921492
{
@@ -1536,7 +1536,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
15361536

15371537
if ( staWidth == endWidth )
15381538
{
1539-
if ( s.size() == 0 )
1539+
if ( s.empty() )
15401540
{
15411541
s << p0;
15421542
hadBulge = hasBulge;
@@ -1604,7 +1604,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
16041604
}
16051605
}
16061606

1607-
if ( s.size() > 0 )
1607+
if ( !s.empty() )
16081608
{
16091609
if ( hadBulge )
16101610
{
@@ -1685,7 +1685,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
16851685
.arg( p1.asWkt() ), 5
16861686
);
16871687

1688-
if ( s.size() > 0 && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
1688+
if ( !s.empty() && ( width != staWidth || width != endWidth || hadBulge != hasBulge ) )
16891689
{
16901690
if ( hadBulge )
16911691
{
@@ -1737,7 +1737,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
17371737

17381738
if ( staWidth == endWidth )
17391739
{
1740-
if ( s.size() == 0 )
1740+
if ( s.empty() )
17411741
{
17421742
s << p0;
17431743
hadBulge = hasBulge;
@@ -1810,7 +1810,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
18101810
}
18111811
}
18121812

1813-
if ( s.size() > 0 )
1813+
if ( !s.empty() )
18141814
{
18151815
if ( hadBulge )
18161816
{
@@ -2052,7 +2052,7 @@ void QgsDwgImporter::addSpline( const DRW_Spline *data )
20522052
}
20532053
}
20542054

2055-
if ( cps.size() > 0 && data->flags & 1 )
2055+
if ( !cps.empty() && data->flags & 1 )
20562056
{
20572057
for ( int i = 0; i < data->degree; ++i )
20582058
cps.push_back( cps[i] );

src/app/qgisapp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4149,7 +4149,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
41494149
QStringList sublayers = layer->subLayers();
41504150
QgsDebugMsg( QString( "raster has %1 sublayers" ).arg( layer->subLayers().size() ) );
41514151

4152-
if ( sublayers.size() < 1 )
4152+
if ( sublayers.empty() )
41534153
return;
41544154

41554155
// if promptLayers=Load all, load all sublayers without prompting
@@ -4256,7 +4256,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
42564256
bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
42574257
{
42584258
// return false if layer is empty or raster has no sublayers
4259-
if ( !layer || layer->providerType() != QLatin1String( "gdal" ) || layer->subLayers().size() < 1 )
4259+
if ( !layer || layer->providerType() != QLatin1String( "gdal" ) || layer->subLayers().empty() )
42604260
return false;
42614261

42624262
QgsSettings settings;
@@ -6151,7 +6151,7 @@ void QgisApp::refreshFeatureActions()
61516151

61526152
//add actions registered in QgsMapLayerActionRegistry
61536153
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
6154-
if ( !actions.isEmpty() && registeredActions.size() > 0 )
6154+
if ( !actions.isEmpty() && !registeredActions.empty() )
61556155
{
61566156
//add a separator between user defined and standard actions
61576157
mFeatureActionMenu->addSeparator();

src/app/qgsattributetabledialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ void QgsAttributeTableDialog::on_mActionRemoveAttribute_triggered()
841841
if ( dialog.exec() == QDialog::Accepted )
842842
{
843843
QList<int> attributes = dialog.selectedAttributes();
844-
if ( attributes.size() < 1 )
844+
if ( attributes.empty() )
845845
{
846846
return;
847847
}

src/app/qgsmaptoolmeasureangle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ QgsMapToolMeasureAngle::~QgsMapToolMeasureAngle()
4444

4545
void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )
4646
{
47-
if ( !mRubberBand || mAnglePoints.size() < 1 || mAnglePoints.size() > 2 )
47+
if ( !mRubberBand || mAnglePoints.empty() || mAnglePoints.size() > 2 )
4848
{
4949
return;
5050
}
@@ -89,7 +89,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )
8989
mAnglePoints.clear();
9090
}
9191

92-
if ( mAnglePoints.size() < 1 )
92+
if ( mAnglePoints.empty() )
9393
{
9494
if ( !mResultDisplay )
9595
{

src/app/qgsmaptooloffsetcurve.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ QgsGeometry QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer *vl, con
284284

285285
//for background layers, try to merge selected entries together if snapped feature is contained in selection
286286
const QgsFeatureIds &selection = vl->selectedFeatureIds();
287-
if ( selection.size() < 1 || !selection.contains( match.featureId() ) )
287+
if ( selection.empty() || !selection.contains( match.featureId() ) )
288288
{
289289
return convertToSingleLine( snappedFeature.geometry(), partVertexNr, mMultiPartGeometry );
290290
}

src/app/qgsmaptoolrotatelabel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ QgsRubberBand *QgsMapToolRotateLabel::createRotationPreviewBox()
189189
{
190190
delete mRotationPreviewBox;
191191
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
192-
if ( boxPoints.size() < 1 )
192+
if ( boxPoints.empty() )
193193
{
194194
return nullptr;
195195
}
@@ -210,7 +210,7 @@ void QgsMapToolRotateLabel::setRotationPreviewBox( double rotation )
210210

211211
mRotationPreviewBox->reset();
212212
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
213-
if ( boxPoints.size() < 1 )
213+
if ( boxPoints.empty() )
214214
{
215215
return;
216216
}

src/app/qgsmeasuredialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void QgsMeasureDialog::mouseMove( const QgsPointXY &point )
154154
double area = mDa.measurePolygon( tmpPoints );
155155
editTotal->setText( formatArea( area ) );
156156
}
157-
else if ( !mMeasureArea && mTool->points().size() >= 1 )
157+
else if ( !mMeasureArea && !mTool->points().empty() )
158158
{
159159
QList< QgsPointXY > tmpPoints = mTool->points();
160160
QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) ), p2( point );

src/app/qgsmeasuretool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void QgsMeasureTool::undo()
222222
{
223223
if ( mRubberBand )
224224
{
225-
if ( mPoints.size() < 1 )
225+
if ( mPoints.empty() )
226226
{
227227
return;
228228
}

src/app/qgsmergeattributesdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureI
524524

525525
QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
526526
{
527-
if ( mFeatureList.size() < 1 )
527+
if ( mFeatureList.empty() )
528528
{
529529
return QgsAttributes();
530530
}

src/app/qgsprojectproperties.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ void QgsProjectProperties::on_mAddWMSComposerButton_clicked()
13811381
QString name = QInputDialog::getItem( this, tr( "Select print composer" ), tr( "Composer Title" ), composerTitles, 0, false, &ok );
13821382
if ( ok )
13831383
{
1384-
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).size() < 1 )
1384+
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).empty() )
13851385
{
13861386
mComposerListWidget->addItem( name );
13871387
}
@@ -1407,7 +1407,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
14071407
QStringList::const_iterator layerIt = layerNames.constBegin();
14081408
for ( ; layerIt != layerNames.constEnd(); ++layerIt )
14091409
{
1410-
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).size() < 1 )
1410+
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).empty() )
14111411
{
14121412
mLayerRestrictionsListWidget->addItem( *layerIt );
14131413
}
@@ -1417,7 +1417,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
14171417
QStringList::const_iterator groupIt = groups.constBegin();
14181418
for ( ; groupIt != groups.constEnd(); ++groupIt )
14191419
{
1420-
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).size() < 1 )
1420+
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).empty() )
14211421
{
14221422
mLayerRestrictionsListWidget->addItem( *groupIt );
14231423
}
@@ -1506,7 +1506,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
15061506
duplicateNames << name;
15071507
}
15081508

1509-
if ( duplicateNames.size() != 0 )
1509+
if ( !duplicateNames.empty() )
15101510
{
15111511
QString nameMessage = "<h1>" + tr( "Some layers and groups have the same name or short name" ) + "</h1>";
15121512
nameMessage += "<h2>" + tr( "Duplicate names:" ) + "</h2>";
@@ -1518,7 +1518,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
15181518
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All names and short names of layer and group are unique" ) + "</h1>" );
15191519
}
15201520

1521-
if ( regExpMessages.size() != 0 )
1521+
if ( !regExpMessages.empty() )
15221522
{
15231523
QString encodingMessage = "<h1>" + tr( "Some layer short names have to be updated:" ) + "</h1><ul><li>" + regExpMessages.join( QStringLiteral( "</li><li>" ) ) + "</li></ul>";
15241524
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
@@ -1528,7 +1528,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
15281528
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer short names are well formed" ) + "</h1>" );
15291529
}
15301530

1531-
if ( encodingMessages.size() != 0 )
1531+
if ( !encodingMessages.empty() )
15321532
{
15331533
QString encodingMessage = "<h1>" + tr( "Some layer encodings are not set:" ) + "</h1><ul><li>" + encodingMessages.join( QStringLiteral( "</li><li>" ) ) + "</li></ul>";
15341534
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );

src/core/auth/qgsauthmanager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ bool QgsAuthManager::rebuildIgnoredSslErrorCache()
22352235

22362236
bool QgsAuthManager::storeCertAuthorities( const QList<QSslCertificate> &certs )
22372237
{
2238-
if ( certs.size() < 1 )
2238+
if ( certs.isEmpty() )
22392239
{
22402240
QgsDebugMsg( "Passed certificate list has no certs" );
22412241
return false;
@@ -2542,7 +2542,7 @@ QgsAuthCertUtils::CertTrustPolicy QgsAuthManager::getCertTrustPolicy( const QSsl
25422542

25432543
bool QgsAuthManager::removeCertTrustPolicies( const QList<QSslCertificate> &certs )
25442544
{
2545-
if ( certs.size() < 1 )
2545+
if ( certs.empty() )
25462546
{
25472547
QgsDebugMsg( "Passed certificate list has no certs" );
25482548
return false;

src/core/composer/qgscomposermap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ void QgsComposerMap::transformShift( double &xShift, double &yShift ) const
17961796
QPointF QgsComposerMap::mapToItemCoords( QPointF mapCoords ) const
17971797
{
17981798
QPolygonF mapPoly = transformedMapPolygon();
1799-
if ( mapPoly.size() < 1 )
1799+
if ( mapPoly.empty() )
18001800
{
18011801
return QPointF( 0, 0 );
18021802
}

src/core/composer/qgscomposermousehandles.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ void QgsComposerMouseHandles::checkNearestItem( double checkCoord, const QMap< d
13731373

13741374
bool QgsComposerMouseHandles::nearestItem( const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue ) const
13751375
{
1376-
if ( coords.size() < 1 )
1376+
if ( coords.empty() )
13771377
{
13781378
return false;
13791379
}

src/core/composer/qgscomposermultiframe.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )
6868

6969
void QgsComposerMultiFrame::recalculateFrameSizes()
7070
{
71-
if ( mFrameItems.size() < 1 )
71+
if ( mFrameItems.empty() )
7272
{
7373
return;
7474
}
@@ -182,7 +182,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()
182182

183183
void QgsComposerMultiFrame::recalculateFrameRects()
184184
{
185-
if ( mFrameItems.size() < 1 )
185+
if ( mFrameItems.empty() )
186186
{
187187
//no frames, nothing to do
188188
return;

src/core/composer/qgscomposition.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ QGraphicsLineItem *QgsComposition::nearestSnapLine( const bool horizontal, const
22002200
int QgsComposition::boundingRectOfSelectedItems( QRectF &bRect )
22012201
{
22022202
QList<QgsComposerItem *> selectedItems = selectedComposerItems();
2203-
if ( selectedItems.size() < 1 )
2203+
if ( selectedItems.empty() )
22042204
{
22052205
return 1;
22062206
}

src/core/dxf/qgsdxfexport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void QgsDxfExport::writeEntities()
10711071
else
10721072
{
10731073
QgsSymbolList symbolList = renderer->symbolsForFeature( fet, ctx );
1074-
if ( symbolList.size() < 1 )
1074+
if ( symbolList.empty() )
10751075
{
10761076
continue;
10771077
}

src/core/dxf/qgsdxfpaintengine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ void QgsDxfPaintEngine::endPolygon()
160160

161161
void QgsDxfPaintEngine::endCurve()
162162
{
163-
if ( mCurrentCurve.size() < 1 )
163+
if ( mCurrentCurve.empty() )
164164
return;
165165

166-
if ( mCurrentPolygon.size() < 1 )
166+
if ( mCurrentPolygon.empty() )
167167
{
168168
mCurrentCurve.clear();
169169
return;

src/core/geometry/qgscircularstring.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void QgsCircularString::setPoints( const QgsPointSequence &points )
435435
{
436436
clearCache();
437437

438-
if ( points.size() < 1 )
438+
if ( points.empty() )
439439
{
440440
mWkbType = QgsWkbTypes::Unknown;
441441
mX.clear();

0 commit comments

Comments
 (0)