39 #include <QDomElement> 40 #include <QDomDocument> 89 return QSet< QString >();
97 mThread = QThread::currentThread();
101 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
109 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
121 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::renderFeature",
"renderFeature called in a different thread - use a cloned renderer instead" );
139 return QStringLiteral(
"UNKNOWN RENDERER\n" );
152 if ( element.isNull() )
156 QString rendererType = element.attribute( QStringLiteral(
"type" ) );
165 r->
setUsingSymbolLevels( element.attribute( QStringLiteral(
"symbollevels" ), QStringLiteral(
"0" ) ).toInt() );
166 r->
setForceRasterRender( element.attribute( QStringLiteral(
"forceraster" ), QStringLiteral(
"0" ) ).toInt() );
169 QDomElement effectElem = element.firstChildElement( QStringLiteral(
"effect" ) );
170 if ( !effectElem.isNull() )
176 QDomElement orderByElem = element.firstChildElement( QStringLiteral(
"orderby" ) );
178 r->
setOrderByEnabled( element.attribute( QStringLiteral(
"enableorderby" ), QStringLiteral(
"0" ) ).toInt() );
188 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
195 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
197 rendererElem.appendChild( orderBy );
199 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
205 QDomElement element = node.toElement();
206 if ( element.isNull() )
210 QDomElement userStyleElem = element.firstChildElement( QStringLiteral(
"UserStyle" ) );
211 if ( userStyleElem.isNull() )
214 errorMessage = QStringLiteral(
"Info: UserStyle element not found." );
219 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral(
"FeatureTypeStyle" ) );
220 if ( featTypeStyleElem.isNull() )
222 errorMessage = QStringLiteral(
"Info: FeatureTypeStyle element not found." );
227 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode(
false ).toElement();
232 bool needRuleRenderer =
false;
235 while ( !featTypeStyleElem.isNull() )
237 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral(
"Rule" ) );
238 while ( !ruleElem.isNull() )
243 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
248 QgsDebugMsg(
"more Rule elements found: need a RuleRenderer" );
249 needRuleRenderer =
true;
252 QDomElement ruleChildElem = ruleElem.firstChildElement();
253 while ( !ruleChildElem.isNull() )
256 if ( ruleChildElem.localName() == QLatin1String(
"Filter" ) ||
257 ruleChildElem.localName() == QLatin1String(
"MinScaleDenominator" ) ||
258 ruleChildElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
260 QgsDebugMsg(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
261 needRuleRenderer =
true;
265 ruleChildElem = ruleChildElem.nextSiblingElement();
268 ruleElem = ruleElem.nextSiblingElement( QStringLiteral(
"Rule" ) );
270 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral(
"FeatureTypeStyle" ) );
273 QString rendererType;
274 if ( needRuleRenderer )
276 rendererType = QStringLiteral(
"RuleRenderer" );
280 rendererType = QStringLiteral(
"singleSymbol" );
282 QgsDebugMsg( QString(
"Instantiating a '%1' renderer..." ).arg( rendererType ) );
288 errorMessage = QStringLiteral(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
298 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"UserStyle" ) );
300 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
301 nameElem.appendChild( doc.createTextNode( styleName ) );
302 userStyleElem.appendChild( nameElem );
304 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"se:FeatureTypeStyle" ) );
305 toSld( doc, featureTypeStyleElem, props );
306 userStyleElem.appendChild( featureTypeStyleElem );
308 return userStyleElem;
359 Q_FOREACH ( QPointF pt, pts )
365 Q_FOREACH ( QPointF pt, pts )
370 Q_FOREACH (
const QPolygonF &ring, *rings )
372 Q_FOREACH ( QPointF pt, ring )
382 if ( s ) lst.append( s );
396 if ( s ) lst.append( s );
469 ? QString::number( s->
angle() ) +
" + " 470 : QString() ) + field );
The class is used as a container of context for various read/write operations on other objects...
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
A rectangle specified with double values.
void setVertexMarkerAppearance(int type, int size)
Sets type and size of editing vertex markers for subsequent rendering.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Calculate scale by the diameter.
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
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
VertexMarkerType
Editing vertex markers.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
Base class for visual effects which can be applied to QPicture drawings.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Container of fields for a vector layer.
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
#define RENDERER_TAG_NAME
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
void setUsingSymbolLevels(bool usingSymbolLevels)
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
QgsPaintEffect * mPaintEffect
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a wkb string in map coordinates.
QMap< QString, QString > QgsStringMap
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the renderer.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
QList< QgsSymbol * > QgsSymbolList
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns new default symbol for specified geometry type.
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects. ...
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Calculate scale by the area.
void renderFeatureWithSymbol(const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
Render the feature with the symbol using context.
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
virtual ~QgsFeatureRenderer()
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, int currentVertexMarkerSize=0)
Render a feature.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
A store for object properties.
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
Point geometry type, with support for z-dimension and m-values.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
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
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Contains information about the context of a rendering operation.
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
QPainter * painter()
Returns the destination QPainter for the render operation.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
double size() const
Returns the size for the whole symbol, which is the maximum size of all marker symbol layers in the s...
int mCurrentVertexMarkerSize
The current size of editing marker.
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 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.
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
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 setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
int mCurrentVertexMarkerType
The current type of editing marker.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
Represents a vector layer which manages a vector based data sets.
QgsFeatureRenderer(const QString &type)
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer...
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
double angle() const
Returns the marker angle for the whole symbol.
Represents a list of OrderByClauses, with the most important first and the least important last...
void renderVertexMarker(QPointF pt, QgsRenderContext &context)
render editing vertex marker at specified point
virtual QString dump() const
Returns debug information about this renderer.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.