40 #include <QDomElement>
41 #include <QDomDocument>
62 , mUsingSymbolLevels( false )
64 , mCurrentVertexMarkerSize( 2 )
65 , mForceRaster( false )
66 , mOrderByEnabled( false )
91 return QSet< QString >();
99 mThread = QThread::currentThread();
103 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
111 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
123 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::renderFeature",
"renderFeature called in a different thread - use a cloned renderer instead" );
141 return QStringLiteral(
"UNKNOWN RENDERER\n" );
154 if ( element.isNull() )
158 QString rendererType = element.attribute( QStringLiteral(
"type" ) );
167 r->
setUsingSymbolLevels( element.attribute( QStringLiteral(
"symbollevels" ), QStringLiteral(
"0" ) ).toInt() );
168 r->
setForceRasterRender( element.attribute( QStringLiteral(
"forceraster" ), QStringLiteral(
"0" ) ).toInt() );
171 QDomElement effectElem = element.firstChildElement( QStringLiteral(
"effect" ) );
172 if ( !effectElem.isNull() )
178 QDomElement orderByElem = element.firstChildElement( QStringLiteral(
"orderby" ) );
180 r->
setOrderByEnabled( element.attribute( QStringLiteral(
"enableorderby" ), QStringLiteral(
"0" ) ).toInt() );
190 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
197 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
199 rendererElem.appendChild(
orderBy );
201 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
207 QDomElement element = node.toElement();
208 if ( element.isNull() )
212 QDomElement userStyleElem = element.firstChildElement( QStringLiteral(
"UserStyle" ) );
213 if ( userStyleElem.isNull() )
216 errorMessage = QStringLiteral(
"Info: UserStyle element not found." );
221 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral(
"FeatureTypeStyle" ) );
222 if ( featTypeStyleElem.isNull() )
224 errorMessage = QStringLiteral(
"Info: FeatureTypeStyle element not found." );
229 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode(
false ).toElement();
234 bool needRuleRenderer =
false;
237 while ( !featTypeStyleElem.isNull() )
239 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral(
"Rule" ) );
240 while ( !ruleElem.isNull() )
244 bool hasRendererSymbolizer =
false;
245 bool hasRuleRenderer =
false;
246 QDomElement ruleChildElem = ruleElem.firstChildElement();
247 while ( !ruleChildElem.isNull() )
250 if ( ruleChildElem.localName() == QLatin1String(
"Filter" ) ||
251 ruleChildElem.localName() == QLatin1String(
"MinScaleDenominator" ) ||
252 ruleChildElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
254 hasRuleRenderer =
true;
257 else if ( ruleChildElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) &&
258 ruleChildElem.localName() != QLatin1String(
"TextSymbolizer" ) )
260 QgsDebugMsgLevel( QStringLiteral(
"Symbolizer element found and not a TextSymbolizer" ), 2 );
261 hasRendererSymbolizer =
true;
264 ruleChildElem = ruleChildElem.nextSiblingElement();
267 if ( hasRendererSymbolizer )
272 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
274 if ( hasRuleRenderer )
276 QgsDebugMsgLevel( QStringLiteral(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" ), 2 );
277 needRuleRenderer =
true;
284 QgsDebugMsgLevel( QStringLiteral(
"more Rule elements found: need a RuleRenderer" ), 2 );
285 needRuleRenderer =
true;
288 ruleElem = ruleElem.nextSiblingElement( QStringLiteral(
"Rule" ) );
290 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral(
"FeatureTypeStyle" ) );
293 QString rendererType;
294 if ( needRuleRenderer )
296 rendererType = QStringLiteral(
"RuleRenderer" );
300 rendererType = QStringLiteral(
"singleSymbol" );
302 QgsDebugMsgLevel( QStringLiteral(
"Instantiating a '%1' renderer..." ).arg( rendererType ), 2 );
308 errorMessage = QStringLiteral(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
318 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"UserStyle" ) );
320 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
321 nameElem.appendChild( doc.createTextNode( styleName ) );
322 userStyleElem.appendChild( nameElem );
324 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
325 toSld( doc, featureTypeStyleElem, props );
326 userStyleElem.appendChild( featureTypeStyleElem );
328 return userStyleElem;
380 const auto constPts = pts;
381 for ( QPointF pt : constPts )
387 const auto constPts = pts;
388 for ( QPointF pt : constPts )
393 const auto constRings = *rings;
394 for (
const QPolygonF &ring : constRings )
396 const auto constRing = ring;
397 for ( QPointF pt : constRing )
407 if ( s ) lst.append( s );
421 if ( s ) lst.append( s );
499 ? QString::number( s->
angle() ) +
" + "
500 : QString() ) +
field );
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a wkb string in map coordinates.
virtual QDomElement writeSld(QDomDocument &doc, const QString &styleName, const QVariantMap &props=QVariantMap()) const
create the SLD UserStyle element following the SLD v1.1 specs with the given name
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
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.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the renderer.
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
QgsFeatureRenderer(const QString &type)
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
QgsPaintEffect * mPaintEffect
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
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 ...
void setVertexMarkerAppearance(int type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
virtual QString dump() const
Returns debug information about this renderer.
void setUsingSymbolLevels(bool usingSymbolLevels)
virtual ~QgsFeatureRenderer()
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
int mCurrentVertexMarkerType
The current type of editing marker.
QgsFeatureRequest::OrderBy mOrderBy
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
void renderVertexMarker(QPointF pt, QgsRenderContext &context)
render editing vertex marker at specified point
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
double mCurrentVertexMarkerSize
The current size of editing marker.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
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.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Represents a list of OrderByClauses, with the most important first and the least important last.
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Container of fields for a vector layer.
A line symbol type, for rendering LineString and MultiLineString geometries.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
A marker symbol type, for rendering Point and MultiPoint geometries.
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
double angle() const
Returns the marker angle for the whole symbol.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
Point geometry type, with support for z-dimension and m-values.
A store for object properties.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
An interface for classes which can visit style entity (e.g.
VertexMarkerType
Editing vertex markers.
static void drawVertexMarker(double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.
int layer() const
The layer of this symbol level.
QgsSymbol * symbol() const
The symbol of this symbol level.
Abstract base class for all rendered symbols.
@ ScaleArea
Calculate scale by the area.
@ ScaleDiameter
Calculate scale by the diameter.
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.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
SymbolType type() const
Returns the symbol's type.
@ RenderMillimeters
Millimeters.
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
#define RENDERER_TAG_NAME
QList< QgsSymbol * > QgsSymbolList