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.35k stars 2.98k forks source link

Layout Legend Not Syncing with Atlas in QGIS 3.34 LTR and 3.38 Using PyQGIS #58496

Open gianvav opened 2 weeks ago

gianvav commented 2 weeks ago

What is the bug or the crash?

I've encountered an issue when using PyQGIS where the layout legend does not sync correctly with the atlas when iterating through the features using the QGIS Layout Atlas in version 3.34 LTR and the latest 3.38 release. The same procedure works flawlessly in QGIS 3.28.12.

Steps to reproduce the issue

  1. Create a print layout with an atlas enabled using PyQGIS.
  2. Set up a custom legend linked to the atlas map through PyQGIS scripting.
  3. Apply an atlas filter with the expression is_selected() to focus on selected features.
  4. Iterate through the atlas features using PyQGIS to generate output PDFs or images.
  5. Observe the legend; it does not update to reflect the current atlas feature.

Versions

Versione di QGIS 3.38.2-Grenoble Revisione codice QGIS 130c432394 Versione Qt 5.15.13 Versione Python 3.12.5 Versione GDAL/OGR 3.9.2 Versione PROJ 9.4.0 Versione database del Registro EPSG v11.004 (2024-02-24) Versione GEOS 3.12.2-CAPI-1.18.2 Versione SQLite 3.45.1 Versione PDAL 2.6.3 Versione client PostgreSQL 16.2 Versione SpatiaLite 5.1.0 Versione QWT 6.2.0 Versione QScintilla2 2.14.1 Versione SO Windows 11 Version 2009

Plugins Python attivi DigitizingTools 1.5.2 Hqgis 1.2.3 MemoryLayerSaver 5.0.2 pluginbuilder3 3.2.1 plugin_reloader 0.10 profiletool 4.2.6 quick_map_services 0.19.34 rectanglify 1.0.3 sit_plugin 0.1 StreetView 3.2 utility_tools 0.1 VectorBender 0.2.1 ViewshedAnalysis 1.9 web2qgis 0.2.0 db_manager 0.1.20 processing 2.12.99 lizmap 4.3.21

Versione di QGIS 3.34.10-Prizren Revisione codice QGIS 113de9e1 Versione Qt 5.15.13 Versione Python 3.12.5 Versione GDAL/OGR 3.9.2 Versione PROJ 9.4.0 Versione database del Registro EPSG v11.004 (2024-02-24) Versione GEOS 3.12.2-CAPI-1.18.2 Versione SQLite 3.45.1 Versione PDAL 2.6.3 Versione client PostgreSQL 16.2 Versione SpatiaLite 5.1.0 Versione QWT 6.2.0 Versione QScintilla2 2.14.1 Versione SO Windows 11 Version 2009

Plugins Python attivi DigitizingTools 1.5.2 lizmap 4.3.21 MemoryLayerSaver 5.0.2 pluginbuilder3 3.2.1 plugin_reloader 0.10 profiletool 4.2.6 quick_map_services 0.19.34 rectanglify 1.0.3 sit_plugin 0.1 StreetView 3.2 utility_tools 0.1 VectorBender 0.2.1 ViewshedAnalysis 1.9 web2qgis 0.2.0 db_manager 0.1.20 otbprovider 2.12.99 processing 2.12.99 Hqgis 1.2.3

Versione di QGIS 3.28.12-Firenze Revisione codice QGIS dcc633b2de Versione Qt 5.15.3 Versione Python 3.9.5 Versione GDAL/OGR 3.7.2 Versione PROJ 9.3.0 Versione database del Registro EPSG v10.094 (2023-08-08) Versione GEOS 3.12.0-CAPI-1.18.0 Versione SQLite 3.41.1 Versione PDAL 2.5.5 Versione client PostgreSQL unknown Versione SpatiaLite 5.1.0 Versione QWT 6.1.6 Versione QScintilla2 2.13.4 Versione SO Windows 10 Version 2009

Plugins Python attivi DigitizingTools 1.5.2 Hqgis 1.2.3 lizmap 4.3.21 MemoryLayerSaver 5.0.2 pluginbuilder3 3.2.1 plugin_reloader 0.10 profiletool 4.2.6 quick_map_services 0.19.34 rectanglify 1.0.3 sit_plugin 0.1 StreetView 3.2 utility_tools 0.1 VectorBender 0.2.1 ViewshedAnalysis 1.9 web2qgis 0.2.0 db_manager 0.1.20 otbprovider 2.12.99 processing 2.12.99 sagaprovider 2.12.99

Supported QGIS version

New profile

Additional context

Expected Behavior: The legend should update to reflect the visible layers and features in the current atlas page as it did in QGIS 3.28.12.

Actual Behavior: In QGIS 3.34 LTR and 3.38, when using PyQGIS, the legend does not update according to the current atlas feature. This issue breaks the expected workflow when generating atlas outputs with custom legends via scripting.

agiudiceandrea commented 2 weeks ago

@gianvav thanks for reporting. It would be useful if you provided a minimal project / layer(s) / script and exact steps in order to replicate the issue.

gianvav commented 2 weeks ago

@agiudiceandrea thanks to you for the interest. I have provided a smaller project (in gpkg) and a minimal script for reproducing the issue.

You have to change the script in line 22 setting the dir of the py script. LegendLayout_issue.zip

The script should work without opening the layout in 3.28.12 (tested) but not in 3.34 or 3.38 (tested - not working).

Thanks.

weca-theo commented 1 week ago

Is this issue limited to pyQGIS only? Or does setting up Atlas using the UI also have this issue?

gianvav commented 1 week ago

it is limited to pyQGIS. Setting up the atlas in the layout ui works