Skip to content

Commit cf2f6b1

Browse files
committedAug 4, 2015
Alias without pending prefix for QgsVectorLayer methods
* pendingAllAttributesList -> attributeList * pendingPkAttributesList -> pkAttributeList * pendingFeatureCount -> featureCount featureCount will now always return the features on the layer and NOT the committed features count as before. This changes its behavior but this way it is coherent with the other methods which work on the layer.
1 parent e832b2a commit cf2f6b1

16 files changed

+89
-75
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,6 @@ class QgsVectorLayer : QgsMapLayer
568568
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
569569
bool readSld( const QDomNode& node, QString& errorMessage );
570570

571-
/**
572-
* Number of features in the layer. This is necessary if features are
573-
* added/deleted or the layer has been subsetted. If the data provider
574-
* chooses not to support this feature, the total number of features
575-
* can be returned.
576-
* @return long containing number of features
577-
*/
578-
virtual long featureCount() const;
579-
580571
/**
581572
* Update the data source of the layer. The layer's renderer and legend will be preserved only
582573
* if the geometry type of the new data source matches the current geometry type of the layer.
@@ -816,16 +807,40 @@ class QgsVectorLayer : QgsMapLayer
816807
*
817808
* @return A list of fields
818809
*/
819-
const QgsFields pendingFields() const;
810+
QgsFields pendingFields() const;
811+
812+
/**
813+
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
814+
* Alias for {@link attributeList()}
815+
*/
816+
QgsAttributeList pendingAllAttributesList() const;
817+
818+
/**
819+
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
820+
* Alias for {@link attributeList()}
821+
*/
822+
QgsAttributeList attributeList() const;
823+
824+
/**
825+
* Returns list of attributes making up the primary key
826+
* Alias for {@link pkAttributeList()}
827+
*/
828+
QgsAttributeList pendingPkAttributesList() const;
820829

821-
/** Returns list of attributes */
822-
QList<int> pendingAllAttributesList();
830+
/** Returns list of attributes making up the primary key */
831+
QgsAttributeList pkAttributeList() const;
823832

824-
/** Returns list of attribute making up the primary key */
825-
QList<int> pendingPkAttributesList();
833+
/**
834+
* Returns feature count including changes which have not yet been committed
835+
* Alias for {@link featureCount()}
836+
*/
837+
long pendingFeatureCount() const;
826838

827-
/** Returns feature count after commit */
828-
int pendingFeatureCount();
839+
/**
840+
* Returns feature count including changes which have not yet been committed
841+
* If you need only the count of committed features call this method on this layer's provider.
842+
*/
843+
long featureCount() const;
829844

830845
/** Make layer read-only (editing disabled) or not
831846
* @return false if the layer is in editing yet

‎src/analysis/vector/qgsgeometryanalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
961961
QgsGeometry* lrsGeom = 0;
962962
double measure1, measure2 = 0.0;
963963

964-
int nEventFeatures = eventLayer->pendingFeatureCount();
964+
int nEventFeatures = eventLayer->featureCount();
965965
int featureCounter = 0;
966966
int nOutputFeatures = 0; //number of output features for the current event feature
967967
if ( p )

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6285,7 +6285,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
62856285

62866286
QHash<int, int> remap;
62876287
const QgsFields &fields = clipboard()->fields();
6288-
QgsAttributeList pkAttrList = pasteVectorLayer->pendingPkAttributesList();
6288+
QgsAttributeList pkAttrList = pasteVectorLayer->pkAttributeList();
62896289
for ( int idx = 0; idx < fields.count(); ++idx )
62906290
{
62916291
int dst = pasteVectorLayer->fieldNameIndex( fields[idx].name() );

‎src/app/qgsmergeattributesdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
8888

8989
//create combo boxes and insert attribute names
9090
const QgsFields& fields = mVectorLayer->fields();
91-
QSet<int> pkAttrList = mVectorLayer->pendingPkAttributesList().toSet();
91+
QSet<int> pkAttrList = mVectorLayer->pkAttributeList().toSet();
9292

9393
int col = 0;
9494
for ( int idx = 0; idx < fields.count(); ++idx )
@@ -487,7 +487,7 @@ void QgsMergeAttributesDialog::on_mFromSelectedPushButton_clicked()
487487
return;
488488
}
489489

490-
QSet<int> pkAttributes = mVectorLayer->pendingPkAttributesList().toSet();
490+
QSet<int> pkAttributes = mVectorLayer->pkAttributeList().toSet();
491491
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
492492
{
493493
if ( pkAttributes.contains( i ) )

‎src/core/composer/qgscomposerlegend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ QVariant QgsLegendModelV2::data( const QModelIndex& index, int role ) const
602602
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
603603
{
604604
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
605-
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
606-
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
605+
if ( vlayer && vlayer->featureCount() >= 0 )
606+
name += QString( " [%1]" ).arg( vlayer->featureCount() );
607607
}
608608
return name;
609609
}

‎src/core/layertree/qgslayertreemodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
168168
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
169169
{
170170
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
171-
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
172-
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
171+
if ( vlayer && vlayer->featureCount() >= 0 )
172+
name += QString( " [%1]" ).arg( vlayer->featureCount() );
173173
}
174174
return name;
175175
}

‎src/core/layertree/qgslayertreemodellegendnode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ void QgsSymbolV2LegendNode::updateLabel()
413413
layerName = mLayerNode->customProperty( "legend/title-label" ).toString();
414414

415415
mLabel = mUserLabel.isEmpty() ? layerName : mUserLabel;
416-
if ( showFeatureCount && vl && vl->pendingFeatureCount() >= 0 )
417-
mLabel += QString( " [%1]" ).arg( vl->pendingFeatureCount() );
416+
if ( showFeatureCount && vl && vl->featureCount() >= 0 )
417+
mLabel += QString( " [%1]" ).arg( vl->featureCount() );
418418
}
419419
else
420420
{

‎src/core/qgsofflineediting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ void QgsOfflineEditing::copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLay
883883
// NOTE: use this to map column indices in case the remote geometry column is not last
884884
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
885885
{
886-
const QgsAttributeList& offlineAttrs = offlineLayer->pendingAllAttributesList();
887-
const QgsAttributeList& remoteAttrs = remoteLayer->pendingAllAttributesList();
886+
const QgsAttributeList& offlineAttrs = offlineLayer->attributeList();
887+
const QgsAttributeList& remoteAttrs = remoteLayer->attributeList();
888888

889889
QMap < int /*offline attr*/, int /*remote attr*/ > attrLookup;
890890
// NOTE: use size of remoteAttrs, as offlineAttrs can have new attributes not yet synced

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
19451945
errorMessage->clear();
19461946
}
19471947

1948-
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->pendingAllAttributesList();
1948+
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->attributeList();
19491949
QgsFeature fet;
19501950

19511951
//add possible attributes needed by renderer

‎src/core/qgsvectorlayer.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,6 @@ bool QgsVectorLayer::diagramsEnabled() const
675675
return false;
676676
}
677677

678-
long QgsVectorLayer::featureCount() const
679-
{
680-
if ( !mDataProvider )
681-
{
682-
QgsDebugMsg( "invoked with null mDataProvider" );
683-
return 0;
684-
}
685-
686-
return mDataProvider->featureCount();
687-
}
688-
689678
long QgsVectorLayer::featureCount( QgsSymbolV2* symbol )
690679
{
691680
if ( !mSymbolFeatureCounted ) return -1;
@@ -716,7 +705,7 @@ bool QgsVectorLayer::countSymbolFeatures( bool showProgress )
716705
mSymbolFeatureCountMap.insert( symbolIt->second, 0 );
717706
}
718707

719-
long nFeatures = pendingFeatureCount();
708+
long nFeatures = featureCount();
720709
QProgressDialog progressDialog( tr( "Updating feature count for layer %1" ).arg( name() ), tr( "Abort" ), 0, nFeatures );
721710
progressDialog.setWindowTitle( tr( "QGIS" ) );
722711
progressDialog.setWindowModality( Qt::WindowModal );
@@ -2218,12 +2207,7 @@ bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
22182207
return res;
22192208
}
22202209

2221-
QgsAttributeList QgsVectorLayer::pendingAllAttributesList()
2222-
{
2223-
return mUpdatedFields.allAttributesList();
2224-
}
2225-
2226-
QgsAttributeList QgsVectorLayer::pendingPkAttributesList()
2210+
QgsAttributeList QgsVectorLayer::pkAttributeList() const
22272211
{
22282212
QgsAttributeList pkAttributesList;
22292213

@@ -2238,7 +2222,7 @@ QgsAttributeList QgsVectorLayer::pendingPkAttributesList()
22382222
return pkAttributesList;
22392223
}
22402224

2241-
int QgsVectorLayer::pendingFeatureCount()
2225+
long QgsVectorLayer::featureCount() const
22422226
{
22432227
return mDataProvider->featureCount() +
22442228
( mEditBuffer ? mEditBuffer->mAddedFeatures.size() - mEditBuffer->mDeletedFeatureIds.size() : 0 );
@@ -3563,7 +3547,7 @@ QString QgsVectorLayer::metadata()
35633547
myMetadata += "</p>\n";
35643548
}
35653549

3566-
QgsAttributeList pkAttrList = pendingPkAttributesList();
3550+
QgsAttributeList pkAttrList = pkAttributeList();
35673551
if ( !pkAttrList.isEmpty() )
35683552
{
35693553
myMetadata += "<p class=\"glossy\">" + tr( "Primary key attributes" ) + "</p>\n";

‎src/core/qgsvectorlayer.h

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,15 +1061,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
10611061
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
10621062
bool readSld( const QDomNode& node, QString& errorMessage ) override;
10631063

1064-
/**
1065-
* Number of features in the layer. This is necessary if features are
1066-
* added/deleted or the layer has been subsetted. If the data provider
1067-
* chooses not to support this feature, the total number of features
1068-
* can be returned.
1069-
* @return long containing number of features
1070-
*/
1071-
virtual long featureCount() const;
1072-
10731064
/**
10741065
* Number of features rendered with specified symbol. Features must be first
10751066
* calculated by countSymbolFeatures()
@@ -1306,7 +1297,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
13061297
*
13071298
* @return A list of fields
13081299
*/
1309-
const inline QgsFields fields() const { return mUpdatedFields; }
1300+
inline QgsFields fields() const { return mUpdatedFields; }
13101301

13111302
/**
13121303
* Returns the list of fields of this layer.
@@ -1315,16 +1306,40 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
13151306
*
13161307
* @return A list of fields
13171308
*/
1318-
const inline QgsFields pendingFields() const { return mUpdatedFields; }
1309+
inline QgsFields pendingFields() const { return mUpdatedFields; }
1310+
1311+
/**
1312+
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
1313+
* Alias for {@link attributeList()}
1314+
*/
1315+
inline QgsAttributeList pendingAllAttributesList() const { return mUpdatedFields.allAttributesList(); }
1316+
1317+
/**
1318+
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
1319+
* Alias for {@link attributeList()}
1320+
*/
1321+
inline QgsAttributeList attributeList() const { return mUpdatedFields.allAttributesList(); }
1322+
1323+
/**
1324+
* Returns list of attributes making up the primary key
1325+
* Alias for {@link pkAttributeList()}
1326+
*/
1327+
inline QgsAttributeList pendingPkAttributesList() const { return pkAttributeList(); }
13191328

1320-
/** Returns list of attributes */
1321-
QgsAttributeList pendingAllAttributesList();
1329+
/** Returns list of attributes making up the primary key */
1330+
QgsAttributeList pkAttributeList() const;
13221331

1323-
/** Returns list of attribute making up the primary key */
1324-
QgsAttributeList pendingPkAttributesList();
1332+
/**
1333+
* Returns feature count including changes which have not yet been committed
1334+
* Alias for {@link featureCount()}
1335+
*/
1336+
inline long pendingFeatureCount() const { return featureCount(); }
13251337

1326-
/** Returns feature count after commit */
1327-
int pendingFeatureCount();
1338+
/**
1339+
* Returns feature count including changes which have not yet been committed
1340+
* If you need only the count of committed features call this method on this layer's provider.
1341+
*/
1342+
long featureCount() const;
13281343

13291344
/** Make layer read-only (editing disabled) or not
13301345
* @return false if the layer is in editing yet

‎src/core/qgsvectorlayercache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsVectorLayerCache::QgsVectorLayerCache( QgsVectorLayer* layer, int cacheSize,
3131
connect( mLayer, SIGNAL( layerDeleted() ), SLOT( layerDeleted() ) );
3232

3333
setCacheGeometry( true );
34-
setCacheSubsetOfAttributes( mLayer->pendingAllAttributesList() );
34+
setCacheSubsetOfAttributes( mLayer->attributeList() );
3535
setCacheAddedAttributes( true );
3636

3737
connect( mLayer, SIGNAL( attributeDeleted( int ) ), SLOT( attributeDeleted( int ) ) );
@@ -330,7 +330,7 @@ bool QgsVectorLayerCache::checkInformationCovered( const QgsFeatureRequest& feat
330330

331331
if ( !featureRequest.flags().testFlag( QgsFeatureRequest::SubsetOfAttributes ) )
332332
{
333-
requestedAttributes = mLayer->pendingAllAttributesList();
333+
requestedAttributes = mLayer->attributeList();
334334
}
335335
else
336336
{

‎src/core/qgsvectorlayerimport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
302302
errorMessage->clear();
303303
}
304304

305-
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->pendingAllAttributesList();
305+
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->attributeList();
306306
QgsFeature fet;
307307

308308
QgsFeatureRequest req;

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void QgsDualView::columnBoxInit()
111111
// if neither diaplay expression nor display field is saved...
112112
if ( displayExpression == "" )
113113
{
114-
QgsAttributeList pkAttrs = mLayerCache->layer()->pendingPkAttributesList();
114+
QgsAttributeList pkAttrs = mLayerCache->layer()->pkAttributeList();
115115

116116
if ( pkAttrs.size() > 0 )
117117
{

‎src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
506506
renderContext.setRendererScale( 0 ); // ignore scale
507507
mRenderer->startRender( renderContext, mLayer->fields() );
508508

509-
int nFeatures = mLayer->pendingFeatureCount();
509+
int nFeatures = mLayer->featureCount();
510510
QProgressDialog p( tr( "Calculating feature count." ), tr( "Abort" ), 0, nFeatures );
511511
p.setWindowModality( Qt::WindowModal );
512512
int featuresCounted = 0;

‎tests/src/core/testqgsvectorlayerjoinbuffer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void TestVectorLayerJoinBuffer::initTestCase()
7777
QgsFeature fA2( mLayerA->dataProvider()->fields(), 2 );
7878
fA2.setAttribute( "id_a", 2 );
7979
mLayerA->dataProvider()->addFeatures( QgsFeatureList() << fA1 << fA2 );
80-
QVERIFY( mLayerA->pendingFeatureCount() == 2 );
80+
QVERIFY( mLayerA->featureCount() == 2 );
8181

8282
// LAYER B //
8383

@@ -92,7 +92,7 @@ void TestVectorLayerJoinBuffer::initTestCase()
9292
fB2.setAttribute( "id_b", 2 );
9393
fB2.setAttribute( "value_b", 12 );
9494
mLayerB->dataProvider()->addFeatures( QgsFeatureList() << fB1 << fB2 );
95-
QVERIFY( mLayerB->pendingFeatureCount() == 2 );
95+
QVERIFY( mLayerB->featureCount() == 2 );
9696

9797
// LAYER C //
9898

@@ -104,7 +104,7 @@ void TestVectorLayerJoinBuffer::initTestCase()
104104
fC1.setAttribute( "id_c", 1 );
105105
fC1.setAttribute( "value_c", 101 );
106106
mLayerC->dataProvider()->addFeatures( QgsFeatureList() << fC1 );
107-
QVERIFY( mLayerC->pendingFeatureCount() == 1 );
107+
QVERIFY( mLayerC->featureCount() == 1 );
108108

109109
QgsMapLayerRegistry::instance()->addMapLayer( mLayerA );
110110
QgsMapLayerRegistry::instance()->addMapLayer( mLayerB );
@@ -259,7 +259,7 @@ void TestVectorLayerJoinBuffer::testJoinSubset()
259259
fX1.setAttribute( "value_x1", 111 );
260260
fX1.setAttribute( "value_x2", 222 );
261261
layerX->dataProvider()->addFeatures( QgsFeatureList() << fX1 );
262-
QVERIFY( layerX->pendingFeatureCount() == 1 );
262+
QVERIFY( layerX->featureCount() == 1 );
263263

264264
QgsMapLayerRegistry::instance()->addMapLayer( layerX );
265265

0 commit comments

Comments
 (0)
Please sign in to comment.