20 #include <QStringList> 203 Q_FOREACH (
const QString &attrName, attrNames )
206 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
224 Q_FOREACH (
const QString &attrName, attrNames )
227 if ( attrNum != -1 && !
mAttrs.contains( attrNum ) )
307 while ( !mActiveIterators.empty() )
317 mActiveIterators.insert( it );
322 mActiveIterators.remove( it );
328 : mExpression( expression )
329 , mAscending( ascending )
336 : mExpression( expression )
337 , mAscending( ascending )
338 , mNullsFirst( nullsfirst )
343 : mExpression( expression )
344 , mAscending( ascending )
351 : mExpression( expression )
352 , mAscending( ascending )
353 , mNullsFirst( nullsfirst )
380 return QStringLiteral(
"%1 %2 %3" )
381 .arg( mExpression.expression(),
382 mAscending ?
"ASC" :
"DESC",
383 mNullsFirst ?
"NULLS FIRST" :
"NULLS LAST" );
393 return mExpression.prepare( context );
413 QDomDocument doc = elem.ownerDocument();
414 QList<OrderByClause>::ConstIterator it;
415 for ( it = constBegin(); it != constEnd(); ++it )
418 QDomElement clauseElem = doc.createElement( QStringLiteral(
"orderByClause" ) );
419 clauseElem.setAttribute( QStringLiteral(
"asc" ), clause.
ascending() );
420 clauseElem.setAttribute( QStringLiteral(
"nullsFirst" ), clause.
nullsFirst() );
421 clauseElem.appendChild( doc.createTextNode( clause.
expression().expression() ) );
423 elem.appendChild( clauseElem );
431 QDomNodeList clauses = elem.childNodes();
433 for (
int i = 0; i < clauses.size(); ++i )
435 QDomElement clauseElem = clauses.at( i ).toElement();
437 bool asc = clauseElem.attribute( QStringLiteral(
"asc" ) ).toInt() != 0;
438 bool nullsFirst = clauseElem.attribute( QStringLiteral(
"nullsFirst" ) ).toInt() != 0;
446 QSet<QString> usedAttributes;
448 QList<OrderByClause>::ConstIterator it;
449 for ( it = constBegin(); it != constEnd(); ++it )
453 usedAttributes.unite( clause.
expression().referencedColumns() );
456 return usedAttributes;
463 QList<OrderByClause>::ConstIterator it;
464 for ( it = constBegin(); it != constEnd(); ++it )
468 results << clause.
dump();
471 return results.join( QStringLiteral(
", " ) );
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
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
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
Get 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.
QSet< QgsFeatureId > QgsFeatureIds
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsFeatureRequest & operator=(const QgsFeatureRequest &rh)
Assignment operator.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
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)
Set 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.
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...
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)
void setConnectionTimeout(int connectionTimeout)
The timeout for how long we should wait for a connection if none is available from the pool at this m...
Contains information about the context in which a coordinate transform is executed.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
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...
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)
Set feature IDs that should be fetched.
QgsCoordinateTransformContext mTransformContext
std::function< void(const QgsFeature &) > mTransformErrorCallback
void setAscending(bool ascending)
Set if ascending order is requested.
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.
QList< int > QgsAttributeList
int connectionTimeout() const
The timeout for how long we should wait for a connection if none is available from the pool at this m...
OrderBy orderBy() const
Return 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
Get 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)
Set flags that affect how features will be fetched.
void iteratorOpened(QgsAbstractFeatureIterator *it)
void setNullsFirst(bool nullsFirst)
Set if NULLS should be returned first.