-
-
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
[feature] Add extra mesh layer legend node for currently displayed vector datasets. #55746
[feature] Add extra mesh layer legend node for currently displayed vector datasets. #55746
Conversation
Tests failed for Qt 5One or more tests failed using the build from commit 955168f legend_diagram_attributes (testDiagramAttributeLegend)legend_diagram_attributesTest failed at _verifyImage at tests/src/core/testqgslegendrenderer.cpp:220 Rendered image did not match tests/testdata/control_images/legend/expected_legend_diagram_attributes/expected_legend_diagram_attributes.png (found 172 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. |
Tests failed for Qt 6One or more tests failed using the build from commit 236e729 legend_mesh_diagram_no_vector (testDiagramMeshLegend)legend_mesh_diagram_no_vectorTest failed at _verifyImage at tests/src/core/testqgslegendrenderer.cpp:167 Rendered image did not match tests/testdata/control_images/legend/expected_legend_mesh_diagram_no_vector/expected_legend_mesh_diagram_no_vector.png (found 697 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. |
@nstrahl Thanks for the PR! Can you make sure the code formatting is according to the QGIS coding standards? There's a script named |
@uclaros Thanks for the reply! I'm on it. I switched over to linux now, but out of curiosity how can the code be formated on Windows? I only see .sh scripts for this. |
Hmm, not sure about that, sorry, but I'd guess either using cygwin on wsl |
if ( layerType == Qgis::LayerType::Mesh ) | ||
{ | ||
QHash<QString, QgsLayerTreeModelLegendNode *> rule2node; | ||
rule2node[QString()] = nullptr; | ||
for ( QgsLayerTreeModelLegendNode *n : nodes ) | ||
{ | ||
QString key = n->objectName(); | ||
if ( key.isEmpty() ) // in tree all nodes must have key | ||
return nullptr; | ||
if ( rule2node.contains( key ) ) // and they must be unique | ||
return nullptr; | ||
rule2node[key] = n; | ||
} | ||
|
||
LayerLegendTree *tree = new LayerLegendTree; | ||
for ( QgsLayerTreeModelLegendNode *n : nodes ) | ||
{ | ||
const QString parentName = n->property( "parentNode" ).toString(); | ||
QgsLayerTreeModelLegendNode *parent = rule2node.value( parentName, nullptr ); | ||
tree->parents[n] = parent; | ||
tree->children[parent] << n; | ||
} | ||
return tree; | ||
} | ||
|
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.
Duplicating this code for mesh layers and relying on custom properties feels a little hacky...
I would suggest to leave this class as is and re-use existing infrastructure for tree-like legend items.
I think you should populate QgsLayerTreeModelLegendNode::RuleKeyRole
for the QgsSimpleLegendNode
s and QgsLayerTreeModelLegendNode::ParentRuleKeyRole
for the QgsRasterSymbolLegendNode
s and QgsColorRampLegendNode
s (you'll have to update their data
/setData
methods as they do not support it now) and the tree should populate itself!
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.
Thanks for the advice. I'll be pushing my commit in a bit. Btw, the KeyRoles are encapsulated in the classes and only settable upon construction and retrievable via the data method, so I stuck to those restrictions.
@@ -143,25 +143,24 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings &setting | |||
|
|||
if ( ctx && ctx->painter ) | |||
{ | |||
const QgsScopedRenderContextScaleToPixels scopedScaleToPixels( *( ctx->context ) ); | |||
const double scaleFactor = ctx->context->scaleFactor(); |
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.
Why do we need to multiply by the scale factor here? Won't this affect other symbols too?
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.
Up to this point the nodes of this type have only been assigned a simple QIcon (square solid color rectangle). Under those circumstances it does not really matter if a scale factor is applied. (A square solid color rectangle more or less remains a square solid color rectangle regardless of scaling). But if a more complex QIcon is assigned (e.g. arrow) without scaling then there will be unwanted distortion/pixelation. If you look at the new /expected_legend_diagram_attributes/expected_legend_diagram_attributes_mask.png I uploaded, you will find that the icons are now slightly more rectangular because proper scaling is applied. I am guessing no one else ever bothered to do so because it was never really noticeable.
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.
Watch out, ctx->context
may be nullptr here. You'll need to check that and handle gracefully.
* \param key rule key | ||
* \param parentKey parent rule key |
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.
* \param key rule key | |
* \param parentKey parent rule key | |
* \param key rule key (since QGIS 3.36) | |
* \param parentKey parent rule key (since QGIS 3.36) |
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.
Also would be better to add some explanatory docs here, eg for when parent rule key should be set.
* \param key rule key | ||
* \param parentKey parent rule key |
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.
* \param key rule key | |
* \param parentKey parent rule key | |
* \param key rule key (since QGIS 3.36) | |
* \param parentKey parent rule key (since QGIS 3.36) |
@@ -677,8 +677,10 @@ class CORE_EXPORT QgsRasterSymbolLegendNode : public QgsLayerTreeModelLegendNode | |||
* \param parent attach a parent QObject to the legend node. | |||
* \param isCheckable set to TRUE to enable the checkbox for the node (since QGIS 3.18) | |||
* \param ruleKey optional identifier to allow a unique ID to be assigned to the node by a renderer (since QGIS 3.18) | |||
* \param parentRuleKey rule key of parent |
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.
* \param parentRuleKey rule key of parent | |
* \param parentRuleKey rule key of parent (since QGIS 3.36) |
Also add explanation of when this should be set
src/core/qgsapplication.cpp
Outdated
if ( QDir dir = QFileInfo( iconPath ).dir(); !dir.exists() ) | ||
{ | ||
dir.mkpath( "." ); | ||
} |
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.
Can you pull this out to a separate pull request? Its unrelated to the legend changes.
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.
Pull request #56171 has now been submitted. It will have to be accepted first so I can then rebase this branch and continue working on this pull request.
@@ -143,25 +143,24 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings &setting | |||
|
|||
if ( ctx && ctx->painter ) | |||
{ | |||
const QgsScopedRenderContextScaleToPixels scopedScaleToPixels( *( ctx->context ) ); | |||
const double scaleFactor = ctx->context->scaleFactor(); |
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.
Watch out, ctx->context
may be nullptr here. You'll need to check that and handle gracefully.
Can you also add some tests covering these changes? |
bce1abc
to
3705bc1
Compare
My test fails on Qt6 when comparing the expected vs. generated .png image, but it succeeds on Qt5. Can someone give me some tips? I saw that I don't have an image mask for the expected .png files so I was thinking maybe I should also add a mask. Would this solve my problem? |
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
|
@uclaros Is there anything missing on this PR? |
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.
The difference in the test results is quite significant. Is that caused by the introduction of the scaleFactor
?
Maybe it makes more sense to update the control images instead of the mask?
:param key: rule key. optional identifier to allow a unique ID to be assigned to the node by a renderer (since QGIS 3.36) | ||
:param parentKey: rule key of parent (since QGIS 3.36) |
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.
All since mentions should now be changed to QGIS 3.38
The differences in For the brand new tests added in tests |
… they pass for qt6 builds as well
a0dd696
to
236e729
Compare
@uclaros @nyalldawson this PR is now probably ready to be merged in. |
[feature] Fixes #55745 feature request.
Mesh layer legend on the layer tree are now shown as two collapsible sub-items. One for contours, another one for vector display.
For single-color Vector rendering configuration, the arrow icon is simply re-colored in the legend (e.g. green)
This now allows for the items to be shown (and modified) in a print layout.
right-hand-side symbol display was also checked and is working: