38 void QgsSymbolLayer::initPropertyDefinitions()
40 if ( !sPropertyDefinitions.isEmpty() )
43 QString origin = QStringLiteral(
"symbol" );
123 Q_UNUSED( mmMapUnitScaleFactor )
124 Q_UNUSED( layerName )
159 return QVector<qreal>();
164 return Qt::SolidLine;
215 QgsSymbolLayer::initPropertyDefinitions();
216 return sPropertyDefinitions;
248 if ( !baseName.isEmpty() )
250 prefix.append( QStringLiteral(
"%1_dd_" ).arg( baseName ) );
253 if ( !map.contains( QStringLiteral(
"%1expression" ).arg( prefix ) ) )
259 bool active = ( map.value( QStringLiteral(
"%1active" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
260 QString expression = map.value( QStringLiteral(
"%1expression" ).arg( prefix ) );
261 bool useExpression = ( map.value( QStringLiteral(
"%1useexpr" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
262 QString field = map.value( QStringLiteral(
"%1field" ).arg( prefix ), QString() );
273 static const QMap< QString, QgsSymbolLayer::Property > OLD_PROPS
348 QgsStringMap::const_iterator propIt = stringMap.constBegin();
349 for ( ; propIt != stringMap.constEnd(); ++propIt )
352 QString propertyName;
354 if ( propIt.key().endsWith( QLatin1String(
"_dd_expression" ) ) )
359 propertyName = propIt.key().left( propIt.key().length() - 14 );
363 else if ( propIt.key().endsWith( QLatin1String(
"_expression" ) ) )
368 propertyName = propIt.key().left( propIt.key().length() - 11 );
373 if ( !prop || !OLD_PROPS.contains( propertyName ) )
381 if ( propertyName == QLatin1String(
"width" ) )
383 else if ( propertyName == QLatin1String(
"color" ) )
450 if ( effect && effect->
enabled() )
453 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
457 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
464 markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
469 markerOffset( context, width, height, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
476 offsetX = mOffset.x();
477 offsetY = mOffset.y();
487 offsetX = offset.x();
488 offsetY = offset.y();
500 if ( exprVal.isValid() )
502 horizontalAnchorPoint = decodeHorizontalAnchorPoint( exprVal.toString() );
508 if ( exprVal.isValid() )
510 verticalAnchorPoint = decodeVerticalAnchorPoint( exprVal.toString() );
515 if ( horizontalAnchorPoint == HCenter && verticalAnchorPoint == VCenter )
522 if ( horizontalAnchorPoint == Left )
524 offsetX += anchorPointCorrectionX;
526 else if ( horizontalAnchorPoint == Right )
528 offsetX -= anchorPointCorrectionX;
532 if ( verticalAnchorPoint == Top )
534 offsetY += anchorPointCorrectionY;
536 else if ( verticalAnchorPoint == Bottom )
538 offsetY -= anchorPointCorrectionY;
545 double c = std::cos( angle ), s = std::sin( angle );
546 return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() *
c );
551 if ( str.compare( QLatin1String(
"left" ), Qt::CaseInsensitive ) == 0 )
555 else if ( str.compare( QLatin1String(
"right" ), Qt::CaseInsensitive ) == 0 )
567 if ( str.compare( QLatin1String(
"top" ), Qt::CaseInsensitive ) == 0 )
571 else if ( str.compare( QLatin1String(
"bottom" ), Qt::CaseInsensitive ) == 0 )
589 if ( mOffsetUnit != mSizeUnit )
598 mSizeMapUnitScale = scale;
599 mOffsetMapUnitScale = scale;
604 if ( mSizeMapUnitScale == mOffsetMapUnitScale )
606 return mSizeMapUnitScale;
623 mWidthMapUnitScale = scale;
628 return mWidthMapUnitScale;
637 points << QPointF( 0,
int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 );
641 if ( effect && effect->
enabled() )
644 renderPolyline( points, context );
648 renderPolyline( points, context );
655 switch ( mRingFilter )
658 case ExteriorRingOnly:
659 renderPolyline( points, context );
661 case InteriorRingsOnly:
667 switch ( mRingFilter )
670 case InteriorRingsOnly:
672 for (
const QPolygonF &ring : qgis::as_const( *rings ) )
673 renderPolyline( ring, context );
676 case ExteriorRingOnly:
696 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) );
699 if ( effect && effect->
enabled() )
719 if ( points.size() <= 5 &&
722 ( p->renderHints() & QPainter::Antialiasing ) )
724 p->setRenderHint( QPainter::Antialiasing,
false );
725 p->drawRect( points.boundingRect() );
726 p->setRenderHint( QPainter::Antialiasing,
true );
732 if ( !rings && p->pen().style() == Qt::NoPen )
735 p->drawPolygon( points );
741 path.addPolygon( points );
745 QList<QPolygonF>::const_iterator it = rings->constBegin();
746 for ( ; it != rings->constEnd(); ++it )
748 QPolygonF ring = *it;
749 path.addPolygon( ring );
759 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PointSymbolizer" ) );
760 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
761 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
762 element.appendChild( symbolizerElem );
767 writeSldMarker( doc, symbolizerElem, props );
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QgsMapUnitScale mapUnitScale() const override
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
QgsLineSymbolLayer(const QgsLineSymbolLayer &other)=delete
QgsLineSymbolLayer cannot be copied.
RenderRingFilter ringFilter() const
Returns the line symbol layer's ring filter, which controls which rings are rendered when the line sy...
Gradient reference point 1 is centroid.
QgsFillSymbolLayer(const QgsFillSymbolLayer &other)=delete
QgsFillSymbolLayer cannot be copied.
double symbologyScale() const
Returns the reference scale for output.
void setRenderingPass(int renderingPass)
Specifies the rendering pass in which this symbol layer should be rendered.
Positive integer values (including 0)
void setMapUnitScale(const QgsMapUnitScale &scale) override
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Gradient reference point 1 x.
QgsFields fields() const
Fields of the layer.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
1D size (eg marker radius, or square marker height/width)
Abstract base class for all rendered symbols.
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
Align to right side of symbol.
virtual void prepareExpressions(const QgsSymbolRenderContext &context)
Prepares all data defined property expressions for evaluation.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QgsMarkerSymbolLayer(const QgsMarkerSymbolLayer &other)=delete
QgsMarkerSymbolLayer cannot be copied.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Base class for visual effects which can be applied to QPicture drawings.
Whether markers should be clipped to polygon boundaries.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
void restoreOldDataDefinedProperties(const QgsStringMap &stringMap)
Restores older data defined properties from string map.
void _renderPolygon(QPainter *p, const QPolygonF &points, const QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
Default method to render polygon.
Color with alpha channel.
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets line width.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Align to horizontal center of symbol.
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
QMap< QString, QString > QgsStringMap
Shapeburst use whole shape.
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
virtual double width() const
Returns the estimated width for the line symbol layer.
Rotation (value between 0-360 degrees)
Name, eg shape name for simple markers.
Gradient reference point 2 y.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
QgsProperty propertyFromMap(const QgsStringMap &map, const QString &baseName)
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
virtual void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)=0
SymbolType
Type of the symbol.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
Align to bottom of symbol.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'...
virtual QgsSymbolLayerReferenceList masks() const
Returns masks defined by this symbol layer.
Gradient coordinate mode.
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
virtual Qt::BrushStyle dxfBrushStyle() const
Gets brush/fill style.
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
Property requires a numeric value.
virtual QColor color() const
The fill color.
Filename, eg for svg files.
float threshold() const
Gets the simplification threshold of the vector layer managed.
Align to left side of symbol.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
void markerOffset(QgsSymbolRenderContext &context, double &offsetX, double &offsetY) const
Calculates the required marker offset, including both the symbol offset and any displacement required...
Shapeburst fill from edge distance.
QgsSymbolLayer(const QgsSymbolLayer &other)=delete
QgsSymbolLayer cannot be copied.
QgsSymbol::SymbolType type() const
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
bool enabled() const
Returns whether the effect is enabled.
Character, eg for font marker symbol layers.
double mapUnitsPerPixel() const
Returns current map units per pixel.
A store for object properties.
Fill style (eg solid, lines)
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
RenderRingFilter
Options for filtering rings when the line symbol layer is being used to render a polygon's rings...
std::unique_ptr< QgsPaintEffect > mPaintEffect
Definition for a property.
HorizontalAnchorPoint
Symbol horizontal anchor points.
Gradient reference point 1 y.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
Gets brush/fill color.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
VerticalAnchorPoint
Symbol vertical anchor points.
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
QgsExpressionContext & expressionContext()
Gets the expression context.
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
Line angle, or angle of hash lines for hash line symbols.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
Stroke style (eg solid, dashed)
Preserve aspect ratio between width and height.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
RenderRingFilter mRingFilter
Property requires a string value.
SymbolType type() const
Returns the symbol's type.
Struct for storing maximum and minimum scales for measurements in map units.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
void setMapUnitScale(const QgsMapUnitScale &scale) override
virtual double dxfAngle(QgsSymbolRenderContext &context) const
Gets angle.
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
Distance between lines, or length of lines for hash line symbols.
Line style (eg solid/dashed)
void setRingFilter(QgsLineSymbolLayer::RenderRingFilter filter)
Sets the line symbol layer's ring filter, which controls which rings are rendered when the line symbo...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
Align to vertical center of symbol.
Secondary color (eg for gradient fills)
bool isEmpty() const
Checks whether the container is empty.
virtual ~QgsSymbolLayer()
virtual void renderPolygonStroke(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
Renders the line symbol layer along the outline of polygon, using the given render context...
Length to average symbol angles over.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
static QPointF _rotatedOffset(QPointF offset, double angle)
Adjusts a marker offset to account for rotation.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
static bool isGeneralizableByDeviceBoundingBox(const QgsRectangle &envelope, float mapToPixelTol=1.0f)
Returns whether the device-envelope can be replaced by its BBOX when is applied the specified toleran...
Line cap style (eg round)
Fill style (eg solid, dots)
Whether symbol layer is enabled.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Gradient reference point 2 is centroid.
A class to manager painter saving and restoring required for effect drawing.
QgsSymbol::SymbolType mType
Gradient reference point 2 x.
QgsPropertyCollection mDataDefinedProperties
QgsMapUnitScale mapUnitScale() const override
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol layer's property collection, used for data defined overrides.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Property
Data definable properties.
RenderUnit
Rendering size units.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
Horizontal distance between points.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Vertical distance between points.
Double value between 0-1 (inclusive)