qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.52k stars 2.99k forks source link

Map Layout composer - Legend item expression not displaying correctly #53244

Closed Hopper92 closed 1 year ago

Hopper92 commented 1 year ago

What is the bug or the crash?

When trying to set a legend item with an expression to rename to another field value the legend displays the expression rather than the target field value.

Steps to reproduce the issue

Set legend to auto update and only show items inside linked map: image

Expression for the target layer and confirmation it is valid in the preview: image

The legend in the map composer showing the expression rather than the target "unitname" value: image

Versions

QGIS version 3.30.2-'s-Hertogenbosch QGIS code revision 0992b533 Qt version 5.15.3 Python version 3.9.5 GDAL/OGR version 3.6.4 PROJ version 9.2.0 EPSG Registry database version v10.082 (2023-02-06) GEOS version 3.11.2-CAPI-1.17.2 SQLite version 3.41.1 PDAL version 2.5.2 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.1.6 QScintilla2 version 2.13.1 OS version Windows 10 Version 2009

Active Python plugins DataPlotly 4.0.1 debug_vs 0.7 enmapboxplugin 3.12.1 FreehandRasterGeoreferencer 0.8.3 geoscience 1.11 inspireatomclient 0.8.1 MagneticDeclination 2.3.1 mapswipetool_plugin 1.2 Mergin 2023.1 processing_saga_nextgen 0.0.7 ProjectPackager 0.7.2 project_report 1.2 qfieldsync v4.4.9 Qgis2threejs 2.7.1 QGISSortAndNumber-master 1.0 quick_map_services 0.19.33 SemiAutomaticClassificationPlugin 7.10.11 slyr 6.3.1 slyr_community 4.0.7 splitmultipart 1.0.0 SpreadsheetLayers 2.1.0 SRTM-Downloader 3.1.17 db_manager 0.1.20 grassprovider 2.12.99 MetaSearch 0.3.6 processing 2.12.99

Supported QGIS version

New profile

Additional context

I hope this one is an easy fix or an easy workaround is possible? Thankyou!

roya0045 commented 1 year ago

Not a bug, the problem is that the expression generator has a feature context where it shouldn't have one to reflect the legend.

Hopper92 commented 1 year ago

Not a bug, the problem is that the expression generator has a feature context where it shouldn't have one to reflect the legend.

Thankyou for the response Alex. I don't really understand though, you might have to dumb it down for me haha. Is there a way to achieve what I want without having to manually type the other field value into the legend items?

roya0045 commented 1 year ago

Depends on what you're using for the symbology. If it's only a single field you can use the collection function with the filter set to replicate the symbology rule used and pick the first element of the returned array. Though for that to work at the moment it will work in your symbol label is exactly the same value as what is used to perform the classification.