Add legend labels to layer attributes (QGIS plugin)

GitHub | QGIS Plugins Repository
The problem
When styling layers in QGIS, users often assign meaningful, human-readable descriptions to categorized or rule-based styles. For example:
- A graduated style for population density, where each value range has a descriptive label.
- A rule-based style for highways, where rules define categories such as "primary," "secondary," or "cycleway."

However, QGIS lacks a built-in tool to transfer these legend descriptions into attribute fields. If you later need these labels for analysis or further processing, there’s no simple way to add them to your data.

The plugin
Add Legend Labels to Layer Attributes is a simple QGIS plugin that adds a tool to the Processing Toolbox. It allows you to:
- Select an input layer.
- Define the new attribute field name.
- Automatically extract legend labels from the layer’s style and assign them as attribute values for each feature.

This is especially useful if you've already spent time defining legend descriptions and later realize you need them as attribute values.

Supported Renderers
- Rule-based renderer (any complexity).
- Graduated renderer (based on a single attribute).
- Categorized renderer (based on a single attribute).
If your graduated or categorized renderer uses complex expressions, you can easily switch to a rule-based renderer — QGIS will convert everything automatically, and the plugin will work as expected.
If you found a bug, have questions or suggestions, please contact me, I would be glad to improve the Plugin.