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

Allow more Expression scopes in virtual Layer SQL #35867

Open
cxcandid opened this issue Apr 20, 2020 · 6 comments
Open

Allow more Expression scopes in virtual Layer SQL #35867

cxcandid opened this issue Apr 20, 2020 · 6 comments
Labels
Data Provider Related to specific vector, raster or mesh data providers Feature Request

Comments

@cxcandid
Copy link

cxcandid commented Apr 20, 2020

I figured out, that I can use global and project variables in virtual layers:
SELECT var('qgis_version') as qgis,var('project_basename') as project

It's also documented that we can speed up our queries when using the hidden column
_search_frame_.

But what I really would like to do is: SELECT ... WHERE _search_frame_ = var(map_extent) which is not possible yet, because - I guess - the variable scope "MapSetting" is not supported.
Maybe that's an oversight, because inside layer labels I can use i.e. geom_to_wkt( @map_extent ) .

It's possible to write a custom Expression function as workaround:

@qgsfunction(args='auto', group='Custom')
def currentExtent(feature, parent):
    return QgsGeometry.fromRect(iface.mapCanvas().extent())

SELECT ... WHERE _search_frame_ = currentExtent()

but this only uses the map canvas extents and not the extents of a layout map window.

@cxcandid
Copy link
Author

cxcandid commented Apr 21, 2020

Maybe @mhugo could add MapSettingsScope to the available Expression scopes:

src/providers/virtual/qgsvirtuallayersqlitemodule.cpp

900  // initialize the expression context
901  qgisFunctionExpressionContext << QgsExpressionContextUtils::globalScope();
902  qgisFunctionExpressionContext << QgsExpressionContextUtils::projectScope( QgsProject::instance() );
>>903  qgisFunctionExpressionContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings::instance() );

@cxcandid
Copy link
Author

Ok, I guess it's not that easy. It has to do with mapSettingsScope, but honestly I don't know how.
If we can use i.e. var('map_extent') in QGIS label strings, showing the right values in canvas and layout map windows, it should be possible to use it in virtual Layer SQL as well... I'm only thinking loud.

@mhugo
Copy link

mhugo commented Apr 28, 2020

@cxcandid Thanks for your proposal. That would be indeed a nice addition to SQL layers.

Ok, I guess it's not that easy. It has to do with mapSettingsScope, but honestly I don't know how.

Did you try that modification you proposed ?

@cxcandid
Copy link
Author

@mhugo No unfortunately not, and I guess it doesn't work, because IMHO mapSettingsScope needs the settings of the layout map. And btw. I have absolutely no C++ knowledge.

Maybe you find the answer in the code for parsing Expression functions in label strings?

@nyalldawson
Copy link
Collaborator

It won't be possible to add the map settings scope for virtual layers -- virtual layers are used everywhere, and not just in situations associated with any particular map. The proposed patch mentions a QgsMapSettings::instance() object which just doesn't exist (and cannot POSSIBLY exist!)

@cxcandid
Copy link
Author

@nyalldawson Thanks for clarification. Totally forgot about the processing tool.

@alexbruy alexbruy added the Data Provider Related to specific vector, raster or mesh data providers label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Data Provider Related to specific vector, raster or mesh data providers Feature Request
Projects
None yet
Development

No branches or pull requests

4 participants