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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsfeaturesource.h
       3                 :            :                          ----------------
       4                 :            :     begin                : May 2017
       5                 :            :     copyright            : (C) 2017 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson at gmail dot com
       7                 :            :  ***************************************************************************/
       8                 :            : 
       9                 :            : /***************************************************************************
      10                 :            :  *                                                                         *
      11                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      12                 :            :  *   it under the terms of the GNU General Public License as published by  *
      13                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      14                 :            :  *   (at your option) any later version.                                   *
      15                 :            :  *                                                                         *
      16                 :            :  ***************************************************************************/
      17                 :            : 
      18                 :            : #ifndef QGSFEATURESOURCE_H
      19                 :            : #define QGSFEATURESOURCE_H
      20                 :            : 
      21                 :            : #include "qgis_core.h"
      22                 :            : #include "qgis_sip.h"
      23                 :            : #include "qgsfeaturerequest.h"
      24                 :            : 
      25                 :            : class QgsFeatureIterator;
      26                 :            : class QgsCoordinateReferenceSystem;
      27                 :            : class QgsFields;
      28                 :            : class QgsFeedback;
      29                 :            : 
      30                 :            : /**
      31                 :            :  * \class QgsFeatureSource
      32                 :            :  * \ingroup core
      33                 :            :  * \brief An interface for objects which provide features via a getFeatures method.
      34                 :            :  *
      35                 :            :  * \since QGIS 3.0
      36                 :            :  */
      37                 :        156 : class CORE_EXPORT QgsFeatureSource
      38                 :            : {
      39                 :            :   public:
      40                 :            : 
      41                 :            :     /**
      42                 :            :      * Possible return value for hasFeatures() to determine if a source is empty.
      43                 :            :      * It is implemented as a three-value logic, so it can return if
      44                 :            :      * there are features available for sure, if there are no features
      45                 :            :      * available for sure or if there might be features available but
      46                 :            :      * there is no guarantee for this.
      47                 :            :      *
      48                 :            :      * \since QGIS 3.4
      49                 :            :      */
      50                 :            :     enum FeatureAvailability
      51                 :            :     {
      52                 :            :       NoFeaturesAvailable, //!< There are certainly no features available in this source
      53                 :            :       FeaturesAvailable, //!< There is at least one feature available in this source
      54                 :            :       FeaturesMaybeAvailable //!< There may be features available in this source
      55                 :            :     };
      56                 :            : 
      57                 :        124 :     virtual ~QgsFeatureSource() = default;
      58                 :            : 
      59                 :            :     /**
      60                 :            :      * Returns an iterator for the features in the source.
      61                 :            :      * An optional \a request can be used to optimise the returned
      62                 :            :      * iterator, eg by restricting the returned attributes or geometry.
      63                 :            :      */
      64                 :            :     virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const = 0;
      65                 :            : 
      66                 :            :     /**
      67                 :            :      * Returns a friendly display name for the source. The returned value can be an empty string.
      68                 :            :      */
      69                 :            :     virtual QString sourceName() const = 0;
      70                 :            : 
      71                 :            :     /**
      72                 :            :      * Returns the coordinate reference system for features in the source.
      73                 :            :      */
      74                 :            :     virtual QgsCoordinateReferenceSystem sourceCrs() const = 0;
      75                 :            : 
      76                 :            :     /**
      77                 :            :      * Returns the fields associated with features in the source.
      78                 :            :      */
      79                 :            :     virtual QgsFields fields() const = 0;
      80                 :            : 
      81                 :            :     /**
      82                 :            :      * Returns the geometry type for features returned by this source.
      83                 :            :      */
      84                 :            :     virtual QgsWkbTypes::Type wkbType() const = 0;
      85                 :            : 
      86                 :            : #ifdef SIP_RUN
      87                 :            : 
      88                 :            :     /**
      89                 :            :      * Returns the number of features contained in the source, or -1
      90                 :            :      * if the feature count is unknown.
      91                 :            :      */
      92                 :            :     int __len__() const;
      93                 :            :     % MethodCode
      94                 :            :     sipRes = sipCpp->featureCount();
      95                 :            :     % End
      96                 :            : 
      97                 :            :     //! Ensures that bool(obj) returns TRUE (otherwise __len__() would be used)
      98                 :            :     int __bool__() const;
      99                 :            :     % MethodCode
     100                 :            :     sipRes = true;
     101                 :            :     % End
     102                 :            : #endif
     103                 :            : 
     104                 :            :     /**
     105                 :            :      * Returns the number of features contained in the source, or -1
     106                 :            :      * if the feature count is unknown.
     107                 :            :      */
     108                 :            :     virtual long featureCount() const = 0;
     109                 :            : 
     110                 :            :     /**
     111                 :            :      * Determines if there are any features available in the source.
     112                 :            :      *
     113                 :            :      * \since QGIS 3.2
     114                 :            :      */
     115                 :            :     virtual FeatureAvailability hasFeatures() const;
     116                 :            : 
     117                 :            :     /**
     118                 :            :      * Returns the set of unique values contained within the specified \a fieldIndex from this source.
     119                 :            :      * If specified, the \a limit option can be used to limit the number of returned values.
     120                 :            :      * The base class implementation uses a non-optimised approach of looping through
     121                 :            :      * all features in the source.
     122                 :            :      * \see minimumValue()
     123                 :            :      * \see maximumValue()
     124                 :            :      */
     125                 :            :     virtual QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const;
     126                 :            : 
     127                 :            :     /**
     128                 :            :      * Returns the minimum value for an attribute column or an invalid variant in case of error.
     129                 :            :      * The base class implementation uses a non-optimised approach of looping through
     130                 :            :      * all features in the source.
     131                 :            :      * \see maximumValue()
     132                 :            :      * \see uniqueValues()
     133                 :            :      */
     134                 :            :     virtual QVariant minimumValue( int fieldIndex ) const;
     135                 :            : 
     136                 :            :     /**
     137                 :            :      * Returns the maximum value for an attribute column or an invalid variant in case of error.
     138                 :            :      * The base class implementation uses a non-optimised approach of looping through
     139                 :            :      * all features in the source.
     140                 :            :      * \see minimumValue()
     141                 :            :      * \see uniqueValues()
     142                 :            :      */
     143                 :            :     virtual QVariant maximumValue( int fieldIndex ) const;
     144                 :            : 
     145                 :            :     /**
     146                 :            :      * Returns the extent of all geometries from the source.
     147                 :            :      * The base class implementation uses a non-optimised approach of looping through
     148                 :            :      * all features in the source.
     149                 :            :      */
     150                 :            :     virtual QgsRectangle sourceExtent() const;
     151                 :            : 
     152                 :            :     /**
     153                 :            :      * Returns a list of all feature IDs for features present in the source.
     154                 :            :      */
     155                 :            :     virtual QgsFeatureIds allFeatureIds() const;
     156                 :            : 
     157                 :            :     /**
     158                 :            :      * Materializes a \a request (query) made against this feature source, by running
     159                 :            :      * it over the source and returning a new memory based vector layer containing
     160                 :            :      * the result. All settings from feature \a request will be honored.
     161                 :            :      *
     162                 :            :      * If a subset of attributes has been set for the request, then only
     163                 :            :      * those selected fields will be present in the output layer.
     164                 :            :      *
     165                 :            :      * The CRS for the output layer will match the input layer, unless
     166                 :            :      * QgsFeatureRequest::setDestinationCrs() has been called with a valid QgsCoordinateReferenceSystem.
     167                 :            :      * In this case the output layer will match the QgsFeatureRequest::destinationCrs() CRS.
     168                 :            :      *
     169                 :            :      * The returned layer WKB type will match wkbType(), unless the QgsFeatureRequest::NoGeometry flag is set
     170                 :            :      * on the \a request. In that case the returned layer will not be a spatial layer.
     171                 :            :      *
     172                 :            :      * An optional \a feedback argument can be used to cancel the materialization
     173                 :            :      * before it has fully completed.
     174                 :            :      *
     175                 :            :      * The returned value is a new instance and the caller takes responsibility
     176                 :            :      * for its ownership.
     177                 :            :      *
     178                 :            :      * \since QGIS 3.0
     179                 :            :      */
     180                 :            :     QgsVectorLayer *materialize( const QgsFeatureRequest &request,
     181                 :            :                                  QgsFeedback *feedback = nullptr ) SIP_FACTORY;
     182                 :            : 
     183                 :            :     /**
     184                 :            :      * Enumeration of spatial index presence states.
     185                 :            :      * \since QGIS 3.10.1
     186                 :            :      */
     187                 :            :     enum SpatialIndexPresence
     188                 :            :     {
     189                 :            :       SpatialIndexUnknown = 0, //!< Spatial index presence cannot be determined, index may or may not exist
     190                 :            :       SpatialIndexNotPresent = 1, //!< No spatial index exists for the source
     191                 :            :       SpatialIndexPresent = 2, //!< A valid spatial index exists for the source
     192                 :            :     };
     193                 :            : 
     194                 :            :     /**
     195                 :            :      * Returns an enum value representing the presence of a valid spatial index on the source,
     196                 :            :      * if it can be determined.
     197                 :            :      *
     198                 :            :      * If QgsFeatureSource::SpatialIndexUnknown is returned then the presence of an index cannot
     199                 :            :      * be determined.
     200                 :            :      *
     201                 :            :      * \since QGIS 3.10.1
     202                 :            :      */
     203                 :            :     virtual SpatialIndexPresence hasSpatialIndex() const;
     204                 :            : };
     205                 :            : 
     206                 :            : Q_DECLARE_METATYPE( QgsFeatureSource * )
     207                 :            : 
     208                 :            : #endif // QGSFEATURESOURCE_H

Generated by: LCOV version 1.14