Skip to content
Permalink
Browse files

[processing] hide 'select file' button for vector layers when there a…

…re dependent params

fixes #21055
  • Loading branch information
volaya committed Jan 23, 2019
1 parent af2501e commit f2044528951bbb09a70b9c696d79d8cd5b756214
Showing with 31 additions and 18 deletions.
  1. +31 −18 python/plugins/processing/gui/wrappers.py
@@ -846,6 +846,11 @@ def setValue(self, value):
def value(self):
return self.widget.getValue()

def hasDependencies(wrappers, name):
for wrapper in wrappers:
if (hasattr(wrapper.parameterDefinition(), "parentLayerParameterName") and
wrapper.parameterDefinition().parentLayerParameterName() == name):
return True

class MapLayerWidgetWrapper(WidgetWrapper):
NOT_SELECTED = '[Not selected]'
@@ -858,12 +863,12 @@ def createWidget(self):
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(6)
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
layout.addWidget(self.combo)
self.btn = QToolButton()
self.btn.setText('…')
self.btn.setToolTip(self.tr("Select file"))
self.btn.clicked.connect(self.selectFile)
layout.addWidget(self.btn)

widget.setLayout(layout)
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
@@ -913,6 +918,9 @@ def createWidget(self):
def setComboBoxFilters(self, combo):
pass

def postInitialize(self, wrappers):
self.btn.setVisible(not hasDependencies(wrappers, self.parameterDefinition().name()))

def getAvailableLayers(self):
return self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterRasterLayer, QgsProcessingParameterMeshLayer, QgsProcessingParameterVectorLayer, QgsProcessingParameterMapLayer, QgsProcessingParameterString],
@@ -1097,12 +1105,12 @@ def createWidget(self):
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
layout.setAlignment(self.combo, Qt.AlignTop)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
layout.setAlignment(btn, Qt.AlignTop)
self.btn = QToolButton()
self.btn.setText('…')
self.btn.setToolTip(self.tr("Select file"))
self.btn.clicked.connect(self.selectFile)
layout.addWidget(self.btn)
layout.setAlignment(self.btn, Qt.AlignTop)

vl = QVBoxLayout()
vl.setMargin(0)
@@ -1133,7 +1141,6 @@ def createWidget(self):
if iface.activeLayer().type() == QgsMapLayer.VectorLayer:
self.combo.setLayer(iface.activeLayer())
self.use_selection_checkbox.setEnabled(iface.activeLayer().selectedFeatureCount() > 0)

except:
pass

@@ -1180,6 +1187,9 @@ def createWidget(self):
widget.setLayout(layout)
return widget

def postInitialize(self, wrappers):
self.btn.setVisible(not hasDependencies(wrappers, self.parameterDefinition().name()))

def layerChanged(self, layer):
if layer is None or layer.type() != QgsMapLayer.VectorLayer or layer.selectedFeatureCount() == 0:
self.use_selection_checkbox.setChecked(False)
@@ -1438,11 +1448,11 @@ def createWidget(self):
layout.setSpacing(6)
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
self.btn = QToolButton()
self.btn.setText('…')
self.btn.setToolTip(self.tr("Select file"))
self.btn.clicked.connect(self.selectFile)
layout.addWidget(self.btn)

widget.setLayout(layout)

@@ -1507,6 +1517,9 @@ def createWidget(self):
widget.setLayout(layout)
return widget

def postInitialize(self, wrappers):
self.btn.setVisible(not hasDependencies(wrappers, self.parameterDefinition().name()))

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:

2 comments on commit f204452

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jan 23, 2019

Hey, I don't think this is correct. See the comment on the ticket

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jan 23, 2019

@volaya I've reverted in db3b9ae -- can you open a PR for this fix for discussion? It breaks existing functionality

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