mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Removed old vector layer API (select(), nextFeature(), featureAtId())
This commit is contained in:
parent
6361d19f43
commit
5d42734cf2
@ -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,
|
||||
@ -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.
|
||||
|
@ -181,9 +181,6 @@ QgsVectorLayer::~QgsVectorLayer()
|
||||
{
|
||||
QgsDebugMsg( "entered." );
|
||||
|
||||
if ( !mLayerIterator.isClosed() )
|
||||
mLayerIterator.close();
|
||||
|
||||
emit layerDeleted();
|
||||
|
||||
mValid = false;
|
||||
@ -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 )
|
||||
{
|
||||
@ -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 )
|
||||
{
|
||||
|
@ -437,28 +437,6 @@ class CORE_EXPORT QgsVectorLayer : public 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)
|
||||
*/
|
||||
Q_DECL_DEPRECATED void select( QgsAttributeList fetchAttributes,
|
||||
QgsRectangle rect = QgsRectangle(),
|
||||
bool fetchGeometry = true,
|
||||
bool useIntersect = false );
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Q_DECL_DEPRECATED bool nextFeature( QgsFeature& feature );
|
||||
|
||||
/**Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
|
||||
@return true in case of success*/
|
||||
Q_DECL_DEPRECATED bool featureAtId( QgsFeatureId featureId, QgsFeature &f, bool fetchGeometries = true, bool fetchAttributes = true );
|
||||
|
||||
/**
|
||||
* Query the provider for features specified in request.
|
||||
*/
|
||||
@ -1088,20 +1066,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
||||
//annotation form for this layer
|
||||
QString mAnnotationForm;
|
||||
|
||||
QgsFeatureIterator mLayerIterator; // temporary: to support old API
|
||||
|
||||
#if 0
|
||||
bool mFetching;
|
||||
QgsRectangle mFetchRect;
|
||||
QgsAttributeList mFetchAttributes;
|
||||
QgsAttributeList mFetchProvAttributes;
|
||||
bool mFetchGeometry;
|
||||
|
||||
QSet<QgsFeatureId> mFetchConsidered;
|
||||
QgsGeometryMap::iterator mFetchChangedGeomIt;
|
||||
QgsFeatureList::iterator mFetchAddedFeaturesIt;
|
||||
#endif
|
||||
|
||||
//! cache for some vector layer data - currently only geometries for faster editing
|
||||
QgsVectorLayerCache* mCache;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user