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