Skip to content

Commit ed4d34f

Browse files
committedAug 4, 2016
QgsFields returns QgsField value instead of const references
(since QgsField is implicitly shared)
1 parent 967d37a commit ed4d34f

25 files changed

+78
-72
lines changed
 

‎doc/api_break.dox

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ None will need to be modified, as the method will return an empty geometry if th
271271
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
272272
</ul>
273273

274+
\subsection qgis_api_break_3_0_QgsFields QgsFields
275+
276+
<ul>
277+
<li>All const methods which return a field from QgsFields now return a QgsField value, not a reference.</li>
278+
</ul>
279+
274280
\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry
275281

276282
<ul>

‎python/core/qgsfield.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class QgsFields
262262
%End
263263

264264
//! Get field at particular index (must be in range 0..N-1)
265-
const QgsField& at( int i ) const /Factory/;
265+
QgsField at( int i ) const /Factory/;
266266
%MethodCode
267267
if ( a0 < 0 || a0 >= sipCpp->count() )
268268
{
@@ -276,7 +276,7 @@ class QgsFields
276276
%End
277277

278278
//! Get field at particular index (must be in range 0..N-1)
279-
const QgsField& field( int fieldIdx ) const /Factory/;
279+
QgsField field( int fieldIdx ) const /Factory/;
280280
%MethodCode
281281
if ( a0 < 0 || a0 >= sipCpp->count() )
282282
{
@@ -290,7 +290,7 @@ class QgsFields
290290
%End
291291

292292
//! Get field at particular index (must be in range 0..N-1)
293-
const QgsField& field( const QString& name ) const /Factory/;
293+
QgsField field( const QString& name ) const /Factory/;
294294
%MethodCode
295295
int fieldIdx = sipCpp->indexFromName(*a0);
296296
if (fieldIdx == -1)

‎src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
271271

272272
for ( int i = 0; i < mLayer->fields().size(); ++i )
273273
{
274-
const QgsField &fld = mLayer->fields().at( i );
274+
QgsField fld = mLayer->fields().at( i );
275275
Qt::ItemFlags flags = mLayer->providerType() != "oracle" || !fld.typeName().contains( "SDO_GEOMETRY" ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
276276
QTableWidgetItem *item;
277277
item = new QTableWidgetItem( fld.name() );

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6848,7 +6848,7 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
68486848
continue;
68496849

68506850
QVariant val = merged.at( i );
6851-
const QgsField &fld( vl->fields().at( i ) );
6851+
QgsField fld( vl->fields().at( i ) );
68526852
bool isDefaultValue = vl->fields().fieldOrigin( i ) == QgsFields::OriginProvider &&
68536853
vl->dataProvider() &&
68546854
vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( i ) ) == val;

‎src/core/qgsfield.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,17 @@ QgsField &QgsFields::operator[]( int i )
382382
return d->fields[i].field;
383383
}
384384

385-
const QgsField &QgsFields::at( int i ) const
385+
QgsField QgsFields::at( int i ) const
386386
{
387387
return d->fields[i].field;
388388
}
389389

390-
const QgsField &QgsFields::field( int fieldIdx ) const
390+
QgsField QgsFields::field( int fieldIdx ) const
391391
{
392392
return d->fields[fieldIdx].field;
393393
}
394394

395-
const QgsField &QgsFields::field( const QString &name ) const
395+
QgsField QgsFields::field( const QString &name ) const
396396
{
397397
return d->fields[ indexFromName( name )].field;
398398
}
@@ -403,7 +403,7 @@ const QgsField &QgsFields::field( const QString &name ) const
403403
* See details in QEP #17
404404
****************************************************************************/
405405

406-
const QgsField &QgsFields::operator[]( int i ) const
406+
QgsField QgsFields::operator[]( int i ) const
407407
{
408408
return d->fields[i].field;
409409
}

‎src/core/qgsfield.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ class CORE_EXPORT QgsFields
255255
bool exists( int i ) const;
256256

257257
//! Get field at particular index (must be in range 0..N-1)
258-
const QgsField& operator[]( int i ) const;
258+
QgsField operator[]( int i ) const;
259259
//! Get field at particular index (must be in range 0..N-1)
260260
QgsField& operator[]( int i );
261261
//! Get field at particular index (must be in range 0..N-1)
262-
const QgsField& at( int i ) const;
262+
QgsField at( int i ) const;
263263
//! Get field at particular index (must be in range 0..N-1)
264-
const QgsField& field( int fieldIdx ) const;
265-
//! Get field at particular index (must be in range 0..N-1)
266-
const QgsField& field( const QString& name ) const;
264+
QgsField field( int fieldIdx ) const;
265+
//! Get field with matching name
266+
QgsField field( const QString& name ) const;
267267

268268
//! Get field's origin (value from an enumeration)
269269
FieldOrigin fieldOrigin( int fieldIdx ) const;

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
21742174
{
21752175
Q_FOREACH ( int idx, layer->attributeList() )
21762176
{
2177-
const QgsField &fld = layer->fields()[idx];
2177+
QgsField fld = layer->fields().at( idx );
21782178
if ( layer->providerType() == "oracle" && fld.typeName().contains( "SDO_GEOMETRY" ) )
21792179
continue;
21802180
attributes.append( idx );
@@ -2186,7 +2186,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
21862186
{
21872187
Q_FOREACH ( int attrIdx, attributes )
21882188
{
2189-
fields.append( layer->fields()[attrIdx] );
2189+
fields.append( layer->fields().at( attrIdx ) );
21902190
}
21912191
}
21922192

‎src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,7 @@ QString QgsVectorLayer::metadata() const
37573757
const QgsFields& myFields = pendingFields();
37583758
for ( int i = 0, n = myFields.size(); i < n; ++i )
37593759
{
3760-
const QgsField& myField = fields[i];
3760+
QgsField myField = fields.at( i );
37613761

37623762
myMetadata += "<tr><td>";
37633763
myMetadata += myField.name();

‎src/core/qgsvectorlayereditbuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
418418

419419
for ( int i = 0; i < qMin( oldFields.count(), newFields.count() ); ++i )
420420
{
421-
const QgsField& oldField = oldFields.at( i );
422-
const QgsField& newField = newFields.at( i );
421+
QgsField oldField = oldFields.at( i );
422+
QgsField newField = newFields.at( i );
423423
if ( attributeChangesOk && oldField != newField )
424424
{
425425
commitErrors

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
296296
QgsFields fields = vectorLayer->fields();
297297
for ( int idx = 0; idx < fields.count(); ++idx )
298298
{
299-
const QgsField &field = fields.at( idx );
299+
QgsField field = fields.at( idx );
300300
const QString& widgetType = vectorLayer->editFormConfig()->widgetType( idx );
301301
if ( !mWidgetFactories.contains( widgetType ) )
302302
{

‎src/providers/db2/qgsdb2featureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ bool QgsDb2FeatureIterator::fetchFeature( QgsFeature& feature )
338338
{
339339
v = QVariant( v.toString() );
340340
}
341-
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
341+
QgsField fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
342342
// QgsDebugMsg( QString( "v.type: %1; fld.type: %2" ).arg( v.type() ).arg( fld.type() ) );
343343
if ( v.type() != fld.type() )
344344
{

‎src/providers/mssql/qgsmssqlfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
300300
for ( int i = 0; i < mAttributesToFetch.count(); i++ )
301301
{
302302
QVariant v = mQuery->value( i );
303-
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
303+
QgsField fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
304304
if ( v.type() != fld.type() )
305305
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
306306
feature.setAttribute( mAttributesToFetch.at( i ), v );

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
27262726
if ( !mValid || index < 0 || index >= mAttributeFields.count() )
27272727
return;
27282728

2729-
const QgsField& fld = mAttributeFields.at( index );
2729+
QgsField fld = mAttributeFields.at( index );
27302730
if ( fld.name().isNull() )
27312731
{
27322732
return; //not a provider field
@@ -2774,7 +2774,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
27742774
{
27752775
return QVariant();
27762776
}
2777-
const QgsField& fld = mAttributeFields.at( index );
2777+
QgsField fld = mAttributeFields.at( index );
27782778

27792779
// Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9)
27802780
QByteArray sql = "SELECT MIN(" + mEncoding->fromUnicode( fld.name() );
@@ -2813,7 +2813,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const
28132813
{
28142814
return QVariant();
28152815
}
2816-
const QgsField& fld = mAttributeFields.at( index );
2816+
QgsField fld = mAttributeFields.at( index );
28172817

28182818
// Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9)
28192819
QByteArray sql = "SELECT MAX(" + mEncoding->fromUnicode( fld.name() );

‎src/providers/oracle/qgsoraclefeatureiterator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
337337
{
338338
Q_FOREACH ( int idx, mSource->mPrimaryKeyAttrs )
339339
{
340-
const QgsField &fld = mSource->mFields[idx];
340+
QgsField fld = mSource->mFields.at( idx );
341341

342342
QVariant v = mQry.value( col );
343343
if ( v.type() != fld.type() )
@@ -373,7 +373,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
373373
if ( mSource->mPrimaryKeyAttrs.contains( idx ) )
374374
continue;
375375

376-
const QgsField &fld = mSource->mFields[idx];
376+
QgsField fld = mSource->mFields.at( idx );
377377

378378
QVariant v = mQry.value( col );
379379
if ( fld.type() == QVariant::ByteArray && fld.typeName().endsWith( ".SDO_GEOMETRY" ) )

‎src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ QString QgsOracleProvider::pkParamWhereClause() const
338338
for ( int i = 0; i < mPrimaryKeyAttrs.size(); i++ )
339339
{
340340
int idx = mPrimaryKeyAttrs[i];
341-
const QgsField &fld = field( idx );
341+
QgsField fld = field( idx );
342342

343343
whereClause += delim + QString( "%1=?" ).arg( mConnection->fieldExpression( fld ) );
344344
delim = " AND ";
@@ -435,7 +435,7 @@ QString QgsOracleUtils::whereClause( QgsFeatureId featureId, const QgsFields& fi
435435
for ( int i = 0; i < primaryKeyAttrs.size(); i++ )
436436
{
437437
int idx = primaryKeyAttrs[i];
438-
const QgsField &fld = fields[ idx ];
438+
QgsField fld = fields.at( idx );
439439

440440
whereClause += delim + QString( "%1=%2" ).arg( QgsOracleConn::fieldExpression( fld ) ).arg( QgsOracleConn::quotedValue( pkVals[i], fld.type() ) );
441441
delim = " AND ";
@@ -504,15 +504,15 @@ QgsWkbTypes::Type QgsOracleProvider::wkbType() const
504504
return mRequestedGeomType != QgsWkbTypes::Unknown ? mRequestedGeomType : mDetectedGeomType;
505505
}
506506

507-
const QgsField &QgsOracleProvider::field( int index ) const
507+
QgsField QgsOracleProvider::field( int index ) const
508508
{
509509
if ( index < 0 || index >= mAttributeFields.size() )
510510
{
511511
QgsMessageLog::logMessage( tr( "FAILURE: Field %1 not found." ).arg( index ), tr( "Oracle" ) );
512512
throw OracleFieldNotFound();
513513
}
514514

515-
return mAttributeFields[ index ];
515+
return mAttributeFields.at( index );
516516
}
517517

518518
QgsFeatureIterator QgsOracleProvider::getFeatures( const QgsFeatureRequest& request ) const
@@ -900,7 +900,7 @@ bool QgsOracleProvider::determinePrimaryKey()
900900
return false;
901901
}
902902

903-
const QgsField &fld = mAttributeFields.at( idx );
903+
QgsField fld = mAttributeFields.at( idx );
904904

905905
if ( isInt &&
906906
fld.type() != QVariant::Int &&
@@ -937,7 +937,7 @@ bool QgsOracleProvider::determinePrimaryKey()
937937

938938
if ( idx >= 0 )
939939
{
940-
const QgsField &fld = mAttributeFields.at( idx );
940+
QgsField fld = mAttributeFields.at( idx );
941941

942942
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
943943
{
@@ -1027,7 +1027,7 @@ QVariant QgsOracleProvider::minimumValue( int index ) const
10271027
try
10281028
{
10291029
// get the field name
1030-
const QgsField &fld = field( index );
1030+
QgsField fld = field( index );
10311031
QString sql = QString( "SELECT min(%1) FROM %2" )
10321032
.arg( quotedIdentifier( fld.name() ) )
10331033
.arg( mQuery );
@@ -1070,7 +1070,7 @@ void QgsOracleProvider::uniqueValues( int index, QList<QVariant> &uniqueValues,
10701070
try
10711071
{
10721072
// get the field name
1073-
const QgsField &fld = field( index );
1073+
QgsField fld = field( index );
10741074
QString sql = QString( "SELECT DISTINCT %1 FROM %2" )
10751075
.arg( quotedIdentifier( fld.name() ) )
10761076
.arg( mQuery );
@@ -1117,7 +1117,7 @@ QVariant QgsOracleProvider::maximumValue( int index ) const
11171117
try
11181118
{
11191119
// get the field name
1120-
const QgsField &fld = field( index );
1120+
QgsField fld = field( index );
11211121
QString sql = QString( "SELECT max(%1) FROM %2" )
11221122
.arg( quotedIdentifier( fld.name() ) )
11231123
.arg( mQuery );
@@ -1227,7 +1227,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
12271227

12281228
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
12291229
{
1230-
const QgsField &fld = field( idx );
1230+
QgsField fld = field( idx );
12311231
insert += delim + quotedIdentifier( fld.name() );
12321232
keys += kdelim + quotedIdentifier( fld.name() );
12331233
values += delim + "?";
@@ -1256,7 +1256,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
12561256
if ( fieldId.contains( idx ) )
12571257
continue;
12581258

1259-
const QgsField &fld = mAttributeFields[idx];
1259+
QgsField fld = mAttributeFields.at( idx );
12601260

12611261
QgsDebugMsgLevel( "Checking field against: " + fld.name(), 4 );
12621262

@@ -1339,7 +1339,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
13391339
QString v;
13401340
if ( !value.isValid() )
13411341
{
1342-
const QgsField &fld = field( fieldId[i] );
1342+
QgsField fld = field( fieldId[i] );
13431343
v = paramValue( defaultValues[i], defaultValues[i] );
13441344
features->setAttribute( fieldId[i], convertValue( fld.type(), v ) );
13451345
}
@@ -1349,7 +1349,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
13491349

13501350
if ( v != value.toString() )
13511351
{
1352-
const QgsField &fld = field( fieldId[i] );
1352+
QgsField fld = field( fieldId[i] );
13531353
features->setAttribute( fieldId[i], convertValue( fld.type(), v ) );
13541354
}
13551355
}
@@ -1375,7 +1375,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )
13751375
int col = 0;
13761376
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
13771377
{
1378-
const QgsField &fld = field( idx );
1378+
QgsField fld = field( idx );
13791379

13801380
QVariant v = getfid.value( col++ );
13811381
if ( v.type() != fld.type() )
@@ -1590,7 +1590,7 @@ bool QgsOracleProvider::deleteAttributes( const QgsAttributeIds& ids )
15901590

15911591
Q_FOREACH ( int id, idsList )
15921592
{
1593-
const QgsField &fld = mAttributeFields.at( id );
1593+
QgsField fld = mAttributeFields.at( id );
15941594

15951595
QString sql = QString( "ALTER TABLE %1 DROP COLUMN %2" )
15961596
.arg( mQuery )
@@ -1751,7 +1751,7 @@ bool QgsOracleProvider::changeAttributeValues( const QgsChangedAttributesMap &at
17511751
{
17521752
try
17531753
{
1754-
const QgsField &fld = field( siter.key() );
1754+
QgsField fld = field( siter.key() );
17551755

17561756
pkChanged = pkChanged || mPrimaryKeyAttrs.contains( siter.key() );
17571757

‎src/providers/oracle/qgsoracleprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
292292

293293
bool hasSufficientPermsAndCapabilities();
294294

295-
const QgsField &field( int index ) const;
295+
QgsField field( int index ) const;
296296

297297
/** Load the field list
298298
*/

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int
737737

738738
Q_FOREACH ( int idx, mSource->mPrimaryKeyAttrs )
739739
{
740-
const QgsField &fld = mSource->mFields.at( idx );
740+
QgsField fld = mSource->mFields.at( idx );
741741

742742
QVariant v = QgsPostgresProvider::convertValue( fld.type(), queryResult.PQgetvalue( row, col ) );
743743
primaryKeyVals << v;

0 commit comments

Comments
 (0)
Please sign in to comment.