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

Colors are tied to the displayed layer/group labels, not to the individual layers/groups [with fix] #2

Open
Alex-Kent opened this issue Mar 7, 2025 · 0 comments · May be fixed by #3

Comments

@Alex-Kent
Copy link

Alex-Kent commented Mar 7, 2025

Currently the color used for a layer/group layer is determined by its name as displayed in the layers tree. If a layer is renamed (e.g. by the user or by selecting "Show Feature Count") then the custom background color is no longer shown. In addition, multiple layers with the same name cannot currently have different colors assigned.


Proposed fix

If the color to be used is retrieved from the layer's highlight_color custom property (instead of from the layer_colors array with the displayed name as the key) then the color will persist if the layer is renamed.

I have written and tested code to do this (I'll submit a pull request shortly [edit: It's linked below]).

Comments

  • An additional benefit to my fix is that layers with the same displayed name can be assigned different colors.

  • One issue is that the color assigned to a layer is no longer automatically applied to all layers with the same displayed name. This could be remedied by adding options to apply the selected groups/layers color to some or all layers/groups that have the same name as the selected layers/groups. [This is something that I'm willing to code.] I can go into detail on this separately.

    Alternatively [and if implemented I think that it should be a user-selectable option] the current behavior could be emulated using the actual layer name (as opposed to the displayed name which may e.g. have a feature count appended) as the array key; this has its own set of issues that I have not fully explored (e.g. if a layer is manually renamed then the extant color should be carried over [but what if the new name already has a color assigned?]).

  • The selected color will be carried over if a layer/group is copied and pasted. A layer's color is not preserved though if "Duplicate Layer" is used; this appears to be due to a bug in QGIS (I've opened a bug report, see "Duplicate Layer" does not copy some custom properties qgis/QGIS#60884).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant