Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use .empty() instead of .size() > 0/.size() >=1/etc
Possibly faster, and clearer to read
  • Loading branch information
nyalldawson committed Sep 11, 2017
1 parent 2a33844 commit c179780
Show file tree
Hide file tree
Showing 53 changed files with 98 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.cpp
Expand Up @@ -37,7 +37,7 @@ QgsInterpolator::QgsInterpolator()

int QgsInterpolator::cacheBaseData()
{
if ( mLayerData.size() < 1 )
if ( mLayerData.empty() )
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/openstreetmap/qgsosmimport.cpp
Expand Up @@ -136,7 +136,7 @@ bool QgsOSMXmlImport::createDatabase()
{
QString version = QString::fromUtf8( results[1] );
QStringList parts = version.split( ' ', QString::SkipEmptyParts );
if ( parts.size() >= 1 )
if ( !parts.empty() )
{
QStringList verparts = parts[0].split( '.', QString::SkipEmptyParts );
above41 = verparts.size() >= 2 && ( verparts[0].toInt() > 4 || ( verparts[0].toInt() == 4 && verparts[1].toInt() >= 1 ) );
Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgsattributeselectiondialog.cpp
Expand Up @@ -340,7 +340,7 @@ void QgsAttributeSelectionDialog::on_mColumnUpPushButton_clicked()
{
//move selected row up
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( viewSelection.size() > 0 )
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftUp );
Expand All @@ -351,7 +351,7 @@ void QgsAttributeSelectionDialog::on_mColumnDownPushButton_clicked()
{
//move selected row down
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( viewSelection.size() > 0 )
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftDown );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -2136,7 +2136,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
return;
}
QStringList s = dlg.selectedFiles();
if ( s.size() < 1 || s.at( 0 ).isEmpty() )
if ( s.empty() || s.at( 0 ).isEmpty() )
{
return;
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -811,7 +811,7 @@ void QgsDwgImporter::addLType( const DRW_LType &data )
}

QString typeName( data.name.c_str() ), dash( "" );
if ( upath.size() > 0 )
if ( !upath.empty() )
{
QStringList l;
if ( upath[0] < 0 )
Expand Down Expand Up @@ -1486,7 +1486,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
.arg( p1.asWkt() ), 5
);

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

if ( staWidth == endWidth )
{
if ( s.size() == 0 )
if ( s.empty() )
{
s << p0;
hadBulge = hasBulge;
Expand Down Expand Up @@ -1604,7 +1604,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
}
}

if ( s.size() > 0 )
if ( !s.empty() )
{
if ( hadBulge )
{
Expand Down Expand Up @@ -1685,7 +1685,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
.arg( p1.asWkt() ), 5
);

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

if ( staWidth == endWidth )
{
if ( s.size() == 0 )
if ( s.empty() )
{
s << p0;
hadBulge = hasBulge;
Expand Down Expand Up @@ -1810,7 +1810,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
}
}

if ( s.size() > 0 )
if ( !s.empty() )
{
if ( hadBulge )
{
Expand Down Expand Up @@ -2052,7 +2052,7 @@ void QgsDwgImporter::addSpline( const DRW_Spline *data )
}
}

if ( cps.size() > 0 && data->flags & 1 )
if ( !cps.empty() && data->flags & 1 )
{
for ( int i = 0; i < data->degree; ++i )
cps.push_back( cps[i] );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -4149,7 +4149,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
QStringList sublayers = layer->subLayers();
QgsDebugMsg( QString( "raster has %1 sublayers" ).arg( layer->subLayers().size() ) );

if ( sublayers.size() < 1 )
if ( sublayers.empty() )
return;

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

QgsSettings settings;
Expand Down Expand Up @@ -6151,7 +6151,7 @@ void QgisApp::refreshFeatureActions()

//add actions registered in QgsMapLayerActionRegistry
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
if ( !actions.isEmpty() && registeredActions.size() > 0 )
if ( !actions.isEmpty() && !registeredActions.empty() )
{
//add a separator between user defined and standard actions
mFeatureActionMenu->addSeparator();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -841,7 +841,7 @@ void QgsAttributeTableDialog::on_mActionRemoveAttribute_triggered()
if ( dialog.exec() == QDialog::Accepted )
{
QList<int> attributes = dialog.selectedAttributes();
if ( attributes.size() < 1 )
if ( attributes.empty() )
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -44,7 +44,7 @@ QgsMapToolMeasureAngle::~QgsMapToolMeasureAngle()

void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )
{
if ( !mRubberBand || mAnglePoints.size() < 1 || mAnglePoints.size() > 2 )
if ( !mRubberBand || mAnglePoints.empty() || mAnglePoints.size() > 2 )
{
return;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )
mAnglePoints.clear();
}

if ( mAnglePoints.size() < 1 )
if ( mAnglePoints.empty() )
{
if ( !mResultDisplay )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -284,7 +284,7 @@ QgsGeometry QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer *vl, con

//for background layers, try to merge selected entries together if snapped feature is contained in selection
const QgsFeatureIds &selection = vl->selectedFeatureIds();
if ( selection.size() < 1 || !selection.contains( match.featureId() ) )
if ( selection.empty() || !selection.contains( match.featureId() ) )
{
return convertToSingleLine( snappedFeature.geometry(), partVertexNr, mMultiPartGeometry );
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolrotatelabel.cpp
Expand Up @@ -189,7 +189,7 @@ QgsRubberBand *QgsMapToolRotateLabel::createRotationPreviewBox()
{
delete mRotationPreviewBox;
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
if ( boxPoints.size() < 1 )
if ( boxPoints.empty() )
{
return nullptr;
}
Expand All @@ -210,7 +210,7 @@ void QgsMapToolRotateLabel::setRotationPreviewBox( double rotation )

mRotationPreviewBox->reset();
QVector< QgsPointXY > boxPoints = mCurrentLabel.pos.cornerPoints;
if ( boxPoints.size() < 1 )
if ( boxPoints.empty() )
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmeasuredialog.cpp
Expand Up @@ -154,7 +154,7 @@ void QgsMeasureDialog::mouseMove( const QgsPointXY &point )
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && mTool->points().size() >= 1 )
else if ( !mMeasureArea && !mTool->points().empty() )
{
QList< QgsPointXY > tmpPoints = mTool->points();
QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) ), p2( point );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmeasuretool.cpp
Expand Up @@ -222,7 +222,7 @@ void QgsMeasureTool::undo()
{
if ( mRubberBand )
{
if ( mPoints.size() < 1 )
if ( mPoints.empty() )
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -524,7 +524,7 @@ void QgsMergeAttributesDialog::createRubberBandForFeature( QgsFeatureId featureI

QgsAttributes QgsMergeAttributesDialog::mergedAttributes() const
{
if ( mFeatureList.size() < 1 )
if ( mFeatureList.empty() )
{
return QgsAttributes();
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -1381,7 +1381,7 @@ void QgsProjectProperties::on_mAddWMSComposerButton_clicked()
QString name = QInputDialog::getItem( this, tr( "Select print composer" ), tr( "Composer Title" ), composerTitles, 0, false, &ok );
if ( ok )
{
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).size() < 1 )
if ( mComposerListWidget->findItems( name, Qt::MatchExactly ).empty() )
{
mComposerListWidget->addItem( name );
}
Expand All @@ -1407,7 +1407,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
QStringList::const_iterator layerIt = layerNames.constBegin();
for ( ; layerIt != layerNames.constEnd(); ++layerIt )
{
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).size() < 1 )
if ( mLayerRestrictionsListWidget->findItems( *layerIt, Qt::MatchExactly ).empty() )
{
mLayerRestrictionsListWidget->addItem( *layerIt );
}
Expand All @@ -1417,7 +1417,7 @@ void QgsProjectProperties::on_mAddLayerRestrictionButton_clicked()
QStringList::const_iterator groupIt = groups.constBegin();
for ( ; groupIt != groups.constEnd(); ++groupIt )
{
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).size() < 1 )
if ( mLayerRestrictionsListWidget->findItems( *groupIt, Qt::MatchExactly ).empty() )
{
mLayerRestrictionsListWidget->addItem( *groupIt );
}
Expand Down Expand Up @@ -1506,7 +1506,7 @@ void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
duplicateNames << name;
}

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

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

if ( encodingMessages.size() != 0 )
if ( !encodingMessages.empty() )
{
QString encodingMessage = "<h1>" + tr( "Some layer encodings are not set:" ) + "</h1><ul><li>" + encodingMessages.join( QStringLiteral( "</li><li>" ) ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
Expand Down
4 changes: 2 additions & 2 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -2235,7 +2235,7 @@ bool QgsAuthManager::rebuildIgnoredSslErrorCache()

bool QgsAuthManager::storeCertAuthorities( const QList<QSslCertificate> &certs )
{
if ( certs.size() < 1 )
if ( certs.isEmpty() )
{
QgsDebugMsg( "Passed certificate list has no certs" );
return false;
Expand Down Expand Up @@ -2542,7 +2542,7 @@ QgsAuthCertUtils::CertTrustPolicy QgsAuthManager::getCertTrustPolicy( const QSsl

bool QgsAuthManager::removeCertTrustPolicies( const QList<QSslCertificate> &certs )
{
if ( certs.size() < 1 )
if ( certs.empty() )
{
QgsDebugMsg( "Passed certificate list has no certs" );
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -1796,7 +1796,7 @@ void QgsComposerMap::transformShift( double &xShift, double &yShift ) const
QPointF QgsComposerMap::mapToItemCoords( QPointF mapCoords ) const
{
QPolygonF mapPoly = transformedMapPolygon();
if ( mapPoly.size() < 1 )
if ( mapPoly.empty() )
{
return QPointF( 0, 0 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermousehandles.cpp
Expand Up @@ -1373,7 +1373,7 @@ void QgsComposerMouseHandles::checkNearestItem( double checkCoord, const QMap< d

bool QgsComposerMouseHandles::nearestItem( const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue ) const
{
if ( coords.size() < 1 )
if ( coords.empty() )
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposermultiframe.cpp
Expand Up @@ -68,7 +68,7 @@ void QgsComposerMultiFrame::setResizeMode( ResizeMode mode )

void QgsComposerMultiFrame::recalculateFrameSizes()
{
if ( mFrameItems.size() < 1 )
if ( mFrameItems.empty() )
{
return;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()

void QgsComposerMultiFrame::recalculateFrameRects()
{
if ( mFrameItems.size() < 1 )
if ( mFrameItems.empty() )
{
//no frames, nothing to do
return;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposition.cpp
Expand Up @@ -2200,7 +2200,7 @@ QGraphicsLineItem *QgsComposition::nearestSnapLine( const bool horizontal, const
int QgsComposition::boundingRectOfSelectedItems( QRectF &bRect )
{
QList<QgsComposerItem *> selectedItems = selectedComposerItems();
if ( selectedItems.size() < 1 )
if ( selectedItems.empty() )
{
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -1071,7 +1071,7 @@ void QgsDxfExport::writeEntities()
else
{
QgsSymbolList symbolList = renderer->symbolsForFeature( fet, ctx );
if ( symbolList.size() < 1 )
if ( symbolList.empty() )
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/dxf/qgsdxfpaintengine.cpp
Expand Up @@ -160,10 +160,10 @@ void QgsDxfPaintEngine::endPolygon()

void QgsDxfPaintEngine::endCurve()
{
if ( mCurrentCurve.size() < 1 )
if ( mCurrentCurve.empty() )
return;

if ( mCurrentPolygon.size() < 1 )
if ( mCurrentPolygon.empty() )
{
mCurrentCurve.clear();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgscircularstring.cpp
Expand Up @@ -435,7 +435,7 @@ void QgsCircularString::setPoints( const QgsPointSequence &points )
{
clearCache();

if ( points.size() < 1 )
if ( points.empty() )
{
mWkbType = QgsWkbTypes::Unknown;
mX.clear();
Expand Down

0 comments on commit c179780

Please sign in to comment.