Skip to content

Reference

IconService

Service for handling and generating SVG icons.

get_icon_name(request_model, imx_version) classmethod

Retrieves the icon name for a given request model and IMX version.

Parameters:

Name Type Description Default
request_model IconRequestModel

The request model containing icon path and properties.

required
imx_version ImxVersionEnum

The IMX version to match.

required

Returns:

Type Description
str

The name of the matching icon.

Raises:

Type Description
ValueError

If no icon is found for the combination of IMX path and version.

get_all_icons(imx_version, icon_type=IconTypesEnum.svg) classmethod

Retrieves all icons for a given IMX version.

Parameters:

Name Type Description Default
imx_version ImxVersionEnum

The IMX version to match.

required
icon_type IconTypesEnum | icon_types_literal

If True, a qgis svg will be returned

svg

Returns:

Type Description
dict[str, dict[str, str | dict[str, str]]]

A dictionary of icon names and their corresponding SVG content and metadata.

Raises:

Type Description
ValueError

If no icons are found for the IMX version.

get_svg(request_model, imx_version, pretty_svg=True, icon_type=IconTypesEnum.svg) classmethod

Retrieves the SVG content for a given request model and IMX version.

Parameters:

Name Type Description Default
request_model IconRequestModel

The model containing icon request details such as the IMX path and properties.

required
imx_version ImxVersionEnum

The IMX version to match for retrieving the icon.

required
pretty_svg

If True, formats the SVG content for pretty printing.

True
icon_type IconTypesEnum | icon_types_literal

If True, a qgis svg will be returned

svg

Returns:

Type Description
Any

The SVG content as a string. If pretty_svg is True, the SVG is formatted for better readability.

Raises:

Type Description
ValueError

If no icon is found for the combination of IMX path and version.

IconRequestModel

Bases: BaseModel

Model representing an icon request with a path and required properties.

Attributes:

Name Type Description
imx_path str

The file path to the IMX data for the icon.

properties dict[str, str]

A dictionary of required properties for the icon request.

optional_properties dict[str, str] | None

A dictionary of optional properties for the icon request, if any.

IconModel

Bases: BaseModel

Model representing an icon with its metadata and optional properties.

Attributes:

Name Type Description
imx_path str

The file path to the IMX data for the icon.

icon_name str

The name of the icon.

properties dict[str, str]

A dictionary of required properties for the icon.

optional_properties dict[str, str] | None

A dictionary of optional properties for the icon, if any.

IconSvgGroup dataclass

Represents a group of SVG elements within an icon.

Attributes:

Name Type Description
group_id str

A unique identifier for the SVG group.

transform str | None

A transformation string to apply to the SVG group (e.g., translation, scaling).

IconEntity dataclass

Represents an icon entity with metadata, properties, and SVG groups.

Attributes:

Name Type Description
imx_version ImxVersionEnum

The version of the IMX format this icon is based on.

imx_path str

The file path to the IMX data.

icon_name str

The name of the icon.

properties dict[str, str]

A dictionary of additional properties for the icon.

icon_groups list[IconSvgGroup]

A list of groups representing the SVG structure of the icon.

extend_icon(name, extra_props, extra_groups)

Creates a new icon entity based on the current one with additional properties and groups, and a different icon name.

Parameters:

Name Type Description Default
name str

The new name for the icon.

required
extra_props dict[str, str]

Additional properties to be added to the icon.

required
extra_groups list[IconSvgGroup]

Additional SVG groups to be added to the icon.

required

Returns:

Type Description

A new IconEntity with updated properties and groups.

ImxVersionEnum

Bases: Enum

Enumeration representing different versions of the IMX format.

Members

v124: Represents version 1.2.4 of the IMX format. v500: Represents version 5.0.0 of the IMX format.