Skip to content
Permalink
Browse files
added listAllFeatureIds and check that features exist when setting se…
…lection
  • Loading branch information
3nids authored and jef-n committed Sep 15, 2013
1 parent 821b1d2 commit 39fab67e602aaa8be7e561a50b40ab7c38914258
Showing with 28 additions and 18 deletions.
  1. +3 −0 python/core/qgsvectorlayer.sip
  2. +22 −18 src/core/qgsvectorlayer.cpp
  3. +3 −0 src/core/qgsvectorlayer.h
@@ -294,6 +294,9 @@ class QgsVectorLayer : QgsMapLayer
/** Select all the features */
void selectAll();

/** Get all feature Ids */
QgsFeatureIds listAllFeatureIds();

/**
* Invert selection of features found within the search rectangle (in layer's coordinates)
*
@@ -792,27 +792,17 @@ void QgsVectorLayer::modifySelection( QgsFeatureIds selectIds, QgsFeatureIds des

void QgsVectorLayer::invertSelection()
{
// copy the ids of selected features to tmp
QgsFeatureIds tmp = mSelectedFeatureIds;

QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFlags( QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( QgsAttributeList() ) );

QgsFeatureIds ids;

QgsFeature fet;
while ( fit.nextFeature( fet ) )
{
ids << fet.id();
}

QgsFeatureIds ids = listAllFeatureIds();
ids.subtract( mSelectedFeatureIds );

setSelectedFeatures( ids );
}

void QgsVectorLayer::selectAll()
{
setSelectedFeatures( listAllFeatureIds() );
}

QgsFeatureIds QgsVectorLayer::listAllFeatureIds()
{
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFlags( QgsFeatureRequest::NoGeometry )
@@ -826,7 +816,7 @@ void QgsVectorLayer::selectAll()
ids << fet.id();
}

setSelectedFeatures( ids );
return ids;
}

void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle & rect )
@@ -2682,9 +2672,23 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
void QgsVectorLayer::setSelectedFeatures( const QgsFeatureIds& ids )
{
QgsFeatureIds deselectedFeatures = mSelectedFeatureIds - ids;
// TODO: check whether features with these ID exist

mSelectedFeatureIds = ids;

QgsFeatureIds allIds = listAllFeatureIds();
QgsFeatureIds::iterator id = mSelectedFeatureIds.begin();
while ( id != mSelectedFeatureIds.end() )
{
if ( !allIds.contains( *id ) )
{
id = mSelectedFeatureIds.erase( id );
}
else
{
++id;
}
}

// invalidate cache
setCacheImage( 0 );

@@ -631,6 +631,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Select all the features */
void selectAll();

/** Get all feature Ids */
QgsFeatureIds listAllFeatureIds();

/**
* Invert selection of features found within the search rectangle (in layer's coordinates)
*

0 comments on commit 39fab67

Please sign in to comment.