Skip to content

Commit

Permalink
Merge pull request #5003 from nyalldawson/proc_algs
Browse files Browse the repository at this point in the history
Followups to rasterise alg
  • Loading branch information
nyalldawson committed Aug 10, 2017
2 parents dc58c1a + 13431ca commit 34032d6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/CheckValidity.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def doCheck(self, method, parameters, context, feedback):


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


outFeat = QgsFeature() outFeat = QgsFeature()
Expand Down
12 changes: 3 additions & 9 deletions python/plugins/processing/algs/qgis/Rasterize.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
***************************************************************************/ ***************************************************************************/
""" """


from processing.core.outputs import OutputRaster

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


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


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


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


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


def tags(self): 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, progress):
def processAlgorithm(self, parameters, context, feedback): def processAlgorithm(self, parameters, context, feedback):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchInputSelectionPanel.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, param, row, col, dialog):
QSizePolicy.Expanding) QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text) self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton() self.pushButton = QPushButton()
self.pushButton.setText('...') self.pushButton.setText('')
self.pushButton.clicked.connect(self.showPopupMenu) self.pushButton.clicked.connect(self.showPopupMenu)
self.horizontalLayout.addWidget(self.pushButton) self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout) self.setLayout(self.horizontalLayout)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchOutputSelectionPanel.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, output, alg, row, col, panel):
QSizePolicy.Expanding) QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text) self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton() self.pushButton = QPushButton()
self.pushButton.setText('...') self.pushButton.setText('')
self.pushButton.clicked.connect(self.showSelectionDialog) self.pushButton.clicked.connect(self.showSelectionDialog)
self.horizontalLayout.addWidget(self.pushButton) self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout) self.setLayout(self.horizontalLayout)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ConfigDialog.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def __init__(self, parent=None, selectFile=False):


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


# create gui # create gui
self.btnSelect = QToolButton() self.btnSelect = QToolButton()
self.btnSelect.setText(self.tr('...')) self.btnSelect.setText('…')
self.lineEdit = QLineEdit() self.lineEdit = QLineEdit()
self.hbl = QHBoxLayout() self.hbl = QHBoxLayout()
self.hbl.setMargin(0) self.hbl.setMargin(0)
Expand Down
63 changes: 43 additions & 20 deletions python/plugins/processing/gui/wrappers.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
QgsProcessingParameterVectorLayer, QgsProcessingParameterVectorLayer,
QgsProcessingParameterField, QgsProcessingParameterField,
QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
QgsProcessingParameterBand, QgsProcessingParameterBand,
QgsProcessingFeatureSourceDefinition, QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer, QgsProcessingOutputRasterLayer,
Expand Down Expand Up @@ -230,7 +231,7 @@ class ExpressionWidgetWrapperMixin():
def wrapWithExpressionButton(self, basewidget): def wrapWithExpressionButton(self, basewidget):
expr_button = QToolButton() expr_button = QToolButton()
expr_button.clicked.connect(self.showExpressionsBuilder) expr_button.clicked.connect(self.showExpressionsBuilder)
expr_button.setText('...') expr_button.setText('')


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




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


NOT_SELECTED = '[Not selected]' NOT_SELECTED = '[Not selected]'


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


self.combo.setFilters(QgsMapLayerProxyModel.RasterLayer) self.setComboBoxFilters(self.combo)
self.combo.setExcludedProviders(['grass'])
try: try:
if iface.activeLayer().type() == QgsMapLayer.RasterLayer: self.combo.setLayer(iface.activeLayer())
self.combo.setLayer(iface.activeLayer())
except: except:
pass pass


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


def setComboBoxFilters(self, combo):
pass

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

def selectFile(self): def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText()) filename, selected_filter = self.getFileName(self.combo.currentText())
if filename: if filename:
filename = dataobjects.getRasterSublayer(filename, self.param)
if isinstance(self.combo, QgsMapLayerComboBox): if isinstance(self.combo, QgsMapLayerComboBox):
items = self.combo.additionalItems() items = self.combo.additionalItems()
items.append(filename) items.append(filename)
Expand Down Expand Up @@ -728,6 +734,28 @@ def validator(v):
return self.comboValue(validator, combobox=self.combo) 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): class SelectionWidgetWrapper(WidgetWrapper):


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




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


class VectorWidgetWrapper(WidgetWrapper): class VectorWidgetWrapper(WidgetWrapper):


NOT_SELECTED = '[Not selected]' NOT_SELECTED = '[Not selected]'
Expand All @@ -774,7 +797,7 @@ def createWidget(self):
layout.addWidget(self.combo) layout.addWidget(self.combo)
layout.setAlignment(self.combo, Qt.AlignTop) layout.setAlignment(self.combo, Qt.AlignTop)
btn = QToolButton() btn = QToolButton()
btn.setText('...') btn.setText('')
btn.setToolTip(self.tr("Select file")) btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile) btn.clicked.connect(self.selectFile)
layout.addWidget(btn) layout.addWidget(btn)
Expand Down Expand Up @@ -843,7 +866,7 @@ def createWidget(self):
layout.setSpacing(2) layout.setSpacing(2)
layout.addWidget(self.combo) layout.addWidget(self.combo)
btn = QToolButton() btn = QToolButton()
btn.setText('...') btn.setText('')
btn.setToolTip(self.tr("Select file")) btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile) btn.clicked.connect(self.selectFile)
layout.addWidget(btn) layout.addWidget(btn)
Expand Down Expand Up @@ -1063,7 +1086,7 @@ def createWidget(self):
self.combo = QgsMapLayerComboBox() self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo) layout.addWidget(self.combo)
btn = QToolButton() btn = QToolButton()
btn.setText('...') btn.setText('')
btn.setToolTip(self.tr("Select file")) btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile) btn.clicked.connect(self.selectFile)
layout.addWidget(btn) layout.addWidget(btn)
Expand Down Expand Up @@ -1113,7 +1136,7 @@ def createWidget(self):
layout.setSpacing(2) layout.setSpacing(2)
layout.addWidget(self.combo) layout.addWidget(self.combo)
btn = QToolButton() btn = QToolButton()
btn.setText('...') btn.setText('')
btn.setToolTip(self.tr("Select file")) btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile) btn.clicked.connect(self.selectFile)
layout.addWidget(btn) layout.addWidget(btn)
Expand Down Expand Up @@ -1394,7 +1417,7 @@ def create_wrapper_from_class(param, dialog, row=0, col=0):
elif param.type() == 'band': elif param.type() == 'band':
wrapper = BandWidgetWrapper wrapper = BandWidgetWrapper
elif param.type() == 'layer': elif param.type() == 'layer':
wrapper = LayerWidgetWrapper wrapper = MapLayerWidgetWrapper
else: else:
assert False, param.type() assert False, param.type()
return wrapper(param, dialog, row, col) return wrapper(param, dialog, row, col)
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/ModelerGraphicItem.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def getAdjustedText(self, text):
if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH: if w < self.BOX_WIDTH - 25 - FlatButtonGraphicItem.WIDTH:
return text return text


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


Expand Down

0 comments on commit 34032d6

Please sign in to comment.