33 #include <QDomDocument> 34 #include <QDomElement> 62 mSymbol->startRender( context, fields );
77 QSet<QString> attributes;
79 attributes.unite(
mSymbol->usedAttributes( context ) );
96 return mSymbol ? QStringLiteral(
"SINGLE: %1" ).arg(
mSymbol->dump() ) : QLatin1String(
"" );
112 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
113 element.appendChild( ruleElem );
115 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
116 nameElem.appendChild( doc.createTextNode( QStringLiteral(
"Single symbol" ) ) );
117 ruleElem.appendChild( nameElem );
135 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
136 if ( symbolsElem.isNull() )
141 if ( !symbolMap.contains( QStringLiteral(
"0" ) ) )
149 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
150 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
155 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
156 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
160 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
163 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
164 if ( !ddsLegendSizeElem.isNull() )
178 QDomElement ruleElem = element.firstChildElement( QStringLiteral(
"Rule" ) );
179 if ( ruleElem.isNull() )
185 QString label, description;
189 QDomElement childElem = ruleElem.firstChildElement();
190 while ( !childElem.isNull() )
192 if ( childElem.localName() == QLatin1String(
"Name" ) )
196 if ( label.isEmpty() )
197 label = childElem.firstChild().nodeValue();
199 else if ( childElem.localName() == QLatin1String(
"Description" ) )
202 QDomElement titleElem = childElem.firstChildElement( QStringLiteral(
"Title" ) );
203 if ( !titleElem.isNull() )
205 label = titleElem.firstChild().nodeValue();
208 QDomElement abstractElem = childElem.firstChildElement( QStringLiteral(
"Abstract" ) );
209 if ( !abstractElem.isNull() )
211 description = abstractElem.firstChild().nodeValue();
214 else if ( childElem.localName() == QLatin1String(
"Abstract" ) )
217 description = childElem.firstChild().nodeValue();
219 else if ( childElem.localName() == QLatin1String(
"Title" ) )
222 label = childElem.firstChild().nodeValue();
224 else if ( childElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) )
230 childElem = childElem.nextSiblingElement();
233 if ( layers.isEmpty() )
237 std::unique_ptr< QgsSymbol >
symbol;
241 symbol = qgis::make_unique< QgsLineSymbol >( layers );
245 symbol = qgis::make_unique< QgsFillSymbol >( layers );
249 symbol = qgis::make_unique< QgsMarkerSymbol >( layers );
253 QgsDebugMsg( QStringLiteral(
"invalid geometry type: found %1" ).arg( geomType ) );
264 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singleSymbol" ) );
265 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
266 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
269 symbols[QStringLiteral(
"0" )] =
mSymbol.get();
271 rendererElem.appendChild( symbolsElem );
273 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
274 rendererElem.appendChild( rotationElem );
276 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
277 rendererElem.appendChild( sizeScaleElem );
284 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
286 rendererElem.appendChild( orderBy );
288 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
292 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
294 rendererElem.appendChild( ddsLegendElem );
306 if ( sizeDD && sizeDD.isActive() )
323 return QSet< QString >() << QStringLiteral(
"0" );
335 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) )
339 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
342 if ( pointDistanceRenderer )
345 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
348 if ( invertedPolygonRenderer )
356 if ( !symbols.isEmpty() )
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new single symbol renderer from an XML element, using the supplied read/write context...
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
used from subclasses to create SLD Rule elements following SLD v1.1 specs
The class is used as a container of context for various read/write operations on other objects...
static QgsSymbol::ScaleMethod decodeScaleMethod(const QString &str)
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QgsSingleSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a new single symbol renderer from an existing renderer.
Container of fields for a vector layer.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
#define RENDERER_TAG_NAME
void setUsingSymbolLevels(bool usingSymbolLevels)
static void clearSymbolMap(QgsSymbolMap &symbols)
QgsPaintEffect * mPaintEffect
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
QMap< QString, QString > QgsStringMap
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
QList< QgsSymbol * > QgsSymbolList
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
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.
QList< QgsSymbolLayer * > QgsSymbolLayerList
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
A store for object properties.
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 ...
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
void setSymbol(QgsSymbol *s)
Sets the symbol which will be rendered for every feature.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QString dump() const override
Returns debug information about this renderer.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QMap< QString, QgsSymbol *> QgsSymbolMap
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols...
QgsSingleSymbolRenderer(QgsSymbol *symbol)
Constructor for QgsSingleSymbolRenderer.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend...
static bool createSymbolLayerListFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType, QgsSymbolLayerList &layers)
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns null on error...
std::unique_ptr< QgsSymbol > mSymbol
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer...
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsSingleSymbolRenderer * clone() const override
Create a deep copy of this renderer.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.