LCOV - code coverage report
Current view: top level - core - qgsfeaturesink.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 2 4 50.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsfeaturesink.h
       3                 :            :                          ----------------
       4                 :            :     begin                : April 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 QGSFEATURESINK_H
      19                 :            : #define QGSFEATURESINK_H
      20                 :            : 
      21                 :            : #include "qgis_core.h"
      22                 :            : #include "qgis_sip.h"
      23                 :            : #include "qgsfeature.h"
      24                 :            : #include "qgsfeatureiterator.h"
      25                 :            : 
      26                 :            : /**
      27                 :            :  * \class QgsFeatureSink
      28                 :            :  * \ingroup core
      29                 :            :  * \brief An interface for objects which accept features via addFeature(s) methods.
      30                 :            :  *
      31                 :            :  * \since QGIS 3.0
      32                 :            :  */
      33                 :        602 : class CORE_EXPORT QgsFeatureSink
      34                 :            : {
      35                 :            :   public:
      36                 :            : 
      37                 :            :     /**
      38                 :            :      * Flags that can be set on a QgsFeatureSink. Not all sinks may implement all flags.
      39                 :            :      *
      40                 :            :      * \since QGIS 3.4
      41                 :            :      */
      42                 :            :     enum SinkFlag
      43                 :            :     {
      44                 :            : 
      45                 :            :       /**
      46                 :            :        * This flag indicates, that a primary key field cannot be guaranteed to be unique and
      47                 :            :        * the sink should ignore it if somehow possible.
      48                 :            :        * This should for example be set for a geopackage file if the field "fid" has a risk
      49                 :            :        * to contain duplicate entries. In this case sinks like QgsVectorFileWriter or
      50                 :            :        * QgsVectorLayerExporter will prefer to regenerate the fid instead of trying to reuse
      51                 :            :        * the fids provided in addFeature calls.
      52                 :            :        *
      53                 :            :        * \since QGIS 3.4
      54                 :            :        */
      55                 :            :       RegeneratePrimaryKey = 1 << 1,
      56                 :            :     };
      57                 :            :     Q_DECLARE_FLAGS( SinkFlags, SinkFlag )
      58                 :            : 
      59                 :            :     //! Flags controlling how features are added to a sink.
      60                 :            :     enum Flag
      61                 :            :     {
      62                 :            : 
      63                 :            :       /**
      64                 :            :         * Use faster inserts, at the cost of updating the passed features to reflect changes made at the provider.
      65                 :            :         * This includes skipping the update of the passed feature IDs to match the resulting feature IDs for the
      66                 :            :         * feature within the data provider.
      67                 :            :         * Individual sink subclasses may or may not choose to respect this flag, depending on whether or not
      68                 :            :         * skipping this update represents a significant speed boost for the operation.
      69                 :            :         */
      70                 :            :       FastInsert = 1 << 1,
      71                 :            : 
      72                 :            :       /**
      73                 :            :        * Roll back the whole transaction if a single add feature operation fails.
      74                 :            :        * Individual sink subclasses may choose to ignore this flag and always roll back
      75                 :            :        * while other providers will respect the flag and accept partial additions if
      76                 :            :        * this flag is not set.
      77                 :            :        */
      78                 :            :       RollBackOnErrors = 1 << 2,
      79                 :            :     };
      80                 :            :     Q_DECLARE_FLAGS( Flags, Flag )
      81                 :            : 
      82                 :        545 :     virtual ~QgsFeatureSink() = default;
      83                 :            : 
      84                 :            :     /**
      85                 :            :      * Adds a single \a feature to the sink. Feature addition behavior is controlled by the specified \a flags.
      86                 :            :      * \see addFeatures()
      87                 :            :      * \returns TRUE in case of success and FALSE in case of failure
      88                 :            :      */
      89                 :            :     virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
      90                 :            : 
      91                 :            :     /**
      92                 :            :      * Adds a list of \a features to the sink. Feature addition behavior is controlled by the specified \a flags.
      93                 :            :      * \see addFeature()
      94                 :            :      * \returns TRUE in case of success and FALSE in case of failure
      95                 :            :      */
      96                 :            :     virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) = 0;
      97                 :            : 
      98                 :            :     /**
      99                 :            :      * Adds all features from the specified \a iterator to the sink. Feature addition behavior is controlled by the specified \a flags.
     100                 :            :      * \returns TRUE if all features were added successfully, or FALSE if any feature could not be added
     101                 :            :      */
     102                 :            :     virtual bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() );
     103                 :            : 
     104                 :            :     /**
     105                 :            :      * Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination.
     106                 :            :      * \returns FALSE if any buffered features could not be added to the sink.
     107                 :            :      */
     108                 :          0 :     virtual bool flushBuffer() { return true; }
     109                 :            : 
     110                 :            :     /**
     111                 :            :      * Returns the most recent error encountered by the sink, e.g. when a call to addFeatures() returns FALSE.
     112                 :            :      *
     113                 :            :      * \since QGIS 3.16
     114                 :            :      */
     115                 :          0 :     virtual QString lastError() const { return QString(); }
     116                 :            : };
     117                 :            : 
     118                 :            : Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureSink::Flags )
     119                 :            : 
     120                 :            : Q_DECLARE_METATYPE( QgsFeatureSink * )
     121                 :            : 
     122                 :            : #endif // QGSFEATURESINK_H

Generated by: LCOV version 1.14