18 #include "qgsexpression.h" 36 void QgsSymbolLayer::initPropertyDefinitions()
38 if ( !sPropertyDefinitions.isEmpty() )
41 QString origin = QStringLiteral(
"symbol" );
107 Q_UNUSED( mmMapUnitScaleFactor );
108 Q_UNUSED( layerName );
143 return QVector<qreal>();
148 return Qt::SolidLine;
197 QgsSymbolLayer::initPropertyDefinitions();
198 return sPropertyDefinitions;
223 if ( !baseName.isEmpty() )
225 prefix.append( QStringLiteral(
"%1_dd_" ).arg( baseName ) );
228 if ( !map.contains( QStringLiteral(
"%1expression" ).arg( prefix ) ) )
234 bool active = ( map.value( QStringLiteral(
"%1active" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
235 QString expression = map.value( QStringLiteral(
"%1expression" ).arg( prefix ) );
236 bool useExpression = ( map.value( QStringLiteral(
"%1useexpr" ).arg( prefix ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
237 QString field = map.value( QStringLiteral(
"%1field" ).arg( prefix ), QString() );
246 static const QMap< QString, QgsSymbolLayer::Property > OLD_PROPS
323 QgsStringMap::const_iterator propIt = stringMap.constBegin();
324 for ( ; propIt != stringMap.constEnd(); ++propIt )
327 QString propertyName;
329 if ( propIt.key().endsWith( QLatin1String(
"_dd_expression" ) ) )
334 propertyName = propIt.key().left( propIt.key().length() - 14 );
338 else if ( propIt.key().endsWith( QLatin1String(
"_expression" ) ) )
343 propertyName = propIt.key().left( propIt.key().length() - 11 );
348 if ( !prop || !OLD_PROPS.contains( propertyName ) )
356 if ( propertyName == QLatin1String(
"width" ) )
358 else if ( propertyName == QLatin1String(
"color" ) )
407 if ( effect && effect->
enabled() )
410 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
414 renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
421 markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
426 markerOffset( context, width, height, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
433 offsetX = mOffset.x();
434 offsetY = mOffset.y();
440 if ( exprVal.isValid() )
443 offsetX = offset.x();
444 offsetY = offset.y();
456 if ( exprVal.isValid() )
458 horizontalAnchorPoint = decodeHorizontalAnchorPoint( exprVal.toString() );
464 if ( exprVal.isValid() )
466 verticalAnchorPoint = decodeVerticalAnchorPoint( exprVal.toString() );
471 if ( horizontalAnchorPoint == HCenter && verticalAnchorPoint == VCenter )
478 if ( horizontalAnchorPoint == Left )
480 offsetX += anchorPointCorrectionX;
482 else if ( horizontalAnchorPoint == Right )
484 offsetX -= anchorPointCorrectionX;
488 if ( verticalAnchorPoint == Top )
490 offsetY += anchorPointCorrectionY;
492 else if ( verticalAnchorPoint == Bottom )
494 offsetY -= anchorPointCorrectionY;
501 double c = std::cos( angle ), s = std::sin( angle );
502 return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
507 if ( str.compare( QLatin1String(
"left" ), Qt::CaseInsensitive ) == 0 )
511 else if ( str.compare( QLatin1String(
"right" ), Qt::CaseInsensitive ) == 0 )
523 if ( str.compare( QLatin1String(
"top" ), Qt::CaseInsensitive ) == 0 )
527 else if ( str.compare( QLatin1String(
"bottom" ), Qt::CaseInsensitive ) == 0 )
545 if ( mOffsetUnit != mSizeUnit )
554 mSizeMapUnitScale = scale;
555 mOffsetMapUnitScale = scale;
560 if ( mSizeMapUnitScale == mOffsetMapUnitScale )
562 return mSizeMapUnitScale;
579 mWidthMapUnitScale = scale;
584 return mWidthMapUnitScale;
593 points << QPointF( 0,
int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 );
597 if ( effect && effect->
enabled() )
600 renderPolyline( points, context );
604 renderPolyline( points, context );
611 renderPolyline( points, context );
614 Q_FOREACH (
const QPolygonF &ring, *rings )
615 renderPolyline( ring, context );
628 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) );
631 if ( effect && effect->
enabled() )
651 if ( points.size() <= 5 &&
654 ( p->renderHints() & QPainter::Antialiasing ) )
656 p->setRenderHint( QPainter::Antialiasing,
false );
657 p->drawRect( points.boundingRect() );
658 p->setRenderHint( QPainter::Antialiasing,
true );
664 if ( !rings && p->pen().style() == Qt::NoPen )
667 p->drawPolygon( points );
673 path.addPolygon( points );
677 QList<QPolygonF>::const_iterator it = rings->constBegin();
678 for ( ; it != rings->constEnd(); ++it )
680 QPolygonF ring = *it;
681 path.addPolygon( ring );
691 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PointSymbolizer" ) );
692 if ( !props.value( QStringLiteral(
"uom" ), QLatin1String(
"" ) ).isEmpty() )
693 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QLatin1String(
"" ) ) );
694 element.appendChild( symbolizerElem );
699 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
get dash pattern
Gradient reference point 1 is centroid.
double symbologyScale() const
Returns the reference scale for output.
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
QgsLineSymbolLayer(bool locked=false)
Positive integer values (including 0)
void setMapUnitScale(const QgsMapUnitScale &scale) override
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
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)
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
get offset
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits)
Calculates a scaling factor to convert from map units to a specified symbol unit. ...
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
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.
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 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
get line width
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
get 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)
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.
Align to bottom of symbol.
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'...
Gradient coordinate mode.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
virtual Qt::BrushStyle dxfBrushStyle() const
get brush/fill style
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.
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.
A store for object properties.
Fill style (eg solid, lines)
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Definition for a property.
HorizontalAnchorPoint
Symbol horizontal anchor points.
Gradient reference point 1 y.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
get 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
get pen style
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
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).
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
virtual double dxfAngle(QgsSymbolRenderContext &context) const
get angle
QgsMarkerSymbolLayer(bool locked=false)
Constructor for QgsMarkerSymbolLayer.
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
get color
QgsPaintEffect * mPaintEffect
Line style (eg solid/dashed)
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
Check whether the container is empty.
bool mEnabled
True if layer is enabled and should be drawn.
virtual ~QgsSymbolLayer()
virtual void renderPolygonStroke(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
QgsFillSymbolLayer(bool locked=false)
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
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
Horizontal distance between points.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Vertical distance between points.
Double value between 0-1 (inclusive)