Skip to content
Permalink
Browse files

Revert "[processing] hide 'select file' button for vector layers when…

… there are dependent params"

This reverts commit f204452.

It's a contentious fix, which needs discussion
  • Loading branch information
nyalldawson committed Jan 23, 2019
1 parent bdf77ac commit db3b9aeb6b374fcbf0994126b177fdcf6651f6f1
Showing with 18 additions and 31 deletions.
  1. +18 −31 python/plugins/processing/gui/wrappers.py
@@ -846,11 +846,6 @@ 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]'
@@ -863,12 +858,12 @@ def createWidget(self):
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(6)
self.combo = QgsMapLayerComboBox()
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)
layout.addWidget(self.combo)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)

widget.setLayout(layout)
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
@@ -918,9 +913,6 @@ 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],
@@ -1105,12 +1097,12 @@ def createWidget(self):
self.combo = QgsMapLayerComboBox()
layout.addWidget(self.combo)
layout.setAlignment(self.combo, 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)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)
layout.setAlignment(btn, Qt.AlignTop)

vl = QVBoxLayout()
vl.setMargin(0)
@@ -1141,6 +1133,7 @@ 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

@@ -1187,9 +1180,6 @@ 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)
@@ -1448,11 +1438,11 @@ def createWidget(self):
layout.setSpacing(6)
self.combo = QgsMapLayerComboBox()
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)
btn = QToolButton()
btn.setText('…')
btn.setToolTip(self.tr("Select file"))
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)

widget.setLayout(layout)

@@ -1517,9 +1507,6 @@ 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:

5 comments on commit db3b9ae

@volaya

This comment has been minimized.

Copy link
Contributor

@volaya volaya replied Jan 23, 2019

Hey Nyall, can you explain why you reverted this? This just brings back the way it was in 2.X

There are other ways to fix this issue (as i wrote in the tracker), but I guess the best thing to do at the moment is just go to the old way of having that.

Thanks!

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Jan 23, 2019

@volaya did you read my comment in the tracker from a couple of days ago? This already works as intended using your 2) method from the ticket.

@volaya

This comment has been minimized.

Copy link
Contributor

@volaya volaya replied Jan 23, 2019

mmm, right...I am seeing it works now. This is what happened to me: I was trying to use the "points from table" algorithm, and selected a csv file as table file. I guess it cannot load that file, and it was not populating anything.

It's ok with you if I add some sort of warning for that case? So if the selected file cannot be loaded in the background, the user knows that he might have selected something invalid

Thanks!

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Jan 23, 2019

It's ok with you if I add some sort of warning for that case? So if the selected file cannot be loaded in the background, the user knows that he might have selected something invalid

Sounds reasonable! Can you do it via a PR?

@volaya

This comment has been minimized.

Copy link
Contributor

@volaya volaya replied Jan 23, 2019

sure! Will put you as reviewer. Thanks!

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