26#include <QDomDocument>
32using namespace Qt::StringLiterals;
46 return QObject::tr(
"Styled Layer Descriptor (SLD)" );
58 QDomElement root = doc.createElement( u
"Rule"_s );
59 symbol->
toSld( doc, root, sldExportContext );
60 doc.appendChild( root );
63 for (
const QString &error : sldExportContext.
errors() )
67 for (
const QString &warning : sldExportContext.
warnings() )
72 return doc.toString();
77 if ( variant.isNull() || !variant.canConvert<QString>() )
80 QString xmlString = variant.toString();
81 if ( xmlString.isEmpty() )
84 if ( !xmlString.contains(
"xmlns:se="_L1 ) )
87 xmlString = u
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><tmp xmlns:se=\"http://www.opengis.net/se\">%1</tmp>"_s.arg( xmlString );
92 int errorLine, errorColumn;
93 if ( !doc.setContent( xmlString,
true, &errorMsg, &errorLine, &errorColumn ) )
95 context.
pushError( QObject::tr(
"Error parsing SLD content: %1" ).arg( errorMsg ) );
99 const QDomElement ruleElem = doc.documentElement().firstChildElement( u
"Rule"_s );
100 if ( ruleElem.isNull() )
102 context.
pushError( QObject::tr(
"Error parsing SLD content: no Rule elements found" ) );
125 QDomElement childElem = ruleElem.firstChildElement();
126 while ( !childElem.isNull() )
128 if ( childElem.localName().endsWith(
"Symbolizer"_L1 ) )
133 childElem = childElem.nextSiblingElement();
136 if ( layers.isEmpty() )
139 std::unique_ptr< QgsSymbol > symbol;
143 symbol = std::make_unique< QgsLineSymbol >( layers );
147 symbol = std::make_unique< QgsFillSymbol >( layers );
151 symbol = std::make_unique< QgsMarkerSymbol >( layers );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
QFlags< SymbolConverterCapability > SymbolConverterCapabilities
Symbol converter capabilities.
@ WriteSymbol
Allows writing symbols to variants.
@ ReadSymbol
Allows reading symbols from variants.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
QStringList warnings() const
Returns a list of warnings which occurred during the conversion.
QStringList errors() const
Returns a list of errors which occurred during the conversion.
Represents the context in which a QgsSymbolConverter conversion occurs.
Qgis::SymbolType typeHint() const
Returns the symbol type hint, or Qgis::SymbolType::Hybrid if unknown.
void pushWarning(const QString &warning)
Pushes a warning message generated during the conversion.
void pushError(const QString &error)
Pushes a error message generated during the conversion.
std::unique_ptr< QgsSymbol > createSymbol(const QVariant &variant, QgsSymbolConverterContext &context) const override
Creates a new QgsSymbol from a QVariant representation.
QVariant toVariant(const QgsSymbol *symbol, QgsSymbolConverterContext &context) const override
Converts a symbol into a QVariant representation.
QString formatName() const override
Returns a translated, user-friendly name for the converter's data format.
Qgis::SymbolConverterCapabilities capabilities() const override
Returns the capabilities of the converter.
QString name() const override
Returns the unique name for the converter.
static bool createSymbolLayerListFromSld(QDomElement &element, Qgis::GeometryType geomType, QList< QgsSymbolLayer * > &layers)
Creates a symbol layer list from a DOM element.
Abstract base class for all rendered symbols.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props) const
Converts the symbol to a SLD representation.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
QList< QgsSymbolLayer * > QgsSymbolLayerList