Skip to content
Permalink
Browse files

Merge pull request #5003 from nyalldawson/proc_algs

Followups to rasterise alg
  • Loading branch information
nyalldawson committed Aug 10, 2017
2 parents dc58c1a + 13431ca commit 34032d662b81bb78b4e5229c489e4cb899160680
@@ -158,7 +158,7 @@ def doCheck(self, method, parameters, context, feedback):

reason = "\n".join(reasons)
if len(reason) > 255:
reason = reason[:252] + '...'
reason = reason[:252] + ''
attrs.append(reason)

outFeat = QgsFeature()
@@ -19,8 +19,6 @@
***************************************************************************/
"""

from processing.core.outputs import OutputRaster

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

from qgis.PyQt.QtGui import QImage, QPainter
@@ -34,10 +32,8 @@
QgsProcessingParameterExtent,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterMapLayer,
QgsProcessingParameterRasterDestination,
QgsMessageLog,
QgsRasterFileWriter
)

@@ -101,9 +97,7 @@ def initAlgorithm(self, config=None):
self.addParameter(map_theme_param)

self.addParameter(
# TODO use QgsProcessingParameterMapLayer when
# the LayerWidgetWrapper class will be implemented
QgsProcessingParameterRasterLayer(
QgsProcessingParameterMapLayer(
self.LAYER,
description=self.tr(
'Layer to render. Will only be used if the map theme '
@@ -119,7 +113,7 @@ def initAlgorithm(self, config=None):
QgsProcessingParameterNumber(
self.TILE_SIZE,
self.tr('Tile size'),
defaultValue=1024))
defaultValue=1024, minValue=64))

self.addParameter(QgsProcessingParameterNumber(
self.MAP_UNITS_PER_PIXEL,
@@ -149,7 +143,7 @@ def group(self):
return self.tr('Raster tools')

def tags(self):
return self.tr('layer,raster,convert,file,map themes,tiles').split(',')
return self.tr('layer,raster,convert,file,map themes,tiles,render').split(',')

# def processAlgorithm(self, progress):
def processAlgorithm(self, parameters, context, feedback):
@@ -72,7 +72,7 @@ def __init__(self, param, row, col, dialog):
QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton()
self.pushButton.setText('...')
self.pushButton.setText('')
self.pushButton.clicked.connect(self.showPopupMenu)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
@@ -64,7 +64,7 @@ def __init__(self, output, alg, row, col, panel):
QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton()
self.pushButton.setText('...')
self.pushButton.setText('')
self.pushButton.clicked.connect(self.showSelectionDialog)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
@@ -405,7 +405,7 @@ def __init__(self, parent=None, selectFile=False):

# create gui
self.btnSelect = QToolButton()
self.btnSelect.setText(self.tr('...'))
self.btnSelect.setText('…')
self.lineEdit = QLineEdit()
self.hbl = QHBoxLayout()
self.hbl.setMargin(0)
@@ -452,7 +452,7 @@ def __init__(self, parent=None):

# create gui
self.btnSelect = QToolButton()
self.btnSelect.setText(self.tr('...'))
self.btnSelect.setText('…')
self.lineEdit = QLineEdit()
self.hbl = QHBoxLayout()
self.hbl.setMargin(0)
@@ -62,6 +62,7 @@
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
QgsProcessingParameterBand,
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
@@ -230,7 +231,7 @@ class ExpressionWidgetWrapperMixin():
def wrapWithExpressionButton(self, basewidget):
expr_button = QToolButton()
expr_button.clicked.connect(self.showExpressionsBuilder)
expr_button.setText('...')
expr_button.setText('')

layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
@@ -626,7 +627,7 @@ def value(self):
return self.widget.getValue()


class RasterWidgetWrapper(WidgetWrapper):
class MapLayerWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'

@@ -640,7 +641,7 @@ def createWidget(self):
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
@@ -651,11 +652,10 @@ def createWidget(self):
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
self.combo.setShowCrs(True)

self.combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
self.combo.setExcludedProviders(['grass'])
self.setComboBoxFilters(self.combo)

try:
if iface.activeLayer().type() == QgsMapLayer.RasterLayer:
self.combo.setLayer(iface.activeLayer())
self.combo.setLayer(iface.activeLayer())
except:
pass

@@ -666,7 +666,7 @@ def createWidget(self):
return BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
else:
self.combo = QComboBox()
layers = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
layers = self.getAvailableLayers()
self.combo.setEditable(True)
for layer in layers:
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
@@ -680,17 +680,23 @@ def createWidget(self):
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
widget.setLayout(layout)
return widget

def setComboBoxFilters(self, combo):
pass

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

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
@@ -728,6 +734,28 @@ def validator(v):
return self.comboValue(validator, combobox=self.combo)


class RasterWidgetWrapper(MapLayerWidgetWrapper):

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)

def setComboBoxFilters(self, combo):
combo.setFilters(QgsMapLayerProxyModel.RasterLayer)
combo.setExcludedProviders(['grass'])

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems()
items.append(filename)
self.combo.setAdditionalItems(items)
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)


class SelectionWidgetWrapper(WidgetWrapper):

def createWidget(self):
@@ -754,11 +782,6 @@ def value(self):
return self.widget.currentData()


class LayerWidgetWrapper(WidgetWrapper):
def __init__(self):
raise NotImplementedError('Layer widget wrapper is not implemented yet')


class VectorWidgetWrapper(WidgetWrapper):

NOT_SELECTED = '[Not selected]'
@@ -774,7 +797,7 @@ def createWidget(self):
layout.addWidget(self.combo)
layout.setAlignment(self.combo, Qt.AlignTop)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
@@ -843,7 +866,7 @@ def createWidget(self):
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
@@ -1063,7 +1086,7 @@ def createWidget(self):
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
@@ -1113,7 +1136,7 @@ def createWidget(self):
layout.setSpacing(2)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('...')
btn.setText('')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
@@ -1394,7 +1417,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
elif param.type() == 'band':
wrapper = BandWidgetWrapper
elif param.type() == 'layer':
wrapper = LayerWidgetWrapper
wrapper = MapLayerWidgetWrapper
else:
assert False, param.type()
return wrapper(param, dialog, row, col)
@@ -260,10 +260,10 @@ def getAdjustedText(self, text):
if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
return text

text = text[0:-3] + '...'
text = text[0:-3] + ''
w = fm.width(text)
while w > self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
text = text[0:-4] + '...'
text = text[0:-4] + ''
w = fm.width(text)
return text

0 comments on commit 34032d6

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