QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
20 #include <QStringList>
31 : mFilter( FilterFid )
38 : mFilter( FilterFids )
52 : mFilter( FilterExpression )
54 , mExpressionContext( context )
213 const auto constAttrNames = attrNames;
214 for (
const QString &attrName : constAttrNames )
217 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
235 const auto constAttrNames = attrNames;
236 for (
const QString &attrName : constAttrNames )
239 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
369 : mExpression( expression )
370 , mAscending( ascending )
377 : mExpression( expression )
378 , mAscending( ascending )
379 , mNullsFirst( nullsfirst )
384 : mExpression( expression )
385 , mAscending( ascending )
392 : mExpression( expression )
393 , mAscending( ascending )
394 , mNullsFirst( nullsfirst )
406 mAscending = ascending;
416 mNullsFirst = nullsFirst;
421 return QStringLiteral(
"%1 %2 %3" )
422 .arg( mExpression.expression(),
423 mAscending ?
"ASC" :
"DESC",
424 mNullsFirst ?
"NULLS FIRST" :
"NULLS LAST" );
434 return mExpression.prepare( context );
441 const auto constOther = other;
455 QDomDocument doc = elem.ownerDocument();
456 QList<OrderByClause>::ConstIterator it;
457 for ( it = constBegin(); it != constEnd(); ++it )
460 QDomElement clauseElem = doc.createElement( QStringLiteral(
"orderByClause" ) );
461 clauseElem.setAttribute( QStringLiteral(
"asc" ), clause.
ascending() );
462 clauseElem.setAttribute( QStringLiteral(
"nullsFirst" ), clause.
nullsFirst() );
465 elem.appendChild( clauseElem );
473 QDomNodeList clauses = elem.childNodes();
475 for (
int i = 0; i < clauses.size(); ++i )
477 QDomElement clauseElem = clauses.at( i ).toElement();
478 QString expression = clauseElem.text();
479 bool asc = clauseElem.attribute( QStringLiteral(
"asc" ) ).toInt() != 0;
480 bool nullsFirst = clauseElem.attribute( QStringLiteral(
"nullsFirst" ) ).toInt() != 0;
488 QSet<QString> usedAttributes;
490 QList<OrderByClause>::ConstIterator it;
491 for ( it = constBegin(); it != constEnd(); ++it )
498 return usedAttributes;
503 QSet<int> usedAttributeIdx;
507 for (
const QString &fieldName : referencedColumns )
512 usedAttributeIdx.insert( idx );
516 return usedAttributeIdx;
523 QList<OrderByClause>::ConstIterator it;
524 for ( it = constBegin(); it != constEnd(); ++it )
528 results << clause.
dump();
531 return results.join( QStringLiteral(
", " ) );
QgsSimplifyMethod mSimplifyMethod
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
@ FilterFid
Filter using feature ID.
QgsExpression expression() const
The expression.
InvalidGeometryCheck mInvalidGeometryFilter
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
QgsFeatureIds mFilterFids
QgsFeatureRequest & addOrderBy(const QString &expression, bool ascending=true)
Adds a new OrderByClause, appending it as the least important one.
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
virtual ~QgsAbstractFeatureSource()
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
CORE_EXPORT OrderBy()
Create a new empty order by.
void setAscending(bool ascending)
Set if ascending order is requested.
#define QgsDebugMsgLevel(str, level)
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
QgsFeatureRequest & operator=(const QgsFeatureRequest &rh)
Assignment operator.
const Flags & flags() const
int timeout() const
Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests bef...
const QgsCoordinateReferenceSystem & crs
QgsCoordinateReferenceSystem mCrs
@ FilterFids
Filter using feature IDs.
QSet< QgsAbstractFeatureIterator * > mActiveIterators
QgsFeatureRequest & setInvalidGeometryCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for feature's geometries, or an invalid QgsCoordi...
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
InvalidGeometryCheck
Handling of features with invalid geometries.
QList< int > QgsAttributeList
bool prepare(QgsExpressionContext *context)
Prepare the expression with the given context.
@ SubsetOfAttributes
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
QSet< QString > CORE_EXPORT usedAttributes() const
Returns a set of used attributes.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void setNullsFirst(bool nullsFirst)
Set if NULLS should be returned first.
QgsFeatureRequest()
construct a default request: for all features get attributes and geometries
QString dump() const
Dumps the content to an SQL equivalent.
QgsExpressionContext mExpressionContext
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
Q_DECL_DEPRECATED QgsFeatureRequest & setConnectionTimeout(int connectionTimeout)
Sets the timeout (in milliseconds) for how long we should wait for a connection if none is available ...
std::unique_ptr< QgsExpression > mFilterExpression
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
QgsFeatureRequest & setTransformErrorCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering a transform error when iterating features and a des...
bool ascending() const
Order ascending.
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
bool requestMayBeNested() const
In case this request may be run nested within another already running iteration on the same connectio...
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
void iteratorClosed(QgsAbstractFeatureIterator *it)
QgsCoordinateTransformContext mTransformContext
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
@ FilterExpression
Filter using expression.
QgsFeatureRequest & setTimeout(int timeout)
Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before...
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QSet< QgsFeatureId > QgsFeatureIds
QSet< int > CORE_EXPORT usedAttributeIndices(const QgsFields &fields) const
Returns a set of used, validated attribute indices.
std::function< void(const QgsFeature &) > mInvalidGeometryCallback
OrderByClause(const QString &expression, bool ascending=true)
Creates a new OrderByClause for a QgsFeatureRequest.
bool nullsFirst() const
Set if NULLS should be returned first.
QgsFeatureRequest & setRequestMayBeNested(bool requestMayBeNested)
In case this request may be run nested within another already running iteration on the same connectio...
OrderBy orderBy() const
Returns a list of order by clauses specified for this feature request.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
QList< QgsFeatureRequest::OrderByClause > CORE_EXPORT list() const
Gets a copy as a list of OrderByClauses.
void iteratorOpened(QgsAbstractFeatureIterator *it)
QString CORE_EXPORT dump() const
Dumps the content to an SQL equivalent syntax.
std::function< void(const QgsFeature &) > mTransformErrorCallback
const QgsSimplifyMethod & simplifyMethod() const
Gets simplification method for geometries that will be fetched.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
Q_DECL_DEPRECATED int connectionTimeout() const
Returns the timeout (in milliseconds) for how long we should wait for a connection if none is availab...
@ FilterNone
No filter is applied.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QString expression() const
Returns the original, unmodified expression string.
virtual bool close()=0
end of iterating: free the resources / lock
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
long limit() const
Returns the maximum number of features to request, or -1 if no limit set.