Skip to content
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

Add setSubsetString into layerutils #5908

Closed
wants to merge 1 commit into from

Conversation

woutergd
Copy link
Contributor

For a plugin in QField we are creating, we want to apply a filter dynamically to a layer. We were however unable to access the setSubsetString method on a vectorlayer from the qml files, so hereby a PR which add this method to the LayerUtils so it becomes accessible through plugins.

@woutergd woutergd marked this pull request as ready for review December 23, 2024 08:14
@woutergd woutergd force-pushed the features/layerutils branch from 7e55490 to 1ea9c4a Compare December 23, 2024 08:18
@nirvn
Copy link
Member

nirvn commented Dec 23, 2024

@woutergd , greatings -- actually , the setSubsetString function is exposed through a Q_PROPERTY on the vector layer (which is more QMLesque :) ). To retrieve or set the current subset string, you'd go through the property.

E.g. to get the current subset string:

let layer = qgisProject.mapLayersByName('my_vector_layer')[0]
console.log(layer.subsetString)

To set a subset string, simply do:

let layer = qgisProject.mapLayersByName('my_vector_layer')[0]
layer.subsetString = '"TYPE" = 1'

Voila :)

That said, thanks for opening a pull request with new code, while this specific PR isn't going to be merged, I certainly hope this will not be the last time we see you guys around :)

Out of curiosity, what functionalities are you adding through your plugin?

@woutergd
Copy link
Contributor Author

@nirvn Thanks for the feedback, you are right. We tried it in (almost) that way, but probably used just setSubstring instead of the subsetString method, which caused errors in our plugin. We checked both the C++ docs and Python docs of QGIS and both mentioned setSubstring so that caused the confusion. Are there any resources online that have documented the syntax you mention?

About the plugin: I can't disclose that publicly at the moment, but if you sent me a direct mail I am happy to share it with you.

@woutergd woutergd closed this Dec 23, 2024
@woutergd woutergd deleted the features/layerutils branch December 23, 2024 08:47
@nirvn
Copy link
Member

nirvn commented Dec 23, 2024

@woutergd , if you check the QGIS API documentation , you'll notice each class can feature a Properties section which lists all available Q_PROPERTY within a given class flagged as Q_OBJECT or Q_GADGET.

E.g., the QgsVectorLayer's subsetString : https://api.qgis.org/api/classQgsVectorLayer.html#a82752c93ea29f4789e2973ef2090b9e7

You can also spot invokable functions by looking for the Q_INKABLE tag next to individual functions (not great, but better than nothing).

I'm always delighted to hear about plugin use cases, you can reach out via [email protected] (since I do not have your email at hand :) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants