Skip to content

Commit

Permalink
Drop QgsVectorLayer::pendingFields()
Browse files Browse the repository at this point in the history
Use QgsVectorLayer::fields() instead.
  • Loading branch information
nyalldawson committed Jan 15, 2018
1 parent 3b3d901 commit 068d51c
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 89 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,7 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
- addPart() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- splitParts() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- splitFeatured() now returns QgsGeometry::OperationResult enum, integer representation of returned values may have changed
- pendingFields() was dropped. Use fields() instead.


QgsVectorLayerEditBuffer {#qgis_api_break_3_0_QgsVectorLayerEditBuffer}
Expand Down
9 changes: 0 additions & 9 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1391,15 +1391,6 @@ Return new instance of QgsMapLayerRenderer that will be used for rendering of gi
Returns the list of fields of this layer.
This also includes fields which have not yet been saved to the provider.

:return: A list of fields
%End

QgsFields pendingFields() const;
%Docstring
Returns the list of fields of this layer.
This also includes fields which have not yet been saved to the provider.
Alias for fields()

:return: A list of fields
%End

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature &f, QgsRenderContext &cont
return;
}

// mCurFields = &layer->pendingFields();
// mCurFields = &layer->fields();

// store data defined-derived values for later adding to label feature for use during rendering
dataDefinedValues.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4093,7 +4093,7 @@ QString QgsVectorLayer::htmlMetadata() const
myMetadata += QLatin1String( "</td></tr>\n" );
}

const QgsFields &myFields = pendingFields();
const QgsFields myFields = fields();

// count fields
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( myFields.size() ) + QStringLiteral( "</td></tr>\n" );
Expand Down
9 changes: 0 additions & 9 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1302,15 +1302,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
inline QgsFields fields() const override { return mFields; }

/**
* Returns the list of fields of this layer.
* This also includes fields which have not yet been saved to the provider.
* Alias for fields()
*
* \returns A list of fields
*/
inline QgsFields pendingFields() const { return mFields; }

/**
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
* Alias for attributeList()
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
QString list = "ERROR: Pending attribute deletes:";
Q_FOREACH ( int idx, mDeletedAttributeIds )
{
list.append( ' ' + L->pendingFields().at( idx ).name() );
list.append( ' ' + L->fields().at( idx ).name() );
}
commitErrors << list;
#endif
Expand Down Expand Up @@ -529,7 +529,7 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
list.append( "\n " + FID_TO_STRING( id ) + '[' );
Q_FOREACH ( int idx, mChangedAttributeValues[ id ].keys() )
{
list.append( QString( " %1:%2" ).arg( L->pendingFields().at( idx ).name() ).arg( mChangedAttributeValues[id][idx].toString() ) );
list.append( QString( " %1:%2" ).arg( L->fields().at( idx ).name() ).arg( mChangedAttributeValues[id][idx].toString() ) );
}
list.append( " ]" );
}
Expand Down Expand Up @@ -619,9 +619,9 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
Q_FOREACH ( QgsFeature f, mAddedFeatures )
{
list.append( ' ' + FID_TO_STRING( f.id() ) + '[' );
for ( int i = 0; i < L->pendingFields().size(); i++ )
for ( int i = 0; i < L->fields().size(); i++ )
{
list.append( QString( " %1:%2" ).arg( L->pendingFields().at( i ).name() ).arg( f.attributes()[i].toString() ) );
list.append( QString( " %1:%2" ).arg( L->fields().at( i ).name() ).arg( f.attributes()[i].toString() ) );
}
list.append( " ]" );
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/globe/featuresource/qgsglobefeaturesource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void QgsGlobeFeatureSource::initialize( const osgDB::Options *dbOptions )
}
QgsRectangle ext = mLayer->extent();
osgEarth::GeoExtent geoext( ref, ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum() );
mSchema = QgsGlobeFeatureUtils::schemaForFields( mLayer->pendingFields() );
mSchema = QgsGlobeFeatureUtils::schemaForFields( mLayer->fields() );
#if OSGEARTH_VERSION_GREATER_OR_EQUAL(2, 8, 0)
setFeatureProfile( new osgEarth::Features::FeatureProfile( geoext ) );
return osgEarth::Status( osgEarth::Status::NoError );
Expand Down Expand Up @@ -139,7 +139,7 @@ void QgsGlobeFeatureSource::attributeValueChanged( const QgsFeatureId &featureId
if ( it != mFeatures.end() )
{
osgEarth::Features::Feature *feature = it->second.get();
QgsGlobeFeatureUtils::setFeatureField( feature, mLayer->pendingFields().at( idx ), value );
QgsGlobeFeatureUtils::setFeatureField( feature, mLayer->fields().at( idx ), value );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/globe/featuresource/qgsglobefeatureutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class QgsGlobeFeatureUtils
osgEarth::SpatialReference *ref = osgEarth::SpatialReference::create( layer->crs().toWkt().toStdString() );
osgEarth::Features::Feature *retFeat = new osgEarth::Features::Feature( nGeom, ref, osgEarth::Style(), feat.id() );

const QgsFields &fields = layer->pendingFields();
const QgsFields fields = layer->fields();
const QgsAttributes &attrs = feat.attributes();

for ( int idx = 0, numFlds = fields.size(); idx < numFlds; ++idx )
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace QgsWfs
sequenceElem.appendChild( geomElem );

//Attributes
const QgsFields &fields = layer->pendingFields();
QgsFields fields = layer->fields();
//hidden attributes for this layer
const QSet<QString> &layerExcludedAttributes = layer->excludeAttributesWfs();
for ( int idx = 0; idx < fields.count(); ++idx )
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ namespace QgsWfs
withGeom = false;
QStringList::const_iterator plstIt;
QList<int> idxList;
QgsFields fields = vlayer->pendingFields();
QgsFields fields = vlayer->fields();
QString fieldName;
for ( plstIt = propertyList.begin(); plstIt != propertyList.end(); ++plstIt )
{
Expand Down Expand Up @@ -294,11 +294,11 @@ namespace QgsWfs
QStringList attributes = QStringList();
Q_FOREACH ( int idx, attrIndexes )
{
attributes.append( vlayer->pendingFields().field( idx ).name() );
attributes.append( vlayer->fields().field( idx ).name() );
}
featureRequest.setSubsetOfAttributes(
accessControl->layerAttributes( vlayer, attributes ),
vlayer->pendingFields() );
vlayer->fields() );
}

if ( onlyOneLayer )
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ namespace QgsWms

//attributes
QDomElement attributesElem = doc.createElement( QStringLiteral( "Attributes" ) );
const QgsFields &layerFields = vLayer->pendingFields();
const QgsFields layerFields = vLayer->fields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QgsField field = layerFields.at( idx );
Expand Down
14 changes: 7 additions & 7 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace QgsWms
{
std::unique_ptr< QgsFeatureRenderer > r( vl->renderer()->clone() );
bool moreSymbolsPerFeature = r->capabilities() & QgsFeatureRenderer::MoreSymbolsPerFeature;
r->startRender( context, vl->pendingFields() );
r->startRender( context, vl->fields() );
QgsFeature f;
QgsFeatureRequest request( context.extent() );
request.setFlags( QgsFeatureRequest::ExactIntersect );
Expand Down Expand Up @@ -821,7 +821,7 @@ namespace QgsWms
int layerAttribute = -1;
if ( layerAttributes.size() > layerIdx )
{
layerAttribute = vlayer->pendingFields().indexFromName( layerAttributes.at( layerIdx ) );
layerAttribute = vlayer->fields().indexFromName( layerAttributes.at( layerIdx ) );
}

dxfLayers.append( qMakePair( vlayer, layerAttribute ) );
Expand Down Expand Up @@ -1401,7 +1401,7 @@ namespace QgsWms
QgsAttributes featureAttributes;
int featureCounter = 0;
layer->updateFields();
const QgsFields &fields = layer->pendingFields();
const QgsFields fields = layer->fields();
bool addWktGeometry = ( QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject ) && mWmsParameters.withGeometry() );
bool segmentizeWktGeometry = QgsServerProjectUtils::wmsFeatureInfoSegmentizeWktGeometry( *mProject );
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();
Expand Down Expand Up @@ -1429,19 +1429,19 @@ namespace QgsWms

QStringList attributes;
QgsField field;
Q_FOREACH ( field, layer->pendingFields().toList() )
Q_FOREACH ( field, layer->fields().toList() )
{
attributes.append( field.name() );
}
attributes = mAccessControl->layerAttributes( layer, attributes );
fReq.setSubsetOfAttributes( attributes, layer->pendingFields() );
fReq.setSubsetOfAttributes( attributes, layer->fields() );
#endif

QgsFeatureIterator fit = layer->getFeatures( fReq );
std::unique_ptr< QgsFeatureRenderer > r2( layer->renderer() ? layer->renderer()->clone() : nullptr );
if ( r2 )
{
r2->startRender( renderContext, layer->pendingFields() );
r2->startRender( renderContext, layer->fields() );
}

bool featureBBoxInitialized = false;
Expand Down Expand Up @@ -2432,7 +2432,7 @@ namespace QgsWms
}

// create feature with label if necessary
QgsFeature fet( layer->pendingFields() );
QgsFeature fet( layer->fields() );
if ( ! param.mLabel.isEmpty() )
{
fet.setAttribute( 0, param.mLabel );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/offlineditingtestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _setUp(self):
layer = self._getLayer('test_point')
assert layer.startEditing()
for id, name, geom in TEST_FEATURES:
f = QgsFeature(layer.pendingFields())
f = QgsFeature(layer.fields())
f['id'] = id
f['name'] = name
f.setGeometry(QgsGeometry.fromPointXY(geom))
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_InsertFeatures(self):
self.assertTrue(offline_layer.startEditing())
features = []
for id, name, geom in TEST_FEATURES_INSERT:
f = QgsFeature(offline_layer.pendingFields())
f = QgsFeature(offline_layer.fields())
f['id'] = id
f['name'] = name
f.setGeometry(QgsGeometry.fromPointXY(geom))
Expand Down
12 changes: 6 additions & 6 deletions tests/src/python/test_qgsexpressionbuilderwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def createReferencingLayer():
"referencinglayer", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setFields(layer.pendingFields())
f1.setFields(layer.fields())
f1.setAttributes(["test1", 123])
f2 = QgsFeature()
f2.setFields(layer.pendingFields())
f2.setFields(layer.fields())
f2.setAttributes(["test2", 123])
f3 = QgsFeature()
f3.setFields(layer.pendingFields())
f3.setFields(layer.fields())
f3.setAttributes(["foobar'bar", 124])
assert pr.addFeatures([f1, f2, f3])
return layer
Expand All @@ -50,13 +50,13 @@ def createReferencedLayer():
"referencedlayer", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setFields(layer.pendingFields())
f1.setFields(layer.fields())
f1.setAttributes(["foo", 123, 321])
f2 = QgsFeature()
f2.setFields(layer.pendingFields())
f2.setFields(layer.fields())
f2.setAttributes(["bar", 456, 654])
f3 = QgsFeature()
f3.setFields(layer.pendingFields())
f3.setFields(layer.fields())
f3.setAttributes(["foobar'bar", 789, 554])
assert pr.addFeatures([f1, f2, f3])
return layer
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_qgsfeatureiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def test_FilterFids(self):

def addFeatures(self, vl):
feat = QgsFeature()
fields = vl.pendingFields()
fields = vl.fields()
feat.setFields(fields)
feat['Staff'] = 4
vl.addFeature(feat)

feat = QgsFeature()
fields = vl.pendingFields()
fields = vl.fields()
feat.setFields(fields)
feat['Staff'] = 2
vl.addFeature(feat)
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_ExpressionFieldNestedCircular(self):
layer = QgsVectorLayer(myShpFile, 'Points', 'ogr')
self.assertTrue(layer.isValid())

cnt = layer.pendingFields().count() # NOQA
cnt = layer.fields().count() # NOQA
idx = layer.addExpressionField('"exp3"*2', QgsField('exp1', QVariant.LongLong)) # NOQA
idx = layer.addExpressionField('"exp1"-1', QgsField('exp2', QVariant.LongLong)) # NOQA
idx = layer.addExpressionField('"exp2"*3', QgsField('exp3', QVariant.LongLong)) # NOQA
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgslayoutatlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def rotation_test(self):
# rotate the map and test that the bounding rectangle
# is smaller than the bounds without rotation.
polygonLayer = QgsVectorLayer('Polygon', 'test_polygon', 'memory')
poly = QgsFeature(polygonLayer.pendingFields())
poly = QgsFeature(polygonLayer.fields())
points = [(10, 15), (15, 10), (45, 40), (40, 45)]
poly.setGeometry(QgsGeometry.fromPolygonXY([[QgsPointXY(x[0], x[1]) for x in points]]))
polygonLayer.dataProvider().addFeatures([poly])
Expand Down
12 changes: 6 additions & 6 deletions tests/src/python/test_qgsrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def createReferencingLayer():
"referencinglayer", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setFields(layer.pendingFields())
f1.setFields(layer.fields())
f1.setAttributes(["test1", 123])
f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
f2 = QgsFeature()
f2.setFields(layer.pendingFields())
f2.setFields(layer.fields())
f2.setAttributes(["test2", 123])
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(101, 201)))
f3 = QgsFeature()
f3.setFields(layer.pendingFields())
f3.setFields(layer.fields())
f3.setAttributes(["foobar'bar", 124])
f3.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(101, 201)))
assert pr.addFeatures([f1, f2, f3])
Expand All @@ -55,15 +55,15 @@ def createReferencedLayer():
"referencedlayer", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setFields(layer.pendingFields())
f1.setFields(layer.fields())
f1.setAttributes(["foo", 123, 321])
f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1, 1)))
f2 = QgsFeature()
f2.setFields(layer.pendingFields())
f2.setFields(layer.fields())
f2.setAttributes(["bar", 456, 654])
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(2, 2)))
f3 = QgsFeature()
f3.setFields(layer.pendingFields())
f3.setFields(layer.fields())
f3.setAttributes(["foobar'bar", 789, 554])
f3.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(2, 3)))
assert pr.addFeatures([f1, f2, f3])
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def createReferencingLayer():
"referencinglayer", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setFields(layer.pendingFields())
f1.setFields(layer.fields())
f1.setAttributes(["test1", 123])
f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
f2 = QgsFeature()
f2.setFields(layer.pendingFields())
f2.setFields(layer.fields())
f2.setAttributes(["test2", 123])
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(101, 201)))
assert pr.addFeatures([f1, f2])
Expand Down
Loading

0 comments on commit 068d51c

Please sign in to comment.