QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgssymbollayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayer.cpp
3 ---------------------
4 begin : November 2009
5 copyright : (C) 2009 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgssymbollayer.h"
17#include "qgsrendercontext.h"
18#include "qgsdxfexport.h"
20#include "qgspainteffect.h"
22#include "qgsproperty.h"
24#include "qgssymbollayerutils.h"
25#include "qgslegendpatchshape.h"
26#include "qgsstyle.h"
28#include "qgssymbol.h"
30
31#include <QSize>
32#include <QPainter>
33#include <QPointF>
34#include <QPolygonF>
35#include <QUuid>
36
37QgsPropertiesDefinition QgsSymbolLayer::sPropertyDefinitions;
38
39void QgsSymbolLayer::initPropertyDefinitions()
40{
41 if ( !sPropertyDefinitions.isEmpty() )
42 return;
43
44 QString origin = QStringLiteral( "symbol" );
45
46 sPropertyDefinitions = QgsPropertiesDefinition
47 {
48 { QgsSymbolLayer::PropertySize, QgsPropertyDefinition( "size", QObject::tr( "Symbol size" ), QgsPropertyDefinition::Size, origin ) },
49 { QgsSymbolLayer::PropertyAngle, QgsPropertyDefinition( "angle", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation, origin ) },
50 { QgsSymbolLayer::PropertyName, QgsPropertyDefinition( "name", QObject::tr( "Symbol name" ), QgsPropertyDefinition::String, origin ) },
51 { QgsSymbolLayer::PropertyFillColor, QgsPropertyDefinition( "fillColor", QObject::tr( "Symbol fill color" ), QgsPropertyDefinition::ColorWithAlpha, origin ) },
52 { QgsSymbolLayer::PropertyStrokeColor, QgsPropertyDefinition( "outlineColor", QObject::tr( "Symbol stroke color" ), QgsPropertyDefinition::ColorWithAlpha, origin ) },
53 { QgsSymbolLayer::PropertyStrokeWidth, QgsPropertyDefinition( "outlineWidth", QObject::tr( "Symbol stroke width" ), QgsPropertyDefinition::StrokeWidth, origin ) },
54 { QgsSymbolLayer::PropertyStrokeStyle, QgsPropertyDefinition( "outlineStyle", QObject::tr( "Symbol stroke style" ), QgsPropertyDefinition::LineStyle, origin )},
55 { QgsSymbolLayer::PropertyOffset, QgsPropertyDefinition( "offset", QObject::tr( "Symbol offset" ), QgsPropertyDefinition::Offset, origin )},
56 { QgsSymbolLayer::PropertyCharacter, QgsPropertyDefinition( "char", QObject::tr( "Marker character(s)" ), QgsPropertyDefinition::String, origin )},
57 { QgsSymbolLayer::PropertyFontFamily, QgsPropertyDefinition( "fontFamily", QObject::tr( "Font family" ), QgsPropertyDefinition::String, origin )},
58 { QgsSymbolLayer::PropertyFontStyle, QgsPropertyDefinition( "fontStyle", QObject::tr( "Font style" ), QgsPropertyDefinition::String, origin )},
59 { QgsSymbolLayer::PropertyWidth, QgsPropertyDefinition( "width", QObject::tr( "Symbol width" ), QgsPropertyDefinition::DoublePositive, origin )},
60 { QgsSymbolLayer::PropertyHeight, QgsPropertyDefinition( "height", QObject::tr( "Symbol height" ), QgsPropertyDefinition::DoublePositive, origin )},
61 { QgsSymbolLayer::PropertyPreserveAspectRatio, QgsPropertyDefinition( "preserveAspectRatio", QObject::tr( "Preserve aspect ratio between width and height" ), QgsPropertyDefinition::Boolean, origin )},
62 { QgsSymbolLayer::PropertyFillStyle, QgsPropertyDefinition( "fillStyle", QObject::tr( "Symbol fill style" ), QgsPropertyDefinition::FillStyle, origin )},
63 { QgsSymbolLayer::PropertyJoinStyle, QgsPropertyDefinition( "joinStyle", QObject::tr( "Outline join style" ), QgsPropertyDefinition::PenJoinStyle, origin )},
64 { QgsSymbolLayer::PropertySecondaryColor, QgsPropertyDefinition( "color2", QObject::tr( "Secondary fill color" ), QgsPropertyDefinition::ColorWithAlpha, origin )},
65 { QgsSymbolLayer::PropertyLineAngle, QgsPropertyDefinition( "lineAngle", QObject::tr( "Angle for line fills" ), QgsPropertyDefinition::Rotation, origin )},
66 { QgsSymbolLayer::PropertyGradientType, QgsPropertyDefinition( "gradientType", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient type" ), QObject::tr( "string " ) + QLatin1String( "[<b>linear</b>|<b>radial</b>|<b>conical</b>]" ), origin )},
67 { QgsSymbolLayer::PropertyCoordinateMode, QgsPropertyDefinition( "gradientMode", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient mode" ), QObject::tr( "string " ) + QLatin1String( "[<b>feature</b>|<b>viewport</b>]" ), origin )},
68 { QgsSymbolLayer::PropertyGradientSpread, QgsPropertyDefinition( "gradientSpread", QgsPropertyDefinition::DataTypeString, QObject::tr( "Gradient spread" ), QObject::tr( "string " ) + QLatin1String( "[<b>pad</b>|<b>repeat</b>|<b>reflect</b>]" ), origin )},
69 { QgsSymbolLayer::PropertyGradientReference1X, QgsPropertyDefinition( "gradientRef1X", QObject::tr( "Reference point 1 (X)" ), QgsPropertyDefinition::Double0To1, origin )},
70 { QgsSymbolLayer::PropertyGradientReference1Y, QgsPropertyDefinition( "gradientRef1Y", QObject::tr( "Reference point 1 (Y)" ), QgsPropertyDefinition::Double0To1, origin )},
71 { QgsSymbolLayer::PropertyGradientReference2X, QgsPropertyDefinition( "gradientRef2X", QObject::tr( "Reference point 2 (X)" ), QgsPropertyDefinition::Double0To1, origin )},
72 { QgsSymbolLayer::PropertyGradientReference2Y, QgsPropertyDefinition( "gradientRef2Y", QObject::tr( "Reference point 2 (Y)" ), QgsPropertyDefinition::Double0To1, origin )},
73 { QgsSymbolLayer::PropertyGradientReference1IsCentroid, QgsPropertyDefinition( "gradientRef1Centroid", QObject::tr( "Reference point 1 follows feature centroid" ), QgsPropertyDefinition::Boolean, origin )},
74 { QgsSymbolLayer::PropertyGradientReference2IsCentroid, QgsPropertyDefinition( "gradientRef2Centroid", QObject::tr( "Reference point 2 follows feature centroid" ), QgsPropertyDefinition::Boolean, origin )},
75 { QgsSymbolLayer::PropertyBlurRadius, QgsPropertyDefinition( "blurRadius", QgsPropertyDefinition::DataTypeNumeric, QObject::tr( "Blur radius" ), QObject::tr( "Integer between 0 and 18" ), origin )},
76 { QgsSymbolLayer::PropertyLineDistance, QgsPropertyDefinition( "lineDistance", QObject::tr( "Distance between lines" ), QgsPropertyDefinition::DoublePositive, origin )},
77 { QgsSymbolLayer::PropertyShapeburstUseWholeShape, QgsPropertyDefinition( "shapeburstWholeShape", QObject::tr( "Shade whole shape" ), QgsPropertyDefinition::Boolean, origin )},
78 { QgsSymbolLayer::PropertyShapeburstMaxDistance, QgsPropertyDefinition( "shapeburstMaxDist", QObject::tr( "Maximum distance for shapeburst fill" ), QgsPropertyDefinition::DoublePositive, origin )},
79 { QgsSymbolLayer::PropertyShapeburstIgnoreRings, QgsPropertyDefinition( "shapeburstIgnoreRings", QObject::tr( "Ignore rings in feature" ), QgsPropertyDefinition::Boolean, origin )},
80 { QgsSymbolLayer::PropertyFile, QgsPropertyDefinition( "file", QObject::tr( "Symbol file path" ), QgsPropertyDefinition::String, origin )},
81 { QgsSymbolLayer::PropertyDistanceX, QgsPropertyDefinition( "distanceX", QObject::tr( "Horizontal distance between markers" ), QgsPropertyDefinition::DoublePositive, origin )},
82 { QgsSymbolLayer::PropertyDistanceY, QgsPropertyDefinition( "distanceY", QObject::tr( "Vertical distance between markers" ), QgsPropertyDefinition::DoublePositive, origin )},
83 { QgsSymbolLayer::PropertyDisplacementX, QgsPropertyDefinition( "displacementX", QObject::tr( "Horizontal displacement between rows" ), QgsPropertyDefinition::DoublePositive, origin )},
84 { QgsSymbolLayer::PropertyDisplacementY, QgsPropertyDefinition( "displacementY", QObject::tr( "Vertical displacement between columns" ), QgsPropertyDefinition::DoublePositive, origin )},
85 { QgsSymbolLayer::PropertyOffsetX, QgsPropertyDefinition( "offsetX", QObject::tr( "Horizontal offset" ), QgsPropertyDefinition::Double, origin )},
86 { QgsSymbolLayer::PropertyOffsetY, QgsPropertyDefinition( "offsetY", QObject::tr( "Vertical offset" ), QgsPropertyDefinition::Double, origin )},
87 { QgsSymbolLayer::PropertyOpacity, QgsPropertyDefinition( "alpha", QObject::tr( "Opacity" ), QgsPropertyDefinition::Opacity, origin )},
88 { QgsSymbolLayer::PropertyCustomDash, QgsPropertyDefinition( "customDash", QgsPropertyDefinition::DataTypeString, QObject::tr( "Custom dash pattern" ), QObject::tr( "[<b><dash>;<space></b>] e.g. '8;2;1;2'" ), origin )},
89 { QgsSymbolLayer::PropertyCapStyle, QgsPropertyDefinition( "capStyle", QObject::tr( "Line cap style" ), QgsPropertyDefinition::CapStyle, origin )},
90 { QgsSymbolLayer::PropertyPlacement, QgsPropertyDefinition( "placement", QgsPropertyDefinition::DataTypeString, QObject::tr( "Marker placement" ), QObject::tr( "string " ) + "[<b>interval</b>|<b>innervertices</b>|<b>vertex</b>|<b>lastvertex</b>|<b>firstvertex</b>|<b>centerpoint</b>|<b>curvepoint</b>|<b>segmentcenter</b>]", origin )},
91 { QgsSymbolLayer::PropertyInterval, QgsPropertyDefinition( "interval", QObject::tr( "Marker interval" ), QgsPropertyDefinition::DoublePositive, origin )},
92 { QgsSymbolLayer::PropertyOffsetAlongLine, QgsPropertyDefinition( "offsetAlongLine", QObject::tr( "Offset along line" ), QgsPropertyDefinition::Double, origin )},
93 { QgsSymbolLayer::PropertyAverageAngleLength, QgsPropertyDefinition( "averageAngleLength", QObject::tr( "Average line angles over" ), QgsPropertyDefinition::DoublePositive, origin )},
94 { QgsSymbolLayer::PropertyHorizontalAnchor, QgsPropertyDefinition( "hAnchor", QObject::tr( "Horizontal anchor point" ), QgsPropertyDefinition::HorizontalAnchor, origin )},
95 { QgsSymbolLayer::PropertyVerticalAnchor, QgsPropertyDefinition( "vAnchor", QObject::tr( "Vertical anchor point" ), QgsPropertyDefinition::VerticalAnchor, origin )},
96 { QgsSymbolLayer::PropertyLayerEnabled, QgsPropertyDefinition( "enabled", QObject::tr( "Layer enabled" ), QgsPropertyDefinition::Boolean, origin )},
97 { QgsSymbolLayer::PropertyArrowWidth, QgsPropertyDefinition( "arrowWidth", QObject::tr( "Arrow line width" ), QgsPropertyDefinition::StrokeWidth, origin )},
98 { QgsSymbolLayer::PropertyArrowStartWidth, QgsPropertyDefinition( "arrowStartWidth", QObject::tr( "Arrow line start width" ), QgsPropertyDefinition::StrokeWidth, origin )},
99 { QgsSymbolLayer::PropertyArrowHeadLength, QgsPropertyDefinition( "arrowHeadLength", QObject::tr( "Arrow head length" ), QgsPropertyDefinition::DoublePositive, origin )},
100 { QgsSymbolLayer::PropertyArrowHeadThickness, QgsPropertyDefinition( "arrowHeadThickness", QObject::tr( "Arrow head thickness" ), QgsPropertyDefinition::DoublePositive, origin )},
101 { QgsSymbolLayer::PropertyArrowHeadType, QgsPropertyDefinition( "arrowHeadType", QgsPropertyDefinition::DataTypeString, QObject::tr( "Arrow head type" ), QObject::tr( "string " ) + QLatin1String( "[<b>single</b>|<b>reversed</b>|<b>double</b>]" ), origin )},
102 { QgsSymbolLayer::PropertyArrowType, QgsPropertyDefinition( "arrowType", QgsPropertyDefinition::DataTypeString, QObject::tr( "Arrow type" ), QObject::tr( "string " ) + QLatin1String( "[<b>plain</b>|<b>lefthalf</b>|<b>righthalf</b>]" ), origin )},
103 { QgsSymbolLayer::PropertyPointCount, QgsPropertyDefinition( "pointCount", QObject::tr( "Point count" ), QgsPropertyDefinition::IntegerPositive, origin )},
104 { QgsSymbolLayer::PropertyRandomSeed, QgsPropertyDefinition( "randomSeed", QgsPropertyDefinition::DataTypeNumeric, QObject::tr( "Random number seed" ), QObject::tr( "integer > 0, or 0 for completely random sequence" ), origin )},
105 { QgsSymbolLayer::PropertyClipPoints, QgsPropertyDefinition( "clipPoints", QObject::tr( "Clip markers" ), QgsPropertyDefinition::Boolean, origin )},
106 { QgsSymbolLayer::PropertyClipPoints, QgsPropertyDefinition( "densityArea", QObject::tr( "Density area" ), QgsPropertyDefinition::DoublePositive, origin )},
107 { QgsSymbolLayer::PropertyDashPatternOffset, QgsPropertyDefinition( "dashPatternOffset", QObject::tr( "Dash pattern offset" ), QgsPropertyDefinition::DoublePositive, origin )},
108 { QgsSymbolLayer::PropertyTrimStart, QgsPropertyDefinition( "trimStart", QObject::tr( "Start trim distance" ), QgsPropertyDefinition::DoublePositive, origin )},
109 { QgsSymbolLayer::PropertyTrimEnd, QgsPropertyDefinition( "trimEnd", QObject::tr( "End trim distance" ), QgsPropertyDefinition::DoublePositive, origin )},
110 { QgsSymbolLayer::PropertyLineStartWidthValue, QgsPropertyDefinition( "lineStartWidthValue", QObject::tr( "Line start width value" ), QgsPropertyDefinition::Double, origin )},
111 { QgsSymbolLayer::PropertyLineEndWidthValue, QgsPropertyDefinition( "lineEndWidthValue", QObject::tr( "Line end width value" ), QgsPropertyDefinition::Double, origin )},
112 { QgsSymbolLayer::PropertyLineStartColorValue, QgsPropertyDefinition( "lineStartColorValue", QObject::tr( "Line start color value" ), QgsPropertyDefinition::Double, origin )},
113 { QgsSymbolLayer::PropertyLineEndColorValue, QgsPropertyDefinition( "lineEndColorValue", QObject::tr( "Line end color value" ), QgsPropertyDefinition::Double, origin )},
114 { QgsSymbolLayer::PropertyMarkerClipping, QgsPropertyDefinition( "markerClipping", QgsPropertyDefinition::DataTypeString, QObject::tr( "Marker clipping mode" ), QObject::tr( "string " ) + QLatin1String( "[<b>no</b>|<b>shape</b>|<b>centroid_within</b>|<b>completely_within</b>]" ), origin )},
115 { QgsSymbolLayer::PropertyRandomOffsetX, QgsPropertyDefinition( "randomOffsetX", QObject::tr( "Horizontal random offset" ), QgsPropertyDefinition::Double, origin )},
116 { QgsSymbolLayer::PropertyRandomOffsetY, QgsPropertyDefinition( "randomOffsetY", QObject::tr( "Vertical random offset" ), QgsPropertyDefinition::Double, origin )},
117 { QgsSymbolLayer::PropertyLineClipping, QgsPropertyDefinition( "lineClipping", QgsPropertyDefinition::DataTypeString, QObject::tr( "Line clipping mode" ), QObject::tr( "string " ) + QLatin1String( "[<b>no</b>|<b>during_render</b>|<b>before_render</b>]" ), origin )},
118 };
119}
120
122{
123 dataDefinedProperties().setProperty( key, property );
124}
125
127{
128 installMasks( context, false );
129
130 if ( QgsSymbol *lSubSymbol = subSymbol() )
131 lSubSymbol->startFeatureRender( feature, context );
132}
133
135{
136 if ( QgsSymbol *lSubSymbol = subSymbol() )
137 lSubSymbol->stopFeatureRender( feature, context );
138
139 removeMasks( context, false );
140}
141
143{
144 return nullptr;
145}
146
148{
149 delete symbol;
150 return false;
151}
152
153bool QgsSymbolLayer::writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift ) const
154{
155 Q_UNUSED( e )
156 Q_UNUSED( mmMapUnitScaleFactor )
157 Q_UNUSED( layerName )
158 Q_UNUSED( context )
159 Q_UNUSED( shift )
160 return false;
161}
162
164{
165 Q_UNUSED( e )
166 Q_UNUSED( context )
167 return 1.0;
168}
169
171{
172 Q_UNUSED( e )
173 Q_UNUSED( context )
174 return 0.0;
175}
176
178{
179 Q_UNUSED( context )
180 return color();
181}
182
184{
185 Q_UNUSED( context )
186 return 0.0;
187}
188
190{
191 Q_UNUSED( unit )
192 return QVector<qreal>();
193}
194
195Qt::PenStyle QgsSymbolLayer::dxfPenStyle() const
196{
197 return Qt::SolidLine;
198}
199
201{
202 Q_UNUSED( context )
203 return color();
204}
205
206Qt::BrushStyle QgsSymbolLayer::dxfBrushStyle() const
207{
208 return Qt::NoBrush;
209}
210
212{
213 return mPaintEffect.get();
214}
215
217{
218 if ( effect == mPaintEffect.get() )
219 return;
220
221 mPaintEffect.reset( effect );
222}
223
225 : mType( type )
226 , mLocked( locked )
227 , mId( QUuid::createUuid().toString() )
228{
229}
230
231Qgis::SymbolLayerFlags QgsSymbolLayer::flags() const
232{
233 return Qgis::SymbolLayerFlags();
234}
235
237{
238 return mColor;
239}
240
241void QgsSymbolLayer::setColor( const QColor &color )
242{
243 mColor = color;
244}
245
246void QgsSymbolLayer::setStrokeColor( const QColor & )
247{
248
249}
250
252{
253 return QColor();
254}
255
256void QgsSymbolLayer::setFillColor( const QColor & )
257{
258}
259
261{
262 return QColor();
263}
264
266{
268
269 if ( !context.fields().isEmpty() )
270 {
271 //QgsFields is implicitly shared, so it's cheap to make a copy
272 mFields = context.fields();
273 }
274}
275
277{
279}
280
282{
283 QgsSymbolLayer::initPropertyDefinitions();
284 return sPropertyDefinitions;
285}
286
288
290{
292 return true;
293
294 return symbol->type() == mType;
295}
296
298{
299 return false;
300}
301
303{
304 return false;
305}
306
307void QgsSymbolLayer::setRenderingPass( int renderingPass )
308{
310}
311
313{
314 return mRenderingPass;
315}
316
317QSet<QString> QgsSymbolLayer::usedAttributes( const QgsRenderContext &context ) const
318{
319 // calling referencedFields() with ignoreContext=true because in our expression context
320 // we do not have valid QgsFields yet - because of that the field names from expressions
321 // wouldn't get reported
322 QSet<QString> columns = mDataDefinedProperties.referencedFields( context.expressionContext(), true );
323 return columns;
324}
325
326QgsProperty propertyFromMap( const QVariantMap &map, const QString &baseName )
327{
328 QString prefix;
329 if ( !baseName.isEmpty() )
330 {
331 prefix.append( QStringLiteral( "%1_dd_" ).arg( baseName ) );
332 }
333
334 if ( !map.contains( QStringLiteral( "%1expression" ).arg( prefix ) ) )
335 {
336 //requires at least the expression value
337 return QgsProperty();
338 }
339
340 bool active = ( map.value( QStringLiteral( "%1active" ).arg( prefix ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
341 QString expression = map.value( QStringLiteral( "%1expression" ).arg( prefix ) ).toString();
342 bool useExpression = ( map.value( QStringLiteral( "%1useexpr" ).arg( prefix ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
343 QString field = map.value( QStringLiteral( "%1field" ).arg( prefix ), QString() ).toString();
344
345 if ( useExpression )
346 return QgsProperty::fromExpression( expression, active );
347 else
348 return QgsProperty::fromField( field, active );
349}
350
351void QgsSymbolLayer::restoreOldDataDefinedProperties( const QVariantMap &stringMap )
352{
353 // property string to type upgrade map
354 static const QMap< QString, QgsSymbolLayer::Property > OLD_PROPS
355 {
357 { "arrow_width", QgsSymbolLayer::PropertyArrowWidth },
358 { "arrow_start_width", QgsSymbolLayer::PropertyArrowStartWidth },
360 { "head_thickness", QgsSymbolLayer::PropertyArrowHeadThickness },
361 { "offset", QgsSymbolLayer::PropertyOffset },
363 { "arrow_type", QgsSymbolLayer::PropertyArrowType },
364 { "width_field", QgsSymbolLayer::PropertyWidth },
365 { "height_field", QgsSymbolLayer::PropertyHeight },
366 { "rotation_field", QgsSymbolLayer::PropertyAngle },
367 { "outline_width_field", QgsSymbolLayer::PropertyStrokeWidth },
368 { "fill_color_field", QgsSymbolLayer::PropertyFillColor },
369 { "outline_color_field", QgsSymbolLayer::PropertyStrokeColor },
370 { "symbol_name_field", QgsSymbolLayer::PropertyName },
371 { "outline_width", QgsSymbolLayer::PropertyStrokeWidth },
372 { "outline_style", QgsSymbolLayer::PropertyStrokeStyle },
373 { "join_style", QgsSymbolLayer::PropertyJoinStyle },
374 { "fill_color", QgsSymbolLayer::PropertyFillColor },
375 { "outline_color", QgsSymbolLayer::PropertyStrokeColor },
377 { "height", QgsSymbolLayer::PropertyHeight },
378 { "symbol_name", QgsSymbolLayer::PropertyName },
380 { "fill_style", QgsSymbolLayer::PropertyFillStyle },
381 { "color_border", QgsSymbolLayer::PropertyStrokeColor },
382 { "width_border", QgsSymbolLayer::PropertyStrokeWidth },
383 { "border_color", QgsSymbolLayer::PropertyStrokeColor },
384 { "border_style", QgsSymbolLayer::PropertyStrokeStyle },
386 { "gradient_type", QgsSymbolLayer::PropertyGradientType },
387 { "coordinate_mode", QgsSymbolLayer::PropertyCoordinateMode },
393 { "reference1_iscentroid", QgsSymbolLayer::PropertyGradientReference1IsCentroid },
394 { "reference2_iscentroid", QgsSymbolLayer::PropertyGradientReference2IsCentroid },
395 { "blur_radius", QgsSymbolLayer::PropertyBlurRadius },
399 { "svgFillColor", QgsSymbolLayer::PropertyFillColor },
400 { "svgOutlineColor", QgsSymbolLayer::PropertyStrokeColor },
401 { "svgOutlineWidth", QgsSymbolLayer::PropertyStrokeWidth },
402 { "svgFile", QgsSymbolLayer::PropertyFile },
403 { "lineangle", QgsSymbolLayer::PropertyLineAngle },
405 { "distance_x", QgsSymbolLayer::PropertyDistanceX },
406 { "distance_y", QgsSymbolLayer::PropertyDistanceY },
407 { "displacement_x", QgsSymbolLayer::PropertyDisplacementX },
408 { "displacement_y", QgsSymbolLayer::PropertyDisplacementY },
411 { "customdash", QgsSymbolLayer::PropertyCustomDash },
412 { "line_style", QgsSymbolLayer::PropertyStrokeStyle },
413 { "joinstyle", QgsSymbolLayer::PropertyJoinStyle },
414 { "capstyle", QgsSymbolLayer::PropertyCapStyle },
415 { "placement", QgsSymbolLayer::PropertyPlacement },
416 { "interval", QgsSymbolLayer::PropertyInterval },
417 { "offset_along_line", QgsSymbolLayer::PropertyOffsetAlongLine },
424 { "rotation", QgsSymbolLayer::PropertyAngle },
425 { "horizontal_anchor_point", QgsSymbolLayer::PropertyHorizontalAnchor },
426 { "vertical_anchor_point", QgsSymbolLayer::PropertyVerticalAnchor },
427 };
428
429 QVariantMap::const_iterator propIt = stringMap.constBegin();
430 for ( ; propIt != stringMap.constEnd(); ++propIt )
431 {
432 std::unique_ptr<QgsProperty> prop;
433 QString propertyName;
434
435 if ( propIt.key().endsWith( QLatin1String( "_dd_expression" ) ) )
436 {
437 //found a data defined property
438
439 //get data defined property name by stripping "_dd_expression" from property key
440 propertyName = propIt.key().left( propIt.key().length() - 14 );
441
442 prop = std::make_unique<QgsProperty>( propertyFromMap( stringMap, propertyName ) );
443 }
444 else if ( propIt.key().endsWith( QLatin1String( "_expression" ) ) )
445 {
446 //old style data defined property, upgrade
447
448 //get data defined property name by stripping "_expression" from property key
449 propertyName = propIt.key().left( propIt.key().length() - 11 );
450
451 prop = std::make_unique<QgsProperty>( QgsProperty::fromExpression( propIt.value().toString() ) );
452 }
453
454 if ( !prop || !OLD_PROPS.contains( propertyName ) )
455 continue;
456
457 QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( OLD_PROPS.value( propertyName ) );
458
459 if ( type() == Qgis::SymbolType::Line )
460 {
461 //these keys had different meaning for line symbol layers
462 if ( propertyName == QLatin1String( "width" ) )
464 else if ( propertyName == QLatin1String( "color" ) )
466 }
467
468 setDataDefinedProperty( key, QgsProperty( *prop.get() ) );
469 }
470}
471
473{
474 if ( !destLayer )
475 return;
476
478}
479
481{
482 if ( !destLayer || !mPaintEffect )
483 return;
484
486 destLayer->setPaintEffect( mPaintEffect->clone() );
487 else
488 destLayer->setPaintEffect( nullptr );
489}
490
492 : QgsSymbolLayer( Qgis::SymbolType::Marker, locked )
493{
494
495}
496
498 : QgsSymbolLayer( Qgis::SymbolType::Line, locked )
499{
500}
501
503{
504 return mRingFilter;
505}
506
508{
509 mRingFilter = filter;
510}
511
513 : QgsSymbolLayer( Qgis::SymbolType::Fill, locked )
514{
515}
516
518{
519 Q_UNUSED( context )
520}
521
523{
524 Q_UNUSED( context )
525}
526
528{
529 startRender( context );
530 QgsPaintEffect *effect = paintEffect();
531
532 QPolygonF points = context.patchShape() ? context.patchShape()->toQPolygonF( Qgis::SymbolType::Marker, size ).value( 0 ).value( 0 )
534
535 std::unique_ptr< QgsEffectPainter > effectPainter;
536 if ( effect && effect->enabled() )
537 effectPainter = std::make_unique< QgsEffectPainter >( context.renderContext(), effect );
538
539 for ( QPointF point : std::as_const( points ) )
540 renderPoint( point, context );
541
542 effectPainter.reset();
543
544 stopRender( context );
545}
546
547void QgsMarkerSymbolLayer::markerOffset( QgsSymbolRenderContext &context, double &offsetX, double &offsetY ) const
548{
550}
551
552void QgsMarkerSymbolLayer::markerOffset( QgsSymbolRenderContext &context, double width, double height, double &offsetX, double &offsetY ) const
553{
554 markerOffset( context, width, height, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
555}
556
557void QgsMarkerSymbolLayer::markerOffset( QgsSymbolRenderContext &context, double width, double height,
558 Qgis::RenderUnit widthUnit, Qgis::RenderUnit heightUnit,
559 double &offsetX, double &offsetY, const QgsMapUnitScale &widthMapUnitScale, const QgsMapUnitScale &heightMapUnitScale ) const
560{
561 offsetX = mOffset.x();
562 offsetY = mOffset.y();
563
565 {
568 bool ok = false;
569 const QPointF offset = QgsSymbolLayerUtils::toPoint( exprVal, &ok );
570 if ( ok )
571 {
572 offsetX = offset.x();
573 offsetY = offset.y();
574 }
575 }
576
579
583 {
585 if ( !QgsVariantUtils::isNull( exprVal ) )
586 {
587 horizontalAnchorPoint = decodeHorizontalAnchorPoint( exprVal.toString() );
588 }
589 }
591 {
593 if ( !QgsVariantUtils::isNull( exprVal ) )
594 {
595 verticalAnchorPoint = decodeVerticalAnchorPoint( exprVal.toString() );
596 }
597 }
598
599 //correct horizontal position according to anchor point
601 {
602 return;
603 }
604
605 double anchorPointCorrectionX = context.renderContext().convertToPainterUnits( width, widthUnit, widthMapUnitScale ) / 2.0;
606 if ( widthUnit == Qgis::RenderUnit::MetersInMapUnits && context.renderContext().flags() & Qgis::RenderContextFlag::RenderSymbolPreview )
607 {
608 // rendering for symbol previews -- an size in meters in map units can't be calculated, so treat the size as millimeters
609 // and clamp it to a reasonable range. It's the best we can do in this situation!
610 anchorPointCorrectionX = std::min( std::max( context.renderContext().convertToPainterUnits( width, Qgis::RenderUnit::Millimeters ), 3.0 ), 100.0 ) / 2.0;
611 }
612
613 double anchorPointCorrectionY = context.renderContext().convertToPainterUnits( height, heightUnit, heightMapUnitScale ) / 2.0;
614 if ( heightUnit == Qgis::RenderUnit::MetersInMapUnits && context.renderContext().flags() & Qgis::RenderContextFlag::RenderSymbolPreview )
615 {
616 // rendering for symbol previews -- an size in meters in map units can't be calculated, so treat the size as millimeters
617 // and clamp it to a reasonable range. It's the best we can do in this situation!
618 anchorPointCorrectionY = std::min( std::max( context.renderContext().convertToPainterUnits( height, Qgis::RenderUnit::Millimeters ), 3.0 ), 100.0 ) / 2.0;
619 }
620
622 {
623 offsetX += anchorPointCorrectionX;
624 }
625 else if ( horizontalAnchorPoint == Right )
626 {
627 offsetX -= anchorPointCorrectionX;
628 }
629
630 //correct vertical position according to anchor point
631 if ( verticalAnchorPoint == Top )
632 {
633 offsetY += anchorPointCorrectionY;
634 }
635 else if ( verticalAnchorPoint == Bottom )
636 {
637 offsetY -= anchorPointCorrectionY;
638 }
639}
640
641QPointF QgsMarkerSymbolLayer::_rotatedOffset( QPointF offset, double angle )
642{
643 angle = DEG2RAD( angle );
644 double c = std::cos( angle ), s = std::sin( angle );
645 return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
646}
647
648QgsMarkerSymbolLayer::HorizontalAnchorPoint QgsMarkerSymbolLayer::decodeHorizontalAnchorPoint( const QString &str )
649{
650 if ( str.compare( QLatin1String( "left" ), Qt::CaseInsensitive ) == 0 )
651 {
653 }
654 else if ( str.compare( QLatin1String( "right" ), Qt::CaseInsensitive ) == 0 )
655 {
657 }
658 else
659 {
661 }
662}
663
664QgsMarkerSymbolLayer::VerticalAnchorPoint QgsMarkerSymbolLayer::decodeVerticalAnchorPoint( const QString &str )
665{
666 if ( str.compare( QLatin1String( "top" ), Qt::CaseInsensitive ) == 0 )
667 {
669 }
670 else if ( str.compare( QLatin1String( "bottom" ), Qt::CaseInsensitive ) == 0 )
671 {
673 }
674 else
675 {
677 }
678}
679
681{
682 mSizeUnit = unit;
683 mOffsetUnit = unit;
684}
685
687{
688 if ( mOffsetUnit != mSizeUnit )
689 {
690 return Qgis::RenderUnit::Unknown;
691 }
692 return mOffsetUnit;
693}
694
696{
697 mSizeMapUnitScale = scale;
698 mOffsetMapUnitScale = scale;
699}
700
702{
704 {
705 return mSizeMapUnitScale;
706 }
707 return QgsMapUnitScale();
708}
709
711{
712 mWidthUnit = unit;
713 mOffsetUnit = unit;
714}
715
717{
718 return mWidthUnit;
719}
720
722{
723 mWidthMapUnitScale = scale;
724}
725
727{
728 return mWidthMapUnitScale;
729}
730
731
733{
734 const QList< QList< QPolygonF > > points = context.patchShape() ? context.patchShape()->toQPolygonF( Qgis::SymbolType::Line, size )
736 startRender( context );
737 QgsPaintEffect *effect = paintEffect();
738
739 std::unique_ptr< QgsEffectPainter > effectPainter;
740 if ( effect && effect->enabled() )
741 effectPainter = std::make_unique< QgsEffectPainter >( context.renderContext(), effect );
742
743 for ( const QList< QPolygonF > &line : points )
744 renderPolyline( line.value( 0 ), context );
745
746 effectPainter.reset();
747
748 stopRender( context );
749}
750
751void QgsLineSymbolLayer::renderPolygonStroke( const QPolygonF &points, const QVector<QPolygonF> *rings, QgsSymbolRenderContext &context )
752{
753 QgsExpressionContextScope *scope = nullptr;
754 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
756 {
757 scope = new QgsExpressionContextScope();
758 scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.renderContext().expressionContext(), scope );
759 }
760
761 switch ( mRingFilter )
762 {
763 case AllRings:
764 case ExteriorRingOnly:
765 {
766 if ( scope )
768 renderPolyline( points, context );
769 break;
770 }
772 break;
773 }
774
775 if ( rings )
776 {
777 switch ( mRingFilter )
778 {
779 case AllRings:
781 {
782 int ringIndex = 1;
783 for ( const QPolygonF &ring : std::as_const( *rings ) )
784 {
785 if ( scope )
787
788 renderPolyline( ring, context );
789 ringIndex++;
790 }
791 }
792 break;
793 case ExteriorRingOnly:
794 break;
795 }
796 }
797}
798
799double QgsLineSymbolLayer::width( const QgsRenderContext &context ) const
800{
802}
803
805{
806 Q_UNUSED( context )
808}
809
810
812{
813 const QList< QList< QPolygonF > > polys = context.patchShape() ? context.patchShape()->toQPolygonF( Qgis::SymbolType::Fill, size )
815
816 startRender( context );
817 QgsPaintEffect *effect = paintEffect();
818
819 std::unique_ptr< QgsEffectPainter > effectPainter;
820 if ( effect && effect->enabled() )
821 effectPainter = std::make_unique< QgsEffectPainter >( context.renderContext(), effect );
822
823 for ( const QList< QPolygonF > &poly : polys )
824 {
825 QVector< QPolygonF > rings;
826 for ( int i = 1; i < poly.size(); ++i )
827 rings << poly.at( i );
828 renderPolygon( poly.value( 0 ), &rings, context );
829 }
830
831 effectPainter.reset();
832
833 stopRender( context );
834}
835
837{
838 return QImage();
839}
840
841void QgsFillSymbolLayer::_renderPolygon( QPainter *p, const QPolygonF &points, const QVector<QPolygonF> *rings, QgsSymbolRenderContext &context )
842{
843 if ( !p )
844 {
845 return;
846 }
847
848 // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
849 if ( points.size() <= 5 &&
852 ( p->renderHints() & QPainter::Antialiasing ) )
853 {
854 p->setRenderHint( QPainter::Antialiasing, false );
855 p->drawRect( points.boundingRect() );
856 p->setRenderHint( QPainter::Antialiasing, true );
857 return;
858 }
859
860 // polygons outlines are sometimes rendered wrongly with drawPolygon, when
861 // clipped (see #13343), so use drawPath instead.
862 if ( !rings && p->pen().style() == Qt::NoPen )
863 {
864 // simple polygon without holes
865 p->drawPolygon( points );
866 }
867 else
868 {
869 // polygon with holes must be drawn using painter path
870 QPainterPath path;
871 path.addPolygon( points );
872
873 if ( rings )
874 {
875 for ( auto it = rings->constBegin(); it != rings->constEnd(); ++it )
876 {
877 QPolygonF ring = *it;
878 path.addPolygon( ring );
879 }
880 }
881
882 p->drawPath( path );
883 }
884}
885
886void QgsMarkerSymbolLayer::toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props ) const
887{
888 QDomElement symbolizerElem = doc.createElement( QStringLiteral( "se:PointSymbolizer" ) );
889 if ( !props.value( QStringLiteral( "uom" ), QString() ).toString().isEmpty() )
890 symbolizerElem.setAttribute( QStringLiteral( "uom" ), props.value( QStringLiteral( "uom" ), QString() ).toString() );
891 element.appendChild( symbolizerElem );
892
893 // <Geometry>
894 QgsSymbolLayerUtils::createGeometryElement( doc, symbolizerElem, props.value( QStringLiteral( "geom" ), QString() ).toString() );
895
896 writeSldMarker( doc, symbolizerElem, props );
897}
898
899QList<QgsSymbolLayerReference> QgsSymbolLayer::masks() const
900{
901 return {};
902}
903
905{
906 mClipPath.clear();
907
908 const QgsRenderContext &renderContext = context.renderContext();
909 const QList<QPainterPath> clipPaths = renderContext.symbolLayerClipPaths( id() );
910 if ( !clipPaths.isEmpty() )
911 {
912 QPainterPath mergedPaths;
913 mergedPaths.setFillRule( Qt::WindingFill );
914 for ( QPainterPath path : clipPaths )
915 {
916 mergedPaths.addPath( path );
917 }
918
919 if ( !mergedPaths.isEmpty() )
920 {
921 mClipPath.addRect( 0, 0, renderContext.outputSize().width(),
922 renderContext.outputSize().height() );
923 mClipPath = mClipPath.subtracted( mergedPaths );
924 }
925 }
926}
927
928void QgsSymbolLayer::installMasks( QgsRenderContext &context, bool recursive )
929{
930 if ( !mClipPath.isEmpty() )
931 {
932 context.painter()->save();
933 context.painter()->setClipPath( mClipPath, Qt::IntersectClip );
934 }
935
936 if ( QgsSymbol *lSubSymbol = recursive ? subSymbol() : nullptr )
937 {
938 for ( QgsSymbolLayer *sl : lSubSymbol->symbolLayers() )
939 sl->installMasks( context, true );
940 }
941}
942
943void QgsSymbolLayer::removeMasks( QgsRenderContext &context, bool recursive )
944{
945 if ( !mClipPath.isEmpty() )
946 {
947 context.painter()->restore();
948 }
949
950 if ( QgsSymbol *lSubSymbol = recursive ? subSymbol() : nullptr )
951 {
952 for ( QgsSymbolLayer *sl : lSubSymbol->symbolLayers() )
953 sl->removeMasks( context, true );
954 }
955}
956
957
958void QgsSymbolLayer::setId( const QString &id )
959{
960 mId = id;
961}
962
963QString QgsSymbolLayer::id() const
964{
965 return mId;
966}
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:55
RenderUnit
Rendering size units.
Definition: qgis.h:3176
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
SymbolType
Symbol types.
Definition: qgis.h:320
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
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...
Exports QGIS layers to the DXF format.
Definition: qgsdxfexport.h:65
static double mapUnitScaleFactor(double scale, Qgis::RenderUnit symbolUnits, Qgis::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
Qgis::DistanceUnit mapUnits() const
Retrieve map units.
double symbologyScale() const
Returns the reference scale for output.
Definition: qgsdxfexport.h:229
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
bool isEmpty() const
Checks whether the container is empty.
Definition: qgsfields.cpp:128
virtual void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context)=0
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
void _renderPolygon(QPainter *p, const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context)
Default method to render polygon.
virtual QImage toTiledPatternImage() const
Renders the symbol layer as an image that can be used as a seamless pattern fill for polygons,...
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
QgsFillSymbolLayer(const QgsFillSymbolLayer &other)=delete
QgsFillSymbolLayer cannot be copied.
QList< QList< QPolygonF > > toQPolygonF(Qgis::SymbolType type, QSizeF size) const
Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for...
Qgis::RenderUnit mOffsetUnit
RenderRingFilter
Options for filtering rings when the line symbol layer is being used to render a polygon's rings.
@ ExteriorRingOnly
Render the exterior ring only.
@ InteriorRingsOnly
Render the interior rings only.
@ AllRings
Render both exterior and interior rings.
QgsMapUnitScale mWidthMapUnitScale
RenderRingFilter ringFilter() const
Returns the line symbol layer's ring filter, which controls which rings are rendered when the line sy...
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
QgsLineSymbolLayer(const QgsLineSymbolLayer &other)=delete
QgsLineSymbolLayer cannot be copied.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
virtual void renderPolygonStroke(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context)
Renders the line symbol layer along the outline of polygon, using the given render context.
Qgis::RenderUnit mWidthUnit
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
Renders the line symbol layer along the line joining points, using the given render context.
RenderRingFilter mRingFilter
virtual double width() const
Returns the estimated width for the line symbol layer.
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
QgsMapUnitScale mapUnitScale() const override
void setRingFilter(QgsLineSymbolLayer::RenderRingFilter filter)
Sets the line symbol layer's ring filter, which controls which rings are rendered when the line symbo...
void setMapUnitScale(const QgsMapUnitScale &scale) override
Qgis::RenderUnit widthUnit() const
Returns the units for the line's width.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
Struct for storing maximum and minimum scales for measurements in map units.
double mSize
Marker size.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Qgis::RenderUnit mOffsetUnit
Offset units.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
HorizontalAnchorPoint
Symbol horizontal anchor points.
@ Right
Align to right side of symbol.
@ HCenter
Align to horizontal center of symbol.
@ Left
Align to left side of symbol.
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
QPointF mOffset
Marker offset.
QgsMapUnitScale mapUnitScale() const override
double size() const
Returns the symbol size.
QgsMapUnitScale mOffsetMapUnitScale
Offset map unit scale.
HorizontalAnchorPoint mHorizontalAnchorPoint
Horizontal anchor point.
QgsMarkerSymbolLayer(const QgsMarkerSymbolLayer &other)=delete
QgsMarkerSymbolLayer cannot be copied.
static QPointF _rotatedOffset(QPointF offset, double angle)
Adjusts a marker offset to account for rotation.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
QgsMapUnitScale mSizeMapUnitScale
Marker size map unit scale.
Qgis::RenderUnit mSizeUnit
Marker size unit.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
VerticalAnchorPoint
Symbol vertical anchor points.
@ VCenter
Align to vertical center of symbol.
@ Bottom
Align to bottom of symbol.
@ Top
Align to top of symbol.
void markerOffset(QgsSymbolRenderContext &context, double &offsetX, double &offsetY) const
Calculates the required marker offset, including both the symbol offset and any displacement required...
VerticalAnchorPoint mVerticalAnchorPoint
Vertical anchor point.
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const
Writes the symbol layer definition as a SLD XML element.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
void setMapUnitScale(const QgsMapUnitScale &scale) override
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.
bool enabled() const
Returns whether the effect is enabled.
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 setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const override
Returns the set of any fields referenced by the active properties from the collection.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Definition for a property.
Definition: qgsproperty.h:46
@ HorizontalAnchor
Horizontal anchor point.
Definition: qgsproperty.h:74
@ Double
Double value (including negative values)
Definition: qgsproperty.h:56
@ VerticalAnchor
Vertical anchor point.
Definition: qgsproperty.h:75
@ Double0To1
Double value between 0-1 (inclusive)
Definition: qgsproperty.h:58
@ FillStyle
Fill style (eg solid, lines)
Definition: qgsproperty.h:72
@ StrokeWidth
Line stroke width.
Definition: qgsproperty.h:71
@ LineStyle
Line style (eg solid/dashed)
Definition: qgsproperty.h:70
@ String
Any string value.
Definition: qgsproperty.h:60
@ Boolean
Boolean value.
Definition: qgsproperty.h:52
@ PenJoinStyle
Pen join style.
Definition: qgsproperty.h:65
@ IntegerPositive
Positive integer values (including 0)
Definition: qgsproperty.h:54
@ Opacity
Opacity (0-100)
Definition: qgsproperty.h:61
@ CapStyle
Line cap style (eg round)
Definition: qgsproperty.h:73
@ Rotation
Rotation (value between 0-360 degrees)
Definition: qgsproperty.h:59
@ Size
1D size (eg marker radius, or square marker height/width)
Definition: qgsproperty.h:68
@ ColorWithAlpha
Color with alpha channel.
Definition: qgsproperty.h:63
@ DoublePositive
Positive double value (including 0)
Definition: qgsproperty.h:57
@ DataTypeString
Property requires a string value.
Definition: qgsproperty.h:91
@ DataTypeNumeric
Property requires a numeric value.
Definition: qgsproperty.h:98
A store for object properties.
Definition: qgsproperty.h:230
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
QList< QPainterPath > symbolLayerClipPaths(const QString &symbolLayerId) const
Returns clip paths to be applied to the symbolLayer before rendering.
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(Qgis::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
Definition: qgsstyle.cpp:1205
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
Property
Data definable properties.
@ PropertyGradientReference1X
Gradient reference point 1 x.
@ PropertyShapeburstIgnoreRings
Shapeburst ignore rings.
@ PropertyGradientReference2X
Gradient reference point 2 x.
@ PropertyStrokeStyle
Stroke style (eg solid, dashed)
@ PropertyPlacement
Line marker placement.
@ PropertyHorizontalAnchor
Horizontal anchor point.
@ PropertyPreserveAspectRatio
Preserve aspect ratio between width and height.
@ PropertyDistanceX
Horizontal distance between points.
@ PropertyFile
Filename, eg for svg files.
@ PropertyGradientType
Gradient fill type.
@ PropertyCapStyle
Line cap style.
@ PropertyLineEndWidthValue
End line width for interpolated line renderer (since QGIS 3.22)
@ PropertyLineEndColorValue
End line color for interpolated line renderer (since QGIS 3.22)
@ PropertyAngle
Symbol angle.
@ PropertyLineClipping
Line clipping mode (since QGIS 3.24)
@ PropertyDistanceY
Vertical distance between points.
@ PropertyDisplacementX
Horizontal displacement.
@ PropertyVerticalAnchor
Vertical anchor point.
@ PropertyGradientSpread
Gradient spread mode.
@ PropertyOffsetY
Vertical offset.
@ PropertyGradientReference1Y
Gradient reference point 1 y.
@ PropertyLineDistance
Distance between lines, or length of lines for hash line symbols.
@ PropertyOffsetAlongLine
Offset along line.
@ PropertyLineStartColorValue
Start line color for interpolated line renderer (since QGIS 3.22)
@ PropertyArrowStartWidth
Arrow tail start width.
@ PropertyBlurRadius
Shapeburst blur radius.
@ PropertyGradientReference2Y
Gradient reference point 2 y.
@ PropertyMarkerClipping
Marker clipping mode (since QGIS 3.24)
@ PropertyArrowHeadLength
Arrow head length.
@ PropertyGradientReference1IsCentroid
Gradient reference point 1 is centroid.
@ PropertyCustomDash
Custom dash pattern.
@ PropertyShapeburstUseWholeShape
Shapeburst use whole shape.
@ PropertySize
Symbol size.
@ PropertyArrowHeadThickness
Arrow head thickness.
@ PropertyOffsetX
Horizontal offset.
@ PropertyJoinStyle
Line join style.
@ PropertyLineStartWidthValue
Start line width for interpolated line renderer (since QGIS 3.22)
@ PropertyTrimEnd
Trim distance from end of line (since QGIS 3.20)
@ PropertyOpacity
Opacity.
@ PropertySecondaryColor
Secondary color (eg for gradient fills)
@ PropertyCharacter
Character, eg for font marker symbol layers.
@ PropertyCoordinateMode
Gradient coordinate mode.
@ PropertyRandomOffsetY
Random offset Y (since QGIS 3.24)
@ PropertyLineAngle
Line angle, or angle of hash lines for hash line symbols.
@ PropertyShapeburstMaxDistance
Shapeburst fill from edge distance.
@ PropertyTrimStart
Trim distance from start of line (since QGIS 3.20)
@ PropertyOffset
Symbol offset.
@ PropertyStrokeWidth
Stroke width.
@ PropertyDashPatternOffset
Dash pattern offset,.
@ PropertyFillColor
Fill color.
@ PropertyArrowHeadType
Arrow head type.
@ PropertyFontStyle
Font style.
@ PropertyHeight
Symbol height.
@ PropertyClipPoints
Whether markers should be clipped to polygon boundaries.
@ PropertyFontFamily
Font family.
@ PropertyPointCount
Point count.
@ PropertyRandomSeed
Random number seed.
@ PropertyLayerEnabled
Whether symbol layer is enabled.
@ PropertyName
Name, eg shape name for simple markers.
@ PropertyAverageAngleLength
Length to average symbol angles over.
@ PropertyInterval
Line marker interval.
@ PropertyRandomOffsetX
Random offset X (since QGIS 3.24)
@ PropertyFillStyle
Fill style (eg solid, dots)
@ PropertyArrowType
Arrow type.
@ PropertyDisplacementY
Vertical displacement.
@ PropertyStrokeColor
Stroke color.
@ PropertyGradientReference2IsCentroid
Gradient reference point 2 is centroid.
@ PropertyArrowWidth
Arrow tail width.
@ PropertyWidth
Symbol width.
QgsFields mFields
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Qgis::SymbolType type() const
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
virtual QColor fillColor() const
Returns the fill color for the symbol layer.
void setId(const QString &id)
Set symbol layer identifier This id has to be unique in the whole project.
virtual void setStrokeColor(const QColor &color)
Sets the stroke color for the symbol layer.
QPainterPath mClipPath
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets offset.
virtual QColor dxfBrushColor(QgsSymbolRenderContext &context) const
Gets brush/fill color.
Qgis::SymbolType mType
void removeMasks(QgsRenderContext &context, bool recursive)
When rendering, remove previously installed masks from context painter if recursive is true masks are...
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
void installMasks(QgsRenderContext &context, bool recursive)
When rendering, install masks on context painter if recursive is true masks are installed recursively...
void restoreOldDataDefinedProperties(const QVariantMap &stringMap)
Restores older data defined properties from string map.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
void setRenderingPass(int renderingPass)
Specifies the rendering pass in which this symbol layer should be rendered.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
QgsSymbolLayer(const QgsSymbolLayer &other)=delete
QgsSymbolLayer cannot be copied.
std::unique_ptr< QgsPaintEffect > mPaintEffect
virtual Qt::PenStyle dxfPenStyle() const
Gets pen style.
virtual void setFillColor(const QColor &color)
Sets the fill color for the symbol layer.
virtual void prepareExpressions(const QgsSymbolRenderContext &context)
Prepares all data defined property expressions for evaluation.
virtual QColor dxfColor(QgsSymbolRenderContext &context) const
Gets color.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
QString id() const
Returns symbol layer identifier This id is unique in the whole project.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
virtual QColor color() const
Returns the "representative" color of the symbol layer.
virtual void prepareMasks(const QgsSymbolRenderContext &context)
Prepares all mask internal objects according to what is defined in context This should be called prio...
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const
Gets line width.
virtual QColor strokeColor() const
Returns the stroke color for the symbol layer.
virtual double dxfAngle(QgsSymbolRenderContext &context) const
Gets angle.
virtual bool canCauseArtifactsBetweenAdjacentTiles() const
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
virtual ~QgsSymbolLayer()
virtual bool usesMapUnits() const
Returns true if the symbol layer has any components which use map unit based sizes.
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
virtual Qgis::SymbolLayerFlags flags() const
Returns flags which control the symbol layer's behavior.
QgsPropertyCollection mDataDefinedProperties
virtual QList< QgsSymbolLayerReference > masks() const
Returns masks defined by this symbol layer.
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.
virtual QVector< qreal > dxfCustomDashPattern(Qgis::RenderUnit &unit) const
Gets dash pattern.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol layer's property collection, used for data defined overrides.
QgsFields fields() const
Fields of the layer.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
const QgsLegendPatchShape * patchShape() const
Returns the symbol patch shape, to use if rendering symbol preview icons.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:152
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
float threshold() const
Gets the simplification threshold of the vector layer managed.
@ AntialiasingSimplification
The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
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
#define str(x)
Definition: qgis.cpp:37
#define DEG2RAD(x)
const QgsField & field
Definition: qgsfield.h:501
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QgsProperty propertyFromMap(const QVariantMap &map, const QString &baseName)
Single variable definition for use within a QgsExpressionContextScope.