Skip to content

Commit ee72079

Browse files
committed
Change size()/count() == 0 and count() > 0 to isEmpty() checks
Because: - easier to read - follows recommendations by clazy/KDAB - potentially performance benefits
1 parent 269f709 commit ee72079

File tree

187 files changed

+489
-489
lines changed

Some content is hidden

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

187 files changed

+489
-489
lines changed

src/analysis/interpolation/DualEdgeTriangulation.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ double leftOfTresh = 0.00000001;
2626
DualEdgeTriangulation::~DualEdgeTriangulation()
2727
{
2828
//remove all the points
29-
if ( mPointVector.count() > 0 )
29+
if ( !mPointVector.isEmpty() )
3030
{
3131
for ( int i = 0; i < mPointVector.count(); i++ )
3232
{
@@ -35,7 +35,7 @@ DualEdgeTriangulation::~DualEdgeTriangulation()
3535
}
3636

3737
//remove all the HalfEdge
38-
if ( mHalfEdge.count() > 0 )
38+
if ( !mHalfEdge.isEmpty() )
3939
{
4040
for ( int i = 0; i < mHalfEdge.count(); i++ )
4141
{
@@ -114,7 +114,7 @@ int DualEdgeTriangulation::addPoint( Point3D* p )
114114
// QgsDebugMsg( QString("inserting point %1,%2//%3//%4").arg(mPointVector.count()).arg(p->getX()).arg(p->getY()).arg(p->getZ()));
115115

116116
//first update the bounding box
117-
if ( mPointVector.count() == 0 )//update bounding box when the first point is inserted
117+
if ( mPointVector.isEmpty() )//update bounding box when the first point is inserted
118118
{
119119
xMin = ( *p ).getX();
120120
yMin = ( *p ).getY();
@@ -743,7 +743,7 @@ void DualEdgeTriangulation::doSwap( unsigned int edge, unsigned int recursiveDee
743743
void DualEdgeTriangulation::draw( QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height ) const
744744
{
745745
//if mPointVector is empty, there is nothing to do
746-
if ( mPointVector.count() == 0 )
746+
if ( mPointVector.isEmpty() )
747747
{
748748
return;
749749
}

src/analysis/interpolation/NormVecDecorator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
NormVecDecorator::~NormVecDecorator()
2323
{
2424
//remove all the normals
25-
if ( mNormVec->count() > 0 )
25+
if ( !mNormVec->isEmpty() )
2626
{
2727
for ( int i = 0; i < mNormVec->count(); i++ )
2828
{

src/analysis/raster/qgsrelief.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ void QgsRelief::optimiseClassBreaks( QList<int>& breaks, double* frequencies )
701701
}
702702

703703
double aParam, bParam;
704-
if ( regressionInput.size() > 0 && calculateRegression( regressionInput, aParam, bParam ) )
704+
if ( !regressionInput.isEmpty() && calculateRegression( regressionInput, aParam, bParam ) )
705705
{
706706
a[i] = aParam;
707707
b[i] = bParam;

src/app/composer/qgscomposer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
16411641
// else, we need to choose a directory
16421642
else
16431643
{
1644-
if ( atlasMap->filenamePattern().size() == 0 )
1644+
if ( atlasMap->filenamePattern().isEmpty() )
16451645
{
16461646
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
16471647
tr( "The filename pattern is empty. A default one will be used." ),
@@ -2127,7 +2127,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
21272127
else
21282128
{
21292129
// else, it has an atlas to render, so a directory must first be selected
2130-
if ( atlasMap->filenamePattern().size() == 0 )
2130+
if ( atlasMap->filenamePattern().isEmpty() )
21312131
{
21322132
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
21332133
tr( "The filename pattern is empty. A default one will be used." ),
@@ -2484,7 +2484,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
24842484
else
24852485
{
24862486
// If we have an Atlas
2487-
if ( atlasMap->filenamePattern().size() == 0 )
2487+
if ( atlasMap->filenamePattern().isEmpty() )
24882488
{
24892489
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
24902490
tr( "The filename pattern is empty. A default one will be used." ),

src/app/composer/qgscomposermanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void QgsComposerManager::toggleButtons()
173173

174174
void QgsComposerManager::addTemplates( const QMap<QString, QString>& templates )
175175
{
176-
if ( templates.size() > 0 )
176+
if ( !templates.isEmpty() )
177177
{
178178
mTemplate->insertSeparator( mTemplate->count() );
179179
QMap<QString, QString>::const_iterator templateIt = templates.constBegin();

src/app/composer/qgscomposermapwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ bool QgsComposerMapWidget::hasPredefinedScales() const
11721172
QSettings settings;
11731173
QString scalesStr( settings.value( "Map/scales", PROJECT_SCALES ).toString() );
11741174
QStringList myScalesList = scalesStr.split( ',' );
1175-
return myScalesList.size() > 0 && myScalesList[0] != "";
1175+
return !myScalesList.isEmpty() && myScalesList[0] != "";
11761176
}
11771177
return true;
11781178
}

src/app/legend/qgsapplegendinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void QgsAppLegendInterface::onAddedChildren( QgsLayerTreeNode* node, int indexFr
314314
emit itemAdded( mLayerTreeView->layerTreeModel()->node2index( child ) );
315315

316316
// also notify about all children
317-
if ( QgsLayerTree::isGroup( child ) && child->children().count() )
317+
if ( QgsLayerTree::isGroup( child ) && !child->children().isEmpty() )
318318
onAddedChildren( child, 0, child->children().count() - 1 );
319319
}
320320
}

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
140140
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex );
141141

142142
QgsPoint curPos = snapPointFromResults( snapResults, e->pos() );
143-
QgsPoint pressPos = snapResults.size() > 0 ? mClosestMapVertex : toMapCoordinates( mPressCoordinates );
143+
QgsPoint pressPos = !snapResults.isEmpty() ? mClosestMapVertex : toMapCoordinates( mPressCoordinates );
144144
double deltaX = curPos.x() - pressPos.x();
145145
double deltaY = curPos.y() - pressPos.y();
146146

@@ -288,7 +288,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
288288
if ( !mIsPoint )
289289
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol, QList<QgsPoint>(), true );
290290

291-
if ( snapResults.size() > 0 )
291+
if ( !snapResults.isEmpty() )
292292
{
293293
// need to check all if there is a point in the feature
294294
mAnother = snapResults.first().snappedAtGeometry;
@@ -431,7 +431,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
431431
QgsPoint releaseLayerCoords = toLayerCoordinates( vlayer, snapPointFromResults( snapResults, e->pos() ) );
432432

433433
QgsPoint pressLayerCoords;
434-
if ( snapResults.size() > 0 )
434+
if ( !snapResults.isEmpty() )
435435
{
436436
pressLayerCoords = toLayerCoordinates( vlayer, mClosestMapVertex );
437437

src/app/ogr/qgsopenvectorlayerdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
272272
if ( radioSrcFile->isChecked() )
273273
{
274274
QStringList selected = openFile();
275-
if ( selected.count() > 0 )
275+
if ( !selected.isEmpty() )
276276
{
277277
inputSrcDataset->setText( selected.join( ";" ) );
278278
buttonBox->button( QDialogButtonBox::Open )->setFocus();

src/app/qgisapp.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,7 @@ void QgisApp::updateNewLayerInsertionPoint()
27492749

27502750
void QgisApp::autoSelectAddedLayer( QList<QgsMapLayer*> layers )
27512751
{
2752-
if ( layers.count() )
2752+
if ( !layers.isEmpty() )
27532753
{
27542754
QgsLayerTreeLayer* nodeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( layers[0]->id() );
27552755

@@ -3172,7 +3172,7 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
31723172
delete layer;
31733173

31743174
}
3175-
else if ( sublayers.count() > 0 ) // there is 1 layer of data available
3175+
else if ( !sublayers.isEmpty() ) // there is 1 layer of data available
31763176
{
31773177
//set friendly name for datasources with only one layer
31783178
QStringList sublayers = layer->dataProvider()->subLayers();
@@ -3208,7 +3208,7 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
32083208
}
32093209

32103210
// make sure at least one layer was successfully added
3211-
if ( myList.count() == 0 )
3211+
if ( myList.isEmpty() )
32123212
{
32133213
return false;
32143214
}
@@ -4016,7 +4016,7 @@ void QgisApp::fileOpenAfterLaunch()
40164016
connect( this, SIGNAL( newProject() ), this, SLOT( showMapCanvas() ) );
40174017
return;
40184018
}
4019-
if ( mProjOpen == 1 && mRecentProjects.size() > 0 ) // most recent project
4019+
if ( mProjOpen == 1 && !mRecentProjects.isEmpty() ) // most recent project
40204020
{
40214021
projPath = mRecentProjects.at( 0 ).path;
40224022
}
@@ -5503,7 +5503,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer* vlayer, bool symbologyOpt
55035503
if ( d.exec() == QDialog::Accepted )
55045504
{
55055505
QList< int > sdt = d.selectedDatumTransform();
5506-
if ( sdt.size() > 0 )
5506+
if ( !sdt.isEmpty() )
55075507
{
55085508
ct->setSourceDatumTransform( sdt.at( 0 ) );
55095509
}
@@ -6713,7 +6713,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
67136713
}
67146714
}
67156715

6716-
QGis::WkbType wkbType = typeCounts.size() > 0 ? typeCounts.keys().value( 0 ) : QGis::WKBPoint;
6716+
QGis::WkbType wkbType = !typeCounts.isEmpty() ? typeCounts.keys().value( 0 ) : QGis::WKBPoint;
67176717

67186718
QString typeName = QString( QGis::featureType( wkbType ) ).remove( "WKB" );
67196719

@@ -6723,11 +6723,11 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
67236723

67246724
QString message;
67256725

6726-
if ( features.size() == 0 )
6726+
if ( features.isEmpty() )
67276727
{
67286728
message = tr( "No features in clipboard." ); // should not happen
67296729
}
6730-
else if ( typeCounts.size() == 0 )
6730+
else if ( typeCounts.isEmpty() )
67316731
{
67326732
message = tr( "No features with geometry found, point type layer will be created." );
67336733
}
@@ -7248,11 +7248,11 @@ void QgisApp::updateLayerModifiedActions()
72487248
mActionRollbackEdits->setEnabled( QgsLayerTreeUtils::layersModified( selectedLayerNodes ) );
72497249
mActionCancelEdits->setEnabled( QgsLayerTreeUtils::layersEditable( selectedLayerNodes ) );
72507250

7251-
bool hasEditLayers = ( editableLayers().count() > 0 );
7251+
bool hasEditLayers = !editableLayers().isEmpty();
72527252
mActionAllEdits->setEnabled( hasEditLayers );
72537253
mActionCancelAllEdits->setEnabled( hasEditLayers );
72547254

7255-
bool hasModifiedLayers = ( editableLayers( true ).count() > 0 );
7255+
bool hasModifiedLayers = !editableLayers( true ).isEmpty();
72567256
mActionSaveAllEdits->setEnabled( hasModifiedLayers );
72577257
mActionRollbackAllEdits->setEnabled( hasModifiedLayers );
72587258
}
@@ -8340,7 +8340,7 @@ void QgisApp::embedLayers()
83408340
}
83418341

83428342
mMapCanvas->freeze( false );
8343-
if ( groups.size() > 0 || layerIds.size() > 0 )
8343+
if ( !groups.isEmpty() || !layerIds.isEmpty() )
83448344
{
83458345
mMapCanvas->refresh();
83468346
}
@@ -8558,7 +8558,7 @@ void QgisApp::removePluginMenu( const QString& name, QAction* action )
85588558
{
85598559
QMenu* menu = getPluginMenu( name );
85608560
menu->removeAction( action );
8561-
if ( menu->actions().count() == 0 )
8561+
if ( menu->actions().isEmpty() )
85628562
{
85638563
mPluginMenu->removeAction( menu->menuAction() );
85648564
}
@@ -8857,13 +8857,13 @@ void QgisApp::removePluginDatabaseMenu( const QString& name, QAction* action )
88578857
{
88588858
QMenu* menu = getDatabaseMenu( name );
88598859
menu->removeAction( action );
8860-
if ( menu->actions().count() == 0 )
8860+
if ( menu->actions().isEmpty() )
88618861
{
88628862
mDatabaseMenu->removeAction( menu->menuAction() );
88638863
}
88648864

88658865
// remove the Database menu from the menuBar if there are no more actions
8866-
if ( mDatabaseMenu->actions().count() > 0 )
8866+
if ( !mDatabaseMenu->actions().isEmpty() )
88678867
return;
88688868

88698869
QList<QAction*> actions = menuBar()->actions();
@@ -8881,7 +8881,7 @@ void QgisApp::removePluginRasterMenu( const QString& name, QAction* action )
88818881
{
88828882
QMenu* menu = getRasterMenu( name );
88838883
menu->removeAction( action );
8884-
if ( menu->actions().count() == 0 )
8884+
if ( menu->actions().isEmpty() )
88858885
{
88868886
mRasterMenu->removeAction( menu->menuAction() );
88878887
}
@@ -8899,13 +8899,13 @@ void QgisApp::removePluginVectorMenu( const QString& name, QAction* action )
88998899
{
89008900
QMenu* menu = getVectorMenu( name );
89018901
menu->removeAction( action );
8902-
if ( menu->actions().count() == 0 )
8902+
if ( menu->actions().isEmpty() )
89038903
{
89048904
mVectorMenu->removeAction( menu->menuAction() );
89058905
}
89068906

89078907
// remove the Vector menu from the menuBar if there are no more actions
8908-
if ( mVectorMenu->actions().count() > 0 )
8908+
if ( !mVectorMenu->actions().isEmpty() )
89098909
return;
89108910

89118911
QList<QAction*> actions = menuBar()->actions();
@@ -8923,13 +8923,13 @@ void QgisApp::removePluginWebMenu( const QString& name, QAction* action )
89238923
{
89248924
QMenu* menu = getWebMenu( name );
89258925
menu->removeAction( action );
8926-
if ( menu->actions().count() == 0 )
8926+
if ( menu->actions().isEmpty() )
89278927
{
89288928
mWebMenu->removeAction( menu->menuAction() );
89298929
}
89308930

89318931
// remove the Web menu from the menuBar if there are no more actions
8932-
if ( mWebMenu->actions().count() > 0 )
8932+
if ( !mWebMenu->actions().isEmpty() )
89338933
return;
89348934

89358935
QList<QAction*> actions = menuBar()->actions();
@@ -9345,9 +9345,9 @@ void QgisApp::legendLayerSelectionChanged( void )
93459345
{
93469346
QList<QgsLayerTreeLayer*> selectedLayers = mLayerTreeView ? mLayerTreeView->selectedLayerNodes() : QList<QgsLayerTreeLayer*>();
93479347

9348-
mActionDuplicateLayer->setEnabled( selectedLayers.count() > 0 );
9349-
mActionSetLayerScaleVisibility->setEnabled( selectedLayers.count() > 0 );
9350-
mActionSetLayerCRS->setEnabled( selectedLayers.count() > 0 );
9348+
mActionDuplicateLayer->setEnabled( !selectedLayers.isEmpty() );
9349+
mActionSetLayerScaleVisibility->setEnabled( !selectedLayers.isEmpty() );
9350+
mActionSetLayerCRS->setEnabled( !selectedLayers.isEmpty() );
93519351
mActionSetProjectCRSFromLayer->setEnabled( selectedLayers.count() == 1 );
93529352

93539353
mActionSaveEdits->setEnabled( QgsLayerTreeUtils::layersModified( selectedLayers ) );
@@ -9519,7 +9519,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
95199519

95209520
bool isEditable = vlayer->isEditable();
95219521
bool layerHasSelection = vlayer->selectedFeatureCount() > 0;
9522-
bool layerHasActions = vlayer->actions()->size() + QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).size() > 0;
9522+
bool layerHasActions = vlayer->actions()->size() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
95239523

95249524
mActionLocalHistogramStretch->setEnabled( false );
95259525
mActionFullHistogramStretch->setEnabled( false );
@@ -9782,7 +9782,7 @@ void QgisApp::refreshActionFeatureAction()
97829782

97839783
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
97849784

9785-
bool layerHasActions = vlayer->actions()->size() + QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).size() > 0;
9785+
bool layerHasActions = vlayer->actions()->size() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
97869786
mActionFeatureAction->setEnabled( layerHasActions );
97879787
}
97889788

@@ -10041,7 +10041,7 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
1004110041
QString msg;
1004210042

1004310043
msg = tr( "%1 is not a supported raster data source" ).arg( *myIterator );
10044-
if ( errMsg.size() > 0 )
10044+
if ( !errMsg.isEmpty() )
1004510045
msg += '\n' + errMsg;
1004610046
error.append( QGS_ERROR_MESSAGE( msg, tr( "Raster layer" ) ) );
1004710047

src/app/qgsaddtaborgroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ QgsAddTabOrGroup::QgsAddTabOrGroup( QgsVectorLayer *lyr, const QList < TabPair >
3333

3434
mTabButton->setChecked( true );
3535
mTabList->setEnabled( false );
36-
if ( mTabs.size() > 0 )
36+
if ( !mTabs.isEmpty() )
3737
{
3838
int i = 0;
3939
Q_FOREACH ( const TabPair& tab, mTabs )

src/app/qgsbookmarks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void QgsBookmarks::deleteClicked()
181181
}
182182
}
183183

184-
if ( rows.size() == 0 )
184+
if ( rows.isEmpty() )
185185
return;
186186

187187
// make sure the user really wants to delete these bookmarks

src/app/qgsbrowserdockwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
421421
menu->addActions( actions );
422422
}
423423

424-
if ( menu->actions().count() == 0 )
424+
if ( menu->actions().isEmpty() )
425425
{
426426
delete menu;
427427
return;

src/app/qgsconfigureshortcutsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void QgsConfigureShortcutsDialog::setCurrentActionShortcut( const QKeySequence&
412412
// reset action of the conflicting other action!
413413
QgsShortcutsManager::instance()->setActionShortcut( otherAction, QString() );
414414
QList<QTreeWidgetItem*> items = treeActions->findItems( otherActionText, Qt::MatchExactly );
415-
if ( items.count() > 0 ) // there should be exactly one
415+
if ( !items.isEmpty() ) // there should be exactly one
416416
items[0]->setText( 1, QString() );
417417
}
418418

src/app/qgsdiagramproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
246246

247247
//assume single category or linearly interpolated diagram renderer for now
248248
QList<QgsDiagramSettings> settingList = dr->diagramSettings();
249-
if ( settingList.size() > 0 )
249+
if ( !settingList.isEmpty() )
250250
{
251251
mEnableDiagramsCheckBox->setChecked( settingList.at( 0 ).enabled );
252252
mDiagramTypeFrame->setEnabled( mEnableDiagramsCheckBox->isChecked() );

0 commit comments

Comments
 (0)