Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 db3b9ae
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -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]'
Expand All @@ -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):
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

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

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

5 comments on commit db3b9ae

@volaya
Copy link
Contributor

@volaya volaya commented on db3b9ae Jan 23, 2019

Choose a reason for hiding this comment

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

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@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
Copy link
Contributor

@volaya volaya commented on db3b9ae Jan 23, 2019

Choose a reason for hiding this comment

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

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

@volaya volaya commented on db3b9ae Jan 23, 2019

Choose a reason for hiding this comment

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

sure! Will put you as reviewer. Thanks!

Please sign in to comment.