QGIS icon indicating copy to clipboard operation
QGIS copied to clipboard

Legend doesn't show totals for rule-based symbologies

Open bkepl opened this issue 3 years ago • 8 comments

When setting a layer in a legend to show totals, subtotals for categories always show up in the print composer but never in the PDF that's created from that layout (N/A is displayed for the count).

To test this further before submitting this, I created (in a map with relatively few layers) a minimal layout of a dataset of parcel centroids, then categorized by municipality, and to my surprise, the subtotals were in the PDF. I converted the symbology to rule-based, and the PDF output was still correct.

I returned to my original map and ran additional tests:

  1. I took the expressions I used for the symbology and created a virtual field, then based my symbology on the value of that field. Result for subcategories: N/A
  2. I created a new field (non-virtual) in the data and updated it to be the value of the virtual field. Result for subcategories: N/A
  3. I deleted the rule-based symbology and re-created it with categories. Result for subcategories: N/A

This has regularly been the case for me, regardless of QGIS or Windows version. The simple, stripped-down map that I used for the PDFs that correctly showed the subcategories the only map in my recent memory where this worked as expected.

QGIS version: all

OS versions: Windows 10 (kept up to date)

bkepl avatar Jul 22 '21 17:07 bkepl

@bkepl can you attach a sample project+data, thanks!

gioman avatar Jul 23 '21 09:07 gioman

Rule based symbologies can have overlap. This us why summing up things is bad and displaying a total could be confusing at it may be inferior to the sums of the child symbiology.

roya0045 avatar Jul 23 '21 14:07 roya0045

I found the issue. I spent way too much time doing it, but here it is.

1. The layout must not be tied to themes in any way. 2. Layers can be locked, but must not be locked for styles. 3. Selecting a layer to use for locking layers and then unchecking Lock layer for styles produces the error; the resolution for this is to also uncheck Lock layers (and to be sure when I tested it I closed the layout and reopened it before re-checking Lock layers).

In my mind this constitutes a real bug. Being able to base layouts on themes is a wonderful thing. (It's too bad labeling styles can't be saved with a theme the way different symbologies on a layer can be saved with a theme. Forget using layer styles; I find it cumbersome and not at all intuitive, but that's another matter.)

bkepl avatar Jul 23 '21 15:07 bkepl

Just noticed that I closed this; it was not intentional.

bkepl avatar Jul 26 '21 14:07 bkepl

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale". If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue. In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue. If there is no further activity on this issue, it will be closed in a week.

github-actions[bot] avatar Aug 10 '21 01:08 github-actions[bot]

I'm not sure what additional information I need to provide. Subtotals are shown correctly as long as I don't use a theme as the basis for a layout. If I use a theme as the basis for a layout (something I find fantastically useful), or if I choose a theme to lock layers, subtotals aren't calculated. If I lock layers without choosing a theme as a source, legends will display subtotals correctly. If I lock styles, subtotals will not display.

bkepl avatar Aug 13 '21 05:08 bkepl

This is still an issue as of 3.30.3.

bkepl avatar Jun 22 '23 21:06 bkepl

This is still an issue in 3.32.

bkepl avatar Jun 30 '23 13:06 bkepl

I guess it's related to #49295. Still an issue in 3.34.

CharlesGag avatar Jan 11 '24 20:01 CharlesGag

As it only seems to affect rule-based symbols, I made further testing. It appears that you can't use the option to add custom a custom expression to vector layers in a legend. I'm just trying to rename the label and nothing change. It does works with my simple symbol layer. So it appears that it's not only the feature count that is problematic.

image

CharlesGag avatar Jan 19 '24 13:01 CharlesGag