mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] indentation update
This commit is contained in:
parent
f002321be1
commit
50a785bdd6
@ -86,7 +86,6 @@ class FieldsMapper(GeoAlgorithm):
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
self.addParameter(ParameterFieldsMapping(self.FIELDS_MAPPING,
|
||||
self.tr('Fields mapping'),
|
||||
self.INPUT_LAYER))
|
||||
|
@ -39,6 +39,7 @@ from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.algs.qgis.ui.RasterCalculatorWidgets import LayersListWidgetWrapper, ExpressionWidgetWrapper
|
||||
|
||||
|
||||
class RasterCalculator(GeoAlgorithm):
|
||||
|
||||
LAYERS = 'LAYERS'
|
||||
@ -52,11 +53,13 @@ class RasterCalculator(GeoAlgorithm):
|
||||
self.group, self.i18n_group = self.trAlgorithm('Raster')
|
||||
|
||||
self.addParameter(ParameterMultipleInput(self.LAYERS,
|
||||
self.tr('Input layers'),
|
||||
datatype=dataobjects.TYPE_RASTER,
|
||||
optional=True,
|
||||
metadata={'widget_wrapper': LayersListWidgetWrapper}))
|
||||
self.tr('Input layers'),
|
||||
datatype=dataobjects.TYPE_RASTER,
|
||||
optional=True,
|
||||
metadata={'widget_wrapper': LayersListWidgetWrapper}))
|
||||
|
||||
class ParameterRasterCalculatorExpression(ParameterString):
|
||||
|
||||
def evaluateForModeler(self, value, model):
|
||||
# print value
|
||||
for i in list(model.inputs.values()):
|
||||
@ -76,8 +79,8 @@ class RasterCalculator(GeoAlgorithm):
|
||||
return value
|
||||
|
||||
self.addParameter(ParameterRasterCalculatorExpression(self.EXPRESSION, self.tr('Expression'),
|
||||
multiline=True,
|
||||
metadata={'widget_wrapper': ExpressionWidgetWrapper}))
|
||||
multiline=True,
|
||||
metadata={'widget_wrapper': ExpressionWidgetWrapper}))
|
||||
self.addParameter(ParameterNumber(self.CELLSIZE,
|
||||
self.tr('Cellsize (use 0 or empty to set it automatically)'),
|
||||
minValue=0.0, default=0.0, optional=True))
|
||||
@ -86,7 +89,6 @@ class RasterCalculator(GeoAlgorithm):
|
||||
optional=True))
|
||||
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Output')))
|
||||
|
||||
|
||||
def processAlgorithm(self, progress):
|
||||
expression = self.getParameterValue(self.EXPRESSION)
|
||||
layersValue = self.getParameterValue(self.LAYERS)
|
||||
@ -123,6 +125,7 @@ class RasterCalculator(GeoAlgorithm):
|
||||
bbox.combineExtentWith(lyr.extent())
|
||||
else:
|
||||
raise GeoAlgorithmExecutionException(self.tr("No layers selected"))
|
||||
|
||||
def _cellsize(layer):
|
||||
return (layer.extent().xMaximum() - layer.extent().xMinimum()) / layer.width()
|
||||
cellsize = self.getParameterValue(self.CELLSIZE) or min([_cellsize(lyr) for lyr in layersDict.values()])
|
||||
@ -130,12 +133,12 @@ class RasterCalculator(GeoAlgorithm):
|
||||
height = math.floor((bbox.yMaximum() - bbox.yMinimum()) / cellsize)
|
||||
driverName = GdalUtils.getFormatShortNameFromFilename(output)
|
||||
calc = QgsRasterCalculator(expression,
|
||||
output,
|
||||
driverName,
|
||||
bbox,
|
||||
width,
|
||||
height,
|
||||
entries)
|
||||
output,
|
||||
driverName,
|
||||
bbox,
|
||||
width,
|
||||
height,
|
||||
entries)
|
||||
|
||||
res = calc.processCalculation()
|
||||
if res == QgsRasterCalculator.ParserError:
|
||||
|
@ -20,37 +20,38 @@ class ExpressionWidget(BASE, WIDGET):
|
||||
def __init__(self, options):
|
||||
super(ExpressionWidget, self).__init__(None)
|
||||
self.setupUi(self)
|
||||
|
||||
|
||||
self.setList(options)
|
||||
|
||||
|
||||
def doubleClicked(item):
|
||||
self.text.insertPlainText(self.options[item.text()])
|
||||
|
||||
def addButtonText(text):
|
||||
if any(c for c in text if c.islower()):
|
||||
self.text.insertPlainText(" %s()" % text)
|
||||
self.text.moveCursor(QTextCursor.PreviousCharacter, QTextCursor.MoveAnchor)
|
||||
else:
|
||||
self.text.insertPlainText(" %s " % text)
|
||||
self.text.insertPlainText(" %s " % text)
|
||||
buttons = [b for b in self.buttonsGroupBox.children()if isinstance(b, QPushButton)]
|
||||
for button in buttons:
|
||||
button.clicked.connect(partial(addButtonText, button.text()))
|
||||
self.listWidget.itemDoubleClicked.connect(doubleClicked)
|
||||
|
||||
|
||||
def setList(self, options):
|
||||
self.options = options
|
||||
self.listWidget.clear()
|
||||
for opt in options.keys():
|
||||
self.listWidget.addItem(opt)
|
||||
|
||||
|
||||
def setValue(self, value):
|
||||
self.text.setPlainText(value)
|
||||
|
||||
|
||||
def value(self):
|
||||
return self.text.toPlainText()
|
||||
|
||||
|
||||
|
||||
class ExpressionWidgetWrapper(WidgetWrapper):
|
||||
|
||||
|
||||
def _panel(self, options):
|
||||
return ExpressionWidget(options)
|
||||
|
||||
@ -61,7 +62,7 @@ class ExpressionWidgetWrapper(WidgetWrapper):
|
||||
for lyr in layers:
|
||||
for n in xrange(lyr.bandCount()):
|
||||
name = '%s@%i' % (lyr.name(), n + 1)
|
||||
options[name] = name
|
||||
options[name] = name
|
||||
return self._panel(options)
|
||||
elif self.dialogType == DIALOG_BATCH:
|
||||
return QLineEdit()
|
||||
@ -109,7 +110,6 @@ class LayersListWidgetWrapper(WidgetWrapper):
|
||||
if self.dialogType == DIALOG_BATCH:
|
||||
return self.widget.setText(value)
|
||||
|
||||
|
||||
def value(self):
|
||||
if self.dialogType == DIALOG_STANDARD:
|
||||
if self.param.datatype == dataobjects.TYPE_FILE:
|
||||
@ -130,6 +130,3 @@ class LayersListWidgetWrapper(WidgetWrapper):
|
||||
if len(values) == 0 and not self.param.optional:
|
||||
raise InvalidParameterValue()
|
||||
return values
|
||||
|
||||
|
||||
|
@ -48,6 +48,7 @@ from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
from processing.tools import dataobjects, vector
|
||||
from processing.algs.help import shortHelp
|
||||
|
||||
|
||||
class GeoAlgorithm(object):
|
||||
|
||||
def __init__(self):
|
||||
@ -132,10 +133,9 @@ class GeoAlgorithm(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def getParametersPanel(self, parent):
|
||||
return ParametersPanel(parent, self)
|
||||
|
||||
return ParametersPanel(parent, self)
|
||||
|
||||
def getCustomParametersDialog(self):
|
||||
"""If the algorithm has a custom parameters dialog, it should
|
||||
be returned here, ready to be executed.
|
||||
@ -185,12 +185,12 @@ class GeoAlgorithm(object):
|
||||
calling from the console.
|
||||
"""
|
||||
return None
|
||||
|
||||
|
||||
def processBeforeAddingToModeler(self, alg, model):
|
||||
"""Add here any task that has to be performed before adding an algorithm
|
||||
to a model, such as changing the value of a parameter depending on value
|
||||
of another one"""
|
||||
pass
|
||||
of another one"""
|
||||
pass
|
||||
|
||||
# =========================================================
|
||||
|
||||
|
@ -119,10 +119,10 @@ class ParametersPanel(BASE, WIDGET):
|
||||
button.toggled.connect(self.buttonToggled)
|
||||
widget = QWidget()
|
||||
widget.setLayout(layout)
|
||||
|
||||
|
||||
tooltips = self.alg.getParameterDescriptions()
|
||||
widget.setToolTip(tooltips.get(param.name, param.description))
|
||||
|
||||
|
||||
label = QLabel(desc)
|
||||
# label.setToolTip(tooltip)
|
||||
self.labels[param.name] = label
|
||||
|
@ -158,7 +158,7 @@ class ModelerParametersDialog(QDialog):
|
||||
label.setVisible(self.showAdvanced)
|
||||
widget.setVisible(self.showAdvanced)
|
||||
self.widgets[param.name] = widget
|
||||
|
||||
|
||||
self.verticalLayout.addWidget(label)
|
||||
self.verticalLayout.addWidget(widget)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user