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

Handle conditional visibility of data defined size legend nodes #57461

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

uclaros
Copy link
Contributor

@uclaros uclaros commented May 16, 2024

Description

This PR Fixes #50301

The solution is a little hacky.

Would it make more sense to have QgsDataDefinedSizeLegendNode class also handle the rendering of the data defined size label and also individual classes, instead of having separate QgsSymbolLegendNodes for them?

@github-actions github-actions bot added this to the 3.38.0 milestone May 16, 2024
Copy link

github-actions bot commented May 16, 2024

🪟 Windows builds ready!

Windows builds of this PR are available for testing here. Debug symbols for this build are available here.

(Built from commit cb491ea)

@nyalldawson nyalldawson added the Freeze Exempt Feature Freeze exemption granted label May 17, 2024
@uclaros uclaros added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label May 20, 2024
Copy link

Tests failed for Qt 6

One or more tests failed using the build from commit 108aa23

legend_data_defined_size_separated (testDataDefinedSizeSeparated)

legend_data_defined_size_separated

Test failed at _verifyImage at tests/src/core/testqgslegendrenderer.cpp:225

Rendered image did not match tests/testdata/control_images/legend/expected_legend_data_defined_size_separated/expected_legend_data_defined_size_separated.png (found 3540 pixels different)

legend_data_defined_size_filter_by_map (testDataDefinedSizeCollapsedFilterByMap)

legend_data_defined_size_filter_by_map

Test failed at _verifyImage at tests/src/core/testqgslegendrenderer.cpp:225

Rendered image did not match tests/testdata/control_images/legend/expected_legend_data_defined_size_filter_by_map/expected_legend_data_defined_size_filter_by_map.png (found 347 pixels different)

legend_data_defined_size_filter_by_map (testDataDefinedSizeSeparatedFilterByMap)

legend_data_defined_size_filter_by_map

Test failed at _verifyImage at tests/src/core/testqgslegendrenderer.cpp:225

Rendered image did not match tests/testdata/control_images/legend/expected_legend_data_defined_size_filter_by_map/expected_legend_data_defined_size_filter_by_map.png (found 347 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.

@uclaros uclaros marked this pull request as ready for review May 21, 2024 13:13
@@ -126,7 +126,8 @@ QgsLegendSymbolList QgsDataDefinedSizeLegend::legendSymbolList() const
QgsLegendSymbolList lst;
if ( !mTitleLabel.isEmpty() )
{
QgsLegendSymbolItem title( nullptr, mTitleLabel, QString() );
// we're abusing the ruleKey field here so we can later identify the resulting legend nodes as data defined size related
QgsLegendSymbolItem title( nullptr, mTitleLabel, QStringLiteral( "data-defined-size" ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the abuse, how about we add a QMap< int, QVariant > userData to QgsLegendSymbolItem, and adapt QgsSymbolLegendNode::data to return those values for unknown roles.

Copy link
Contributor Author

@uclaros uclaros May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a new role in QgsLayerTreeModelLegendNode::CustomRole for that, instead of handling all unknown roles.
But, why a QMap< int, QVariant >? What would you store there (in this case and/or in future uses of it)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a new role in QgsLayerTreeModelLegendNode::CustomRole for that, instead of handling all unknown roles.

That also works. I was just thinking ahead if allowing custom roles in QgsLegendSymbolItem would also be useful in future.

But, why a QMap< int, QVariant >? What would you store there (in this case and/or in future uses of it)?

The int keys would correspond to a role from QgsLayerTreeModelLegendNode (either public or private). I'd find a QMap approach slightly preferable to having separate members for every property we decide to add in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Freeze Exempt Feature Freeze exemption granted
Projects
None yet
2 participants