Skip to content
Permalink
Browse files

Formatting

  • Loading branch information
nyalldawson committed Sep 22, 2017
1 parent 94530a9 commit c5b9fa23cd4bfab0049368c3dfeee11c6b3d1e3e
@@ -18,7 +18,6 @@
***************************************************************************
"""


__author__ = 'Arnaud Morvan'
__date__ = 'May 2016'
__copyright__ = '(C) 2016, Arnaud Morvan'
@@ -27,7 +26,6 @@

__revision__ = '$Format:%H$'


import locale
import os
from functools import cmp_to_key
@@ -124,6 +122,7 @@
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
from processing.gui.ParameterGuiUtils import getFileFilter

DIALOG_STANDARD = 'standard'
DIALOG_BATCH = 'batch'
DIALOG_MODELER = 'modeler'
@@ -147,7 +146,6 @@ def getExtendedLayerName(layer):


class WidgetWrapper(QObject):

widgetValueHasChanged = pyqtSignal(object)

def __init__(self, param, dialog, row=0, col=0, **kwargs):
@@ -324,8 +322,10 @@ def createWidget(self):
crss = self.dialog.getAvailableValuesOfType(QgsProcessingParameterCrs)
for crs in crss:
self.combo.addItem(self.dialog.resolveValueDescription(crs), crs)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
vector = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer,
QgsProcessingOutputRasterLayer)
vector = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource,
QgsProcessingOutputVectorLayer)
for r in raster:
self.combo.addItem("Crs of layer " + self.dialog.resolveValueDescription(r), r)
for v in vector:
@@ -378,7 +378,6 @@ def value(self):


class ExtentWidgetWrapper(WidgetWrapper):

USE_MIN_COVERING_EXTENT = "[Use min covering extent]"

def createWidget(self):
@@ -390,8 +389,10 @@ def createWidget(self):
extents = self.dialog.getAvailableValuesOfType(QgsProcessingParameterExtent, OutputExtent)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
widget.addItem(self.USE_MIN_COVERING_EXTENT, None)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
vector = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer)
raster = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer,
QgsProcessingOutputRasterLayer)
vector = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource,
QgsProcessingOutputVectorLayer)
for ex in extents:
widget.addItem(self.dialog.resolveValueDescription(ex), ex)
for r in raster:
@@ -482,7 +483,8 @@ class FileWidgetWrapper(WidgetWrapper):

def createWidget(self):
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
return FileSelectionPanel(self.param.behavior() == QgsProcessingParameterFile.Folder, self.param.extension())
return FileSelectionPanel(self.param.behavior() == QgsProcessingParameterFile.Folder,
self.param.extension())
else:
self.combo = QComboBox()
self.combo.setEditable(True)
@@ -515,7 +517,8 @@ def selectFile(self):
path = ''

if self.param.extension():
filter = self.tr('{} files').format(self.param.extension().upper()) + ' (*.' + self.param.extension() + self.tr(
filter = self.tr('{} files').format(
self.param.extension().upper()) + ' (*.' + self.param.extension() + self.tr(
');;All files (*.*)')
else:
filter = self.tr('All files (*.*)')
@@ -561,20 +564,39 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):

def _getOptions(self):
if self.param.layerType() == QgsProcessing.TypeVectorAnyGeometry:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, QgsProcessingParameterMultipleLayers), QgsProcessingOutputVectorLayer)
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers),
QgsProcessingOutputVectorLayer)
elif self.param.layerType() == QgsProcessing.TypeVectorPoint:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, QgsProcessingParameterMultipleLayers), QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorAnyGeometry])
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers),
QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorPoint,
QgsProcessing.TypeVectorAnyGeometry])
elif self.param.layerType() == QgsProcessing.TypeVectorLine:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, QgsProcessingParameterMultipleLayers), QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorAnyGeometry])
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers),
QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorLine,
QgsProcessing.TypeVectorAnyGeometry])
elif self.param.layerType() == QgsProcessing.TypeVectorPolygon:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, QgsProcessingParameterMultipleLayers), QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorAnyGeometry])
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers),
QgsProcessingOutputVectorLayer,
[QgsProcessing.TypeVectorPolygon,
QgsProcessing.TypeVectorAnyGeometry])
elif self.param.layerType() == QgsProcessing.TypeRaster:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterRasterLayer, QgsProcessingParameterMultipleLayers), QgsProcessingOutputRasterLayer)
options = self.dialog.getAvailableValuesOfType(
(QgsProcessingParameterRasterLayer, QgsProcessingParameterMultipleLayers),
QgsProcessingOutputRasterLayer)
elif self.param.layerType() == QgsProcessing.TypeVector:
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer, QgsProcessingParameterMultipleLayers), OutputTable)
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMultipleLayers), OutputTable)
else:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile)
options = sorted(options, key=lambda opt: self.dialog.resolveValueDescription(opt))
@@ -590,7 +612,8 @@ def createWidget(self):
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
False)
opts = [getExtendedLayerName(opt) for opt in options]
return MultipleInputPanel(opts, datatype=self.param.layerType())
elif self.dialogType == DIALOG_BATCH:
@@ -608,7 +631,8 @@ def refresh(self):
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
False)
opts = [getExtendedLayerName(opt) for opt in options]
self.widget.updateForOptions(opts)

@@ -644,13 +668,15 @@ def value(self):
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
False)
return [options[i] if isinstance(i, int) else i for i in self.widget.selectedoptions]
elif self.dialogType == DIALOG_BATCH:
return self.widget.getText()
else:
options = self._getOptions()
values = [options[i] if isinstance(i, int) else QgsProcessingModelChildParameterSource.fromStaticValue(i) for i in self.widget.selectedoptions]
values = [options[i] if isinstance(i, int) else QgsProcessingModelChildParameterSource.fromStaticValue(i)
for i in self.widget.selectedoptions]
if len(values) == 0 and not self.param.flags() & QgsProcessing.FlagOptional:
raise InvalidParameterValue()
return values
@@ -674,7 +700,6 @@ def value(self):


class MapLayerWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'

def createWidget(self):
@@ -737,8 +762,9 @@ def setComboBoxFilters(self, combo):
pass

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType([QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer],
[QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer])
return self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterRasterLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer],
[QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer])

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
@@ -777,6 +803,7 @@ def validator(v):
return self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
else:
return os.path.exists(v)

return self.comboValue(validator, combobox=self.combo)


@@ -839,7 +866,6 @@ def value(self):


class FeatureSourceWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'

def createWidget(self):
@@ -908,7 +934,9 @@ def createWidget(self):
return widget
else:
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer), QgsProcessingOutputVectorLayer, self.param.dataTypes())
layers = self.dialog.getAvailableValuesOfType(
(QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer),
QgsProcessingOutputVectorLayer, self.param.dataTypes())
self.combo.setEditable(True)
for layer in layers:
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
@@ -979,6 +1007,7 @@ def validator(v):
return self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
else:
return os.path.exists(v)

return self.comboValue(validator, combobox=self.combo)


@@ -997,8 +1026,9 @@ def createWidget(self):

else:
# strings, numbers, files and table fields are all allowed input types
strings = self.dialog.getAvailableValuesOfType([QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile,
QgsProcessingParameterField, QgsProcessingParameterExpression], [QgsProcessingOutputString])
strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile,
QgsProcessingParameterField, QgsProcessingParameterExpression], [QgsProcessingOutputString])
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
if self.param.multiLine():
widget = MultilineTextPanel(options)
@@ -1068,6 +1098,7 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional

return self.comboValue(validator)


@@ -1082,7 +1113,9 @@ def createWidget(self):
if self.param.defaultValue():
widget.setExpression(self.param.defaultValue())
else:
strings = self.dialog.getAvailableValuesOfType([QgsProcessingParameterExpression, QgsProcessingParameterString, QgsProcessingParameterNumber], QgsProcessingOutputString)
strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterExpression, QgsProcessingParameterString, QgsProcessingParameterNumber],
QgsProcessingOutputString)
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
widget = QComboBox()
widget.setEditable(True)
@@ -1125,11 +1158,11 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional

return self.comboValue(validator)


class VectorLayerWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'

def createWidget(self):
@@ -1182,7 +1215,8 @@ def createWidget(self):
else:
self.combo = QComboBox()
self.combo.setEditable(True)
tables = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer, QgsProcessingOutputVectorLayer)
tables = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer,
QgsProcessingOutputVectorLayer)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.addItem(self.NOT_SELECTED, None)
for table in tables:
@@ -1237,11 +1271,11 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional

return self.comboValue(validator, combobox=self.combo)


class TableFieldWidgetWrapper(WidgetWrapper):

NOT_SET = '[Not set]'

def createWidget(self):
@@ -1264,13 +1298,15 @@ def createWidget(self):
else:
widget = QComboBox()
widget.setEditable(True)
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString], [QgsProcessingOutputString])
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString],
[QgsProcessingOutputString])
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
widget.addItem(self.NOT_SET, None)
for f in fields:
widget.addItem(self.dialog.resolveValueDescription(f), f)
widget.setToolTip(
self.tr('Input parameter, or name of field (separate field names with ; for multiple field parameters)'))
self.tr(
'Input parameter, or name of field (separate field names with ; for multiple field parameters)'))
return widget

def postInitialize(self, wrappers):
@@ -1326,7 +1362,7 @@ def setValue(self, value):
options = self.widget.options
selected = []
for i, opt in enumerate(options):
if opt in value or opt==value:
if opt in value or opt == value:
selected.append(i)
self.widget.setSelectedItems(selected)
else:
@@ -1346,11 +1382,11 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional

return self.comboValue(validator)


class BandWidgetWrapper(WidgetWrapper):

NOT_SET = '[Not set]'

def createWidget(self):
@@ -1364,7 +1400,8 @@ def createWidget(self):
else:
widget = QComboBox()
widget.setEditable(True)
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterBand, QgsProcessingParameterNumber], [QgsProcessingOutputNumber])
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterBand, QgsProcessingParameterNumber],
[QgsProcessingOutputNumber])
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
widget.addItem(self.NOT_SET, None)
for f in fields:
@@ -1410,11 +1447,11 @@ def value(self):
else:
def validator(v):
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional

return self.comboValue(validator)


class WidgetWrapperFactory:

"""
Factory for parameter widget wrappers
"""

0 comments on commit c5b9fa2

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