Skip to content
Permalink
Browse files

Fix QgsExpressionContextUtils::projectScope() usage in processing

  • Loading branch information
wonder-sk committed Jan 6, 2017
1 parent 660867c commit 63d1cfddc8b83347c010f9c05865eba2c2aa2ccb
@@ -108,10 +108,7 @@ def processAlgorithm(self, progress):
exp.setDistanceUnits(QgsProject.instance().distanceUnits())
exp.setAreaUnits(QgsProject.instance().areaUnits())

exp_context = QgsExpressionContext()
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
exp_context.appendScope(QgsExpressionContextUtils.layerScope(layer))
exp_context = QgsExpressionContext(QgsExpressionContextUtils.globalProjectLayerScopes(layer))

if not exp.prepare(exp_context):
raise GeoAlgorithmExecutionException(
@@ -95,10 +95,7 @@ def processAlgorithm(self, progress):
if expression.hasParserError():
raise GeoAlgorithmExecutionException(expression.parserErrorString())

exp_context = QgsExpressionContext()
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
exp_context.appendScope(QgsExpressionContextUtils.layerScope(layer))
exp_context = QgsExpressionContext(QgsExpressionContextUtils.globalProjectLayerScopes(layer))

if not expression.prepare(exp_context):
raise GeoAlgorithmExecutionException(
@@ -95,9 +95,7 @@ def manageGui(self):

def initContext(self):
exp_context = self.builder.expressionContext()
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
exp_context.appendScope(QgsExpressionContextUtils.layerScope(self.layer))
exp_context.appendScopes(QgsExpressionContextUtils.globalProjectLayerScopes(self.layer))
exp_context.lastScope().setVariable("row_number", 1)
exp_context.setHighlightedVariables(["row_number"])
self.builder.setExpressionContext(exp_context)
@@ -38,13 +38,13 @@
from processing.tools.vector import VectorWriter, TableWriter
from processing.tools import dataobjects

from qgis.core import QgsExpressionContext, QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope
from qgis.core import QgsExpressionContext, QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope, QgsProject


def _expressionContext(alg):
context = QgsExpressionContext()
context.appendScope(QgsExpressionContextUtils.globalScope())
context.appendScope(QgsExpressionContextUtils.projectScope())
context.appendScope(QgsExpressionContextUtils.projectScope(QgsProject.instance()))
processingScope = QgsExpressionContextScope()
for param in alg.parameters:
processingScope.setVariable('%s_value' % param.name, '')
@@ -38,7 +38,8 @@
from qgis.utils import iface
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinateReferenceSystem,
QgsExpressionContext, QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope)
QgsExpressionContext, QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope,
QgsProject)

from processing.tools.vector import resolveFieldIndex, features
from processing.tools import dataobjects
@@ -70,7 +71,7 @@ def _createDescriptiveName(s):
def _expressionContext():
context = QgsExpressionContext()
context.appendScope(QgsExpressionContextUtils.globalScope())
context.appendScope(QgsExpressionContextUtils.projectScope())
context.appendScope(QgsExpressionContextUtils.projectScope(QgsProject.instance()))

if iface.mapCanvas():
context.appendScope(QgsExpressionContextUtils.mapSettingsScope(iface.mapCanvas().mapSettings()))
@@ -29,7 +29,7 @@
import os
import re
import json
from qgis.core import QgsExpressionContextUtils, QgsExpressionContext
from qgis.core import QgsExpressionContextUtils, QgsExpressionContext, QgsProject
from qgis.PyQt.QtGui import QIcon
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.gui.Help2Html import getHtmlFromHelpFile
@@ -166,7 +166,7 @@ def processAlgorithm(self, progress):

context = QgsExpressionContext()
context.appendScope(QgsExpressionContextUtils.globalScope())
context.appendScope(QgsExpressionContextUtils.projectScope())
context.appendScope(QgsExpressionContextUtils.projectScope(QgsProject.instance()))
for var in variables:
varname = var[1:]
if context.hasVariable(varname):

0 comments on commit 63d1cfd

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