Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Clean migration path to new order_expression parameter
  • Loading branch information
m-kuhn authored and nyalldawson committed Oct 24, 2020
1 parent e95b62d commit 84e2d78
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions python/plugins/processing/algs/qgis/PointsToPaths.py
Expand Up @@ -44,7 +44,8 @@
QgsProcessingFeatureSource,
QgsProcessing,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFolderDestination)
QgsProcessingParameterFolderDestination,
QgsProcessingParameterDefinition)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from PyQt5.QtCore import QVariant
Expand All @@ -55,6 +56,7 @@ class PointsToPaths(QgisAlgorithm):
CLOSE_PATH = 'CLOSE_PATH'
GROUP_FIELD = 'GROUP_FIELD'
ORDER_FIELD = 'ORDER_FIELD'
ORDER_EXPRESSION = 'ORDER_EXPRESSION'
DATE_FORMAT = 'DATE_FORMAT'
OUTPUT = 'OUTPUT'
OUTPUT_TEXT_DIR = 'OUTPUT_TEXT_DIR'
Expand All @@ -76,7 +78,11 @@ def initAlgorithm(self, config=None):
self.tr('Input point layer'), [QgsProcessing.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterBoolean(self.CLOSE_PATH,
self.tr('Close path'), defaultValue=False))
self.addParameter(QgsProcessingParameterExpression(self.ORDER_FIELD,
order_field_param = QgsProcessingParameterField(self.ORDER_FIELD,
self.tr('Order field'), parentLayerParameterName=self.INPUT, optional=True)
order_field_param.setFlags(order_field_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
self.addParameter(order_field_param)
self.addParameter(QgsProcessingParameterExpression(self.ORDER_EXPRESSION,
self.tr('Order expression'), parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterField(self.GROUP_FIELD,
self.tr('Group field'), parentLayerParameterName=self.INPUT, optional=True))
Expand All @@ -101,7 +107,8 @@ def processAlgorithm(self, parameters, context, feedback):

close_path = self.parameterAsBool(parameters, self.CLOSE_PATH, context)
group_field_name = self.parameterAsString(parameters, self.GROUP_FIELD, context)
order_expression = self.parameterAsString(parameters, self.ORDER_FIELD, context)
order_field_name = self.parameterAsString(parameters, self.ORDER_FIELD, context)
order_expression = self.parameterAsString(parameters, self.ORDER_EXPRESSION, context)
date_format = self.parameterAsString(parameters, self.DATE_FORMAT, context)
text_dir = self.parameterAsString(parameters, self.OUTPUT_TEXT_DIR, context)

Expand All @@ -112,6 +119,9 @@ def processAlgorithm(self, parameters, context, feedback):
else:
group_field_def = None

if order_field_name:
order_expression = QgsExpression.quotedColumnRef(order_field_name)

expression_context = self.createExpressionContext(parameters, context, source)
expression = QgsExpression(order_expression)
if expression.hasParserError():
Expand Down

0 comments on commit 84e2d78

Please sign in to comment.