Skip to content

Commit

Permalink
Removed old vector layer API (select(), nextFeature(), featureAtId())
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 16, 2013
1 parent 6361d19 commit 5d42734
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 356 deletions.
40 changes: 0 additions & 40 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ class QgsVectorLayer : QgsMapLayer

public:

QgsVectorLayer* __iter__();
%MethodCode
sipRes = sipCpp;
%End

SIP_PYOBJECT __next__();
%MethodCode
QgsFeature* f = new QgsFeature;
if (sipCpp->nextFeature(*f))
sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None);
else
{
delete f;
PyErr_SetString(PyExc_StopIteration,"");
}
%End

enum EditorLayout
{
GeneratedLayout,
Expand Down Expand Up @@ -382,34 +365,11 @@ class QgsVectorLayer : QgsMapLayer
*/
virtual QString subsetString();

/**
* Select features with or without attributes in a given window.
* @param fetchAttributes indizes of attributes to fetch
* @param rect window (QgsRectangle() for all)
* @param fetchGeometry fetch features with geometry
* @param useIntersect fetch only features that actually intersect the window (not just the bounding box)
*/
void select( QList<int> fetchAttributes,
QgsRectangle rect = QgsRectangle(),
bool fetchGeometry = true,
bool useIntersect = false ) /Deprecated/;

/**
* Query the provider for features specified in request.
*/
QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() );

/**
* fetch a feature (after select)
* @param feature buffer to read the feature into
* @return true, if a feature was fetched, false, if there are no more features
*/
bool nextFeature( QgsFeature& feature ) /Deprecated/;

/**Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
@return true in case of success*/
bool featureAtId( QgsFeatureId featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true ) /Deprecated/;

/** Adds a feature
@param f feature to add
@param alsoUpdateExtent If True, will also go to the effort of e.g. updating the extents.
Expand Down
280 changes: 0 additions & 280 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ QgsVectorLayer::~QgsVectorLayer()
{
QgsDebugMsg( "entered." );

if ( !mLayerIterator.isClosed() )
mLayerIterator.close();

emit layerDeleted();

mValid = false;
Expand Down Expand Up @@ -1667,15 +1664,6 @@ bool QgsVectorLayer::setSubsetString( QString subset )
return res;
}

#if 0
void QgsVectorLayer::addJoinedAttributes( QgsFeature& f, bool all )
{
if ( all || ( mFetchAttributes.size() > 0 && mJoinBuffer->containsFetchJoins() ) )
{
mJoinBuffer->updateFeatureAttributes( f, f.attributes().count(), all );
}
}
#endif

QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
{
Expand All @@ -1685,274 +1673,6 @@ QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request
return QgsFeatureIterator( new QgsVectorLayerFeatureIterator( this, request ) );
}

void QgsVectorLayer::select( QgsAttributeList attributes, QgsRectangle rect, bool fetchGeometries, bool useIntersect )
{
QgsFeatureRequest request;
if ( !rect.isEmpty() )
request.setFilterRect( rect );
if ( !fetchGeometries )
request.setFlags( QgsFeatureRequest::NoGeometry );
if ( useIntersect )
request.setFlags( request.flags() | QgsFeatureRequest::ExactIntersect );
if ( attributes != pendingAllAttributesList() )
request.setSubsetOfAttributes( attributes );

if ( !mLayerIterator.isClosed() )
mLayerIterator.close();

mLayerIterator = getFeatures( request );
}

bool QgsVectorLayer::nextFeature( QgsFeature &f )
{
return mLayerIterator.nextFeature( f );

#if 0
if ( !mFetching )
return false;

if ( mEditBuffer )
{
if ( !mFetchRect.isEmpty() )
{
// check if changed geometries are in rectangle
for ( ; mFetchChangedGeomIt != mEditBuffer->mChangedGeometries.end(); mFetchChangedGeomIt++ )
{
QgsFeatureId fid = mFetchChangedGeomIt.key();

if ( mFetchConsidered.contains( fid ) )
// skip deleted features
continue;

mFetchConsidered << fid;

if ( !mFetchChangedGeomIt->intersects( mFetchRect ) )
// skip changed geometries not in rectangle and don't check again
continue;

f.setFeatureId( fid );
f.setValid( true );

if ( mFetchGeometry )
f.setGeometry( mFetchChangedGeomIt.value() );

if ( mFetchAttributes.size() > 0 )
{
if ( fid < 0 )
{
// fid<0 => in mAddedFeatures
bool found = false;

for ( QgsFeatureList::iterator it = mEditBuffer->mAddedFeatures.begin(); it != mEditBuffer->mAddedFeatures.end(); it++ )
{
if ( fid == it->id() )
{
found = true;
f.setAttributes( it->attributes() );
// no need to update (always up-to-date) updateFeatureAttributes( f );
break;
}
}

if ( !found )
{
QgsDebugMsg( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
}
}
else
{
// retrieve attributes from provider
QgsFeature tmp;
//mDataProvider->featureAtId( fid, tmp, false, mFetchProvAttributes );
QgsFeatureRequest request;
request.setFilterFid( fid ).setSubsetOfAttributes( mFetchProvAttributes );
QgsFeatureIterator fi = mDataProvider->getFeatures( request );
if ( fi.nextFeature( tmp ) )
{
if ( mEditBuffer )
mEditBuffer->updateChangedAttributes( tmp );
f.setAttributes( tmp.attributes() );
}
}
}

addJoinedAttributes( f );

// return complete feature
mFetchChangedGeomIt++;
return true;
}

// no more changed geometries
}

for ( ; mFetchAddedFeaturesIt != mEditBuffer->mAddedFeatures.end(); mFetchAddedFeaturesIt++ )
{
QgsFeatureId fid = mFetchAddedFeaturesIt->id();

if ( mFetchConsidered.contains( fid ) )
// must have changed geometry outside rectangle
continue;

if ( !mFetchRect.isEmpty() &&
mFetchAddedFeaturesIt->geometry() &&
!mFetchAddedFeaturesIt->geometry()->intersects( mFetchRect ) )
// skip added features not in rectangle
continue;

f.setFeatureId( fid );
f.setValid( true );

if ( mFetchGeometry )
f.setGeometry( *mFetchAddedFeaturesIt->geometry() );

if ( mFetchAttributes.size() > 0 )
{
f.setAttributes( mFetchAddedFeaturesIt->attributes() );
// no need to do this (always up-to-date) updateFeatureAttributes( f );
}

addJoinedAttributes( f );

mFetchAddedFeaturesIt++;
return true;
}

// no more added features
}

while ( mProviderIterator.nextFeature( f ) )
{
if ( mFetchConsidered.contains( f.id() ) )
{
continue;
}
if ( mFetchAttributes.size() > 0 )
{
if ( mEditBuffer )
mEditBuffer->updateChangedAttributes( f ); //check changed attributes
addJoinedAttributes( f ); // check joined attributes
}
if ( mEditBuffer && mFetchGeometry )
{
mEditBuffer->updateFeatureGeometry( f );
}

return true;
}

mFetching = false;
return false;
#endif
}

bool QgsVectorLayer::featureAtId( QgsFeatureId featureId, QgsFeature& f, bool fetchGeometries, bool fetchAttributes )
{
QgsFeatureRequest request;
request.setFilterFid( featureId );
if ( !fetchGeometries )
request.setFlags( QgsFeatureRequest::NoGeometry );
if ( !fetchAttributes )
request.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator fi = getFeatures( request );
return fi.nextFeature( f );

#if 0
if ( !mDataProvider )
return false;

if ( mEditBuffer && mEditBuffer->mDeletedFeatureIds.contains( featureId ) )
return false;

if ( fetchGeometries && mEditBuffer->mChangedGeometries.contains( featureId ) )
{
f.setFeatureId( featureId );
f.setValid( true );
f.setGeometry( mEditBuffer->mChangedGeometries[featureId] );

if ( fetchAttributes )
{
if ( featureId < 0 && mEditBuffer )
{
// featureId<0 => in mAddedFeatures
bool found = false;

for ( QgsFeatureList::iterator it = mEditBuffer->mAddedFeatures.begin(); it != mEditBuffer->mAddedFeatures.end(); it++ )
{
if ( featureId != it->id() )
{
found = true;
f.setAttributes( it->attributes() );
break;
}
}

if ( !found )
{
QgsDebugMsg( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
}
}
else
{
// retrieve attributes from provider
QgsFeature tmp;
//mDataProvider->featureAtId( featureId, tmp, false, mDataProvider->attributeIndexes() );
QgsFeatureRequest request;
request.setFilterFid( featureId ).setFlags( QgsFeatureRequest::NoGeometry );
QgsFeatureIterator fi = mDataProvider->getFeatures( request );
if ( fi.nextFeature( tmp ) )
{
f.setAttributes( tmp.attributes() );
if ( mEditBuffer )
mEditBuffer->updateChangedAttributes( f );
}
}
addJoinedAttributes( f, true );
}
return true;
}

//added features
if ( mEditBuffer )
{
for ( QgsFeatureList::iterator iter = mEditBuffer->mAddedFeatures.begin(); iter != mEditBuffer->mAddedFeatures.end(); ++iter )
{
if ( iter->id() == featureId )
{
f.setFeatureId( iter->id() );
f.setValid( true );
if ( fetchGeometries )
f.setGeometry( *iter->geometry() );

if ( fetchAttributes )
f.setAttributes( iter->attributes() );

return true;
}
}
}

// regular features
QgsFeatureRequest request;
request.setFilterFid( featureId );
if ( !fetchGeometries )
request.setFlags( QgsFeatureRequest::NoGeometry );
if ( !fetchAttributes )
request.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator fi = mDataProvider->getFeatures( request );
if ( fi.nextFeature( f ) )
{
if ( mEditBuffer )
mEditBuffer->updateChangedAttributes( f );
addJoinedAttributes( f, true );
return true;
}

return false;
#endif
}

bool QgsVectorLayer::addFeature( QgsFeature& f, bool alsoUpdateExtent )
{
Expand Down
Loading

0 comments on commit 5d42734

Please sign in to comment.