QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
40 #include <QDomElement>
41 #include <QDomDocument>
61 , mUsingSymbolLevels( false )
63 , mCurrentVertexMarkerSize( 2 )
64 , mForceRaster( false )
65 , mOrderByEnabled( false )
90 return QSet< QString >();
98 mThread = QThread::currentThread();
102 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
110 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
122 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::renderFeature",
"renderFeature called in a different thread - use a cloned renderer instead" );
140 return QStringLiteral(
"UNKNOWN RENDERER\n" );
153 if ( element.isNull() )
157 QString rendererType = element.attribute( QStringLiteral(
"type" ) );
166 r->
setUsingSymbolLevels( element.attribute( QStringLiteral(
"symbollevels" ), QStringLiteral(
"0" ) ).toInt() );
167 r->
setForceRasterRender( element.attribute( QStringLiteral(
"forceraster" ), QStringLiteral(
"0" ) ).toInt() );
170 QDomElement effectElem = element.firstChildElement( QStringLiteral(
"effect" ) );
171 if ( !effectElem.isNull() )
177 QDomElement orderByElem = element.firstChildElement( QStringLiteral(
"orderby" ) );
179 r->
setOrderByEnabled( element.attribute( QStringLiteral(
"enableorderby" ), QStringLiteral(
"0" ) ).toInt() );
189 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
196 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
198 rendererElem.appendChild(
orderBy );
200 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
206 QDomElement element = node.toElement();
207 if ( element.isNull() )
211 QDomElement userStyleElem = element.firstChildElement( QStringLiteral(
"UserStyle" ) );
212 if ( userStyleElem.isNull() )
215 errorMessage = QStringLiteral(
"Info: UserStyle element not found." );
220 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral(
"FeatureTypeStyle" ) );
221 if ( featTypeStyleElem.isNull() )
223 errorMessage = QStringLiteral(
"Info: FeatureTypeStyle element not found." );
228 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode(
false ).toElement();
233 bool needRuleRenderer =
false;
236 while ( !featTypeStyleElem.isNull() )
238 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral(
"Rule" ) );
239 while ( !ruleElem.isNull() )
243 bool hasRendererSymbolizer =
false;
244 bool hasRuleRenderer =
false;
245 QDomElement ruleChildElem = ruleElem.firstChildElement();
246 while ( !ruleChildElem.isNull() )
249 if ( ruleChildElem.localName() == QLatin1String(
"Filter" ) ||
250 ruleChildElem.localName() == QLatin1String(
"MinScaleDenominator" ) ||
251 ruleChildElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
253 hasRuleRenderer =
true;
256 else if ( ruleChildElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) &&
257 ruleChildElem.localName() != QLatin1String(
"TextSymbolizer" ) )
259 QgsDebugMsgLevel( QStringLiteral(
"Symbolizer element found and not a TextSymbolizer" ), 2 );
260 hasRendererSymbolizer =
true;
263 ruleChildElem = ruleChildElem.nextSiblingElement();
266 if ( hasRendererSymbolizer )
271 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
273 if ( hasRuleRenderer )
275 QgsDebugMsgLevel( QStringLiteral(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" ), 2 );
276 needRuleRenderer =
true;
283 QgsDebugMsgLevel( QStringLiteral(
"more Rule elements found: need a RuleRenderer" ), 2 );
284 needRuleRenderer =
true;
287 ruleElem = ruleElem.nextSiblingElement( QStringLiteral(
"Rule" ) );
289 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral(
"FeatureTypeStyle" ) );
292 QString rendererType;
293 if ( needRuleRenderer )
295 rendererType = QStringLiteral(
"RuleRenderer" );
299 rendererType = QStringLiteral(
"singleSymbol" );
301 QgsDebugMsgLevel( QStringLiteral(
"Instantiating a '%1' renderer..." ).arg( rendererType ), 2 );
307 errorMessage = QStringLiteral(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
317 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"UserStyle" ) );
319 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
320 nameElem.appendChild( doc.createTextNode( styleName ) );
321 userStyleElem.appendChild( nameElem );
323 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
324 toSld( doc, featureTypeStyleElem, props );
325 userStyleElem.appendChild( featureTypeStyleElem );
327 return userStyleElem;
379 const auto constPts = pts;
380 for ( QPointF pt : constPts )
386 const auto constPts = pts;
387 for ( QPointF pt : constPts )
392 const auto constRings = *rings;
393 for (
const QPolygonF &ring : constRings )
395 const auto constRing = ring;
396 for ( QPointF pt : constRing )
406 if ( s ) lst.append( s );
420 if ( s ) lst.append( s );
498 ? QString::number( s->
angle() ) +
" + "
499 : QString() ) +
field );
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual QDomElement writeSld(QDomDocument &doc, const QString &styleName, const QgsStringMap &props=QgsStringMap()) const
create the SLD UserStyle element following the SLD v1.1 specs with the given name
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QgsPaintEffect * mPaintEffect
double mCurrentVertexMarkerSize
The current size of editing marker.
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer.
Point geometry type, with support for z-dimension and m-values.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
#define QgsDebugMsgLevel(str, level)
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
Container of fields for a vector layer.
void renderFeatureWithSymbol(const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker) SIP_THROW(QgsCsException)
Render the feature with the symbol using context.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
@ ScaleDiameter
Calculate scale by the diameter.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
@ RenderMillimeters
Millimeters.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Abstract base class for all rendered symbols.
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
double angle() const
Returns the marker angle for the whole symbol.
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual ~QgsFeatureRenderer()
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
A rectangle specified with double values.
int layer() const
The layer of this symbol level.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void setVertexMarkerAppearance(int type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
QgsSymbol * symbol() const
The symbol of this symbol level.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
int mCurrentVertexMarkerType
The current type of editing marker.
QgsFeatureRenderer(const QString &type)
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
void setUsingSymbolLevels(bool usingSymbolLevels)
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a wkb string in map coordinates.
QList< QgsSymbol * > QgsSymbolList
A marker symbol type, for rendering Point and MultiPoint geometries.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, double currentVertexMarkerSize=0.0) SIP_THROW(QgsCsException)
Render a feature.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
#define RENDERER_TAG_NAME
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
A line symbol type, for rendering LineString and MultiLineString geometries.
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
QgsFeatureRequest::OrderBy mOrderBy
QMap< QString, QString > QgsStringMap
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Represents a list of OrderByClauses, with the most important first and the least important last.
Represents a vector layer which manages a vector based data sets.
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)
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
Base class for visual effects which can be applied to QPicture drawings.
void renderVertexMarker(QPointF pt, QgsRenderContext &context)
render editing vertex marker at specified point
VertexMarkerType
Editing vertex markers.
SymbolType type() const
Returns the symbol's type.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the renderer.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
virtual QString dump() const
Returns debug information about this renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
QPainter * painter()
Returns the destination QPainter for the render operation.
@ ScaleArea
Calculate scale by the area.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
static QgsFeatureRenderer * loadSld(const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
static void drawVertexMarker(double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.