-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 'legend_item_expression' variable to the Layout Legend expression scope #59276
Conversation
Simpler version, handles style difference between layout and canvas.
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
QgsMapLayerStyleOverride styleOverride( vl ); | ||
if ( modelstyles.contains( vl->id() ) ) | ||
styleOverride.setOverrideStyle( modelstyles.value( vl->id() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applying an override is a very slow operation -- is this actually required? Or just copied/pasted from elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required AFAIK, previously the implementation called the renderer directly, but if the style of a given layer in the canvas was different than in the layout ( cause by using a theme in the layout) then the expression could not be retreived by the renderer as legendKeyToExpression
could not return the value.
If you think there is another way to retraive the expression from the renderer without using the override, this would be good. Though maybe some logic could be implemented to bypass the override and only perform the operation when required.
I'll let you make the call on what could be improved and I'll rework the PR as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have expected that this was already handled prior to calling any of this code -- otherwise even the simple case of a map with a different style having different color fills would be broken.
Can you try removing this code and retest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As suggested, I removed the style override and both with local manual tests and in the test image, the lines are just NULL.
Tests failed for Qt 6One or more tests failed using the build from commit 51108eb composer_legend_theme_expression_scopecomposer_legend_theme_expression_scopeTest failed at testLegendExpressionWithStyles at tests/src/python/test_qgslayoutlegend.py:1131 Rendered image did not match tests/testdata/control_images/composer_legend/expected_composer_legend_theme_expression_scope/expected_composer_legend_theme_expression_scope.png (found 57430 pixels different) The full test report (included comparison of rendered vs expected images) can be found here. Further documentation on the QGIS test infrastructure can be found in the Developer's Guide. |
The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check
|
While we hate to see this happen, this PR has been automatically closed because it has not had any activity in the last 21 days. If this pull request should be reconsidered, please follow the guidelines in the previous comment and reopen this pull request. Or, if you have any further questions, just ask! We love to help, and if there's anything the QGIS project can do to help push this PR forward please let us know how we can assist. |
Description
This is an updated version of previous PR, not the function is directly within the scope creation and the expression can be fetched if the style of the layer is different between the canvas and the layout ( which was a limitation of the previous version).
This PR allows the user to access the expression representing a symbol rule in the Legend of a layout. Ultimately this allows the end user to perform calculation taking into acocunt the symbology in an aggregate operation.
Curerntly the only way to do such calculation is to have the label matching a single field(categorized) or single symbols, this does not work for complex symbology, which should not be the case anymore.
For instance the total area of each symbols can be displayed in the legend or any other operation with an aggregate expression,
PR aims to fix #21988 & fix #33312