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 authored 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 Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 3 additions & 9 deletions python/plugins/processing/algs/qgis/Rasterize.py
Original file line number 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 qgis.PyQt.QtGui import QImage, QPainter
Expand All @@ -34,10 +32,8 @@
QgsProcessingParameterExtent,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterMapLayer,
QgsProcessingParameterRasterDestination,
QgsMessageLog,
QgsRasterFileWriter
)

Expand Down Expand Up @@ -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 '
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchInputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchOutputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ConfigDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 43 additions & 20 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
QgsProcessingParameterBand,
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -626,7 +627,7 @@ def value(self):
return self.widget.getValue()


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

NOT_SELECTED = '[Not selected]'

Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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]'
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/ModelerGraphicItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 34032d6

Please sign in to comment.