38#include <QDomDocument>
77 mSymbol->startRender( context, fields );
92 QSet<QString> attributes;
94 attributes.unite(
mSymbol->usedAttributes( context ) );
121 return mSymbol ? QStringLiteral(
"SINGLE: %1" ).arg(
mSymbol->dump() ) : QString();
136 toSld( doc, element, context );
142 QVariantMap newProps = oldProps;
144 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
145 element.appendChild( ruleElem );
147 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
148 nameElem.appendChild( doc.createTextNode( QStringLiteral(
"Single symbol" ) ) );
149 ruleElem.appendChild( nameElem );
155 mSymbol->toSld( doc, ruleElem, context );
172 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
173 if ( symbolsElem.isNull() )
178 if ( !symbolMap.contains( QStringLiteral(
"0" ) ) )
186 const QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
187 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
192 const QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
193 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
197 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
200 const QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
201 if ( !ddsLegendSizeElem.isNull() )
215 const QDomElement ruleElem = element.firstChildElement( QStringLiteral(
"Rule" ) );
216 if ( ruleElem.isNull() )
218 QgsDebugError( QStringLiteral(
"no Rule elements found!" ) );
222 QString label, description;
226 QDomElement childElem = ruleElem.firstChildElement();
227 while ( !childElem.isNull() )
229 if ( childElem.localName() == QLatin1String(
"Name" ) )
233 if ( label.isEmpty() )
234 label = childElem.firstChild().nodeValue();
236 else if ( childElem.localName() == QLatin1String(
"Description" ) )
239 const QDomElement titleElem = childElem.firstChildElement( QStringLiteral(
"Title" ) );
240 if ( !titleElem.isNull() )
242 label = titleElem.firstChild().nodeValue();
245 const QDomElement abstractElem = childElem.firstChildElement( QStringLiteral(
"Abstract" ) );
246 if ( !abstractElem.isNull() )
248 description = abstractElem.firstChild().nodeValue();
251 else if ( childElem.localName() == QLatin1String(
"Abstract" ) )
254 description = childElem.firstChild().nodeValue();
256 else if ( childElem.localName() == QLatin1String(
"Title" ) )
259 label = childElem.firstChild().nodeValue();
261 else if ( childElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) )
267 childElem = childElem.nextSiblingElement();
270 if ( layers.isEmpty() )
274 std::unique_ptr< QgsSymbol >
symbol;
278 symbol = std::make_unique< QgsLineSymbol >( layers );
282 symbol = std::make_unique< QgsFillSymbol >( layers );
286 symbol = std::make_unique< QgsMarkerSymbol >( layers );
301 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singleSymbol" ) );
306 rendererElem.appendChild( symbolsElem );
308 const QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
309 rendererElem.appendChild( rotationElem );
311 const QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
312 rendererElem.appendChild( sizeScaleElem );
316 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
318 rendererElem.appendChild( ddsLegendElem );
349 return QSet< QString >() << QStringLiteral(
"0" );
354 if ( key == QLatin1String(
"0" ) )
357 return QStringLiteral(
"TRUE" );
375 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) )
379 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
382 if ( pointDistanceRenderer )
385 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
388 if ( invertedPolygonRenderer )
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
@ AffectsLabeling
If present, indicates that the renderer will participate in the map labeling problem.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ AffectsLabeling
If present, indicates that the symbol will participate in the map labeling problem.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns nullptr on error...
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
Abstract base class for all 2D vector feature renderers.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Converts old rotation expressions to symbol level data defined angles.
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
Converts old sizeScale expressions to symbol level data defined sizes.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
A polygon-only feature renderer used to display features inverted.
Stores information about one class/rule of a vector layer renderer in a unified way that can be used ...
A marker symbol type, for rendering Point and MultiPoint geometries.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
A store for object properties.
bool isActive() const
Returns whether the property is currently active.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
A feature renderer which renders all features with the same symbol.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
Qgis::FeatureRendererFlags flags() const override
Returns flags associated with the renderer.
QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const override
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
void setSymbol(QgsSymbol *s)
Sets the symbol which will be rendered for every feature.
static QgsFeatureRenderer * createFromSld(QDomElement &element, Qgis::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
std::unique_ptr< QgsSymbol > mSymbol
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new single symbol renderer from an XML element, using the supplied read/write context.
~QgsSingleSymbolRenderer() override
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
static QgsSingleSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a new single symbol renderer from an existing renderer.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const override
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
QgsSingleSymbolRenderer * clone() const override
Create a deep copy of this renderer.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QString dump() const override
Returns debug information about this renderer.
QgsSingleSymbolRenderer(QgsSymbol *symbol)
Constructor for QgsSingleSymbolRenderer.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
QVariantMap extraProperties() const
Returns the open ended set of properties that can drive/inform the SLD encoding.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A symbol entity for QgsStyle databases.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
static bool createSymbolLayerListFromSld(QDomElement &element, Qgis::GeometryType geomType, QList< QgsSymbolLayer * > &layers)
Creates a symbol layer list from a DOM element.
static Qgis::ScaleMethod decodeScaleMethod(const QString &str)
Decodes a symbol scale method from a string.
static void clearSymbolMap(QgsSymbolMap &symbols)
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
Abstract base class for all rendered symbols.
Represents a vector layer which manages a vector based dataset.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugError(str)
#define RENDERER_TAG_NAME
QMap< QString, QgsSymbol * > QgsSymbolMap
QList< QgsSymbol * > QgsSymbolList
QList< QgsSymbolLayer * > QgsSymbolLayerList
Contains information relating to the style entity currently being visited.