20 #include <QStringList> 209 Q_FOREACH (
const QString &attrName, attrNames )
212 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
230 Q_FOREACH (
const QString &attrName, attrNames )
233 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
336 while ( !mActiveIterators.empty() )
339 QgsDebugMsg( QStringLiteral(
"closing active iterator" ) );
346 mActiveIterators.insert( it );
351 mActiveIterators.remove( it );
357 : mExpression( expression )
358 , mAscending( ascending )
365 : mExpression( expression )
366 , mAscending( ascending )
367 , mNullsFirst( nullsfirst )
372 : mExpression( expression )
373 , mAscending( ascending )
380 : mExpression( expression )
381 , mAscending( ascending )
382 , mNullsFirst( nullsfirst )
409 return QStringLiteral(
"%1 %2 %3" )
411 mAscending ?
"ASC" :
"DESC",
412 mNullsFirst ?
"NULLS FIRST" :
"NULLS LAST" );
422 return mExpression.
prepare( context );
442 QDomDocument doc = elem.ownerDocument();
443 QList<OrderByClause>::ConstIterator it;
444 for ( it = constBegin(); it != constEnd(); ++it )
447 QDomElement clauseElem = doc.createElement( QStringLiteral(
"orderByClause" ) );
448 clauseElem.setAttribute( QStringLiteral(
"asc" ), clause.
ascending() );
449 clauseElem.setAttribute( QStringLiteral(
"nullsFirst" ), clause.
nullsFirst() );
452 elem.appendChild( clauseElem );
460 QDomNodeList clauses = elem.childNodes();
462 for (
int i = 0; i < clauses.size(); ++i )
464 QDomElement clauseElem = clauses.at( i ).toElement();
466 bool asc = clauseElem.attribute( QStringLiteral(
"asc" ) ).toInt() != 0;
467 bool nullsFirst = clauseElem.attribute( QStringLiteral(
"nullsFirst" ) ).toInt() != 0;
475 QSet<QString> usedAttributes;
477 QList<OrderByClause>::ConstIterator it;
478 for ( it = constBegin(); it != constEnd(); ++it )
485 return usedAttributes;
492 QList<OrderByClause>::ConstIterator it;
493 for ( it = constBegin(); it != constEnd(); ++it )
497 results << clause.
dump();
500 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)
void setNullsFirst(bool nullsFirst)
Set if NULLS should be returned first.