Skip to content

Commit

Permalink
[processing] hide 'select file' button for vector layers when there a…
Browse files Browse the repository at this point in the history
…re dependent params

fixes #21055
  • Loading branch information
volaya committed Jan 23, 2019
1 parent af2501e commit f204452
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand All @@ -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):
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

2 comments on commit f204452

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.