-
-
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
Remove expression evaluation in layout legend widget #56372
Conversation
@elpaso I did not take the time to answer your review, sorry. So I just rebased on master, and I can't reopen #53631.
No, it's only for the layout, and specifically with atlas enabled.
I did not, because it appeared to be too custom here (and I chose the "minimal" effort way, when I realized that a big refactoring would be the right approach...). |
python/PyQt6/core/auto_generated/layertree/qgslayertreemodellegendnode.sip.in
Show resolved
Hide resolved
@elpaso Seems ok to you? |
Unrelated check error |
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.
LGTM
Thanks @elpaso 👍🏼 😃 |
Still unrelated test failure |
bb56f25
to
fcaad72
Compare
I did a light rebase to categorize the changes, to avoid having too many commits. |
Again, unrelated test error
|
Re-opening of #53631 for bugfix session.
Description
This PR comes from trying to fix #53442.
I jumped into parts of code that are very strange.
The evaluation of expressions for the
QgsLayoutLegendItem
in the composer, vs the evaluation of expressions in theQTreeView
in the composer legend widget are somewhat correlated but not completely...I will explain my observations, and why I suggest the changes in this PR.
User observations
The layout item always evaluates the legend label, expression or not being present (in
QgsLayerTreeModelLegendNode::draw
)The legend tree view does not always evaluate the legend labels
![image](https://private-user-images.githubusercontent.com/34267385/249464316-76d45747-a67a-4dff-8327-c6b6dc7246ec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4OTkyNTksIm5iZiI6MTcyMDg5ODk1OSwicGF0aCI6Ii8zNDI2NzM4NS8yNDk0NjQzMTYtNzZkNDU3NDctYTY3YS00ZGZmLTgzMjctYzZiNmRjNzI0NmVjLnBuZz9Y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mQ5MTVhYWEyNjdjYmM1MDcyMjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wkR4ZUG5MgEnpkwpI88FRlesQz6rZpWKsP4afLpYoaI)
![image](https://private-user-images.githubusercontent.com/34267385/249466752-7c289170-b590-4ef2-ac44-dff724ac7602.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4OTkyNTksIm5iZiI6MTcyMDg5ODk1OSwicGF0aCI6Ii8zNDI2NzM4NS8yNDk0NjY3NTItN2MyODkxNzAtYjU5MC00ZWYyLWFjNDQtZGZmNzI0YWM3NjAyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEzVDE5MjkxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUyMzg2MDcxM2U0ZTBiNWU5MDU1ZDU1ODlhZDNhZDA4YzRlMzlkMjBjMzYwMjUyMzI1NGJmYzM3MGJlZDJhOGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DjfUBBdFIgVSfyi97sfdnArMvyaHbSR8sBZYf9YgDJY)
The legend tree view does not evaluate expressions when refreshing the layout (
) or when moving to the next atlas page (except if the filtering for items - in linked map or atlas - is enabled)
Technical observations
Technically, what is very strange, is that the label evaluation occurs in the
getData
method of the legend model.That means that the model is changed inside a method that should not change the model (and the model is not aware of this change).
Also, the legend layout item evaluates the label of the model, whereas the legend tree view evaluates the
UserLabel
(edit role) to change and update the model label...The way it is implemented is also strange (evaluating children symbols nodes but not layer nodes, only if the layer node has an expression... !).
After a lot of time digging into the code, trying to update the labels at the right place/moment, I ended with this conclusion:
the expression evaluation is very situational (symbol expressions that can be added for every child, atlas page number, layer feature-count enabled, user-defined variables, filters, etc.) and should not be part of the model. It is a representation, by definition, the real data being the raw expression. Furthermore, the expressions are today evaluated at different places with possibly different contexts (for the legend layout item and for the legend tree view).
Suggested changes
I think that the model should contain the label, with the textual expression (not evaluated), and that it is the responsibility of the view to evaluate the expression, like it is done with the legend layout item.
As a result, in this PR I removed the label evaluation taking place in the
getData
method of the model.The proposition is to always see the expressions in the legend tree view, and leave the layout legend item be the only one evaluating the label.
It is technically easier because evaluating the label in every situation is difficult to handle (with expressions being able to be in the layer style label, in the legend node widget, with the entity count, atlas page, etc.), so having the "total" expression, not evaluated, in the model label makes sense, and it is evaluated at the very end, for the rendering.
From a user point of view it can be argued that it is also more convenient to see his expression in the legend tree widget, and the evaluation on his composer page.