Skip to content
Permalink
Browse files

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.
  • Loading branch information
m-kuhn committed Aug 4, 2015
1 parent e832b2a commit cf2f6b17fab9d69edb2f9c9ebdbee9d1597bcade
@@ -568,15 +568,6 @@ class QgsVectorLayer : QgsMapLayer
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
bool readSld( const QDomNode& node, QString& errorMessage );

/**
* Number of features in the layer. This is necessary if features are
* added/deleted or the layer has been subsetted. If the data provider
* chooses not to support this feature, the total number of features
* can be returned.
* @return long containing number of features
*/
virtual long featureCount() const;

/**
* Update the data source of the layer. The layer's renderer and legend will be preserved only
* if the geometry type of the new data source matches the current geometry type of the layer.
@@ -816,16 +807,40 @@ class QgsVectorLayer : QgsMapLayer
*
* @return A list of fields
*/
const QgsFields pendingFields() const;
QgsFields pendingFields() const;

/**
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
* Alias for {@link attributeList()}
*/
QgsAttributeList pendingAllAttributesList() const;

/**
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
* Alias for {@link attributeList()}
*/
QgsAttributeList attributeList() const;

/**
* Returns list of attributes making up the primary key
* Alias for {@link pkAttributeList()}
*/
QgsAttributeList pendingPkAttributesList() const;

/** Returns list of attributes */
QList<int> pendingAllAttributesList();
/** Returns list of attributes making up the primary key */
QgsAttributeList pkAttributeList() const;

/** Returns list of attribute making up the primary key */
QList<int> pendingPkAttributesList();
/**
* Returns feature count including changes which have not yet been committed
* Alias for {@link featureCount()}
*/
long pendingFeatureCount() const;

/** Returns feature count after commit */
int pendingFeatureCount();
/**
* Returns feature count including changes which have not yet been committed
* If you need only the count of committed features call this method on this layer's provider.
*/
long featureCount() const;

/** Make layer read-only (editing disabled) or not
* @return false if the layer is in editing yet
@@ -961,7 +961,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
QgsGeometry* lrsGeom = 0;
double measure1, measure2 = 0.0;

int nEventFeatures = eventLayer->pendingFeatureCount();
int nEventFeatures = eventLayer->featureCount();
int featureCounter = 0;
int nOutputFeatures = 0; //number of output features for the current event feature
if ( p )
@@ -6285,7 +6285,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )

QHash<int, int> remap;
const QgsFields &fields = clipboard()->fields();
QgsAttributeList pkAttrList = pasteVectorLayer->pendingPkAttributesList();
QgsAttributeList pkAttrList = pasteVectorLayer->pkAttributeList();
for ( int idx = 0; idx < fields.count(); ++idx )
{
int dst = pasteVectorLayer->fieldNameIndex( fields[idx].name() );
@@ -88,7 +88,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()

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

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

QSet<int> pkAttributes = mVectorLayer->pendingPkAttributesList().toSet();
QSet<int> pkAttributes = mVectorLayer->pkAttributeList().toSet();
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
{
if ( pkAttributes.contains( i ) )
@@ -602,8 +602,8 @@ QVariant QgsLegendModelV2::data( const QModelIndex& index, int role ) const
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->featureCount() );
}
return name;
}
@@ -168,8 +168,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->featureCount() );
}
return name;
}
@@ -413,8 +413,8 @@ void QgsSymbolV2LegendNode::updateLabel()
layerName = mLayerNode->customProperty( "legend/title-label" ).toString();

mLabel = mUserLabel.isEmpty() ? layerName : mUserLabel;
if ( showFeatureCount && vl && vl->pendingFeatureCount() >= 0 )
mLabel += QString( " [%1]" ).arg( vl->pendingFeatureCount() );
if ( showFeatureCount && vl && vl->featureCount() >= 0 )
mLabel += QString( " [%1]" ).arg( vl->featureCount() );
}
else
{
@@ -883,8 +883,8 @@ void QgsOfflineEditing::copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLay
// NOTE: use this to map column indices in case the remote geometry column is not last
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
{
const QgsAttributeList& offlineAttrs = offlineLayer->pendingAllAttributesList();
const QgsAttributeList& remoteAttrs = remoteLayer->pendingAllAttributesList();
const QgsAttributeList& offlineAttrs = offlineLayer->attributeList();
const QgsAttributeList& remoteAttrs = remoteLayer->attributeList();

QMap < int /*offline attr*/, int /*remote attr*/ > attrLookup;
// NOTE: use size of remoteAttrs, as offlineAttrs can have new attributes not yet synced
@@ -1945,7 +1945,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
errorMessage->clear();
}

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

//add possible attributes needed by renderer
@@ -675,17 +675,6 @@ bool QgsVectorLayer::diagramsEnabled() const
return false;
}

long QgsVectorLayer::featureCount() const
{
if ( !mDataProvider )
{
QgsDebugMsg( "invoked with null mDataProvider" );
return 0;
}

return mDataProvider->featureCount();
}

long QgsVectorLayer::featureCount( QgsSymbolV2* symbol )
{
if ( !mSymbolFeatureCounted ) return -1;
@@ -716,7 +705,7 @@ bool QgsVectorLayer::countSymbolFeatures( bool showProgress )
mSymbolFeatureCountMap.insert( symbolIt->second, 0 );
}

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

QgsAttributeList QgsVectorLayer::pendingAllAttributesList()
{
return mUpdatedFields.allAttributesList();
}

QgsAttributeList QgsVectorLayer::pendingPkAttributesList()
QgsAttributeList QgsVectorLayer::pkAttributeList() const
{
QgsAttributeList pkAttributesList;

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

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

QgsAttributeList pkAttrList = pendingPkAttributesList();
QgsAttributeList pkAttrList = pkAttributeList();
if ( !pkAttrList.isEmpty() )
{
myMetadata += "<p class=\"glossy\">" + tr( "Primary key attributes" ) + "</p>\n";
@@ -1061,15 +1061,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
bool readSld( const QDomNode& node, QString& errorMessage ) override;

/**
* Number of features in the layer. This is necessary if features are
* added/deleted or the layer has been subsetted. If the data provider
* chooses not to support this feature, the total number of features
* can be returned.
* @return long containing number of features
*/
virtual long featureCount() const;

/**
* Number of features rendered with specified symbol. Features must be first
* calculated by countSymbolFeatures()
@@ -1306,7 +1297,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*
* @return A list of fields
*/
const inline QgsFields fields() const { return mUpdatedFields; }
inline QgsFields fields() const { return mUpdatedFields; }

/**
* Returns the list of fields of this layer.
@@ -1315,16 +1306,40 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*
* @return A list of fields
*/
const inline QgsFields pendingFields() const { return mUpdatedFields; }
inline QgsFields pendingFields() const { return mUpdatedFields; }

/**
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
* Alias for {@link attributeList()}
*/
inline QgsAttributeList pendingAllAttributesList() const { return mUpdatedFields.allAttributesList(); }

/**
* Returns list of attribute indexes. i.e. a list from 0 ... fieldCount()
* Alias for {@link attributeList()}
*/
inline QgsAttributeList attributeList() const { return mUpdatedFields.allAttributesList(); }

/**
* Returns list of attributes making up the primary key
* Alias for {@link pkAttributeList()}
*/
inline QgsAttributeList pendingPkAttributesList() const { return pkAttributeList(); }

/** Returns list of attributes */
QgsAttributeList pendingAllAttributesList();
/** Returns list of attributes making up the primary key */
QgsAttributeList pkAttributeList() const;

/** Returns list of attribute making up the primary key */
QgsAttributeList pendingPkAttributesList();
/**
* Returns feature count including changes which have not yet been committed
* Alias for {@link featureCount()}
*/
inline long pendingFeatureCount() const { return featureCount(); }

/** Returns feature count after commit */
int pendingFeatureCount();
/**
* Returns feature count including changes which have not yet been committed
* If you need only the count of committed features call this method on this layer's provider.
*/
long featureCount() const;

/** Make layer read-only (editing disabled) or not
* @return false if the layer is in editing yet
@@ -31,7 +31,7 @@ QgsVectorLayerCache::QgsVectorLayerCache( QgsVectorLayer* layer, int cacheSize,
connect( mLayer, SIGNAL( layerDeleted() ), SLOT( layerDeleted() ) );

setCacheGeometry( true );
setCacheSubsetOfAttributes( mLayer->pendingAllAttributesList() );
setCacheSubsetOfAttributes( mLayer->attributeList() );
setCacheAddedAttributes( true );

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

if ( !featureRequest.flags().testFlag( QgsFeatureRequest::SubsetOfAttributes ) )
{
requestedAttributes = mLayer->pendingAllAttributesList();
requestedAttributes = mLayer->attributeList();
}
else
{
@@ -302,7 +302,7 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer,
errorMessage->clear();
}

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

QgsFeatureRequest req;
@@ -111,7 +111,7 @@ void QgsDualView::columnBoxInit()
// if neither diaplay expression nor display field is saved...
if ( displayExpression == "" )
{
QgsAttributeList pkAttrs = mLayerCache->layer()->pendingPkAttributesList();
QgsAttributeList pkAttrs = mLayerCache->layer()->pkAttributeList();

if ( pkAttrs.size() > 0 )
{
@@ -506,7 +506,7 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
renderContext.setRendererScale( 0 ); // ignore scale
mRenderer->startRender( renderContext, mLayer->fields() );

int nFeatures = mLayer->pendingFeatureCount();
int nFeatures = mLayer->featureCount();
QProgressDialog p( tr( "Calculating feature count." ), tr( "Abort" ), 0, nFeatures );
p.setWindowModality( Qt::WindowModal );
int featuresCounted = 0;
@@ -77,7 +77,7 @@ void TestVectorLayerJoinBuffer::initTestCase()
QgsFeature fA2( mLayerA->dataProvider()->fields(), 2 );
fA2.setAttribute( "id_a", 2 );
mLayerA->dataProvider()->addFeatures( QgsFeatureList() << fA1 << fA2 );
QVERIFY( mLayerA->pendingFeatureCount() == 2 );
QVERIFY( mLayerA->featureCount() == 2 );

// LAYER B //

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

// LAYER C //

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

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

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

0 comments on commit cf2f6b1

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