Skip to content
Permalink
Browse files

Avoid potential QgsFields detachments

  • Loading branch information
nyalldawson committed Aug 4, 2016
1 parent ed4d34f commit 4f3564cc7bb54b9b9ff418d1cc2c43a699da3394
@@ -192,7 +192,7 @@ void QgsOverlayAnalyzer::combineFieldLists( QgsFields& fieldListA, const QgsFiel

for ( int idx = 0; idx < fieldListB.count(); ++idx )
{
QgsField field = fieldListB[idx];
QgsField field = fieldListB.at( idx );
int count = 0;
while ( names.contains( field.name() ) )
{
@@ -34,7 +34,7 @@ QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer* vl )
const QgsFields& layerAttributes = vl->fields();
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
{
QListWidgetItem* item = new QListWidgetItem( layerAttributes[idx].name(), listBox2 );
QListWidgetItem* item = new QListWidgetItem( layerAttributes.at( idx ).name(), listBox2 );
switch ( vl->fields().fieldOrigin( idx ) )
{
case QgsFields::OriginExpression:
@@ -184,14 +184,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer,
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
QString name = QString( "\"%1\"" ).arg( layerFields[idx].name() );
QString name = QString( "\"%1\"" ).arg( layerFields.at( idx ).name() );
newItem->setText( 0, name );
newItem->setData( 0, Qt::UserRole, name );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );

mDataDefinedXComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedYComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedVisibilityComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedXComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedYComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedVisibilityComboBox->addItem( layerFields.at( idx ).name(), idx );
}

const QgsDiagramRendererV2* dr = layer->diagramRenderer();
@@ -234,7 +234,7 @@ void QgsFieldCalculator::accept()

for ( int idx = 0; idx < fields.count(); ++idx )
{
if ( fields[idx].name() == mOutputFieldNameLineEdit->text() )
if ( fields.at( idx ).name() == mOutputFieldNameLineEdit->text() )
{
mAttributeId = idx;
break;
@@ -576,7 +576,7 @@ void QgsFieldsProperties::attributeAdded( int idx )
const QgsFields &fields = mLayer->fields();
int row = mFieldsList->rowCount();
mFieldsList->insertRow( row );
setRow( row, idx, fields[idx] );
setRow( row, idx, fields.at( idx ) );
mFieldsList->setCurrentCell( row, idx );

for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
@@ -493,7 +493,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
featItem->addChild( attrItem );

attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
attrItem->setData( 0, Qt::UserRole, fields[i].name() );
attrItem->setData( 0, Qt::UserRole, fields.at( i ).name() );
attrItem->setData( 0, Qt::UserRole + 1, i );

attrItem->setData( 1, Qt::UserRole, value );
@@ -515,7 +515,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
attrItem->treeWidget()->setItemWidget( attrItem, 1, nullptr );
}

if ( fields[i].name() == vlayer->displayField() )
if ( fields.at( i ).name() == vlayer->displayField() )
{
featItem->setText( 0, attrItem->text( 0 ) );
featItem->setText( 1, attrItem->text( 1 ) );
@@ -560,11 +560,11 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
tblResults->setItem( j, 1, item );

item = new QTableWidgetItem( QString::number( i ) );
if ( fields[i].name() == vlayer->displayField() )
if ( fields.at( i ).name() == vlayer->displayField() )
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) + " *" );
else
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
item->setData( Qt::UserRole, fields[i].name() );
item->setData( Qt::UserRole, fields.at( i ).name() );
item->setData( Qt::UserRole + 1, i );
tblResults->setItem( j, 2, item );

@@ -765,7 +765,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,

QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << attrs.at( i ).toString() );

attrItem->setData( 0, Qt::DisplayRole, fields[i].name() );
attrItem->setData( 0, Qt::DisplayRole, fields.at( i ).name() );

QVariant value = attrs.at( i );
attrItem->setData( 1, Qt::DisplayRole, value );
@@ -1188,7 +1188,7 @@ void QgsIdentifyResultsDialog::doAction( QTreeWidgetItem *item, int action )
const QgsFields& fields = layer->fields();
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
if ( fields[fldIdx].name() == fieldName )
if ( fields.at( fldIdx ).name() == fieldName )
{
idx = fldIdx;
break;
@@ -1741,7 +1741,7 @@ void QgsIdentifyResultsDialog::copyFeatureAttributes()
if ( attrIdx < 0 || attrIdx >= fields.count() )
continue;

text += QString( "%1: %2\n" ).arg( fields[attrIdx].name(), it.value().toString() );
text += QString( "%1: %2\n" ).arg( fields.at( attrIdx ).name(), it.value().toString() );
}
}
else if ( rlayer )
@@ -103,7 +103,7 @@ void QgsLabelPropertyDialog::init( const QString& layerId, const QString& provid
{
mLabelTextLineEdit->setText( attributeValues.at( mCurLabelField ).toString() );
const QgsFields& layerFields = vlayer->fields();
switch ( layerFields[mCurLabelField].type() )
switch ( layerFields.at( mCurLabelField ).type() )
{
case QVariant::Double:
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
@@ -358,7 +358,7 @@ QVariant QgsMergeAttributesDialog::calcStatistic( int col, QgsStatisticalSummary

if ( values.isEmpty() )
{
return QVariant( mVectorLayer->fields()[col].type() );
return QVariant( mVectorLayer->fields().at( col ).type() );
}

summary.calculate( values );
@@ -241,7 +241,7 @@ void QgsComposerAttributeTable::setDisplayAttributes( const QSet<int>& attr, boo
}
QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setAttribute( fields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
@@ -652,7 +652,7 @@ bool QgsComposerAttributeTable::readXml( const QDomElement& itemElem, const QDom
//find corresponding column
Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
{
if ( column->attribute() == fields[attribute].name() )
if ( column->attribute() == fields.at( attribute ).name() )
{
column->setSortByRank( i + 1 );
column->setSortOrder( order );
@@ -338,7 +338,7 @@ void QgsComposerAttributeTableV2::setDisplayAttributes( const QSet<int>& attr, b
}
QString currentAlias = source->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setAttribute( fields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
@@ -210,13 +210,13 @@ QString QgsActionManager::expandAction( QString action, const QgsAttributeMap &a
switch ( i )
{
case 0:
to_replace = "[%" + fields[attrIdx].name() + ']';
to_replace = "[%" + fields.at( attrIdx ).name() + ']';
break;
case 1:
to_replace = "[%" + mLayer->attributeDisplayName( attrIdx ) + ']';
break;
case 2:
to_replace = '%' + fields[attrIdx].name();
to_replace = '%' + fields.at( attrIdx ).name();
break;
case 3:
to_replace = '%' + mLayer->attributeDisplayName( attrIdx );
@@ -294,7 +294,7 @@ QgsGmlStreamingParser::QgsGmlStreamingParser( const QString& typeName,
mThematicAttributes.clear();
for ( int i = 0; i < fields.size(); i++ )
{
mThematicAttributes.insert( fields[i].name(), qMakePair( i, fields[i] ) );
mThematicAttributes.insert( fields.at( i ).name(), qMakePair( i, fields.at( i ) ) );
}

mEndian = QgsApplication::endian();
@@ -355,13 +355,13 @@ QgsGmlStreamingParser::QgsGmlStreamingParser( const QList<LayerProperties>& laye
mThematicAttributes.clear();
for ( int i = 0; i < fields.size(); i++ )
{
QMap< QString, QPair<QString, QString> >::const_iterator att_it = mapFieldNameToSrcLayerNameFieldName.constFind( fields[i].name() );
QMap< QString, QPair<QString, QString> >::const_iterator att_it = mapFieldNameToSrcLayerNameFieldName.constFind( fields.at( i ).name() );
if ( att_it != mapFieldNameToSrcLayerNameFieldName.constEnd() )
{
if ( mLayerProperties.size() == 1 )
mThematicAttributes.insert( att_it.value().second, qMakePair( i, fields[i] ) );
mThematicAttributes.insert( att_it.value().second, qMakePair( i, fields.at( i ) ) );
else
mThematicAttributes.insert( stripNS( att_it.value().first ) + "|" + att_it.value().second, qMakePair( i, fields[i] ) );
mThematicAttributes.insert( stripNS( att_it.value().first ) + "|" + att_it.value().second, qMakePair( i, fields.at( i ) ) );
}
}
bool alreadyFoundGeometry = false;
@@ -398,13 +398,13 @@ void QgsVectorFileWriter::init( QString vectorFileName,

for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
QgsField attrField = fields[fldIdx];
QgsField attrField = fields.at( fldIdx );

OGRFieldType ogrType = OFTString; //default to string

if ( fieldValueConverter )
{
attrField = fieldValueConverter->fieldDefinition( fields[fldIdx] );
attrField = fieldValueConverter->fieldDefinition( fields.at( fldIdx ) );
}

int ogrWidth = attrField.length();
@@ -489,7 +489,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
name = QString( "ogc_fid%1" ).arg( i );

int j;
for ( j = 0; j < fields.size() && name.compare( fields[j].name(), Qt::CaseInsensitive ) != 0; j++ )
for ( j = 0; j < fields.size() && name.compare( fields.at( j ).name(), Qt::CaseInsensitive ) != 0; j++ )
;

if ( j == fields.size() )
@@ -77,7 +77,7 @@ void QgsQueryBuilder::populateFields()
// only consider native fields
continue;
}
QStandardItem *myItem = new QStandardItem( fields[idx].name() );
QStandardItem *myItem = new QStandardItem( fields.at( idx ).name() );
myItem->setData( idx );
myItem->setEditable( false );
mModelFields->insertRow( mModelFields->rowCount(), myItem );
@@ -77,7 +77,7 @@ void QgsSearchQueryBuilder::populateFields()
const QgsFields& fields = mLayer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
QString fieldName = fields[idx].name();
QString fieldName = fields.at( idx ).name();
mFieldMap[fieldName] = idx;
QStandardItem *myItem = new QStandardItem( fieldName );
myItem->setEditable( false );
@@ -1332,7 +1332,7 @@ QgsVectorLayerImport::ImportError QgsDb2Provider::createEmptyLayer( const QStrin
QString pk = primaryKey = "QGS_FID";
for ( int i = 0; i < fieldCount; ++i )
{
if ( fields[i].name() == primaryKey )
if ( fields.at( i ).name() == primaryKey )
{
// it already exists, try again with a new name
primaryKey = QString( "%1_%2" ).arg( pk ).arg( index++ );
@@ -1345,10 +1345,10 @@ QgsVectorLayerImport::ImportError QgsDb2Provider::createEmptyLayer( const QStrin
// search for the passed field
for ( int i = 0; i < fieldCount; ++i )
{
if ( fields[i].name() == primaryKey )
if ( fields.at( i ).name() == primaryKey )
{
// found, get the field type
QgsField fld = fields[i];
QgsField fld = fields.at( i );
if ( convertField( fld ) )
{
primaryKeyType = fld.typeName();
@@ -262,7 +262,7 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
QgsAttributeList attrs = const_cast<QgsMemoryProvider *>( this )->attributeIndexes();
for ( int i = 0; i < attrs.size(); i++ )
{
QgsField field = mFields[attrs[i]];
QgsField field = mFields.at( attrs[i] );
QString fieldDef = field.name();
fieldDef.append( QString( ":%2(%3,%4)" ).arg( field.typeName() ).arg( field.length() ).arg( field.precision() ) );
uri.addQueryItem( "field", fieldDef );
@@ -1669,7 +1669,7 @@ QgsVectorLayerImport::ImportError QgsMssqlProvider::createEmptyLayer( const QStr
QString pk = primaryKey = "qgs_fid";
for ( int i = 0, n = fields.size(); i < n; ++i )
{
if ( fields[i].name() == primaryKey )
if ( fields.at( i ).name() == primaryKey )
{
// it already exists, try again with a new name
primaryKey = QString( "%1_%2" ).arg( pk ).arg( index++ );
@@ -1682,10 +1682,10 @@ QgsVectorLayerImport::ImportError QgsMssqlProvider::createEmptyLayer( const QStr
// search for the passed field
for ( int i = 0, n = fields.size(); i < n; ++i )
{
if ( fields[i].name() == primaryKey )
if ( fields.at( i ).name() == primaryKey )
{
// found, get the field type
QgsField fld = fields[i];
QgsField fld = fields.at( i );
if ( convertField( fld ) )
{
primaryKeyType = fld.typeName();
@@ -1830,7 +1830,7 @@ QgsVectorLayerImport::ImportError QgsMssqlProvider::createEmptyLayer( const QStr
QList<QgsField> flist;
for ( int i = 0, n = fields.size(); i < n; ++i )
{
QgsField fld = fields[i];
QgsField fld = fields.at( i );
if ( oldToNewAttrIdxMap && fld.name() == primaryKey )
{
oldToNewAttrIdxMap->insert( fields.fieldNameIndex( fld.name() ), 0 );
@@ -452,14 +452,14 @@ bool QgsOracleFeatureIterator::openQuery( QString whereClause, bool showLog )
break;

case pktInt:
query += delim + QgsOracleProvider::quotedIdentifier( mSource->mFields[ mSource->mPrimaryKeyAttrs[0] ].name() );
query += delim + QgsOracleProvider::quotedIdentifier( mSource->mFields.at( mSource->mPrimaryKeyAttrs[0] ).name() );
delim = ",";
break;

case pktFidMap:
Q_FOREACH ( int idx, mSource->mPrimaryKeyAttrs )
{
query += delim + mConnection->fieldExpression( mSource->mFields[idx] );
query += delim + mConnection->fieldExpression( mSource->mFields.at( idx ) );
delim = ",";
}
break;
@@ -475,7 +475,7 @@ bool QgsOracleFeatureIterator::openQuery( QString whereClause, bool showLog )
if ( mSource->mPrimaryKeyAttrs.contains( idx ) )
continue;

query += delim + mConnection->fieldExpression( mSource->mFields[idx] );
query += delim + mConnection->fieldExpression( mSource->mFields.at( idx ) );
}

query += QString( " FROM %1 \"FEATUREREQUEST\"" ).arg( mSource->mQuery );
@@ -181,7 +181,7 @@ QgsOracleProvider::QgsOracleProvider( QString const & uri )
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
{
Q_ASSERT( idx >= 0 && idx < mAttributeFields.size() );
key += delim + mAttributeFields[ idx ].name();
key += delim + mAttributeFields.at( idx ).name();
delim = ",";
}
}
@@ -416,7 +416,7 @@ QString QgsOracleUtils::whereClause( QgsFeatureId featureId, const QgsFields& fi
{
case pktInt:
Q_ASSERT( primaryKeyAttrs.size() == 1 );
whereClause = QString( "%1=%2" ).arg( QgsOracleConn::quotedIdentifier( fields[ primaryKeyAttrs[0] ].name() ) ).arg( featureId );
whereClause = QString( "%1=%2" ).arg( QgsOracleConn::quotedIdentifier( fields.at( primaryKeyAttrs[0] ).name() ) ).arg( featureId );
break;

case pktRowId:
@@ -966,9 +966,9 @@ bool QgsOracleProvider::determinePrimaryKey()
int idx = fieldNameIndex( mUri.keyColumn() );

if ( idx >= 0 && (
mAttributeFields[idx].type() == QVariant::Int ||
mAttributeFields[idx].type() == QVariant::LongLong ||
mAttributeFields[idx].type() == QVariant::Double
mAttributeFields.at( idx ).type() == QVariant::Int ||
mAttributeFields.at( idx ).type() == QVariant::LongLong ||
mAttributeFields.at( idx ).type() == QVariant::Double
) )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
@@ -1299,7 +1299,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
}
else
{
values += delim + quotedValue( v, mAttributeFields[idx].type() );
values += delim + quotedValue( v, mAttributeFields.at( idx ).type() );
}
}
else
@@ -2091,7 +2091,7 @@ bool QgsOracleProvider::setSubsetString( const QString& theSQL, bool updateFeatu
}
qry.finish();

if ( mPrimaryKeyType == pktInt && !uniqueData( mQuery, mAttributeFields[ mPrimaryKeyAttrs[0] ].name() ) )
if ( mPrimaryKeyType == pktInt && !uniqueData( mQuery, mAttributeFields.at( mPrimaryKeyAttrs[0] ).name() ) )
{
mSqlWhereClause = prevWhere;
return false;
@@ -2649,7 +2649,7 @@ QgsVectorLayerImport::ImportError QgsOracleProvider::createEmptyLayer(
int idx = fields.indexFromName( primaryKey );
if ( idx >= 0 )
{
QgsField fld = fields[idx];
QgsField fld = fields.at( idx );
if ( convertField( fld ) )
{
primaryKeyType = fld.typeName();
@@ -2856,7 +2856,7 @@ QgsVectorLayerImport::ImportError QgsOracleProvider::createEmptyLayer(
QList<QgsField> launderedFields;
for ( int i = 0; i < fields.size(); i++ )
{
QgsField fld = fields[i];
QgsField fld = fields.at( i );

QString name = fld.name().left( 30 ).toUpper();

0 comments on commit 4f3564c

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