Skip to content

Commit 09195fb

Browse files
authoredSep 18, 2017
[processing] implement source flag for feature based algorithms (#5208)
1 parent ffbb244 commit 09195fb

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed
 

‎python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
795795
:rtype: QgsProcessing.SourceType
796796
%End
797797

798+
virtual QgsProcessingFeatureSource::Flag sourceFlags() const;
799+
%Docstring
800+
Returns the processing feature source flags to be used in the algorithm.
801+
:rtype: QgsProcessingFeatureSource.Flag
802+
%End
803+
798804
virtual QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const;
799805
%Docstring
800806
Maps the input WKB geometry type (``inputWkbType``) to the corresponding

‎src/core/processing/qgsnativealgorithms.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgis.h"
2525
#include "qgsprocessingalgorithm.h"
2626
#include "qgsprocessingprovider.h"
27+
#include "qgsprocessingutils.h"
2728
#include "qgsmaptopixelgeometrysimplifier.h"
2829

2930
///@cond PRIVATE
@@ -598,6 +599,7 @@ class QgsFixGeometriesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
598599
QgsFixGeometriesAlgorithm *createInstance() const override SIP_FACTORY;
599600

600601
protected:
602+
QgsProcessingFeatureSource::Flag sourceFlags() const override { return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks; }
601603
QString outputName() const override { return QObject::tr( "Fixed geometries" ); }
602604
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type type ) const override { return QgsWkbTypes::multiType( type ); }
603605
QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) override;

‎src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
654654
long count = mSource->featureCount();
655655

656656
QgsFeature f;
657-
QgsFeatureIterator it = mSource->getFeatures();
657+
QgsFeatureIterator it = mSource->getFeatures( QgsFeatureRequest(), sourceFlags() );
658658

659659
double step = count > 0 ? 100.0 / count : 1;
660660
int current = 0;

‎src/core/processing/qgsprocessingalgorithm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsprocessingparameters.h"
2424
#include "qgsprocessingoutputs.h"
2525
#include "qgsprocessingcontext.h"
26+
#include "qgsprocessingutils.h"
2627
#include "qgsfeaturesource.h"
2728
#include <QString>
2829
#include <QVariant>
@@ -782,6 +783,11 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
782783
*/
783784
virtual QgsProcessing::SourceType outputLayerType() const { return QgsProcessing::TypeVectorAnyGeometry; }
784785

786+
/**
787+
* Returns the processing feature source flags to be used in the algorithm.
788+
*/
789+
virtual QgsProcessingFeatureSource::Flag sourceFlags() const { return static_cast<QgsProcessingFeatureSource::Flag>( 0 ); }
790+
785791
/**
786792
* Maps the input WKB geometry type (\a inputWkbType) to the corresponding
787793
* output WKB type generated by the algorithm. The default behavior is that the algorithm maintains
@@ -853,7 +859,7 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
853859

854860
private:
855861

856-
std::unique_ptr< QgsFeatureSource > mSource;
862+
std::unique_ptr< QgsProcessingFeatureSource > mSource;
857863

858864
};
859865

0 commit comments

Comments
 (0)
Please sign in to comment.