Skip to content
Permalink
Browse files

[processing] Allow QgsVectorLayerSelectedFeatureSource to

create expression context scopes

Allows algorithms which require the underlying layer scope
to operate correctly when running in selected features only
mode.

Fixes #17170
  • Loading branch information
nyalldawson committed Apr 3, 2018
1 parent 8326510 commit d5617b8025e0b1ea09a4f83ca464b7306cad535b
@@ -153,7 +153,7 @@ Setup the simplification of geometries to fetch using the specified simplify met



class QgsVectorLayerSelectedFeatureSource : QgsFeatureSource
class QgsVectorLayerSelectedFeatureSource : QgsFeatureSource, QgsExpressionContextScopeGenerator
{
%Docstring
QgsFeatureSource subclass for the selected features from a :py:class:`QgsVectorLayer`.
@@ -185,6 +185,8 @@ the QgsVectorLayerSelectedFeatureSource will not be reflected.

virtual QString sourceName() const;

virtual QgsExpressionContextScope *createExpressionContextScope() const;



};
@@ -1083,6 +1083,7 @@ QgsVectorLayerSelectedFeatureSource::QgsVectorLayerSelectedFeatureSource( QgsVec
, mSelectedFeatureIds( layer->selectedFeatureIds() )
, mWkbType( layer->wkbType() )
, mName( layer->name() )
, mLayer( layer )
{}

QgsFeatureIterator QgsVectorLayerSelectedFeatureSource::getFeatures( const QgsFeatureRequest &request ) const
@@ -1127,3 +1128,11 @@ QString QgsVectorLayerSelectedFeatureSource::sourceName() const
{
return mName;
}

QgsExpressionContextScope *QgsVectorLayerSelectedFeatureSource::createExpressionContextScope() const
{
if ( mLayer )
return mLayer->createExpressionContextScope();
else
return nullptr;
}
@@ -21,7 +21,9 @@
#include "qgsfields.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsfeaturesource.h"
#include "qgsexpressioncontextscopegenerator.h"

#include <QPointer>
#include <QSet>
#include <memory>

@@ -285,7 +287,7 @@ class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureItera
* QgsFeatureSource subclass for the selected features from a QgsVectorLayer.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource
class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource, public QgsExpressionContextScopeGenerator
{
public:

@@ -302,6 +304,7 @@ class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
QString sourceName() const override;
QgsExpressionContextScope *createExpressionContextScope() const override;


private:
@@ -311,6 +314,7 @@ class CORE_EXPORT QgsVectorLayerSelectedFeatureSource : public QgsFeatureSource
QgsFeatureIds mSelectedFeatureIds;
QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
QString mName;
QPointer< QgsVectorLayer > mLayer;

};

0 comments on commit d5617b8

Please sign in to comment.
You can’t perform that action at this time.