Class: QgsAbstractSymbolConverter

An abstract base class for converting between QgsSymbol objects and QVariant representations.

This interface provides a standard mechanism for serializing QGIS symbols to a generic data container (based on QVariant) and deserializing them back into native QgsSymbol objects.

Concrete implementations of this class are intended to handle specific external styling formats, such as SLD (Styled Layer Descriptor) or Mapbox GL styles.

Added in version 4.2.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: capabilities(), createSymbol(), formatName(), name(), toVariant()

List of all members, including inherited members

Abstract Methods

capabilities

Returns the capabilities of the converter.

createSymbol

Creates a new QgsSymbol from a QVariant representation.

formatName

Returns a translated, user-friendly name for the converter's data format.

name

Returns the unique name for the converter.

toVariant

Converts a symbol into a QVariant representation.

class qgis.core.QgsAbstractSymbolConverter[source]

Bases: object

abstract capabilities(self) Qgis.SymbolConverterCapability[source]

Returns the capabilities of the converter.

Return type:

Qgis.SymbolConverterCapability

abstract createSymbol(self, variant: Any, context: QgsSymbolConverterContext) QgsSymbol | None

Creates a new QgsSymbol from a QVariant representation.

Parameters:
Return type:

Optional[QgsSymbol]

Returns:

A new QgsSymbol instance representing the data in the variant. The caller takes ownership of the returned object. Returns None if the variant cannot be converted or parsed.

Raises:

QgsNotSupportedException – if the converter does not support deserialization of symbols.

abstract formatName(self) str[source]

Returns a translated, user-friendly name for the converter’s data format.

E.g. “Styled Layer Descriptor (SLD)” for a converter which handles the SLD format.

See also

name()

Return type:

str

abstract name(self) str[source]

Returns the unique name for the converter.

This should be an untranslated string identifying the converter.

See also

formatName()

Return type:

str

abstract toVariant(self, symbol: QgsSymbol | None, context: QgsSymbolConverterContext) Any[source]

Converts a symbol into a QVariant representation.

The resulting QVariant may be a dictionary (QVariantMap), a JSON string, an XML representation of the symbol, or some binary QByteArray value, depending on the concrete implementation (e.g., SLD vs. Mapbox GL).

Returns an invalid variant if the symbol could not be converted, or if serialization of symbols is not supported for this converter.

Raises:

QgsNotSupportedException – if the converter does not support serialization of symbols.

Parameters:
Return type:

Any