QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
QgsFeatureRequest Class Reference

This class wraps a request for features to a vector layer (or directly its vector data provider). More...

#include <qgsfeaturerequest.h>

Collaboration diagram for QgsFeatureRequest:
Collaboration graph
[legend]

Public Types

enum  Flag { NoFlags = 0, NoGeometry = 1, SubsetOfAttributes = 2, ExactIntersect = 4 }
enum  FilterType {
  FilterNone, FilterRect, FilterFid, FilterExpression,
  FilterFids
}

Public Member Functions

 QgsFeatureRequest ()
 construct a default request: for all features get attributes and geometries
 QgsFeatureRequest (QgsFeatureId fid)
 construct a request with feature ID filter
 QgsFeatureRequest (const QgsRectangle &rect)
 construct a request with rectangle filter
 QgsFeatureRequest (const QgsExpression &expr)
 construct a request with a filter expression
 QgsFeatureRequest (const QgsFeatureRequest &rh)
 copy constructor
QgsFeatureRequestoperator= (const QgsFeatureRequest &rh)
 ~QgsFeatureRequest ()
FilterType filterType () const
QgsFeatureRequestsetFilterRect (const QgsRectangle &rect)
 Set rectangle from which features will be taken.
const QgsRectanglefilterRect () const
QgsFeatureRequestsetFilterFid (QgsFeatureId fid)
 Set feature ID that should be fetched.
const QgsFeatureIdfilterFid () const
QgsFeatureRequestsetFilterFids (QgsFeatureIds fids)
 Set feature ID that should be fetched.
const QgsFeatureIdsfilterFids () const
QgsFeatureRequestsetFilterExpression (const QString &expression)
 Set filter expression. {.
QgsExpressionfilterExpression () const
QgsFeatureRequestsetFlags (Flags flags)
 Set flags that affect how features will be fetched.
const Flags & flags () const
QgsFeatureRequestsetSubsetOfAttributes (const QgsAttributeList &attrs)
 Set a subset of attributes that will be fetched.
const QgsAttributeListsubsetOfAttributes () const
QgsFeatureRequestsetSubsetOfAttributes (const QStringList &attrNames, const QgsFields &fields)
 Set a subset of attributes by names that will be fetched.
QgsFeatureRequestsetSimplifyMethod (const QgsSimplifyMethod &simplifyMethod)
 Set a simplification method for geometries that will be fetched.
const QgsSimplifyMethodsimplifyMethod () const
 Get simplification method for geometries that will be fetched.
bool acceptFeature (const QgsFeature &feature)
 Check if a feature is accepted by this requests filter.

Protected Attributes

FilterType mFilter
QgsRectangle mFilterRect
QgsFeatureId mFilterFid
QgsFeatureIds mFilterFids
QgsExpressionmFilterExpression
Flags mFlags
QgsAttributeList mAttrs
QgsSimplifyMethod mSimplifyMethod

Detailed Description

This class wraps a request for features to a vector layer (or directly its vector data provider).

The request may apply a filter to fetch only a particular subset of features. Currently supported filters:

For efficiency, it is also possible to tell provider that some data is not required:

The options may be chained, e.g.: QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest::ExactIntersect)

Examples:

Definition at line 58 of file qgsfeaturerequest.h.

Member Enumeration Documentation

Enumerator:
FilterNone 

No filter is applied.

FilterRect 

Filter using a rectangle, no need to set NoGeometry.

FilterFid 

Filter using feature ID.

FilterExpression 

Filter using expression.

FilterFids 

Filter using feature IDs.

Definition at line 70 of file qgsfeaturerequest.h.

Enumerator:
NoFlags 
NoGeometry 

Geometry is not required. It may still be returned if e.g. required for a filter condition.

SubsetOfAttributes 

Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)

ExactIntersect 

Use exact geometry intersection (slower) instead of bounding boxes.

Definition at line 61 of file qgsfeaturerequest.h.

Constructor & Destructor Documentation

QgsFeatureRequest::QgsFeatureRequest ( )

construct a default request: for all features get attributes and geometries

Definition at line 22 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( QgsFeatureId  fid)
explicit

construct a request with feature ID filter

Definition at line 29 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsRectangle rect)
explicit

construct a request with rectangle filter

Definition at line 37 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsExpression expr)
explicit

construct a request with a filter expression

Definition at line 45 of file qgsfeaturerequest.cpp.

QgsFeatureRequest::QgsFeatureRequest ( const QgsFeatureRequest rh)

copy constructor

Definition at line 52 of file qgsfeaturerequest.cpp.

References operator=().

QgsFeatureRequest::~QgsFeatureRequest ( )

Definition at line 77 of file qgsfeaturerequest.cpp.

References mFilterExpression.

Member Function Documentation

bool QgsFeatureRequest::acceptFeature ( const QgsFeature feature)

Check if a feature is accepted by this requests filter.

Parameters
featureThe feature which will be tested
Returns
true, if the filter accepts the feature
Note
added in 2.1

Definition at line 144 of file qgsfeaturerequest.cpp.

References QgsExpression::evaluate(), FilterExpression, FilterFid, FilterFids, FilterNone, FilterRect, QgsFeature::geometry(), QgsFeature::id(), QgsGeometry::intersects(), mFilter, mFilterExpression, mFilterFid, mFilterFids, and mFilterRect.

Referenced by QgsAttributeTableModel::attributeValueChanged(), QgsAttributeTableModel::featureAdded(), QgsCachedFeatureIterator::fetchFeature(), and QgsVectorLayerFeatureIterator::fetchNextAddedFeature().

QgsExpression* QgsFeatureRequest::filterExpression ( ) const
inline
const QgsFeatureId& QgsFeatureRequest::filterFid ( ) const
inline
const QgsFeatureIds& QgsFeatureRequest::filterFids ( ) const
inline
const QgsRectangle& QgsFeatureRequest::filterRect ( ) const
inline
FilterType QgsFeatureRequest::filterType ( ) const
inline
const Flags& QgsFeatureRequest::flags ( ) const
inline
QgsFeatureRequest & QgsFeatureRequest::operator= ( const QgsFeatureRequest rh)
QgsFeatureRequest & QgsFeatureRequest::setFilterExpression ( const QString &  expression)

Set filter expression. {.

See Also
QgsExpression}

Definition at line 103 of file qgsfeaturerequest.cpp.

References FilterExpression, mFilter, and mFilterExpression.

Referenced by QgsRelation::getRelatedFeaturesRequest().

QgsFeatureRequest & QgsFeatureRequest::setFilterFid ( QgsFeatureId  fid)
QgsFeatureRequest & QgsFeatureRequest::setFilterFids ( QgsFeatureIds  fids)

Set feature ID that should be fetched.

Definition at line 96 of file qgsfeaturerequest.cpp.

References FilterFids, mFilter, and mFilterFids.

Referenced by QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator().

QgsFeatureRequest & QgsFeatureRequest::setFilterRect ( const QgsRectangle rect)

Set rectangle from which features will be taken.

Empty rectangle removes the filter.

Definition at line 82 of file qgsfeaturerequest.cpp.

References FilterRect, mFilter, and mFilterRect.

Referenced by QgsVectorLayer::draw(), and QgsComposerAttributeTable::getFeatureAttributes().

QgsFeatureRequest & QgsFeatureRequest::setFlags ( Flags  flags)
QgsFeatureRequest & QgsFeatureRequest::setSimplifyMethod ( const QgsSimplifyMethod simplifyMethod)

Set a simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 138 of file qgsfeaturerequest.cpp.

References mSimplifyMethod, and simplifyMethod().

Referenced by QgsVectorLayer::draw().

QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes ( const QgsAttributeList attrs)
QgsFeatureRequest & QgsFeatureRequest::setSubsetOfAttributes ( const QStringList &  attrNames,
const QgsFields fields 
)

Set a subset of attributes by names that will be fetched.

Definition at line 124 of file qgsfeaturerequest.cpp.

References QgsFields::count(), mAttrs, mFlags, and SubsetOfAttributes.

const QgsSimplifyMethod& QgsFeatureRequest::simplifyMethod ( ) const
inline

Get simplification method for geometries that will be fetched.

Note
added in 2.2

Definition at line 130 of file qgsfeaturerequest.h.

Referenced by QgsAbstractFeatureIterator::ref(), and setSimplifyMethod().

const QgsAttributeList& QgsFeatureRequest::subsetOfAttributes ( ) const
inline

Member Data Documentation

QgsAttributeList QgsFeatureRequest::mAttrs
protected

Definition at line 154 of file qgsfeaturerequest.h.

Referenced by operator=(), and setSubsetOfAttributes().

FilterType QgsFeatureRequest::mFilter
protected
QgsExpression* QgsFeatureRequest::mFilterExpression
protected
QgsFeatureId QgsFeatureRequest::mFilterFid
protected

Definition at line 150 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterFid().

QgsFeatureIds QgsFeatureRequest::mFilterFids
protected

Definition at line 151 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterFids().

QgsRectangle QgsFeatureRequest::mFilterRect
protected

Definition at line 149 of file qgsfeaturerequest.h.

Referenced by acceptFeature(), operator=(), and setFilterRect().

Flags QgsFeatureRequest::mFlags
protected

Definition at line 153 of file qgsfeaturerequest.h.

Referenced by operator=(), setFlags(), and setSubsetOfAttributes().

QgsSimplifyMethod QgsFeatureRequest::mSimplifyMethod
protected

Definition at line 155 of file qgsfeaturerequest.h.

Referenced by operator=(), and setSimplifyMethod().


The documentation for this class was generated from the following files: