Skip to content

Commit

Permalink
Change size()/count() == 0 and count() > 0 to isEmpty() checks
Browse files Browse the repository at this point in the history
Because:
- easier to read
- follows recommendations by clazy/KDAB
- potentially performance benefits
  • Loading branch information
nyalldawson committed Dec 8, 2015
1 parent 269f709 commit ee72079
Show file tree
Hide file tree
Showing 187 changed files with 489 additions and 489 deletions.
8 changes: 4 additions & 4 deletions src/analysis/interpolation/DualEdgeTriangulation.cc
Expand Up @@ -26,7 +26,7 @@ double leftOfTresh = 0.00000001;
DualEdgeTriangulation::~DualEdgeTriangulation()
{
//remove all the points
if ( mPointVector.count() > 0 )
if ( !mPointVector.isEmpty() )
{
for ( int i = 0; i < mPointVector.count(); i++ )
{
Expand All @@ -35,7 +35,7 @@ DualEdgeTriangulation::~DualEdgeTriangulation()
}

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

//first update the bounding box
if ( mPointVector.count() == 0 )//update bounding box when the first point is inserted
if ( mPointVector.isEmpty() )//update bounding box when the first point is inserted
{
xMin = ( *p ).getX();
yMin = ( *p ).getY();
Expand Down Expand Up @@ -743,7 +743,7 @@ void DualEdgeTriangulation::doSwap( unsigned int edge, unsigned int recursiveDee
void DualEdgeTriangulation::draw( QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height ) const
{
//if mPointVector is empty, there is nothing to do
if ( mPointVector.count() == 0 )
if ( mPointVector.isEmpty() )
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/NormVecDecorator.cc
Expand Up @@ -22,7 +22,7 @@
NormVecDecorator::~NormVecDecorator()
{
//remove all the normals
if ( mNormVec->count() > 0 )
if ( !mNormVec->isEmpty() )
{
for ( int i = 0; i < mNormVec->count(); i++ )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrelief.cpp
Expand Up @@ -701,7 +701,7 @@ void QgsRelief::optimiseClassBreaks( QList<int>& breaks, double* frequencies )
}

double aParam, bParam;
if ( regressionInput.size() > 0 && calculateRegression( regressionInput, aParam, bParam ) )
if ( !regressionInput.isEmpty() && calculateRegression( regressionInput, aParam, bParam ) )
{
a[i] = aParam;
b[i] = bParam;
Expand Down
6 changes: 3 additions & 3 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -1641,7 +1641,7 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
// else, we need to choose a directory
else
{
if ( atlasMap->filenamePattern().size() == 0 )
if ( atlasMap->filenamePattern().isEmpty() )
{
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
tr( "The filename pattern is empty. A default one will be used." ),
Expand Down Expand Up @@ -2127,7 +2127,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
else
{
// else, it has an atlas to render, so a directory must first be selected
if ( atlasMap->filenamePattern().size() == 0 )
if ( atlasMap->filenamePattern().isEmpty() )
{
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
tr( "The filename pattern is empty. A default one will be used." ),
Expand Down Expand Up @@ -2484,7 +2484,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
else
{
// If we have an Atlas
if ( atlasMap->filenamePattern().size() == 0 )
if ( atlasMap->filenamePattern().isEmpty() )
{
int res = QMessageBox::warning( 0, tr( "Empty filename pattern" ),
tr( "The filename pattern is empty. A default one will be used." ),
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermanager.cpp
Expand Up @@ -173,7 +173,7 @@ void QgsComposerManager::toggleButtons()

void QgsComposerManager::addTemplates( const QMap<QString, QString>& templates )
{
if ( templates.size() > 0 )
if ( !templates.isEmpty() )
{
mTemplate->insertSeparator( mTemplate->count() );
QMap<QString, QString>::const_iterator templateIt = templates.constBegin();
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -1172,7 +1172,7 @@ bool QgsComposerMapWidget::hasPredefinedScales() const
QSettings settings;
QString scalesStr( settings.value( "Map/scales", PROJECT_SCALES ).toString() );
QStringList myScalesList = scalesStr.split( ',' );
return myScalesList.size() > 0 && myScalesList[0] != "";
return !myScalesList.isEmpty() && myScalesList[0] != "";
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -314,7 +314,7 @@ void QgsAppLegendInterface::onAddedChildren( QgsLayerTreeNode* node, int indexFr
emit itemAdded( mLayerTreeView->layerTreeModel()->node2index( child ) );

// also notify about all children
if ( QgsLayerTree::isGroup( child ) && child->children().count() )
if ( QgsLayerTree::isGroup( child ) && !child->children().isEmpty() )
onAddedChildren( child, 0, child->children().count() - 1 );
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -140,7 +140,7 @@ void QgsMapToolNodeTool::canvasMoveEvent( QgsMapMouseEvent* e )
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex );

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

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

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

QgsPoint pressLayerCoords;
if ( snapResults.size() > 0 )
if ( !snapResults.isEmpty() )
{
pressLayerCoords = toLayerCoordinates( vlayer, mClosestMapVertex );

Expand Down
2 changes: 1 addition & 1 deletion src/app/ogr/qgsopenvectorlayerdialog.cpp
Expand Up @@ -272,7 +272,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
if ( radioSrcFile->isChecked() )
{
QStringList selected = openFile();
if ( selected.count() > 0 )
if ( !selected.isEmpty() )
{
inputSrcDataset->setText( selected.join( ";" ) );
buttonBox->button( QDialogButtonBox::Open )->setFocus();
Expand Down
50 changes: 25 additions & 25 deletions src/app/qgisapp.cpp
Expand Up @@ -2749,7 +2749,7 @@ void QgisApp::updateNewLayerInsertionPoint()

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

Expand Down Expand Up @@ -3172,7 +3172,7 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
delete layer;

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

// make sure at least one layer was successfully added
if ( myList.count() == 0 )
if ( myList.isEmpty() )
{
return false;
}
Expand Down Expand Up @@ -4016,7 +4016,7 @@ void QgisApp::fileOpenAfterLaunch()
connect( this, SIGNAL( newProject() ), this, SLOT( showMapCanvas() ) );
return;
}
if ( mProjOpen == 1 && mRecentProjects.size() > 0 ) // most recent project
if ( mProjOpen == 1 && !mRecentProjects.isEmpty() ) // most recent project
{
projPath = mRecentProjects.at( 0 ).path;
}
Expand Down Expand Up @@ -5503,7 +5503,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer* vlayer, bool symbologyOpt
if ( d.exec() == QDialog::Accepted )
{
QList< int > sdt = d.selectedDatumTransform();
if ( sdt.size() > 0 )
if ( !sdt.isEmpty() )
{
ct->setSourceDatumTransform( sdt.at( 0 ) );
}
Expand Down Expand Up @@ -6713,7 +6713,7 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
}
}

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

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

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

QString message;

if ( features.size() == 0 )
if ( features.isEmpty() )
{
message = tr( "No features in clipboard." ); // should not happen
}
else if ( typeCounts.size() == 0 )
else if ( typeCounts.isEmpty() )
{
message = tr( "No features with geometry found, point type layer will be created." );
}
Expand Down Expand Up @@ -7248,11 +7248,11 @@ void QgisApp::updateLayerModifiedActions()
mActionRollbackEdits->setEnabled( QgsLayerTreeUtils::layersModified( selectedLayerNodes ) );
mActionCancelEdits->setEnabled( QgsLayerTreeUtils::layersEditable( selectedLayerNodes ) );

bool hasEditLayers = ( editableLayers().count() > 0 );
bool hasEditLayers = !editableLayers().isEmpty();
mActionAllEdits->setEnabled( hasEditLayers );
mActionCancelAllEdits->setEnabled( hasEditLayers );

bool hasModifiedLayers = ( editableLayers( true ).count() > 0 );
bool hasModifiedLayers = !editableLayers( true ).isEmpty();
mActionSaveAllEdits->setEnabled( hasModifiedLayers );
mActionRollbackAllEdits->setEnabled( hasModifiedLayers );
}
Expand Down Expand Up @@ -8340,7 +8340,7 @@ void QgisApp::embedLayers()
}

mMapCanvas->freeze( false );
if ( groups.size() > 0 || layerIds.size() > 0 )
if ( !groups.isEmpty() || !layerIds.isEmpty() )
{
mMapCanvas->refresh();
}
Expand Down Expand Up @@ -8558,7 +8558,7 @@ void QgisApp::removePluginMenu( const QString& name, QAction* action )
{
QMenu* menu = getPluginMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
mPluginMenu->removeAction( menu->menuAction() );
}
Expand Down Expand Up @@ -8857,13 +8857,13 @@ void QgisApp::removePluginDatabaseMenu( const QString& name, QAction* action )
{
QMenu* menu = getDatabaseMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
mDatabaseMenu->removeAction( menu->menuAction() );
}

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

QList<QAction*> actions = menuBar()->actions();
Expand All @@ -8881,7 +8881,7 @@ void QgisApp::removePluginRasterMenu( const QString& name, QAction* action )
{
QMenu* menu = getRasterMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
mRasterMenu->removeAction( menu->menuAction() );
}
Expand All @@ -8899,13 +8899,13 @@ void QgisApp::removePluginVectorMenu( const QString& name, QAction* action )
{
QMenu* menu = getVectorMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
mVectorMenu->removeAction( menu->menuAction() );
}

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

QList<QAction*> actions = menuBar()->actions();
Expand All @@ -8923,13 +8923,13 @@ void QgisApp::removePluginWebMenu( const QString& name, QAction* action )
{
QMenu* menu = getWebMenu( name );
menu->removeAction( action );
if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
mWebMenu->removeAction( menu->menuAction() );
}

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

QList<QAction*> actions = menuBar()->actions();
Expand Down Expand Up @@ -9345,9 +9345,9 @@ void QgisApp::legendLayerSelectionChanged( void )
{
QList<QgsLayerTreeLayer*> selectedLayers = mLayerTreeView ? mLayerTreeView->selectedLayerNodes() : QList<QgsLayerTreeLayer*>();

mActionDuplicateLayer->setEnabled( selectedLayers.count() > 0 );
mActionSetLayerScaleVisibility->setEnabled( selectedLayers.count() > 0 );
mActionSetLayerCRS->setEnabled( selectedLayers.count() > 0 );
mActionDuplicateLayer->setEnabled( !selectedLayers.isEmpty() );
mActionSetLayerScaleVisibility->setEnabled( !selectedLayers.isEmpty() );
mActionSetLayerCRS->setEnabled( !selectedLayers.isEmpty() );
mActionSetProjectCRSFromLayer->setEnabled( selectedLayers.count() == 1 );

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

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

mActionLocalHistogramStretch->setEnabled( false );
mActionFullHistogramStretch->setEnabled( false );
Expand Down Expand Up @@ -9782,7 +9782,7 @@ void QgisApp::refreshActionFeatureAction()

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

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

Expand Down Expand Up @@ -10041,7 +10041,7 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
QString msg;

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

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsaddtaborgroup.cpp
Expand Up @@ -33,7 +33,7 @@ QgsAddTabOrGroup::QgsAddTabOrGroup( QgsVectorLayer *lyr, const QList < TabPair >

mTabButton->setChecked( true );
mTabList->setEnabled( false );
if ( mTabs.size() > 0 )
if ( !mTabs.isEmpty() )
{
int i = 0;
Q_FOREACH ( const TabPair& tab, mTabs )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -181,7 +181,7 @@ void QgsBookmarks::deleteClicked()
}
}

if ( rows.size() == 0 )
if ( rows.isEmpty() )
return;

// make sure the user really wants to delete these bookmarks
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -421,7 +421,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
menu->addActions( actions );
}

if ( menu->actions().count() == 0 )
if ( menu->actions().isEmpty() )
{
delete menu;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsconfigureshortcutsdialog.cpp
Expand Up @@ -412,7 +412,7 @@ void QgsConfigureShortcutsDialog::setCurrentActionShortcut( const QKeySequence&
// reset action of the conflicting other action!
QgsShortcutsManager::instance()->setActionShortcut( otherAction, QString() );
QList<QTreeWidgetItem*> items = treeActions->findItems( otherActionText, Qt::MatchExactly );
if ( items.count() > 0 ) // there should be exactly one
if ( !items.isEmpty() ) // there should be exactly one
items[0]->setText( 1, QString() );
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdiagramproperties.cpp
Expand Up @@ -246,7 +246,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare

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

0 comments on commit ee72079

Please sign in to comment.