Skip to content
Permalink
Browse files

Open heart surgery on expression context for processing sources

  • Loading branch information
m-kuhn committed Nov 24, 2017
1 parent aaf70de commit 916c9c4cdb5734142be7012e92cdec007956a22e
@@ -41,6 +41,7 @@
%Include qgserror.sip
%Include qgsexpressioncontext.sip
%Include qgsexpressioncontextgenerator.sip
%Include qgsexpressioncontextscopegenerator.sip
%Include qgsexpressionfieldbuffer.sip
%Include qgsfeaturefilterprovider.sip
%Include qgsfeatureiterator.sip
@@ -274,11 +274,10 @@ class QgsProcessingFeatureSource : QgsFeatureSource
virtual QVariant maximumValue( int fieldIndex ) const;


QgsExpressionContext createExpressionContext( const QgsProcessingContext &context ) const;
QgsExpressionContextScope *createExpressionContextScope() const /Factory/;
%Docstring
Returns an expression context scope suitable for this source or a default global/project
context if nothing more specific can be created.
:rtype: QgsExpressionContext
Returns an expression context scope suitable for this source.
:rtype: QgsExpressionContextScope
%End

};
@@ -0,0 +1,42 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsexpressioncontextscopegenerator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsExpressionContextScopeGenerator
{
%Docstring
Abstract interface for generating an expression context scope.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsexpressioncontextscopegenerator.h"
%End
public:

virtual QgsExpressionContextScope *createExpressionContextScope() const = 0 /Factory/;
%Docstring
This method needs to be reimplemented in all classes which implement this interface
and return an expression context scope.

.. versionadded:: 3.0
:rtype: QgsExpressionContextScope
%End

virtual ~QgsExpressionContextScopeGenerator();
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsexpressioncontextscopegenerator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -17,7 +17,7 @@ typedef QList<int> QgsAttributeList;
typedef QSet<int> QgsAttributeIds;


class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSink, QgsFeatureSource
class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsExpressionContextScopeGenerator, QgsFeatureSink, QgsFeatureSource
{
%Docstring
Represents a vector layer which manages a vector based data sets.
@@ -1783,6 +1783,9 @@ Returns the current blending mode for features
virtual QgsExpressionContext createExpressionContext() const;


virtual QgsExpressionContextScope *createExpressionContextScope() const /Factory/;


QgsEditFormConfig editFormConfig() const;
%Docstring
Get the configuration of the form used to represent this vector layer.
@@ -855,6 +855,7 @@ SET(QGIS_CORE_HDRS
qgsexception.h
qgsexpressioncontext.h
qgsexpressioncontextgenerator.h
qgsexpressioncontextscopegenerator.h
qgsexpressionfieldbuffer.h
qgsfeaturefilterprovider.h
qgsfeatureiterator.h
@@ -132,8 +132,8 @@ QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext( const QVar
// If there's a source capable of generating a context scope, use it
if ( source )
{
const auto &scopes = source->createExpressionContext( context ).takeScopes();
for ( QgsExpressionContextScope *scope : scopes )
QgsExpressionContextScope *scope = source->createExpressionContextScope();
if ( scope )
c << scope;
}
else if ( c.scopeCount() == 0 )
@@ -26,6 +26,7 @@
#include "qgsprocessingparameters.h"
#include "qgsprocessingalgorithm.h"
#include "qgsvectorlayerfeatureiterator.h"
#include "qgsexpressioncontextscopegenerator.h"

QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
{
@@ -721,19 +722,13 @@ QVariant QgsProcessingFeatureSource::maximumValue( int fieldIndex ) const
return mSource->maximumValue( fieldIndex );
}

QgsExpressionContext QgsProcessingFeatureSource::createExpressionContext( const QgsProcessingContext &context ) const
QgsExpressionContextScope *QgsProcessingFeatureSource::createExpressionContextScope() const
{
QgsExpressionContext expressionContext;
QgsExpressionContextGenerator *generator = dynamic_cast<QgsExpressionContextGenerator *>( mSource );
QgsExpressionContextScope *expressionContextScope = nullptr;
QgsExpressionContextScopeGenerator *generator = dynamic_cast<QgsExpressionContextScopeGenerator *>( mSource );
if ( generator )
{
expressionContext = generator->createExpressionContext();
expressionContextScope = generator->createExpressionContextScope();
}
else
{
expressionContext
<< QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope( context.project() );
}
return expressionContext;
return expressionContextScope;
}
@@ -320,10 +320,9 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
QVariant maximumValue( int fieldIndex ) const override;

/**
* Returns an expression context scope suitable for this source or a default global/project
* context if nothing more specific can be created.
* Returns an expression context scope suitable for this source.
*/
QgsExpressionContext createExpressionContext( const QgsProcessingContext &context ) const;
QgsExpressionContextScope *createExpressionContextScope() const SIP_FACTORY;

private:

@@ -0,0 +1,43 @@
/***************************************************************************
qgsexpressioncontextscopegenerator.h - QgsExpressionContextScopeGenerator
---------------------
begin : 24.11.2017
copyright : (C) 2017 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSEXPRESSIONCONTEXTSCOPEGENERATOR_H
#define QGSEXPRESSIONCONTEXTSCOPEGENERATOR_H

#include "qgsexpressioncontext.h"

/**
* \ingroup core
* Abstract interface for generating an expression context scope.
*
* \since QGIS 3.0
*/

class CORE_EXPORT QgsExpressionContextScopeGenerator
{
public:

/**
* This method needs to be reimplemented in all classes which implement this interface
* and return an expression context scope.
*
* \since QGIS 3.0
*/
virtual QgsExpressionContextScope *createExpressionContextScope() const = 0 SIP_FACTORY;

virtual ~QgsExpressionContextScopeGenerator() = default;
};

#endif // QGSEXPRESSIONCONTEXTGENERATOR_H
@@ -3975,6 +3975,11 @@ QgsExpressionContext QgsVectorLayer::createExpressionContext() const
return QgsExpressionContext( QgsExpressionContextUtils::globalProjectLayerScopes( this ) );
}

QgsExpressionContextScope *QgsVectorLayer::createExpressionContextScope() const
{
return QgsExpressionContextUtils::layerScope( this );
}

void QgsVectorLayer::setDiagramLayerSettings( const QgsDiagramLayerSettings &s )
{
if ( !mDiagramLayerSettings )
@@ -40,6 +40,7 @@
#include "qgsaggregatecalculator.h"
#include "qgsfeatureiterator.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgsexpressioncontextscopegenerator.h"

class QPainter;
class QImage;
@@ -350,7 +351,7 @@ typedef QSet<int> QgsAttributeIds;
* TODO QGIS3: Remove virtual from non-inherited methods (like isModified)
* \see QgsVectorLayerUtils()
*/
class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionContextGenerator, public QgsFeatureSink, public QgsFeatureSource
class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionContextGenerator, public QgsExpressionContextScopeGenerator, public QgsFeatureSink, public QgsFeatureSource
{
Q_OBJECT

@@ -1741,6 +1742,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

QgsExpressionContext createExpressionContext() const override;

QgsExpressionContextScope *createExpressionContextScope() const override SIP_FACTORY;

/**
* Get the configuration of the form used to represent this vector layer.
* This is a writable configuration that can directly be changed in place.

0 comments on commit 916c9c4

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