LCOV - code coverage report
Current view: top level - core - qgsfeaturerequest.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 12 19 63.2 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :     qgsfeaturerequest.h
       3                 :            :     ---------------------
       4                 :            :     begin                : Mai 2012
       5                 :            :     copyright            : (C) 2012 by Martin Dobias
       6                 :            :     email                : wonder dot sk at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : #ifndef QGSFEATUREREQUEST_H
      16                 :            : #define QGSFEATUREREQUEST_H
      17                 :            : 
      18                 :            : #include "qgis_core.h"
      19                 :            : #include "qgis_sip.h"
      20                 :            : #include <QFlags>
      21                 :            : #include <QList>
      22                 :            : #include <memory>
      23                 :            : 
      24                 :            : #include "qgsfeature.h"
      25                 :            : #include "qgsrectangle.h"
      26                 :            : #include "qgsexpression.h"
      27                 :            : #include "qgsexpressioncontext.h"
      28                 :            : #include "qgssimplifymethod.h"
      29                 :            : 
      30                 :            : 
      31                 :            : 
      32                 :            : /**
      33                 :            :  * \ingroup core
      34                 :            :  * \brief This class wraps a request for features to a vector layer (or directly its vector data provider).
      35                 :            :  *
      36                 :            :  * The request may apply a filter to fetch only a particular subset of features. Currently supported filters:
      37                 :            :  *
      38                 :            :  * - no filter - all features are returned
      39                 :            :  * - feature id - only feature that matches given feature id is returned
      40                 :            :  * - feature ids - only features that match any of the given feature ids are returned
      41                 :            :  * - filter expression - only features that match the given filter expression are returned
      42                 :            :  *
      43                 :            :  * Additionally a spatial rectangle can be set in combination:
      44                 :            :  * Only features that intersect given rectangle should be fetched. For the sake of speed,
      45                 :            :  * the intersection is often done only using feature's bounding box. There is a flag
      46                 :            :  * ExactIntersect that makes sure that only intersecting features will be returned.
      47                 :            :  *
      48                 :            :  * For efficiency, it is also possible to tell provider that some data is not required:
      49                 :            :  *
      50                 :            :  * - NoGeometry flag
      51                 :            :  * - SubsetOfAttributes flag
      52                 :            :  * - SimplifyMethod for geometries to fetch
      53                 :            :  *
      54                 :            :  * The options may be chained, e.g.:
      55                 :            :  *
      56                 :            :  * \code{.py}
      57                 :            :  *   QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest.ExactIntersect)
      58                 :            :  * \endcode
      59                 :            :  *
      60                 :            :  * Examples:
      61                 :            :  *
      62                 :            :  * \code{.py}
      63                 :            :  *   # fetch all features:
      64                 :            :  *   QgsFeatureRequest()
      65                 :            :  *   # fetch all features, only one attribute
      66                 :            :  *   QgsFeatureRequest().setSubsetOfAttributes(['myfield'], layer.fields())
      67                 :            :  *   # fetch all features, without geometries
      68                 :            :  *   QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
      69                 :            :  *   # fetch only features from particular extent
      70                 :            :  *   QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1))
      71                 :            :  *   # fetch only one feature
      72                 :            :  *   QgsFeatureRequest().setFilterFid(45)
      73                 :            :  * \endcode
      74                 :            :  *
      75                 :            :  */
      76                 :        846 : class CORE_EXPORT QgsFeatureRequest
      77                 :            : {
      78                 :            :   public:
      79                 :            :     enum Flag
      80                 :            :     {
      81                 :            :       NoFlags            = 0,
      82                 :            :       NoGeometry         = 1,  //!< Geometry is not required. It may still be returned if e.g. required for a filter condition.
      83                 :            :       SubsetOfAttributes = 2,  //!< Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
      84                 :            :       ExactIntersect     = 4,   //!< Use exact geometry intersection (slower) instead of bounding boxes
      85                 :            :       IgnoreStaticNodesDuringExpressionCompilation = 8, //!< If a feature request uses a filter expression which can be partially precalculated due to static nodes in the expression, setting this flag will prevent these precalculated values from being utilized during compilation of the filter for the backend provider. This flag significantly slows down feature requests and should be used for debugging purposes only. (Since QGIS 3.18)
      86                 :            :       EmbeddedSymbols    = 16,  //!< Retrieve any embedded feature symbology (since QGIS 3.20)
      87                 :            :     };
      88                 :            :     Q_DECLARE_FLAGS( Flags, Flag )
      89                 :            : 
      90                 :            :     /**
      91                 :            :      * Types of filters.
      92                 :            :      */
      93                 :            :     enum FilterType
      94                 :            :     {
      95                 :            :       FilterNone,       //!< No filter is applied
      96                 :            :       FilterFid,        //!< Filter using feature ID
      97                 :            :       FilterExpression, //!< Filter using expression
      98                 :            :       FilterFids        //!< Filter using feature IDs
      99                 :            :     };
     100                 :            : 
     101                 :            :     //! Handling of features with invalid geometries
     102                 :            :     enum InvalidGeometryCheck
     103                 :            :     {
     104                 :            :       GeometryNoCheck = 0, //!< No invalid geometry checking
     105                 :            :       GeometrySkipInvalid = 1, //!< Skip any features with invalid geometry. This requires a slow geometry validity check for every feature.
     106                 :            :       GeometryAbortOnInvalid = 2, //!< Close iterator on encountering any features with invalid geometry. This requires a slow geometry validity check for every feature.
     107                 :            :     };
     108                 :            : 
     109                 :            :     /**
     110                 :            :      * \ingroup core
     111                 :            :      * \brief The OrderByClause class represents an order by clause for a QgsFeatureRequest.
     112                 :            :      *
     113                 :            :      * It can be a simple field or an expression. Multiple order by clauses can be added to
     114                 :            :      * a QgsFeatureRequest to fine tune the behavior if a single field or expression is not
     115                 :            :      * enough to completely specify the required behavior.
     116                 :            :      *
     117                 :            :      * If expression compilation is activated in the settings and the expression can be
     118                 :            :      * translated for the provider in question, it will be evaluated on provider side.
     119                 :            :      * If one of these two premises does not apply, the ordering will take place locally
     120                 :            :      * which results in increased memory and CPU usage.
     121                 :            :      *
     122                 :            :      * If the ordering is done on strings, the order depends on the system's locale if the
     123                 :            :      * local fallback implementation is used. The order depends on the server system's locale
     124                 :            :      * and implementation if ordering is done on the server.
     125                 :            :      *
     126                 :            :      * In case the fallback code needs to be used, a limit set on the request will be respected
     127                 :            :      * for the features returned by the iterator but internally all features will be requested
     128                 :            :      * from the provider.
     129                 :            :      *
     130                 :            :      * \since QGIS 2.14
     131                 :            :      */
     132                 :          0 :     class CORE_EXPORT OrderByClause
     133                 :            :     {
     134                 :            :       public:
     135                 :            : 
     136                 :            :         /**
     137                 :            :          * Creates a new OrderByClause for a QgsFeatureRequest
     138                 :            :          *
     139                 :            :          * \param expression The expression to use for ordering
     140                 :            :          * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     141                 :            :          *                   If the order is ascending, by default nulls are last
     142                 :            :          *                   If the order is descending, by default nulls are first
     143                 :            :          */
     144                 :            :         OrderByClause( const QString &expression, bool ascending = true );
     145                 :            : 
     146                 :            :         /**
     147                 :            :          * Creates a new OrderByClause for a QgsFeatureRequest
     148                 :            :          *
     149                 :            :          * \param expression The expression to use for ordering
     150                 :            :          * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     151                 :            :          * \param nullsfirst If TRUE, NULLS are at the beginning, if FALSE, NULLS are at the end
     152                 :            :          */
     153                 :            :         OrderByClause( const QString &expression, bool ascending, bool nullsfirst );
     154                 :            : 
     155                 :            :         /**
     156                 :            :          * Creates a new OrderByClause for a QgsFeatureRequest
     157                 :            :          *
     158                 :            :          * \param expression The expression to use for ordering
     159                 :            :          * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     160                 :            :          *                   If the order is ascending, by default nulls are last
     161                 :            :          *                   If the order is descending, by default nulls are first
     162                 :            :          */
     163                 :            :         OrderByClause( const QgsExpression &expression, bool ascending = true );
     164                 :            : 
     165                 :            :         /**
     166                 :            :          * Creates a new OrderByClause for a QgsFeatureRequest
     167                 :            :          *
     168                 :            :          * \param expression The expression to use for ordering
     169                 :            :          * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     170                 :            :          * \param nullsfirst If TRUE, NULLS are at the beginning, if FALSE, NULLS are at the end
     171                 :            :          */
     172                 :            :         OrderByClause( const QgsExpression &expression, bool ascending, bool nullsfirst );
     173                 :            : 
     174                 :            :         /**
     175                 :            :          * The expression
     176                 :            :          * \returns the expression
     177                 :            :          */
     178                 :            :         QgsExpression expression() const;
     179                 :            : 
     180                 :            :         /**
     181                 :            :          * Prepare the expression with the given context.
     182                 :            :          *
     183                 :            :          * \see QgsExpression::prepare
     184                 :            :          *
     185                 :            :          * \since QGIS 3.0
     186                 :            :          */
     187                 :            :         bool prepare( QgsExpressionContext *context );
     188                 :            : 
     189                 :            :         /**
     190                 :            :          * Order ascending
     191                 :            :          * \returns If ascending order is requested
     192                 :            :          */
     193                 :            :         bool ascending() const;
     194                 :            : 
     195                 :            :         /**
     196                 :            :          * Set if ascending order is requested
     197                 :            :          */
     198                 :            :         void setAscending( bool ascending );
     199                 :            : 
     200                 :            :         /**
     201                 :            :          * Set if NULLS should be returned first
     202                 :            :          * \returns if NULLS should be returned first
     203                 :            :          */
     204                 :            :         bool nullsFirst() const;
     205                 :            : 
     206                 :            :         /**
     207                 :            :          * Set if NULLS should be returned first
     208                 :            :          */
     209                 :            :         void setNullsFirst( bool nullsFirst );
     210                 :            : 
     211                 :            :         /**
     212                 :            :          * Dumps the content to an SQL equivalent
     213                 :            :          */
     214                 :            :         QString dump() const;
     215                 :            : 
     216                 :            :         // friend inline int qHash(const OrderByClause &a) { return qHash(a.mExpression.expression()) ^ qHash(a.mAscending) ^ qHash( a.mNullsFirst); }
     217                 :            : 
     218                 :            :       private:
     219                 :            :         QgsExpression mExpression;
     220                 :            :         bool mAscending;
     221                 :            :         bool mNullsFirst;
     222                 :            :     };
     223                 :            : 
     224                 :            : 
     225                 :            :     /**
     226                 :            :      * \ingroup core
     227                 :            :      * \brief Represents a list of OrderByClauses, with the most important first and the least
     228                 :            :      * important last.
     229                 :            :      *
     230                 :            :      * \since QGIS 2.14
     231                 :            :      */
     232                 :       2549 :     class OrderBy : public QList<QgsFeatureRequest::OrderByClause>
     233                 :            :     {
     234                 :            :       public:
     235                 :            : 
     236                 :            :         /**
     237                 :            :          * Create a new empty order by
     238                 :            :          */
     239                 :            :         CORE_EXPORT OrderBy();
     240                 :            : 
     241                 :            :         /**
     242                 :            :          * Create a new order by from a list of clauses
     243                 :            :          */
     244                 :            :         CORE_EXPORT OrderBy( const QList<QgsFeatureRequest::OrderByClause> &other );
     245                 :            : 
     246                 :            :         /**
     247                 :            :          * Gets a copy as a list of OrderByClauses
     248                 :            :          *
     249                 :            :          * This is only required in Python where the inheritance
     250                 :            :          * is not properly propagated and this makes it usable.
     251                 :            :          */
     252                 :            :         QList<QgsFeatureRequest::OrderByClause> CORE_EXPORT list() const;
     253                 :            : 
     254                 :            :         /**
     255                 :            :          * Serialize to XML
     256                 :            :          */
     257                 :            :         void CORE_EXPORT save( QDomElement &elem ) const;
     258                 :            : 
     259                 :            :         /**
     260                 :            :          * Deserialize from XML
     261                 :            :          */
     262                 :            :         void CORE_EXPORT load( const QDomElement &elem );
     263                 :            : 
     264                 :            :         /**
     265                 :            :          * Returns a set of used attributes
     266                 :            :          * \note The returned attributes names are NOT guaranteed to be valid.
     267                 :            :          */
     268                 :            :         QSet<QString> CORE_EXPORT usedAttributes() const;
     269                 :            : 
     270                 :            :         /**
     271                 :            :          * Returns a set of used, validated attribute indices
     272                 :            :          * \since QGIS 3.8
     273                 :            :          */
     274                 :            :         QSet<int> CORE_EXPORT usedAttributeIndices( const QgsFields &fields ) const;
     275                 :            : 
     276                 :            :         /**
     277                 :            :          * Dumps the content to an SQL equivalent syntax
     278                 :            :          */
     279                 :            :         QString CORE_EXPORT dump() const;
     280                 :            :     };
     281                 :            : 
     282                 :            :     /**
     283                 :            :      * A special attribute that if set matches all attributes
     284                 :            :      */
     285                 :            :     static const QString ALL_ATTRIBUTES;
     286                 :            : 
     287                 :            :     //! construct a default request: for all features get attributes and geometries
     288                 :            :     QgsFeatureRequest();
     289                 :            :     //! construct a request with feature ID filter
     290                 :            :     explicit QgsFeatureRequest( QgsFeatureId fid );
     291                 :            :     //! construct a request with feature ID filter
     292                 :            :     explicit QgsFeatureRequest( const QgsFeatureIds &fids );
     293                 :            : 
     294                 :            :     /**
     295                 :            :      * Construct a request with \a rectangle bounding box filter.
     296                 :            :      *
     297                 :            :      * When a destination CRS is set using setDestinationCrs(), \a rectangle
     298                 :            :      * is expected to be in the same CRS as the destinationCrs(). Otherwise, \a rectangle
     299                 :            :      * should use the same CRS as the source layer/provider.
     300                 :            :      */
     301                 :            :     explicit QgsFeatureRequest( const QgsRectangle &rectangle );
     302                 :            : 
     303                 :            :     //! construct a request with a filter expression
     304                 :            :     explicit QgsFeatureRequest( const QgsExpression &expr, const QgsExpressionContext &context = QgsExpressionContext() );
     305                 :            :     //! copy constructor
     306                 :            :     QgsFeatureRequest( const QgsFeatureRequest &rh );
     307                 :            :     //! Assignment operator
     308                 :            :     QgsFeatureRequest &operator=( const QgsFeatureRequest &rh );
     309                 :            : 
     310                 :            :     /**
     311                 :            :      * Returns the filter type which is currently set on this request
     312                 :            :      *
     313                 :            :      * \returns Filter type
     314                 :            :      */
     315                 :       9005 :     FilterType filterType() const { return mFilter; }
     316                 :            : 
     317                 :            :     /**
     318                 :            :      * Sets the \a rectangle from which features will be taken. An empty rectangle removes the filter.
     319                 :            :      *
     320                 :            :      * When a destination CRS is set using setDestinationCrs(), \a rectangle
     321                 :            :      * is expected to be in the same CRS as the destinationCrs(). Otherwise, \a rectangle
     322                 :            :      * should use the same CRS as the source layer/provider.
     323                 :            :      *
     324                 :            :      * \see filterRect()
     325                 :            :      */
     326                 :            :     QgsFeatureRequest &setFilterRect( const QgsRectangle &rectangle );
     327                 :            : 
     328                 :            :     /**
     329                 :            :      * Returns the rectangle from which features will be taken. If the returned
     330                 :            :      * rectangle is null, then no filter rectangle is set.
     331                 :            :      *
     332                 :            :      * When a destination CRS is set using setDestinationCrs(), the rectangle
     333                 :            :      * will be in the same CRS as the destinationCrs(). Otherwise, the rectangle
     334                 :            :      * will use the same CRS as the source layer/provider.
     335                 :            :      *
     336                 :            :      * \see setFilterRect()
     337                 :            :      */
     338                 :       1419 :     const QgsRectangle &filterRect() const { return mFilterRect; }
     339                 :            : 
     340                 :            :     //! Sets feature ID that should be fetched.
     341                 :            :     QgsFeatureRequest &setFilterFid( QgsFeatureId fid );
     342                 :            :     //! Gets the feature ID that should be fetched.
     343                 :         47 :     QgsFeatureId filterFid() const { return mFilterFid; }
     344                 :            : 
     345                 :            :     //! Sets feature IDs that should be fetched.
     346                 :            :     QgsFeatureRequest &setFilterFids( const QgsFeatureIds &fids );
     347                 :            :     //! Gets feature IDs that should be fetched.
     348                 :        288 :     const QgsFeatureIds &filterFids() const { return mFilterFids; }
     349                 :            : 
     350                 :            :     /**
     351                 :            :      * Sets invalid geometry checking behavior.
     352                 :            :      * \note Invalid geometry checking is not performed when retrieving features
     353                 :            :      * directly from a QgsVectorDataProvider.
     354                 :            :      * \see invalidGeometryCheck()
     355                 :            :      * \since QGIS 3.0
     356                 :            :      */
     357                 :            :     QgsFeatureRequest &setInvalidGeometryCheck( InvalidGeometryCheck check );
     358                 :            : 
     359                 :            :     /**
     360                 :            :      * Returns the invalid geometry checking behavior.
     361                 :            :      * \see setInvalidGeometryCheck()
     362                 :            :      * \since QGIS 3.0
     363                 :            :      */
     364                 :       1047 :     InvalidGeometryCheck invalidGeometryCheck() const { return mInvalidGeometryFilter; }
     365                 :            : 
     366                 :            :     /**
     367                 :            :      * Sets a callback function to use when encountering an invalid geometry and
     368                 :            :      * invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid. This function will be
     369                 :            :      * called using the feature with invalid geometry as a parameter.
     370                 :            :      * \see invalidGeometryCallback()
     371                 :            :      * \since QGIS 3.0
     372                 :            :      */
     373                 :            : #ifndef SIP_RUN
     374                 :            :     QgsFeatureRequest &setInvalidGeometryCallback( const std::function< void( const QgsFeature & )> &callback );
     375                 :            : #else
     376                 :            :     QgsFeatureRequest &setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
     377                 :            :     % MethodCode
     378                 :            :     Py_BEGIN_ALLOW_THREADS
     379                 :            : 
     380                 :            :     sipCpp->setInvalidGeometryCallback( [a0]( const QgsFeature &arg )
     381                 :            :     {
     382                 :            :       SIP_BLOCK_THREADS
     383                 :            :       Py_XDECREF( sipCallMethod( NULL, a0, "D", &arg, sipType_QgsFeature, NULL ) );
     384                 :            :       SIP_UNBLOCK_THREADS
     385                 :            :     } );
     386                 :            : 
     387                 :            :     sipRes = sipCpp;
     388                 :            : 
     389                 :            :     Py_END_ALLOW_THREADS
     390                 :            :     % End
     391                 :            : #endif
     392                 :            : 
     393                 :            :     /**
     394                 :            :      * Returns the callback function to use when encountering an invalid geometry and
     395                 :            :      * invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
     396                 :            :      * \note not available in Python bindings
     397                 :            :      * \see setInvalidGeometryCallback()
     398                 :            :      * \since QGIS 3.0
     399                 :            :      */
     400                 :          0 :     std::function< void( const QgsFeature & ) > invalidGeometryCallback() const { return mInvalidGeometryCallback; } SIP_SKIP
     401                 :            : 
     402                 :            :     /**
     403                 :            :      * Set the filter expression. {\see QgsExpression}
     404                 :            :      * \param expression expression string
     405                 :            :      * \see filterExpression
     406                 :            :      * \see setExpressionContext
     407                 :            :      */
     408                 :            :     QgsFeatureRequest &setFilterExpression( const QString &expression );
     409                 :            : 
     410                 :            :     /**
     411                 :            :      * Returns the filter expression if set.
     412                 :            :      * \see setFilterExpression
     413                 :            :      * \see expressionContext
     414                 :            :      */
     415                 :          0 :     QgsExpression *filterExpression() const { return mFilterExpression.get(); }
     416                 :            : 
     417                 :            :     /**
     418                 :            :      * Modifies the existing filter expression to add an additional expression filter. The
     419                 :            :      * filter expressions are combined using AND, so only features matching both
     420                 :            :      * the existing expression and the additional expression will be returned.
     421                 :            :      * \since QGIS 2.14
     422                 :            :      */
     423                 :            :     QgsFeatureRequest &combineFilterExpression( const QString &expression );
     424                 :            : 
     425                 :            :     /**
     426                 :            :      * Returns the expression context used to evaluate filter expressions.
     427                 :            :      * \see setExpressionContext
     428                 :            :      * \see filterExpression
     429                 :            :      * \since QGIS 2.12
     430                 :            :      */
     431                 :          0 :     QgsExpressionContext *expressionContext() { return &mExpressionContext; }
     432                 :            : 
     433                 :            :     /**
     434                 :            :      * Sets the expression context used to evaluate filter expressions.
     435                 :            :      * \see expressionContext
     436                 :            :      * \see setFilterExpression
     437                 :            :      * \since QGIS 2.12
     438                 :            :      */
     439                 :            :     QgsFeatureRequest &setExpressionContext( const QgsExpressionContext &context );
     440                 :            : 
     441                 :            :     /**
     442                 :            :      * Disables filter conditions.
     443                 :            :      * The spatial filter (filterRect) will be kept in place.
     444                 :            :      *
     445                 :            :      * \returns The object the method is called on for chaining
     446                 :            :      *
     447                 :            :      * \since QGIS 2.12
     448                 :            :      */
     449                 :          0 :     QgsFeatureRequest &disableFilter() { mFilter = FilterNone; mFilterExpression.reset(); return *this; }
     450                 :            : 
     451                 :            :     /**
     452                 :            :      * Adds a new OrderByClause, appending it as the least important one.
     453                 :            :      *
     454                 :            :      * \param expression The expression to use for ordering
     455                 :            :      * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     456                 :            :      *                   If the order is ascending, by default nulls are last
     457                 :            :      *                   If the order is descending, by default nulls are first
     458                 :            :      *
     459                 :            :      * \since QGIS 2.14
     460                 :            :      */
     461                 :            : 
     462                 :            :     QgsFeatureRequest &addOrderBy( const QString &expression, bool ascending = true );
     463                 :            : 
     464                 :            :     /**
     465                 :            :      * Adds a new OrderByClause, appending it as the least important one.
     466                 :            :      *
     467                 :            :      * \param expression The expression to use for ordering
     468                 :            :      * \param ascending  If the order should be ascending (1,2,3) or descending (3,2,1)
     469                 :            :      * \param nullsfirst If TRUE, NULLS are at the beginning, if FALSE, NULLS are at the end
     470                 :            :      *
     471                 :            :      * \since QGIS 2.14
     472                 :            :      */
     473                 :            :     QgsFeatureRequest &addOrderBy( const QString &expression, bool ascending, bool nullsfirst );
     474                 :            : 
     475                 :            :     /**
     476                 :            :      * Returns a list of order by clauses specified for this feature request.
     477                 :            :      *
     478                 :            :      * \since QGIS 2.14
     479                 :            :      */
     480                 :            :     OrderBy orderBy() const;
     481                 :            : 
     482                 :            :     /**
     483                 :            :      * Set a list of order by clauses.
     484                 :            :      *
     485                 :            :      * \since QGIS 2.14
     486                 :            :      */
     487                 :            :     QgsFeatureRequest &setOrderBy( const OrderBy &orderBy );
     488                 :            : 
     489                 :            :     /**
     490                 :            :      * Set the maximum number of features to request.
     491                 :            :      * \param limit maximum number of features, or -1 to request all features.
     492                 :            :      * \see limit()
     493                 :            :      * \since QGIS 2.14
     494                 :            :      */
     495                 :            :     QgsFeatureRequest &setLimit( long limit );
     496                 :            : 
     497                 :            :     /**
     498                 :            :      * Returns the maximum number of features to request, or -1 if no limit set.
     499                 :            :      * \see setLimit
     500                 :            :      * \since QGIS 2.14
     501                 :            :      */
     502                 :       2505 :     long limit() const { return mLimit; }
     503                 :            : 
     504                 :            :     //! Sets flags that affect how features will be fetched
     505                 :            :     QgsFeatureRequest &setFlags( QgsFeatureRequest::Flags flags );
     506                 :       3938 :     const Flags &flags() const { return mFlags; }
     507                 :            : 
     508                 :            :     /**
     509                 :            :      * Set a subset of attributes that will be fetched.
     510                 :            :      *
     511                 :            :      * An empty attributes list indicates that no attributes will be fetched.
     512                 :            :      * To revert a call to setSubsetOfAttributes and fetch all available attributes,
     513                 :            :      * the SubsetOfAttributes flag should be removed from the request.
     514                 :            :      */
     515                 :            :     QgsFeatureRequest &setSubsetOfAttributes( const QgsAttributeList &attrs );
     516                 :            : 
     517                 :            :     /**
     518                 :            :      * Set that no attributes will be fetched.
     519                 :            :      * To revert a call to setNoAttributes and fetch all or some available attributes,
     520                 :            :      * the SubsetOfAttributes flag should be removed from the request.
     521                 :            :      * \since QGIS 3.4
     522                 :            :      */
     523                 :            :     QgsFeatureRequest &setNoAttributes();
     524                 :            : 
     525                 :            :     /**
     526                 :            :      * Returns the subset of attributes which at least need to be fetched
     527                 :            :      * \returns A list of attributes to be fetched
     528                 :            :      */
     529                 :        290 :     QgsAttributeList subsetOfAttributes() const { return mAttrs; }
     530                 :            : 
     531                 :            :     //! Sets a subset of attributes by names that will be fetched
     532                 :            :     QgsFeatureRequest &setSubsetOfAttributes( const QStringList &attrNames, const QgsFields &fields );
     533                 :            : 
     534                 :            :     //! Sets a subset of attributes by names that will be fetched
     535                 :            :     QgsFeatureRequest &setSubsetOfAttributes( const QSet<QString> &attrNames, const QgsFields &fields );
     536                 :            : 
     537                 :            :     /**
     538                 :            :      * Set a simplification method for geometries that will be fetched
     539                 :            :      * \since QGIS 2.2
     540                 :            :      */
     541                 :            :     QgsFeatureRequest &setSimplifyMethod( const QgsSimplifyMethod &simplifyMethod );
     542                 :            : 
     543                 :            :     /**
     544                 :            :      * Gets simplification method for geometries that will be fetched
     545                 :            :      * \since QGIS 2.2
     546                 :            :      */
     547                 :        318 :     const QgsSimplifyMethod &simplifyMethod() const { return mSimplifyMethod; }
     548                 :            : 
     549                 :            :     /**
     550                 :            :      * Returns the destination coordinate reference system for feature's geometries,
     551                 :            :      * or an invalid QgsCoordinateReferenceSystem if no reprojection will be done
     552                 :            :      * and all features will be left with their original geometry.
     553                 :            :      * \see setDestinationCrs()
     554                 :            :      * \see transformContext()
     555                 :            :      * \since QGIS 3.0
     556                 :            :      */
     557                 :            :     QgsCoordinateReferenceSystem destinationCrs() const;
     558                 :            : 
     559                 :            :     /**
     560                 :            :      * Returns the transform context, for use when a destinationCrs() has been set
     561                 :            :      * and reprojection is required
     562                 :            :      * \see setDestinationCrs()
     563                 :            :      * \see destinationCrs()
     564                 :            :      * \since QGIS 3.0
     565                 :            :      */
     566                 :            :     QgsCoordinateTransformContext transformContext() const;
     567                 :            : 
     568                 :            :     /**
     569                 :            :      * Sets the destination \a crs for feature's geometries. If set, all
     570                 :            :      * geometries will be reprojected from their original coordinate reference
     571                 :            :      * system to this desired reference system. If \a crs is an invalid
     572                 :            :      * QgsCoordinateReferenceSystem then no reprojection will be done
     573                 :            :      * and all features will be left with their original geometry.
     574                 :            :      *
     575                 :            :      * When a \a crs is set using setDestinationCrs(), then any filterRect()
     576                 :            :      * set on the request is expected to be in the same CRS as the destination
     577                 :            :      * CRS.
     578                 :            :      *
     579                 :            :      * The feature geometry transformation to the destination CRS is performed
     580                 :            :      * after all filter expressions are tested and any virtual fields are
     581                 :            :      * calculated. Accordingly, any geometric expressions used in
     582                 :            :      * filterExpression() will be performed in the original
     583                 :            :      * source CRS. This ensures consistent results are returned regardless of the
     584                 :            :      * destination CRS. Similarly, virtual field values will be calculated using the
     585                 :            :      * original geometry in the source CRS, so these values are not affected by
     586                 :            :      * any destination CRS transform present in the feature request.
     587                 :            :      *
     588                 :            :      * \see destinationCrs()
     589                 :            :      * \since QGIS 3.0
     590                 :            :      */
     591                 :            :     QgsFeatureRequest &setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
     592                 :            : 
     593                 :            :     /**
     594                 :            :      * Sets a callback function to use when encountering a transform error when iterating
     595                 :            :      * features and a destinationCrs() is set. This function will be
     596                 :            :      * called using the feature which encountered the transform error as a parameter.
     597                 :            :      * \see transformErrorCallback()
     598                 :            :      * \see setDestinationCrs()
     599                 :            :      * \since QGIS 3.0
     600                 :            :      */
     601                 :            : #ifndef SIP_RUN
     602                 :            :     QgsFeatureRequest &setTransformErrorCallback( const std::function< void( const QgsFeature & )> &callback );
     603                 :            : #else
     604                 :            :     QgsFeatureRequest &setTransformErrorCallback( SIP_PYCALLABLE / AllowNone / );
     605                 :            :     % MethodCode
     606                 :            :     Py_BEGIN_ALLOW_THREADS
     607                 :            : 
     608                 :            :     sipCpp->setTransformErrorCallback( [a0]( const QgsFeature &arg )
     609                 :            :     {
     610                 :            :       SIP_BLOCK_THREADS
     611                 :            :       Py_XDECREF( sipCallMethod( NULL, a0, "D", &arg, sipType_QgsFeature, NULL ) );
     612                 :            :       SIP_UNBLOCK_THREADS
     613                 :            :     } );
     614                 :            : 
     615                 :            :     sipRes = sipCpp;
     616                 :            : 
     617                 :            :     Py_END_ALLOW_THREADS
     618                 :            :     % End
     619                 :            : #endif
     620                 :            : 
     621                 :            :     /**
     622                 :            :      * Returns the callback function to use when encountering a transform error when iterating
     623                 :            :      * features and a destinationCrs() is set.
     624                 :            :      * \note not available in Python bindings
     625                 :            :      * \see setTransformErrorCallback()
     626                 :            :      * \see destinationCrs()
     627                 :            :      * \since QGIS 3.0
     628                 :            :      */
     629                 :          0 :     std::function< void( const QgsFeature & ) > transformErrorCallback() const { return mTransformErrorCallback; } SIP_SKIP
     630                 :            : 
     631                 :            : 
     632                 :            :     /**
     633                 :            :      * Check if a feature is accepted by this requests filter
     634                 :            :      *
     635                 :            :      * \param feature  The feature which will be tested
     636                 :            :      *
     637                 :            :      * \returns TRUE, if the filter accepts the feature
     638                 :            :      *
     639                 :            :      * \since QGIS 2.1
     640                 :            :      */
     641                 :            :     bool acceptFeature( const QgsFeature &feature );
     642                 :            : 
     643                 :            :     /**
     644                 :            :      * Returns the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool
     645                 :            :      * at this moment. A negative value (which is set by default) will wait forever.
     646                 :            :      *
     647                 :            :      * \note Only works if the provider supports this option.
     648                 :            :      *
     649                 :            :      * \deprecated Use timeout() instead.
     650                 :            :      * \since QGIS 3.0
     651                 :            :      */
     652                 :            :     Q_DECL_DEPRECATED int connectionTimeout() const SIP_DEPRECATED;
     653                 :            : 
     654                 :            :     /**
     655                 :            :      * Sets the timeout (in milliseconds) for how long we should wait for a connection if none is available from the pool
     656                 :            :      * at this moment. A negative value (which is set by default) will wait forever.
     657                 :            :      *
     658                 :            :      * \note Only works if the provider supports this option.
     659                 :            :      *
     660                 :            :      * \deprecated Use setTimeout() instead.
     661                 :            :      * \since QGIS 3.0
     662                 :            :      */
     663                 :            :     Q_DECL_DEPRECATED QgsFeatureRequest &setConnectionTimeout( int connectionTimeout ) SIP_DEPRECATED;
     664                 :            : 
     665                 :            :     /**
     666                 :            :      * Returns the timeout (in milliseconds) for the maximum time we should wait during feature requests before a
     667                 :            :      * feature is returned. A negative value (which is set by default) will wait forever.
     668                 :            :      *
     669                 :            :      * \note Only works if the provider supports this option.
     670                 :            :      *
     671                 :            :      * \since QGIS 3.4
     672                 :            :      */
     673                 :            :     int timeout() const;
     674                 :            : 
     675                 :            :     /**
     676                 :            :      * Sets the \a timeout (in milliseconds) for the maximum time we should wait during feature requests before a
     677                 :            :      * feature is returned. A negative value (which is set by default) will wait forever.
     678                 :            :      *
     679                 :            :      * \note Only works if the provider supports this option.
     680                 :            :      *
     681                 :            :      * \since QGIS 3.4
     682                 :            :      */
     683                 :            :     QgsFeatureRequest &setTimeout( int timeout );
     684                 :            : 
     685                 :            :     /**
     686                 :            :      * In case this request may be run nested within another already running
     687                 :            :      * iteration on the same connection, set this to TRUE.
     688                 :            :      *
     689                 :            :      * If this flag is TRUE, this request will be able to make use of "spare"
     690                 :            :      * connections to avoid deadlocks.
     691                 :            :      *
     692                 :            :      * For example, this should be set on requests that are issued from an
     693                 :            :      * expression function.
     694                 :            :      *
     695                 :            :      * \since QGIS 3.4
     696                 :            :      */
     697                 :            :     bool requestMayBeNested() const;
     698                 :            : 
     699                 :            :     /**
     700                 :            :      * In case this request may be run nested within another already running
     701                 :            :      * iteration on the same connection, set this to TRUE.
     702                 :            :      *
     703                 :            :      * If this flag is TRUE, this request will be able to make use of "spare"
     704                 :            :      * connections to avoid deadlocks.
     705                 :            :      *
     706                 :            :      * For example, this should be set on requests that are issued from an
     707                 :            :      * expression function.
     708                 :            :      *
     709                 :            :      * \since QGIS 3.4
     710                 :            :      */
     711                 :            :     QgsFeatureRequest &setRequestMayBeNested( bool requestMayBeNested );
     712                 :            : 
     713                 :            :   protected:
     714                 :            :     FilterType mFilter = FilterNone;
     715                 :            :     QgsRectangle mFilterRect;
     716                 :            :     QgsFeatureId mFilterFid = -1;
     717                 :            :     QgsFeatureIds mFilterFids;
     718                 :            :     std::unique_ptr< QgsExpression > mFilterExpression;
     719                 :            :     QgsExpressionContext mExpressionContext;
     720                 :            :     Flags mFlags = Flags();
     721                 :            :     QgsAttributeList mAttrs;
     722                 :            :     QgsSimplifyMethod mSimplifyMethod;
     723                 :            :     long mLimit = -1;
     724                 :            :     OrderBy mOrderBy;
     725                 :            :     InvalidGeometryCheck mInvalidGeometryFilter = GeometryNoCheck;
     726                 :            :     std::function< void( const QgsFeature & ) > mInvalidGeometryCallback;
     727                 :            :     std::function< void( const QgsFeature & ) > mTransformErrorCallback;
     728                 :            :     QgsCoordinateReferenceSystem mCrs;
     729                 :            :     QgsCoordinateTransformContext mTransformContext;
     730                 :            :     int mTimeout = -1;
     731                 :            :     int mRequestMayBeNested = false;
     732                 :            : };
     733                 :            : 
     734                 :          0 : Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
     735                 :            : 
     736                 :            : 
     737                 :            : class QgsFeatureIterator;
     738                 :            : class QgsAbstractFeatureIterator;
     739                 :            : 
     740                 :            : /**
     741                 :            :  * \ingroup core
     742                 :            :  * \brief Base class that can be used for any class that is capable of returning features
     743                 :            :  * \since QGIS 2.4
     744                 :            :  */
     745                 :        399 : class CORE_EXPORT QgsAbstractFeatureSource
     746                 :            : {
     747                 :            :   public:
     748                 :            :     virtual ~QgsAbstractFeatureSource();
     749                 :            : 
     750                 :            : 
     751                 :            :     // IMPORTANT -- do NOT remove the /TransferBack/ annotation here -- while it looks completely wrong, it's
     752                 :            :     // required for Python data providers to work correctly! Argh!
     753                 :            : 
     754                 :            :     /**
     755                 :            :      * Gets an iterator for features matching the specified request
     756                 :            :      * \param request The request
     757                 :            :      * \returns A feature iterator
     758                 :            :      */
     759                 :            :     virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) = 0 SIP_TRANSFERBACK;
     760                 :            : 
     761                 :            :     // IMPORTANT -- do NOT remove the /TransferBack/ annotation here -- while it looks completely wrong, it's
     762                 :            :     // required for Python data providers to work correctly! Argh!
     763                 :            : 
     764                 :            :   protected:
     765                 :            :     void iteratorOpened( QgsAbstractFeatureIterator *it );
     766                 :            :     void iteratorClosed( QgsAbstractFeatureIterator *it );
     767                 :            : 
     768                 :            :     QSet< QgsAbstractFeatureIterator * > mActiveIterators;
     769                 :            : 
     770                 :            :     template<typename> friend class QgsAbstractFeatureIteratorFromSource;
     771                 :            : };
     772                 :            : 
     773                 :            : #endif // QGSFEATUREREQUEST_H

Generated by: LCOV version 1.14