Skip to content
Permalink
Browse files

QgsFields returns QgsField value instead of const references

(since QgsField is implicitly shared)
  • Loading branch information
nyalldawson committed Aug 4, 2016
1 parent 967d37a commit ed4d34fdbc0aba32da12ac5886c33e682c6a8f18
@@ -271,6 +271,12 @@ None will need to be modified, as the method will return an empty geometry if th
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
</ul>

\subsection qgis_api_break_3_0_QgsFields QgsFields

<ul>
<li>All const methods which return a field from QgsFields now return a QgsField value, not a reference.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry

<ul>
@@ -262,7 +262,7 @@ class QgsFields
%End

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

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

//! Get field at particular index (must be in range 0..N-1)
const QgsField& field( const QString& name ) const /Factory/;
QgsField field( const QString& name ) const /Factory/;
%MethodCode
int fieldIdx = sipCpp->indexFromName(*a0);
if (fieldIdx == -1)
@@ -271,7 +271,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx

for ( int i = 0; i < mLayer->fields().size(); ++i )
{
const QgsField &fld = mLayer->fields().at( i );
QgsField fld = mLayer->fields().at( i );
Qt::ItemFlags flags = mLayer->providerType() != "oracle" || !fld.typeName().contains( "SDO_GEOMETRY" ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
QTableWidgetItem *item;
item = new QTableWidgetItem( fld.name() );
@@ -6848,7 +6848,7 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
continue;

QVariant val = merged.at( i );
const QgsField &fld( vl->fields().at( i ) );
QgsField fld( vl->fields().at( i ) );
bool isDefaultValue = vl->fields().fieldOrigin( i ) == QgsFields::OriginProvider &&
vl->dataProvider() &&
vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( i ) ) == val;
@@ -382,17 +382,17 @@ QgsField &QgsFields::operator[]( int i )
return d->fields[i].field;
}

const QgsField &QgsFields::at( int i ) const
QgsField QgsFields::at( int i ) const
{
return d->fields[i].field;
}

const QgsField &QgsFields::field( int fieldIdx ) const
QgsField QgsFields::field( int fieldIdx ) const
{
return d->fields[fieldIdx].field;
}

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

const QgsField &QgsFields::operator[]( int i ) const
QgsField QgsFields::operator[]( int i ) const
{
return d->fields[i].field;
}
@@ -255,15 +255,15 @@ class CORE_EXPORT QgsFields
bool exists( int i ) const;

//! Get field at particular index (must be in range 0..N-1)
const QgsField& operator[]( int i ) const;
QgsField operator[]( int i ) const;
//! Get field at particular index (must be in range 0..N-1)
QgsField& operator[]( int i );
//! Get field at particular index (must be in range 0..N-1)
const QgsField& at( int i ) const;
QgsField at( int i ) const;
//! Get field at particular index (must be in range 0..N-1)
const QgsField& field( int fieldIdx ) const;
//! Get field at particular index (must be in range 0..N-1)
const QgsField& field( const QString& name ) const;
QgsField field( int fieldIdx ) const;
//! Get field with matching name
QgsField field( const QString& name ) const;

//! Get field's origin (value from an enumeration)
FieldOrigin fieldOrigin( int fieldIdx ) const;
@@ -2174,7 +2174,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
{
Q_FOREACH ( int idx, layer->attributeList() )
{
const QgsField &fld = layer->fields()[idx];
QgsField fld = layer->fields().at( idx );
if ( layer->providerType() == "oracle" && fld.typeName().contains( "SDO_GEOMETRY" ) )
continue;
attributes.append( idx );
@@ -2186,7 +2186,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
{
Q_FOREACH ( int attrIdx, attributes )
{
fields.append( layer->fields()[attrIdx] );
fields.append( layer->fields().at( attrIdx ) );
}
}

@@ -3757,7 +3757,7 @@ QString QgsVectorLayer::metadata() const
const QgsFields& myFields = pendingFields();
for ( int i = 0, n = myFields.size(); i < n; ++i )
{
const QgsField& myField = fields[i];
QgsField myField = fields.at( i );

myMetadata += "<tr><td>";
myMetadata += myField.name();
@@ -418,8 +418,8 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )

for ( int i = 0; i < qMin( oldFields.count(), newFields.count() ); ++i )
{
const QgsField& oldField = oldFields.at( i );
const QgsField& newField = newFields.at( i );
QgsField oldField = oldFields.at( i );
QgsField newField = newFields.at( i );
if ( attributeChangesOk && oldField != newField )
{
commitErrors
@@ -296,7 +296,7 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
QgsFields fields = vectorLayer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
const QgsField &field = fields.at( idx );
QgsField field = fields.at( idx );
const QString& widgetType = vectorLayer->editFormConfig()->widgetType( idx );
if ( !mWidgetFactories.contains( widgetType ) )
{
@@ -338,7 +338,7 @@ bool QgsDb2FeatureIterator::fetchFeature( QgsFeature& feature )
{
v = QVariant( v.toString() );
}
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
QgsField fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
// QgsDebugMsg( QString( "v.type: %1; fld.type: %2" ).arg( v.type() ).arg( fld.type() ) );
if ( v.type() != fld.type() )
{
@@ -300,7 +300,7 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
for ( int i = 0; i < mAttributesToFetch.count(); i++ )
{
QVariant v = mQuery->value( i );
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
QgsField fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
if ( v.type() != fld.type() )
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
feature.setAttribute( mAttributesToFetch.at( i ), v );
@@ -2726,7 +2726,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
if ( !mValid || index < 0 || index >= mAttributeFields.count() )
return;

const QgsField& fld = mAttributeFields.at( index );
QgsField fld = mAttributeFields.at( index );
if ( fld.name().isNull() )
{
return; //not a provider field
@@ -2774,7 +2774,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
{
return QVariant();
}
const QgsField& fld = mAttributeFields.at( index );
QgsField fld = mAttributeFields.at( index );

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

// Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9)
QByteArray sql = "SELECT MAX(" + mEncoding->fromUnicode( fld.name() );
@@ -337,7 +337,7 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
{
Q_FOREACH ( int idx, mSource->mPrimaryKeyAttrs )
{
const QgsField &fld = mSource->mFields[idx];
QgsField fld = mSource->mFields.at( idx );

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

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

QVariant v = mQry.value( col );
if ( fld.type() == QVariant::ByteArray && fld.typeName().endsWith( ".SDO_GEOMETRY" ) )
@@ -338,7 +338,7 @@ QString QgsOracleProvider::pkParamWhereClause() const
for ( int i = 0; i < mPrimaryKeyAttrs.size(); i++ )
{
int idx = mPrimaryKeyAttrs[i];
const QgsField &fld = field( idx );
QgsField fld = field( idx );

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

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

const QgsField &QgsOracleProvider::field( int index ) const
QgsField QgsOracleProvider::field( int index ) const
{
if ( index < 0 || index >= mAttributeFields.size() )
{
QgsMessageLog::logMessage( tr( "FAILURE: Field %1 not found." ).arg( index ), tr( "Oracle" ) );
throw OracleFieldNotFound();
}

return mAttributeFields[ index ];
return mAttributeFields.at( index );
}

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

const QgsField &fld = mAttributeFields.at( idx );
QgsField fld = mAttributeFields.at( idx );

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

if ( idx >= 0 )
{
const QgsField &fld = mAttributeFields.at( idx );
QgsField fld = mAttributeFields.at( idx );

if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
@@ -1027,7 +1027,7 @@ QVariant QgsOracleProvider::minimumValue( int index ) const
try
{
// get the field name
const QgsField &fld = field( index );
QgsField fld = field( index );
QString sql = QString( "SELECT min(%1) FROM %2" )
.arg( quotedIdentifier( fld.name() ) )
.arg( mQuery );
@@ -1070,7 +1070,7 @@ void QgsOracleProvider::uniqueValues( int index, QList<QVariant> &uniqueValues,
try
{
// get the field name
const QgsField &fld = field( index );
QgsField fld = field( index );
QString sql = QString( "SELECT DISTINCT %1 FROM %2" )
.arg( quotedIdentifier( fld.name() ) )
.arg( mQuery );
@@ -1117,7 +1117,7 @@ QVariant QgsOracleProvider::maximumValue( int index ) const
try
{
// get the field name
const QgsField &fld = field( index );
QgsField fld = field( index );
QString sql = QString( "SELECT max(%1) FROM %2" )
.arg( quotedIdentifier( fld.name() ) )
.arg( mQuery );
@@ -1227,7 +1227,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist )

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

const QgsField &fld = mAttributeFields[idx];
QgsField fld = mAttributeFields.at( idx );

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

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

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

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

Q_FOREACH ( int id, idsList )
{
const QgsField &fld = mAttributeFields.at( id );
QgsField fld = mAttributeFields.at( id );

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

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

@@ -292,7 +292,7 @@ class QgsOracleProvider : public QgsVectorDataProvider

bool hasSufficientPermsAndCapabilities();

const QgsField &field( int index ) const;
QgsField field( int index ) const;

/** Load the field list
*/
@@ -737,7 +737,7 @@ bool QgsPostgresFeatureIterator::getFeature( QgsPostgresResult &queryResult, int

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

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

0 comments on commit ed4d34f

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