QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
34 #include <QDomDocument>
35 #include <QDomElement>
65 mSymbol->startRender( context, fields );
80 QSet<QString> attributes;
82 attributes.unite(
mSymbol->usedAttributes( context ) );
109 return mSymbol ? QStringLiteral(
"SINGLE: %1" ).arg(
mSymbol->dump() ) : QString();
125 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
126 element.appendChild( ruleElem );
128 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
129 nameElem.appendChild( doc.createTextNode( QStringLiteral(
"Single symbol" ) ) );
130 ruleElem.appendChild( nameElem );
148 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
149 if ( symbolsElem.isNull() )
154 if ( !symbolMap.contains( QStringLiteral(
"0" ) ) )
162 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
163 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
168 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
169 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
173 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
176 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
177 if ( !ddsLegendSizeElem.isNull() )
191 QDomElement ruleElem = element.firstChildElement( QStringLiteral(
"Rule" ) );
192 if ( ruleElem.isNull() )
194 QgsDebugMsg( QStringLiteral(
"no Rule elements found!" ) );
198 QString label, description;
202 QDomElement childElem = ruleElem.firstChildElement();
203 while ( !childElem.isNull() )
205 if ( childElem.localName() == QLatin1String(
"Name" ) )
209 if ( label.isEmpty() )
210 label = childElem.firstChild().nodeValue();
212 else if ( childElem.localName() == QLatin1String(
"Description" ) )
215 QDomElement titleElem = childElem.firstChildElement( QStringLiteral(
"Title" ) );
216 if ( !titleElem.isNull() )
218 label = titleElem.firstChild().nodeValue();
221 QDomElement abstractElem = childElem.firstChildElement( QStringLiteral(
"Abstract" ) );
222 if ( !abstractElem.isNull() )
224 description = abstractElem.firstChild().nodeValue();
227 else if ( childElem.localName() == QLatin1String(
"Abstract" ) )
230 description = childElem.firstChild().nodeValue();
232 else if ( childElem.localName() == QLatin1String(
"Title" ) )
235 label = childElem.firstChild().nodeValue();
237 else if ( childElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) )
243 childElem = childElem.nextSiblingElement();
246 if ( layers.isEmpty() )
250 std::unique_ptr< QgsSymbol >
symbol;
254 symbol = qgis::make_unique< QgsLineSymbol >( layers );
258 symbol = qgis::make_unique< QgsFillSymbol >( layers );
262 symbol = qgis::make_unique< QgsMarkerSymbol >( layers );
266 QgsDebugMsg( QStringLiteral(
"invalid geometry type: found %1" ).arg( geomType ) );
277 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"singleSymbol" ) );
278 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
279 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
284 rendererElem.appendChild( symbolsElem );
286 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
287 rendererElem.appendChild( rotationElem );
289 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
290 rendererElem.appendChild( sizeScaleElem );
297 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
299 rendererElem.appendChild(
orderBy );
301 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
305 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
307 rendererElem.appendChild( ddsLegendElem );
336 return QSet< QString >() << QStringLiteral(
"0" );
348 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) )
352 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
355 if ( pointDistanceRenderer )
358 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
361 if ( invertedPolygonRenderer )
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
QgsSingleSymbolRenderer(QgsSymbol *symbol)
Constructor for QgsSingleSymbolRenderer.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
bool isActive() const
Returns whether the property is currently active.
static QgsSingleSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a new single symbol renderer from an existing renderer.
QgsPaintEffect * mPaintEffect
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 ...
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
std::unique_ptr< QgsSymbol > mSymbol
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
A symbol entity for QgsStyle databases.
QgsSingleSymbolRenderer * clone() const override
Create a deep copy of this renderer.
QMap< QString, QgsSymbol * > QgsSymbolMap
static QgsSymbol::ScaleMethod decodeScaleMethod(const QString &str)
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
Container of fields for a vector layer.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Abstract base class for all rendered symbols.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
Contains information relating to the style entity currently being visited.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
~QgsSingleSymbolRenderer() override
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
void setUsingSymbolLevels(bool usingSymbolLevels)
QList< QgsSymbol * > QgsSymbolList
A marker symbol type, for rendering Point and MultiPoint geometries.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
#define RENDERER_TAG_NAME
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
QString dump() const override
Returns debug information about this renderer.
bool usingSymbolLevels() const
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
static bool createSymbolLayerListFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType, QgsSymbolLayerList &layers)
void setSymbol(QgsSymbol *s)
Sets the symbol which will be rendered for every feature.
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 mOrderBy
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
QMap< QString, QString > QgsStringMap
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 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.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
QList< QgsSymbolLayer * > QgsSymbolLayerList
static void clearSymbolMap(QgsSymbolMap &symbols)
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
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...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new single symbol renderer from an XML element, using the supplied read/write context.
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...