20 #include <QStringList> 209 const auto constAttrNames = attrNames;
210 for (
const QString &attrName : constAttrNames )
213 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
231 const auto constAttrNames = attrNames;
232 for (
const QString &attrName : constAttrNames )
235 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
338 while ( !mActiveIterators.empty() )
341 QgsDebugMsg( QStringLiteral(
"closing active iterator" ) );
348 mActiveIterators.insert( it );
353 mActiveIterators.remove( it );
359 : mExpression( expression )
360 , mAscending( ascending )
367 : mExpression( expression )
368 , mAscending( ascending )
369 , mNullsFirst( nullsfirst )
374 : mExpression( expression )
375 , mAscending( ascending )
382 : mExpression( expression )
383 , mAscending( ascending )
384 , mNullsFirst( nullsfirst )
411 return QStringLiteral(
"%1 %2 %3" )
413 mAscending ?
"ASC" :
"DESC",
414 mNullsFirst ?
"NULLS FIRST" :
"NULLS LAST" );
424 return mExpression.
prepare( context );
431 const auto constOther = other;
445 QDomDocument doc = elem.ownerDocument();
446 QList<OrderByClause>::ConstIterator it;
447 for ( it = constBegin(); it != constEnd(); ++it )
450 QDomElement clauseElem = doc.createElement( QStringLiteral(
"orderByClause" ) );
451 clauseElem.setAttribute( QStringLiteral(
"asc" ), clause.
ascending() );
452 clauseElem.setAttribute( QStringLiteral(
"nullsFirst" ), clause.
nullsFirst() );
455 elem.appendChild( clauseElem );
463 QDomNodeList clauses = elem.childNodes();
465 for (
int i = 0; i < clauses.size(); ++i )
467 QDomElement clauseElem = clauses.at( i ).toElement();
469 bool asc = clauseElem.attribute( QStringLiteral(
"asc" ) ).toInt() != 0;
470 bool nullsFirst = clauseElem.attribute( QStringLiteral(
"nullsFirst" ) ).toInt() != 0;
478 QSet<QString> usedAttributes;
480 QList<OrderByClause>::ConstIterator it;
481 for ( it = constBegin(); it != constEnd(); ++it )
488 return usedAttributes;
493 QSet<int> usedAttributeIdx;
497 for (
const QString &fieldName : referencedColumns )
502 usedAttributeIdx.insert( idx );
506 return usedAttributeIdx;
513 QList<OrderByClause>::ConstIterator it;
514 for ( it = constBegin(); it != constEnd(); ++it )
518 results << clause.
dump();
521 return results.join( QStringLiteral(
", " ) );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsCoordinateReferenceSystem mCrs
QgsFeatureIds mFilterFids
virtual bool close()=0
end of iterating: free the resources / lock
A rectangle specified with double values.
long limit() const
Returns the maximum number of features to request, or -1 if no limit set.
bool nullsFirst() const
Set if NULLS should be returned first.
bool acceptFeature(const QgsFeature &feature)
Check if a feature is accepted by this requests filter.
QSet< QString > CORE_EXPORT usedAttributes() const
Returns a set of used attributes.
Filter using feature IDs.
QgsSimplifyMethod mSimplifyMethod
QSet< QgsFeatureId > QgsFeatureIds
QgsFeatureRequest & setInvalidGeometryCallback(const std::function< void(const QgsFeature &)> &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
bool ascending() const
Order ascending.
const Flags & flags() const
QString dump() const
Dumps the content to an SQL equivalent.
void iteratorClosed(QgsAbstractFeatureIterator *it)
QgsFeatureRequest & setInvalidGeometryCheck(InvalidGeometryCheck check)
Sets invalid geometry checking behavior.
InvalidGeometryCheck mInvalidGeometryFilter
QList< QgsFeatureRequest::OrderByClause > CORE_EXPORT list() const
Gets a copy as a list of OrderByClauses.
QString CORE_EXPORT dump() const
Dumps the content to an SQL equivalent syntax.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
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.
Container of fields for a vector layer.
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
QgsFeatureRequest & addOrderBy(const QString &expression, bool ascending=true)
Adds a new OrderByClause, appending it as the least important one.
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 ...
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
QgsFeatureRequest & operator=(const QgsFeatureRequest &rh)
Assignment operator.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
int timeout() const
Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests bef...
QgsExpressionContext mExpressionContext
InvalidGeometryCheck
Handling of features with invalid geometries.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
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.
CORE_EXPORT OrderBy()
Create a new empty order by.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
OrderByClause(const QString &expression, bool ascending=true)
Creates a new OrderByClause for a QgsFeatureRequest.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
std::unique_ptr< QgsExpression > mFilterExpression
Internal feature iterator to be implemented within data providers.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool requestMayBeNested() const
In case this request may be run nested within another already running iteration on the same connectio...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureRequest()
construct a default request: for all features get attributes and geometries
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.
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
Contains information about the context in which a coordinate transform is executed.
virtual ~QgsAbstractFeatureSource()
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...
QString expression() const
Returns the original, unmodified expression string.
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
bool prepare(QgsExpressionContext *context)
Prepare the expression with the given context.
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
QgsExpression expression() const
The expression.
std::function< void(const QgsFeature &) > mInvalidGeometryCallback
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
QgsCoordinateTransformContext mTransformContext
std::function< void(const QgsFeature &) > mTransformErrorCallback
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
void setAscending(bool ascending)
Set if ascending order is requested.
QgsFeatureRequest & setTimeout(int timeout)
Sets the timeout (in milliseconds) for the maximum time we should wait during feature requests before...
This class represents a coordinate reference system (CRS).
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
QgsFeatureRequest & setRequestMayBeNested(bool requestMayBeNested)
In case this request may be run nested within another already running iteration on the same connectio...
QList< int > QgsAttributeList
Q_DECL_DEPRECATED int connectionTimeout() const
Returns the timeout (in milliseconds) for how long we should wait for a connection if none is availab...
OrderBy orderBy() const
Returns a list of order by clauses specified for this feature request.
QgsCoordinateTransformContext transformContext() const
Returns the transform context, for use when a destinationCrs() has been set and reprojection is requi...
const QgsSimplifyMethod & simplifyMethod() const
Gets simplification method for geometries that will be fetched.
Represents a list of OrderByClauses, with the most important first and the least important last...
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
void iteratorOpened(QgsAbstractFeatureIterator *it)
QSet< int > CORE_EXPORT usedAttributeIndices(const QgsFields &fields) const
Returns a set of used, validated attribute indices.
void setNullsFirst(bool nullsFirst)
Set if NULLS should be returned first.