37 void QgsSymbolLayer::initPropertyDefinitions()
39 if ( !sPropertyDefinitions.isEmpty() )
42 QString origin = QStringLiteral(
"symbol" );
108 Q_UNUSED( mmMapUnitScaleFactor );
109 Q_UNUSED( layerName );
144 return QVector<qreal>();
149 return Qt::SolidLine;
203 QgsSymbolLayer::initPropertyDefinitions();
204 return sPropertyDefinitions;
229 if ( !baseName.isEmpty() )
231 prefix.append( QStringLiteral(
"%1_dd_" ).arg( baseName ) );
234 if ( !map.contains( QStringLiteral(
"%1expression" ).arg( prefix ) ) )
240 bool active = ( map.value( QStringLiteral(
"%1active" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
241 QString expression = map.value( QStringLiteral(
"%1expression" ).arg( prefix ) );
242 bool useExpression = ( map.value( QStringLiteral(
"%1useexpr" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
243 QString field = map.value( QStringLiteral(
"%1field" ).arg( prefix ), QString() );
252 static const QMap< QString, QgsSymbolLayer::Property > OLD_PROPS
329 QgsStringMap::const_iterator propIt = stringMap.constBegin();
330 for ( ; propIt != stringMap.constEnd(); ++propIt )
333 QString propertyName;
335 if ( propIt.key().endsWith( QLatin1String(
"_dd_expression" ) ) )
340 propertyName = propIt.key().left( propIt.key().length() - 14 );
344 else if ( propIt.key().endsWith( QLatin1String(
"_expression" ) ) )
349 propertyName = propIt.key().left( propIt.key().length() - 11 );
354 if ( !prop || !OLD_PROPS.contains( propertyName ) )
362 if ( propertyName == QLatin1String(
"width" ) )
364 else if ( propertyName == QLatin1String(
"color" ) )
423 if ( effect && effect->
enabled() )
426 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
430 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
437 markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
442 markerOffset( context, width, height, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
449 offsetX = mOffset.x();
450 offsetY = mOffset.y();
456 if ( exprVal.isValid() )
459 offsetX = offset.x();
460 offsetY = offset.y();
472 if ( exprVal.isValid() )
474 horizontalAnchorPoint = decodeHorizontalAnchorPoint( exprVal.toString() );
480 if ( exprVal.isValid() )
482 verticalAnchorPoint = decodeVerticalAnchorPoint( exprVal.toString() );
487 if ( horizontalAnchorPoint == HCenter && verticalAnchorPoint == VCenter )
494 if ( horizontalAnchorPoint == Left )
496 offsetX += anchorPointCorrectionX;
498 else if ( horizontalAnchorPoint == Right )
500 offsetX -= anchorPointCorrectionX;
504 if ( verticalAnchorPoint == Top )
506 offsetY += anchorPointCorrectionY;
508 else if ( verticalAnchorPoint == Bottom )
510 offsetY -= anchorPointCorrectionY;
517 double c = std::cos( angle ), s = std::sin( angle );
518 return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() *
c );
523 if ( str.compare( QLatin1String(
"left" ), Qt::CaseInsensitive ) == 0 )
527 else if ( str.compare( QLatin1String(
"right" ), Qt::CaseInsensitive ) == 0 )
539 if ( str.compare( QLatin1String(
"top" ), Qt::CaseInsensitive ) == 0 )
543 else if ( str.compare( QLatin1String(
"bottom" ), Qt::CaseInsensitive ) == 0 )
561 if ( mOffsetUnit != mSizeUnit )
570 mSizeMapUnitScale = scale;
571 mOffsetMapUnitScale = scale;
576 if ( mSizeMapUnitScale == mOffsetMapUnitScale )
578 return mSizeMapUnitScale;
595 mWidthMapUnitScale = scale;
600 return mWidthMapUnitScale;
609 points << QPointF( 0,
int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 );
613 if ( effect && effect->
enabled() )
616 renderPolyline( points, context );
620 renderPolyline( points, context );
627 switch ( mRingFilter )
630 case ExteriorRingOnly:
631 renderPolyline( points, context );
633 case InteriorRingsOnly:
639 switch ( mRingFilter )
642 case InteriorRingsOnly:
644 for (
const QPolygonF &ring : qgis::as_const( *rings ) )
645 renderPolyline( ring, context );
648 case ExteriorRingOnly:
668 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) );
671 if ( effect && effect->
enabled() )
691 if ( points.size() <= 5 &&
694 ( p->renderHints() & QPainter::Antialiasing ) )
696 p->setRenderHint( QPainter::Antialiasing,
false );
697 p->drawRect( points.boundingRect() );
698 p->setRenderHint( QPainter::Antialiasing,
true );
704 if ( !rings && p->pen().style() == Qt::NoPen )
707 p->drawPolygon( points );
713 path.addPolygon( points );
717 QList<QPolygonF>::const_iterator it = rings->constBegin();
718 for ( ; it != rings->constEnd(); ++it )
720 QPolygonF ring = *it;
721 path.addPolygon( ring );
731 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PointSymbolizer" ) );
732 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
733 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
734 element.appendChild( symbolizerElem );
739 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
Gradient reference point 1 is centroid.
QgsLineSymbolLayer(bool locked=false)
float threshold() const
Gets the simplification threshold of the vector layer managed.
void setMapUnitScale(const QgsMapUnitScale &scale) override
Gradient reference point 1 x.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
double symbologyScale() const
Returns the reference scale for output.
1D size (eg marker radius, or square marker height/width)
Abstract base class for all rendered symbols.
RenderRingFilter ringFilter() const
Returns the line symbol layer's ring filter, which controls which rings are rendered when the line sy...
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
Align to right side of symbol.
virtual void prepareExpressions(const QgsSymbolRenderContext &context)
Prepares all data defined property expressions for evaluation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void startRender(QgsSymbolRenderContext &context) override
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
bool enabled() const
Returns whether the effect is enabled.
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.
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.
virtual QVector< qreal > dxfCustomDashPattern(QgsUnitTypes::RenderUnit &unit) const
Gets dash pattern.
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.
Rotation (value between 0-360 degrees)
Name, eg shape name for simple markers.
Gradient reference point 2 y.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
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)
QgsSymbolLayer(QgsSymbol::SymbolType type, bool locked=false)
void markerOffset(QgsSymbolRenderContext &context, double &offsetX, double &offsetY) const
Calculates the required marker offset, including both the symbol offset and any displacement required...
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.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
Gets brush/fill color.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
Align to bottom of symbol.
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects. ...
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 bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
QgsSymbol::SymbolType type() const
Gradient coordinate mode.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
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.
Filename, eg for svg files.
Align to left side of symbol.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Shapeburst fill from edge distance.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
Character, eg for font marker symbol layers.
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...
Definition for a property.
HorizontalAnchorPoint
Symbol horizontal anchor points.
Gradient reference point 1 y.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
VerticalAnchorPoint
Symbol vertical anchor points.
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
QgsFields fields() const
Fields of the layer.
QgsExpressionContext & expressionContext()
Gets the expression context.
virtual double width() const
Returns the estimated width for the line symbol layer.
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.
Contains information about the context of a rendering operation.
virtual double dxfAngle(QgsSymbolRenderContext &context) const
Gets angle.
RenderRingFilter mRingFilter
Property requires a string value.
Struct for storing maximum and minimum scales for measurements in map units.
virtual void stopRender(QgsSymbolRenderContext &context)=0
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsMarkerSymbolLayer(bool locked=false)
Constructor for QgsMarkerSymbolLayer.
QgsPaintEffect * mPaintEffect
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
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...
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets line width.
SymbolType type() const
Returns the symbol's type.
Align to vertical center of symbol.
Secondary color (eg for gradient fills)
bool mEnabled
True if layer is enabled and should be drawn.
virtual ~QgsSymbolLayer()
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
virtual void renderPolygonStroke(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QgsFillSymbolLayer(bool locked=false)
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
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.
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)
bool isEmpty() const
Checks whether the container is empty.
virtual QColor color() const
The fill color.
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.
virtual Qt::BrushStyle dxfBrushStyle() const
Gets brush/fill style.
RenderUnit
Rendering size units.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
virtual void startRender(QgsSymbolRenderContext &context)=0
Horizontal distance between points.
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Vertical distance between points.
Double value between 0-1 (inclusive)