-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
properly get layer from a QgsProcessingFeatureSourceDefinition #41457
properly get layer from a QgsProcessingFeatureSourceDefinition #41457
Conversation
I'm -1 to this approach -- a feature source isn't the same thing as a vector layer, and we run into risks of api abuse if we allow users to treat them as the same. I think a better approach would be to create a new QgsProcessingParameters::parameterAsQgsFields method which can take a parameter definition and value and return the corresponding QgsFields associated with the value. So if the parameter definition is a QgsProcessingParameterVectorLayer then it gets the layer's fields, but if the definition is a feature source definition then it evaluates the source and gets the fields from the QgsProcessingFeatureSource instead. That would give you a means of retrieving the fields for the parent parameter, and you could use them in the widget wrapper to update the widget accordingly. |
@nyalldawson I understand your point. I should have been more complete on the issue description. The issue is because of the QgsMapLayerComboBox::value methods which returns a QgsProcessingFeatureSourceDefinition when the only selected feature is checked. I changed my PR to fix
I need the layer object and not just the fields, so the expression builder could have the layer specific variable (layer_id, layer_name...) |
Ok, this approach looks good, thanks! |
@troopa81 Did this change the 'source' behavior in Q3.16.6? This was working before in pyqgis: and is now throwing 'Could not load source layer' when passed to processing.run |
I'm pretty sure your issue is not related to this PR because it doesn't change the QgsProcessingFeatureSourceDefinition behavior, only the way |
Fixes #40055 : Complete the
QgsProcessingParameters::parameterAsLayer
method to deal with QgsProcessingFeatureSourceDefinition