Skip to content
Permalink
Browse files

Clazy issues:

- use at() instead of [] for temporary containers (at() returns
const reference, so it avoids the detach which occurs with [])
- use at( 0 ) rather than first() for containers, because first()
detaches (Qt5 introduced constFirst()/constLast() to overcome this)
  • Loading branch information
nyalldawson committed Oct 20, 2015
1 parent 099a40b commit 9a94132fb441340290e823004392b72a8cc0a707
@@ -3277,7 +3277,7 @@ bool QgisApp::askUserForZipItemLayers( QString path )
QStringList layers;
for ( int i = 0; i < zipItem->children().size(); i++ )
{
QgsDataItem *item = zipItem->children()[i];
QgsDataItem *item = zipItem->children().at( i );
QgsLayerItem *layerItem = dynamic_cast<QgsLayerItem *>( item );
if ( layerItem )
{
@@ -3299,7 +3299,7 @@ bool QgisApp::askUserForZipItemLayers( QString path )
{
Q_FOREACH ( int i, chooseSublayersDialog.selectionIndexes() )
{
childItems << zipItem->children()[i];
childItems << zipItem->children().at( i );
}
}
}
@@ -311,7 +311,7 @@ void QgsFieldsProperties::loadRelations()
item->setFlags( Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mRelationsList->setItem( idx, RelLayerCol, item );

item = new QTableWidgetItem( relation.fieldPairs().first().referencingField() );
item = new QTableWidgetItem( relation.fieldPairs().at( 0 ).referencingField() );
item->setFlags( Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mRelationsList->setItem( idx, RelFieldCol, item );

@@ -580,7 +580,7 @@ QgsIdentifyPlotCurve::QgsIdentifyPlotCurve( const QMap<QString, QString> &attrib

if ( color == QColor() )
{
color = QgsVectorRandomColorRampV2::randomColors( 1 )[0];
color = QgsVectorRandomColorRampV2::randomColors( 1 ).at( 0 );
}
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
mPlotCurve->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
@@ -335,8 +335,8 @@ void QgsBrowser::saveWindowState()
QSettings settings;
settings.setValue( "/Windows/Browser/state", saveState() );
settings.setValue( "/Windows/Browser/geometry", saveGeometry() );
settings.setValue( "/Windows/Browser/sizes/0", splitter->sizes()[0] );
settings.setValue( "/Windows/Browser/sizes/1", splitter->sizes()[1] );
settings.setValue( "/Windows/Browser/sizes/0", splitter->sizes().at( 0 ) );
settings.setValue( "/Windows/Browser/sizes/1", splitter->sizes().at( 1 ) );
}

void QgsBrowser::restoreWindowState()
@@ -257,7 +257,7 @@ int QgsAtlasComposition::updateFeatures()

if ( mSortFeatures && sortIdx != -1 )
{
mFeatureKeys.insert( feat.id(), feat.attributes()[ sortIdx ] );
mFeatureKeys.insert( feat.id(), feat.attributes().at( sortIdx ) );
}
}

@@ -445,7 +445,7 @@ bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributeMap> &at
int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
if ( idx != -1 )
{
attributeMaps.last().insert( i, f.attributes()[idx] );
attributeMaps.last().insert( i, f.attributes().at( idx ) );
}
else
{
@@ -549,7 +549,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
int idx = layer->fieldNameIndex(( *columnIt )->attribute() );
if ( idx != -1 )
{
currentRow << replaceWrapChar( f.attributes()[idx] );
currentRow << replaceWrapChar( f.attributes().at( idx ) );
}
else
{
@@ -52,7 +52,7 @@ QSizeF QgsPieDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCon
}
else
{
attrVal = feature.attributes()[is.classificationAttribute];
attrVal = feature.attributes().at( is.classificationAttribute );
}

if ( !attrVal.isValid() )
@@ -51,7 +51,7 @@ QSizeF QgsTextDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCo
}
else
{
attrVal = feature.attributes()[is.classificationAttribute];
attrVal = feature.attributes().at( is.classificationAttribute );
}

if ( !attrVal.isValid() )
@@ -99,7 +99,7 @@ static void _collectLayerIdsInGroup( QgsLayerTreeGroup* group, int indexFrom, in
{
for ( int i = indexFrom; i <= indexTo; ++i )
{
QgsLayerTreeNode* child = group->children()[i];
QgsLayerTreeNode* child = group->children().at( i );
if ( QgsLayerTree::isLayer( child ) )
{
lst << QgsLayerTree::toLayer( child )->layerId();
@@ -846,7 +846,7 @@ static QVariant fcnRegexpSubstr( const QVariantList& values, const QgsExpression
if ( re.captureCount() > 0 )
{
// return first capture
return QVariant( re.capturedTexts()[1] );
return QVariant( re.capturedTexts().at( 1 ) );
}
else
{
@@ -1197,7 +1197,7 @@ static QVariant fcnX( const QVariantList&, const QgsExpressionContext* context,
ENSURE_GEOM_TYPE( f, g, QGis::Point );
if ( g->isMultipart() )
{
return g->asMultiPoint()[ 0 ].x();
return g->asMultiPoint().at( 0 ).x();
}
else
{
@@ -1211,7 +1211,7 @@ static QVariant fcnY( const QVariantList&, const QgsExpressionContext* context,
ENSURE_GEOM_TYPE( f, g, QGis::Point );
if ( g->isMultipart() )
{
return g->asMultiPoint()[ 0 ].y();
return g->asMultiPoint().at( 0 ).y();
}
else
{
@@ -199,7 +199,7 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation& relation, bool
mReferencingLayer = relation.referencingLayer();
mRelationName = relation.name();
mReferencedLayer = relation.referencedLayer();
mFkeyFieldIdx = mReferencedLayer->fieldNameIndex( relation.fieldPairs().first().second );
mFkeyFieldIdx = mReferencedLayer->fieldNameIndex( relation.fieldPairs().at( 0 ).second );

QgsAttributeEditorContext context( mEditorContext, relation, QgsAttributeEditorContext::Single, QgsAttributeEditorContext::Embed );

@@ -485,7 +485,7 @@ void QgsRelationReferenceWidget::init()
QgsExpression exp( mReferencedLayer->displayExpression() );

requestedAttrs += exp.referencedColumns().toSet();
requestedAttrs << mRelation.fieldPairs().first().second;
requestedAttrs << mRelation.fieldPairs().at( 0 ).second;

QgsAttributeList attributes;
Q_FOREACH ( const QString& attr, requestedAttrs )
@@ -113,7 +113,7 @@ void QgsValueMapConfigDlg::removeSelectedButtonPushed()
}
for ( i = 0; i < rowsToRemove.values().size(); i++ )
{
tableWidget->removeRow( rowsToRemove.values()[i] - removed );
tableWidget->removeRow( rowsToRemove.values().at( i ) - removed );
removed++;
}
}
@@ -320,8 +320,8 @@ void QgsAttributeForm::onUpdatedFields()
int idx = mFeature.fields()->indexFromName( layer()->fields()[i].name() );
if ( idx != -1 )
{
attrs[i] = mFeature.attributes()[idx];
if ( mFeature.attributes()[idx].type() != layer()->fields()[i].type() )
attrs[i] = mFeature.attributes().at( idx );
if ( mFeature.attributes().at( idx ).type() != layer()->fields()[i].type() )
{
attrs[i].convert( layer()->fields()[i].type() );
}
@@ -57,15 +57,15 @@ void QgsRelationManagerDialog::addRelation( const QgsRelation &rel )
item->setFlags( Qt::ItemIsEditable );
mRelationsTable->setItem( row, 1, item );

item = new QTableWidgetItem( rel.fieldPairs().first().referencingField() );
item = new QTableWidgetItem( rel.fieldPairs().at( 0 ).referencingField() );
item->setFlags( Qt::ItemIsEditable );
mRelationsTable->setItem( row, 2, item );

item = new QTableWidgetItem( rel.referencedLayer()->name() );
item->setFlags( Qt::ItemIsEditable );
mRelationsTable->setItem( row, 3, item );

item = new QTableWidgetItem( rel.fieldPairs().first().referencedField() );
item = new QTableWidgetItem( rel.fieldPairs().at( 0 ).referencedField() );
item->setFlags( Qt::ItemIsEditable );
mRelationsTable->setItem( row, 4, item );

@@ -89,9 +89,9 @@ void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
if ( addDlg.relationId() == "" )
relationId = QString( "%1_%2_%3_%4" )
.arg( addDlg.referencingLayerId(),
addDlg.references().first().first,
addDlg.references().at( 0 ).first,
addDlg.referencedLayerId(),
addDlg.references().first().second );
addDlg.references().at( 0 ).second );

QStringList existingNames;

@@ -109,7 +109,7 @@ void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
++suffix;
}
relation.setRelationId( relationId );
relation.addFieldPair( addDlg.references().first().first, addDlg.references().first().second );
relation.addFieldPair( addDlg.references().at( 0 ).first, addDlg.references().at( 0 ).second );
relation.setRelationName( addDlg.relationName() );

addRelation( relation );
@@ -95,7 +95,7 @@ void QgsFeaturePool::updateFeature( QgsFeature& feature )
QgsAttributeMap attribMap;
for ( int i = 0, n = feature.attributes().size(); i < n; ++i )
{
attribMap.insert( i, feature.attributes()[i] );
attribMap.insert( i, feature.attributes().at( i ) );
}
changedAttributesMap.insert( feature.id(), attribMap );
mLayerMutex.lock();
@@ -1263,7 +1263,7 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
QgsMessageLog::logMessage( tr( "Second geometry missing or GEOS import failed." ), tr( "Topology plugin" ) );
continue;
}
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2->asPolyline().first() );
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2->asPolyline().at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2->asPolyline().last() );
touched = g1->intersects( startPoint ) || g1->intersects( endPoint );
delete startPoint;
@@ -1329,7 +1329,7 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
break;
QgsGeometry* g1 = it->feature.geometry();

QgsGeometry* startPoint = QgsGeometry::fromPoint( g1->asPolyline().first() );
QgsGeometry* startPoint = QgsGeometry::fromPoint( g1->asPolyline().at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1->asPolyline().last() );

QgsRectangle bb = g1->boundingBox();
@@ -437,7 +437,7 @@ void QgsDelimitedTextFile::setFieldNames( const QStringList &names )
// valid if the number matches its column number..
else if ( mDefaultFieldRegexp.indexIn( name ) == 0 )
{
int col = mDefaultFieldRegexp.capturedTexts()[1].toInt();
int col = mDefaultFieldRegexp.capturedTexts().at( 1 ).toInt();
nameOk = col == fieldNo;
}
// Otherwise it is valid if isn't the name of an existing field...
@@ -493,7 +493,7 @@ int QgsDelimitedTextFile::fieldIndex( QString name )
// Field_### and simple integer fields.
if ( mDefaultFieldRegexp.indexIn( name ) == 0 )
{
return mDefaultFieldRegexp.capturedTexts()[1].toInt() - 1;
return mDefaultFieldRegexp.capturedTexts().at( 1 ).toInt() - 1;
}
for ( int i = 0; i < mFieldNames.size(); i++ )
{
@@ -838,18 +838,18 @@ double QgsDelimitedTextProvider::dmsStringToDouble( const QString &sX, bool *xOk

*xOk = re.indexIn( sX ) == 0;
if ( ! *xOk ) return 0.0;
QString dms1 = re.capturedTexts()[2];
QString dms2 = re.capturedTexts()[3];
QString dms3 = re.capturedTexts()[4];
QString dms1 = re.capturedTexts().at( 2 );
QString dms2 = re.capturedTexts().at( 3 );
QString dms3 = re.capturedTexts().at( 4 );
x = dms3.toDouble( xOk );
// Allow for Degrees/minutes format as well as DMS
if ( ! dms2.isEmpty() )
{
x = dms2.toInt( xOk ) + x / 60.0;
}
x = dms1.toInt( xOk ) + x / 60.0;
QString sign1 = re.capturedTexts()[1];
QString sign2 = re.capturedTexts()[5];
QString sign1 = re.capturedTexts().at( 1 );
QString sign2 = re.capturedTexts().at( 5 );

if ( sign1.isEmpty() )
{
@@ -1317,11 +1317,11 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
{
continue;
}
if ( feature.attributes()[i].isNull() )
if ( feature.attributes().at( i ).isNull() )
{
continue;
}
addedFeature.setAttribute( i, feature.attributes()[i] );
addedFeature.setAttribute( i, feature.attributes().at( i ) );
}
addedFeatures[addedFid] = addedFeature;
}
@@ -936,7 +936,7 @@ void QgsGrassVectorMapLayer::updateAttributes( int cat, QgsFeature &feature, QSt
// update feature null values by existing values
if ( cacheIndex != -1 )
{
feature.setAttribute( i, mAttributes[cat][cacheIndex] );
feature.setAttribute( i, mAttributes[cat].at( cacheIndex ) );
}
continue;
}
@@ -148,8 +148,8 @@ void TestOpenStreetMap::importAndQueries()
QgsOSMWay w = db.way( 32137532 );
QCOMPARE( w.isValid(), true );
QCOMPARE( w.nodes().count(), 5 );
QCOMPARE( w.nodes()[0], ( qint64 )360769661 );
QCOMPARE( w.nodes()[1], ( qint64 )360769664 );
QCOMPARE( w.nodes().at( 0 ), ( qint64 )360769661 );
QCOMPARE( w.nodes().at( 1 ), ( qint64 )360769664 );

QgsOSMWay wNot = db.way( 1234567 );
QCOMPARE( wNot.isValid(), false );
@@ -174,7 +174,7 @@ void TestQgsAuthConfig::testPkiConfigBundle()
mconfig.setUri( "http://example.com" );
QVERIFY( mconfig.isValid( true ) );

QSslCertificate clientcert( QSslCertificate::fromPath( smPkiData + "/gerardus_cert.pem" ).first() );
QSslCertificate clientcert( QSslCertificate::fromPath( smPkiData + "/gerardus_cert.pem" ).at( 0 ) );
QByteArray keydata;
QFile file( smPkiData + "/gerardus_key.pem" );
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
@@ -201,7 +201,7 @@ void TestQgsAuthConfig::testConfigSslServer()
{
QString hostport( "localhost:443" );
QString confstr( "2|||470|||2|||10~~19|||0~~2" );
QSslCertificate sslcert( QSslCertificate::fromPath( smPkiData + "/localhost_ssl_cert.pem" ).first() );
QSslCertificate sslcert( QSslCertificate::fromPath( smPkiData + "/localhost_ssl_cert.pem" ).at( 0 ) );

QgsAuthConfigSslServer sslconfig;
QVERIFY( sslconfig.isNull() );
@@ -41,11 +41,11 @@ class TestQgsLayerTree : public QObject

Qt::CheckState childState( int childIndex )
{
return QgsLayerTree::toGroup( mRoot->children()[childIndex] )->isVisible();
return QgsLayerTree::toGroup( mRoot->children().at( childIndex ) )->isVisible();
}
void setChildState( int childIndex, Qt::CheckState state )
{
QgsLayerTree::toGroup( mRoot->children()[childIndex] )->setVisible( state );
QgsLayerTree::toGroup( mRoot->children().at( childIndex ) )->setVisible( state );
}
};

@@ -145,7 +145,7 @@ void TestQgsLayerTree::testCheckStateMutuallyExclusive()
QCOMPARE( mRoot->isVisible(), Qt::Checked );

// remove a child
mRoot->removeChildNode( mRoot->children()[0] );
mRoot->removeChildNode( mRoot->children().at( 0 ) );
QCOMPARE( childState( 0 ), Qt::Unchecked );
QCOMPARE( childState( 1 ), Qt::Checked );
QCOMPARE( mRoot->isVisible(), Qt::Checked );
@@ -158,7 +158,7 @@ void TestQgsLayerTree::testCheckStateMutuallyExclusive()
QCOMPARE( mRoot->isVisible(), Qt::Checked );

// remove a child that is checked
mRoot->removeChildNode( mRoot->children()[2] );
mRoot->removeChildNode( mRoot->children().at( 2 ) );
QCOMPARE( childState( 0 ), Qt::Unchecked );
QCOMPARE( childState( 1 ), Qt::Unchecked );
QCOMPARE( mRoot->isVisible(), Qt::Unchecked );
@@ -190,22 +190,22 @@ void TestQgsLayerTree::testCheckStateMutuallyExclusiveEdgeCases()
QgsLayerTreeGroup* root2 = new QgsLayerTreeGroup();
root2->setIsMutuallyExclusive( true );
root2->addGroup( "1" );
QCOMPARE( QgsLayerTree::toGroup( root2->children()[0] )->isVisible(), Qt::Checked );
QCOMPARE( QgsLayerTree::toGroup( root2->children().at( 0 ) )->isVisible(), Qt::Checked );
root2->addGroup( "2" );
QCOMPARE( QgsLayerTree::toGroup( root2->children()[0] )->isVisible(), Qt::Checked );
QCOMPARE( QgsLayerTree::toGroup( root2->children()[1] )->isVisible(), Qt::Unchecked );
QCOMPARE( QgsLayerTree::toGroup( root2->children().at( 0 ) )->isVisible(), Qt::Checked );
QCOMPARE( QgsLayerTree::toGroup( root2->children().at( 1 ) )->isVisible(), Qt::Unchecked );
delete root2;

// check-uncheck the only child
QgsLayerTreeGroup* root3 = new QgsLayerTreeGroup();
root3->setIsMutuallyExclusive( true );
root3->addGroup( "1" );
QCOMPARE( QgsLayerTree::toGroup( root3->children()[0] )->isVisible(), Qt::Checked );
QgsLayerTree::toGroup( root3->children()[0] )->setVisible( Qt::Unchecked );
QCOMPARE( QgsLayerTree::toGroup( root3->children()[0] )->isVisible(), Qt::Unchecked );
QCOMPARE( QgsLayerTree::toGroup( root3->children().at( 0 ) )->isVisible(), Qt::Checked );
QgsLayerTree::toGroup( root3->children().at( 0 ) )->setVisible( Qt::Unchecked );
QCOMPARE( QgsLayerTree::toGroup( root3->children().at( 0 ) )->isVisible(), Qt::Unchecked );
QCOMPARE( root3->isVisible(), Qt::Unchecked );
QgsLayerTree::toGroup( root3->children()[0] )->setVisible( Qt::Checked );
QCOMPARE( QgsLayerTree::toGroup( root3->children()[0] )->isVisible(), Qt::Checked );
QgsLayerTree::toGroup( root3->children().at( 0 ) )->setVisible( Qt::Checked );
QCOMPARE( QgsLayerTree::toGroup( root3->children().at( 0 ) )->isVisible(), Qt::Checked );
QCOMPARE( root3->isVisible(), Qt::Checked );
delete root3;
}

0 comments on commit 9a94132

Please sign in to comment.
You can’t perform that action at this time.