20#include <QSvgGenerator>
67 for (
int i = 0; i <
mLayers.count(); i++ )
73 else if ( !
mLayers.at( i )->isCompatibleWithSymbol(
this ) )
85 return _getLineString3d( context, curve, clipToExtent );
87 return _getLineString2d( context, curve, clipToExtent );
92 const unsigned int nPoints = curve.
numPoints();
96 QVector< double > pointsX;
97 QVector< double > pointsY;
98 QVector< double > pointsZ;
104 const double cw = e.
width() / 10;
105 const double ch = e.
height() / 10;
109 std::unique_ptr< QgsLineString > segmentized;
110 if (
const QgsLineString *ls = qgsgeometry_cast< const QgsLineString * >( &curve ) )
116 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
117 lineString = segmentized.get();
125 if (
const QgsLineString *ls = qgsgeometry_cast<const QgsLineString *>( &curve ) )
127 pointsX = ls->xVector();
128 pointsY = ls->yVector();
129 pointsZ = ls->zVector();
133 std::unique_ptr< QgsLineString > segmentized;
134 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
136 pointsX = segmentized->xVector();
137 pointsY = segmentized->yVector();
138 pointsZ = segmentized->zVector();
143 const QVector< double > preTransformPointsZ = pointsZ;
144 bool wasTransformed =
false;
148 const int nVertices = pointsX.size();
149 wasTransformed =
true;
163 const int size = pointsX.size();
165 const double *xIn = pointsX.data();
166 const double *yIn = pointsY.data();
167 const double *zIn = pointsZ.data();
169 const double *preTransformZIn = wasTransformed ? preTransformPointsZ.constData() :
nullptr;
171 double *xOut = pointsX.data();
172 double *yOut = pointsY.data();
173 double *zOut = pointsZ.data();
175 for (
int i = 0; i < size; ++i )
177 bool pointOk = std::isfinite( *xIn ) && std::isfinite( *yIn );
184 pointOk &= !wasTransformed || std::isfinite( *zIn ) || !std::isfinite( *preTransformZIn );
200 if ( preTransformZIn )
203 pointsX.resize( outSize );
204 pointsY.resize( outSize );
205 pointsZ.resize( outSize );
212 const double cw = e.
width() / 10;
213 const double ch = e.
height() / 10;
216 QVector< double > tempX;
217 QVector< double > tempY;
218 QVector< double > tempZ;
225 const int polygonSize = pointsX.size();
226 QPolygonF out( polygonSize );
227 const double *x = pointsX.constData();
228 const double *y = pointsY.constData();
229 QPointF *dest = out.data();
230 for (
int i = 0; i < polygonSize; ++i )
232 double screenX = *x++;
233 double screenY = *y++;
235 *dest++ = QPointF( screenX, screenY );
243 const unsigned int nPoints = curve.
numPoints();
253 const double cw = e.
width() / 10;
254 const double ch = e.
height() / 10;
277 pts.erase( std::remove_if( pts.begin(), pts.end(),
278 [](
const QPointF point )
280 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
287 const double cw = e.
width() / 10;
288 const double ch = e.
height() / 10;
293 QPointF *ptr = pts.data();
294 for (
int i = 0; i < pts.size(); ++i, ++ptr )
306 return _getPolygonRing3d( context, curve, clipToExtent, isExteriorRing, correctRingOrientation );
308 return _getPolygonRing2d( context, curve, clipToExtent, isExteriorRing, correctRingOrientation );
311QPolygonF QgsSymbol::_getPolygonRing3d(
QgsRenderContext &context,
const QgsCurve &curve,
const bool clipToExtent,
const bool isExteriorRing,
const bool correctRingOrientation )
316 QVector< double > pointsX;
317 QVector< double > pointsY;
318 QVector< double > pointsZ;
323 bool reverseRing =
false;
324 if ( correctRingOrientation )
337 const double cw = e.
width() / 10;
338 const double ch = e.
height() / 10;
342 std::unique_ptr< QgsLineString > segmentized;
343 if (
const QgsLineString *ls = qgsgeometry_cast< const QgsLineString * >( &curve ) )
349 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
350 lineString = segmentized.get();
353 pointsX = lineString->
xVector();
354 pointsY = lineString->
yVector();
355 pointsZ = lineString->
zVector();
362 if (
const QgsLineString *ls = qgsgeometry_cast<const QgsLineString *>( &curve ) )
364 pointsX = ls->xVector();
365 pointsY = ls->yVector();
366 pointsZ = ls->zVector();
370 std::unique_ptr< QgsLineString > segmentized;
371 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
373 pointsX = segmentized->xVector();
374 pointsY = segmentized->yVector();
375 pointsZ = segmentized->zVector();
381 std::reverse( pointsX.begin(), pointsX.end() );
382 std::reverse( pointsY.begin(), pointsY.end() );
383 std::reverse( pointsZ.begin(), pointsZ.end() );
387 const QVector< double > preTransformPointsZ = pointsZ;
388 bool wasTransformed =
false;
391 const int nVertices = pointsX.size();
392 wasTransformed =
true;
405 const int size = pointsX.size();
407 const double *xIn = pointsX.data();
408 const double *yIn = pointsY.data();
409 const double *zIn = pointsZ.data();
411 const double *preTransformZIn = wasTransformed ? preTransformPointsZ.constData() :
nullptr;
413 double *xOut = pointsX.data();
414 double *yOut = pointsY.data();
415 double *zOut = pointsZ.data();
417 for (
int i = 0; i < size; ++i )
419 bool pointOk = std::isfinite( *xIn ) && std::isfinite( *yIn );
425 pointOk &= !wasTransformed || std::isfinite( *zIn ) || !std::isfinite( *preTransformZIn );
441 if ( preTransformZIn )
444 pointsX.resize( outSize );
445 pointsY.resize( outSize );
446 pointsZ.resize( outSize );
453 const double cw = e.
width() / 10;
454 const double ch = e.
height() / 10;
460 const int polygonSize = pointsX.size();
461 QPolygonF out( polygonSize );
462 const double *x = pointsX.constData();
463 const double *y = pointsY.constData();
464 QPointF *dest = out.data();
465 for (
int i = 0; i < polygonSize; ++i )
467 double screenX = *x++;
468 double screenY = *y++;
470 *dest++ = QPointF( screenX, screenY );
473 if ( !out.empty() && !out.isClosed() )
480QPolygonF QgsSymbol::_getPolygonRing2d(
QgsRenderContext &context,
const QgsCurve &curve,
const bool clipToExtent,
const bool isExteriorRing,
const bool correctRingOrientation )
490 if ( correctRingOrientation )
494 std::reverse( poly.begin(), poly.end() );
496 std::reverse( poly.begin(), poly.end() );
503 const double cw = e.
width() / 10;
504 const double ch = e.
height() / 10;
523 poly.erase( std::remove_if( poly.begin(), poly.end(),
524 [](
const QPointF point )
526 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
533 const double cw = e.
width() / 10;
534 const double ch = e.
height() / 10;
539 QPointF *ptr = poly.data();
540 for (
int i = 0; i < poly.size(); ++i, ++ptr )
545 if ( !poly.empty() && !poly.isClosed() )
546 poly << poly.at( 0 );
557 holes.reserve( ringCount );
558 for (
int idx = 0; idx < ringCount; idx++ )
561 if ( !hole.isEmpty() )
562 holes.append( hole );
571 return QObject::tr(
"Marker" );
573 return QObject::tr(
"Line" );
575 return QObject::tr(
"Fill" );
577 return QObject::tr(
"Hybrid" );
601 QgsSymbol::initPropertyDefinitions();
602 return sPropertyDefinitions;
618 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
622 for ( ; it !=
mLayers.constEnd(); ++it )
624 if ( ( *it )->outputUnit() != unit )
641 if (
layer->usesMapUnits() )
656 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
657 if ( it ==
mLayers.constEnd() )
663 for ( ; it !=
mLayers.constEnd(); ++it )
665 if ( ( *it )->mapUnitScale() != scale )
675 const auto constMLayers =
mLayers;
678 layer->setOutputUnit( u );
684 const auto constMLayers =
mLayers;
687 layer->setMapUnitScale( scale );
708 std::unique_ptr< QgsSymbol > s;
732 s = std::make_unique< QgsMarkerSymbol >();
735 s = std::make_unique< QgsLineSymbol >();
738 s = std::make_unique< QgsFillSymbol >();
741 QgsDebugError( QStringLiteral(
"unknown layer's geometry type" ) );
773 if ( index < 0 || index >
mLayers.count() )
776 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
786 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
796 if ( index < 0 || index >=
mLayers.count() )
807 if ( index < 0 || index >=
mLayers.count() )
810 return mLayers.takeAt( index );
818 if ( oldLayer ==
layer )
821 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
832 Q_ASSERT_X( !mStarted,
"startRender",
"Rendering has already been started for this symbol instance!" );
845 const long long mapFrameNumber = context.
currentFrame();
846 double animationTimeSeconds = 0;
847 if ( mapFrameNumber >= 0 && context.
frameRate() > 0 )
850 animationTimeSeconds = mapFrameNumber / context.
frameRate();
855 animationTimeSeconds = QDateTime::currentMSecsSinceEpoch() / 1000.0;
859 scope->setVariable( QStringLiteral(
"symbol_frame" ), symbolFrame, true );
862 mSymbolRenderContext->setExpressionContextScope( scope.release() );
871 layer->prepareExpressions( symbolContext );
889 layer->prepareMasks( symbolContext );
890 layer->startRender( symbolContext );
896 Q_ASSERT_X( mStarted,
"startRender",
"startRender was not called for this symbol instance!" );
900 if ( mSymbolRenderContext )
902 const auto constMLayers =
mLayers;
908 layer->stopRender( *mSymbolRenderContext );
912 mSymbolRenderContext.reset(
nullptr );
921 const auto constMLayers =
mLayers;
924 if ( !
layer->isLocked() )
934 if ( !
layer->isLocked() )
936 const QColor layerColor =
layer->color();
937 if ( layerColor.isValid() )
941 return QColor( 0, 0, 0 );
947 std::unique_ptr< QgsRenderContext > tempContext;
951 context = tempContext.get();
986 if ( !customContext && expressionContext )
990 else if ( !customContext )
1014 const QSizeF targetSize = QSizeF( size.width() - 1, size.height() - 1 );
1022 std::unique_ptr< QgsEffectPainter > effectPainter;
1023 if ( effect && effect->
enabled() )
1024 effectPainter = std::make_unique< QgsEffectPainter >( symbolContext.
renderContext(), effect );
1026 for (
const QList< QPolygonF > &poly : polys )
1028 QVector< QPolygonF > rings;
1029 rings.reserve( poly.size() );
1030 for (
int i = 1; i < poly.size(); ++i )
1031 rings << poly.at( i );
1035 effectPainter.reset();
1040 layer->drawPreviewIcon( symbolContext, size );
1048 if ( format.compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
1050 QSvgGenerator generator;
1051 generator.setFileName( path );
1052 generator.setSize( size );
1053 generator.setViewBox( QRect( 0, 0, size.height(), size.height() ) );
1055 QPainter painter( &generator );
1061 QImage image =
asImage( size );
1068 QImage image( size, QImage::Format_ARGB32_Premultiplied );
1071 QPainter p( &image );
1072 p.setRenderHint( QPainter::Antialiasing );
1073 p.setRenderHint( QPainter::SmoothPixmapTransform );
1084 QImage preview( QSize( 100, 100 ) * devicePixelRatio, QImage::Format_ARGB32_Premultiplied );
1086 preview.setDevicePixelRatio( devicePixelRatio );
1088 QPainter p( &preview );
1089 p.setRenderHint( QPainter::Antialiasing );
1090 p.translate( 0.5, 0.5 );
1094 p.setPen( QPen( Qt::gray ) );
1095 p.drawLine( QLineF( 0, 50, 100, 50 ) );
1096 p.drawLine( QLineF( 50, 0, 50, 100 ) );
1110 if ( expressionContext )
1119 poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
1120 static_cast<QgsLineSymbol *
>( this )->renderPolyline( poly,
nullptr, context );
1125 polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
1126 static_cast<QgsFillSymbol *
>( this )->renderPolygon( polygon,
nullptr,
nullptr, context );
1130 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( QPointF( 50, 50 ),
nullptr, context );
1148 t = QStringLiteral(
"MARKER" );
1151 t = QStringLiteral(
"LINE" );
1154 t = QStringLiteral(
"FILL" );
1157 Q_ASSERT(
false &&
"unknown symbol type" );
1161 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1170 props[ QStringLiteral(
"alpha" )] = QString::number(
opacity() );
1171 double scaleFactor = 1.0;
1175 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1177 ( *it )->toSld( doc, element, props );
1184 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1187 layer->setLocked( ( *it )->isLocked() );
1188 layer->setRenderingPass( ( *it )->renderingPass() );
1189 layer->setEnabled( ( *it )->enabled() );
1191 layer->setUserFlags( ( *it )->userFlags() );
1192 lst.append(
layer );
1207 if ( effect && effect->
enabled() )
1210 generatorLayer->
render( context, geometryType, points, rings );
1214 generatorLayer->
render( context, geometryType, points, rings );
1224 QgsSymbolLayerList::const_iterator sIt =
mLayers.constBegin();
1225 for ( ; sIt !=
mLayers.constEnd(); ++sIt )
1229 attributes.unite( ( *sIt )->usedAttributes( context ) );
1237 mDataDefinedProperties.
setProperty( key, property );
1247 if (
layer->hasDataDefinedProperties() )
1257 if (
layer->canCauseArtifactsBetweenAdjacentTiles() )
1282class ExpressionContextScopePopper
1286 ExpressionContextScopePopper() =
default;
1288 ~ExpressionContextScopePopper()
1291 context->popScope();
1300class GeometryRestorer
1304 : mContext( context ),
1305 mGeometry( context.geometry() )
1310 mContext.setGeometry( mGeometry );
1330 GeometryRestorer geomRestorer( context );
1332 bool usingSegmentizedGeometry =
false;
1340 if ( std::isfinite( boundsOrigin.x() ) && std::isfinite( boundsOrigin.y() ) )
1355 clippingEnabled =
false;
1366 clippingEnabled =
false;
1370 clippingEnabled =
false;
1373 mSymbolRenderContext->setGeometryPartNum( 1 );
1376 ExpressionContextScopePopper scopePopper;
1377 if ( mSymbolRenderContext->expressionContextScope() )
1379 if ( needsExpressionContext )
1405 QPointF renderPoint;
1406 const QgsPoint *originalGeometry =
nullptr;
1408 QVector< PointInfo > pointsToRender;
1412 QPolygonF renderLine;
1413 const QgsCurve *originalGeometry =
nullptr;
1415 QVector< LineInfo > linesToRender;
1419 QPolygonF renderExterior;
1420 QVector< QPolygonF > renderRings;
1422 int originalPartIndex = 0;
1424 QVector< PolygonInfo > polygonsToRender;
1427 getPartGeometry = [&pointsToRender, &linesToRender, &polygonsToRender, &getPartGeometry, &context, &clippingEnabled, &markers, &feature, &usingSegmentizedGeometry,
this](
const QgsAbstractGeometry * part,
int partIndex = 0 )
1438 const bool isMultiPart = qgsgeometry_cast< const QgsGeometryCollection * >( part ) && qgsgeometry_cast< const QgsGeometryCollection * >( part )->numGeometries() > 1;
1444 if ( needsSegmentizing )
1447 if ( !segmentizedPart )
1451 temporaryGeometryContainer.
set( segmentizedPart.release() );
1452 processedGeometry = temporaryGeometryContainer.
constGet();
1453 usingSegmentizedGeometry =
true;
1458 processedGeometry = part;
1468 std::unique_ptr< QgsAbstractGeometry > simplified( simplifier.
simplify( processedGeometry ) );
1471 temporaryGeometryContainer.
set( simplified.release() );
1472 processedGeometry = temporaryGeometryContainer.
constGet();
1487 temporaryGeometryContainer.
set( clippedGeom.release() );
1488 processedGeometry = temporaryGeometryContainer.
constGet();
1495 processedGeometry = part;
1498 if ( !processedGeometry )
1501 QgsDebugError( QStringLiteral(
"No processed geometry to render for part!" ) );
1511 QgsDebugMsgLevel( QStringLiteral(
"point can be drawn only with marker symbol!" ), 2 );
1516 info.originalGeometry = qgsgeometry_cast< const QgsPoint * >( part );
1517 info.renderPoint =
_getPoint( context, *info.originalGeometry );
1518 pointsToRender << info;
1526 QgsDebugMsgLevel( QStringLiteral(
"linestring can be drawn only with line symbol!" ), 2 );
1531 info.originalGeometry = qgsgeometry_cast<const QgsCurve *>( part );
1532 info.renderLine =
_getLineString( context, *qgsgeometry_cast<const QgsCurve *>( processedGeometry ), clippingEnabled );
1533 linesToRender << info;
1543 QgsDebugMsgLevel( QStringLiteral(
"polygon can be drawn only with fill symbol!" ), 2 );
1548 info.originalGeometry = qgsgeometry_cast<const QgsCurvePolygon *>( part );
1549 info.originalPartIndex = partIndex;
1550 if ( !qgsgeometry_cast<const QgsPolygon *>( processedGeometry )->exteriorRing() )
1552 QgsDebugError( QStringLiteral(
"cannot render polygon with no exterior ring" ) );
1556 _getPolygon( info.renderExterior, info.renderRings, context, *qgsgeometry_cast<const QgsPolygon *>( processedGeometry ), clippingEnabled,
mForceRHR );
1557 polygonsToRender << info;
1563 const QgsMultiPoint *mp = qgsgeometry_cast< const QgsMultiPoint * >( processedGeometry );
1571 const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( processedGeometry );
1574 for (
unsigned int i = 0; i < num; ++i )
1579 getPartGeometry( geomCollection->
geometryN( i ), i );
1589 QgsDebugMsgLevel( QStringLiteral(
"multi-polygon can be drawn only with fill symbol!" ), 2 );
1600 std::map<double, QList<unsigned int> > thisAreaToPartNum;
1601 for (
unsigned int i = 0; i < num; ++i )
1610 std::map<double, QList<unsigned int> >::const_reverse_iterator iter = thisAreaToPartNum.rbegin();
1611 for ( ; iter != thisAreaToPartNum.rend(); ++iter )
1613 const QList<unsigned int> &listPartIndex = iter->second;
1614 for (
int idx = 0; idx < listPartIndex.size(); ++idx )
1616 const unsigned i = listPartIndex[idx];
1617 getPartGeometry( geomCollection->
geometryN( i ), i );
1624 QgsDebugError( QStringLiteral(
"feature %1: unsupported wkb type %2/%3 for rendering" )
1625 .arg( feature.
id() )
1627 .arg(
static_cast< quint32
>( part->wkbType() ), 0, 16 ) );
1637 std::vector< int > layers;
1640 layers.reserve(
mLayers.count() );
1641 for (
int i = 0; i <
mLayers.count(); ++i )
1642 layers.emplace_back( i );
1646 layers.emplace_back(
layer );
1651 if ( needsExpressionContext )
1657 for (
const int symbolLayerIndex : layers )
1663 if ( needsExpressionContext )
1669 const bool hasClipGeometries = !maskGeometriesDisabledForSymbol
1672 QPainter *previousPainter =
nullptr;
1673 std::unique_ptr< QPicture > renderedPicture;
1674 std::unique_ptr< QPainter > picturePainter;
1675 if ( hasClipGeometries )
1677 previousPainter = context.
painter();
1678 renderedPicture = std::make_unique< QPicture >();
1679 picturePainter = std::make_unique< QPainter >( renderedPicture.get() );
1689 int geometryPartNumber = 0;
1690 for (
const PointInfo &point : std::as_const( pointsToRender ) )
1695 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1696 if ( needsExpressionContext )
1699 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( point.renderPoint, &feature, context, symbolLayerIndex, selected );
1700 geometryPartNumber++;
1708 if ( linesToRender.empty() )
1711 int geometryPartNumber = 0;
1712 for (
const LineInfo &line : std::as_const( linesToRender ) )
1717 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1718 if ( needsExpressionContext )
1722 static_cast<QgsLineSymbol *
>( this )->renderPolyline( line.renderLine, &feature, context, symbolLayerIndex, selected );
1723 geometryPartNumber++;
1730 for (
const PolygonInfo &info : std::as_const( polygonsToRender ) )
1735 mSymbolRenderContext->setGeometryPartNum( info.originalPartIndex + 1 );
1736 if ( needsExpressionContext )
1740 static_cast<QgsFillSymbol *
>( this )->renderPolygon( info.renderExterior, ( !info.renderRings.isEmpty() ? &info.renderRings : nullptr ), &feature, context, symbolLayerIndex, selected );
1752 if ( hasClipGeometries )
1756 picturePainter->end();
1757 picturePainter.reset();
1760 QRectF maximalBounds = renderedPicture->boundingRect();
1761 constexpr double BOUNDS_MARGIN = 0.05;
1762 maximalBounds.adjust( -maximalBounds.width() * BOUNDS_MARGIN, -maximalBounds.height() * BOUNDS_MARGIN, maximalBounds.width() * BOUNDS_MARGIN, maximalBounds.height() * BOUNDS_MARGIN );
1764 const bool hadClipping = context.
painter()->hasClipping();
1765 const QPainterPath oldClipPath = hadClipping ? context.
painter()->clipPath() : QPainterPath();
1769 context.
painter()->drawPicture( QPointF( 0, 0 ), *renderedPicture );
1773 context.
painter()->setClipPath( oldClipPath );
1774 context.
painter()->setClipping( hadClipping );
1784 markers.reserve( pointsToRender.size() );
1785 for (
const PointInfo &info : std::as_const( pointsToRender ) )
1789 const QRectF bounds =
static_cast<QgsMarkerSymbol *
>( this )->bounds( info.renderPoint, context, feature );
1798 context.
painter()->setPen( Qt::red );
1799 context.
painter()->setBrush( QColor( 255, 0, 0, 100 ) );
1800 context.
painter()->drawRect( bounds );
1804 if ( drawVertexMarker && !usingSegmentizedGeometry )
1806 markers.append( info.renderPoint );
1814 for (
const LineInfo &info : std::as_const( linesToRender ) )
1822 if ( drawVertexMarker && !usingSegmentizedGeometry )
1824 markers << info.renderLine;
1832 for (
const PolygonInfo &info : std::as_const( polygonsToRender ) )
1841 if ( drawVertexMarker && !usingSegmentizedGeometry )
1843 markers << info.renderExterior;
1845 for (
const QPolygonF &hole : info.renderRings )
1863 handler->handleRenderedFeature( feature, renderedBoundsGeom, featureContext );
1866 if ( drawVertexMarker )
1870 const auto constMarkers = markers;
1871 for ( QPointF marker : constMarkers )
1873 renderVertexMarker( marker, context, currentVertexMarkerType, currentVertexMarkerSize );
1888 x = vertexPoint.
x();
1889 y = vertexPoint.
y();
1898 renderVertexMarker( mapPoint, context, currentVertexMarkerType, currentVertexMarkerSize );
1906 return mSymbolRenderContext.get();
1915void QgsSymbol::initPropertyDefinitions()
1917 if ( !sPropertyDefinitions.isEmpty() )
1920 QString origin = QStringLiteral(
"symbol" );
1941 const QList< QgsSymbolLayer * > layers =
mLayers;
1965 const QList< QgsSymbolLayer * > layers =
mLayers;
@ CounterClockwise
Counter-clockwise direction.
@ Clockwise
Clockwise direction.
@ IsSymbolLayerSubSymbol
Symbol is being rendered as a sub-symbol of a QgsSymbolLayer (since QGIS 3.38)
@ DisableFeatureClipping
If present, indicates that features should never be clipped to the map extent during rendering.
@ CanCalculateMaskGeometryPerFeature
If present, indicates that mask geometry can safely be calculated per feature for the symbol layer....
QFlags< SymbolPreviewFlag > SymbolPreviewFlags
Symbol preview flags.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
RenderUnit
Rendering size units.
@ Millimeters
Millimeters.
@ Unknown
Mixed or unknown units.
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
@ ApplyClipAfterReprojection
Feature geometry clipping to mapExtent() must be performed after the geometries are transformed using...
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ AlwaysUseGlobalMasks
When applying clipping paths for selective masking, always use global ("entire map") paths,...
@ Antialiasing
Use antialiasing while drawing.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
@ FlagIncludeCrosshairsForMarkerSymbols
Include a crosshairs reference image in the background of marker symbol previews.
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ GeometryCollection
GeometryCollection.
@ MultiSurface
MultiSurface.
@ Forward
Forward transform (from source to destination)
Abstract base class for all geometries.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
A 3-dimensional box composed of x, y, z coordinates.
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
Trims the given polygon to a rectangular box, by modifying the given polygon in place.
static QPolygonF clippedLine(const QgsCurve &curve, const QgsRectangle &clipExtent)
Takes a linestring and clips it to clipExtent.
static void clipped3dLine(const QVector< double > &xIn, const QVector< double > &yIn, const QVector< double > &zIn, QVector< double > &x, QVector< double > &y, QVector< double > &z, const QgsBox3D &clipExtent)
Takes a line with 3D coordinates and clips it to clipExtent.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Abstract base class for curved geometry type.
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
virtual int numPoints() const =0
Returns the number of points in the curve.
QgsCurve * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
A class to manager painter saving and restoring required for effect drawing.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
void render(QgsSymbolRenderContext &context, Qgis::GeometryType geometryType=Qgis::GeometryType::Unknown, const QPolygonF *points=nullptr, const QVector< QPolygonF > *rings=nullptr)
Will render this symbol layer using the context.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void set(QgsAbstractGeometry *geometry)
Sets the underlying geometry store.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Does vector analysis using the geos library and handles import, export, exception handling*.
Represents a patch shape for use in map legends.
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...
Line string geometry type, with support for z-dimension and m-values.
QVector< double > xVector() const
Returns the x vertex values as a vector.
QVector< double > yVector() const
Returns the y vertex values as a vector.
QVector< double > zVector() const
Returns the z vertex values as a vector.
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.
A line symbol type, for rendering LineString and MultiLineString geometries.
bool setId(const QString &id)
Sets the layer's id.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
Perform transforms between map coordinates and device coordinates.
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
Multi point geometry collection.
Base class for visual effects which can be applied to QPicture drawings.
bool enabled() const
Returns whether the effect is enabled.
Point geometry type, with support for z-dimension and m-values.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const final
Prepares the collection against a specified expression context.
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const final
Returns the set of any fields referenced by the active properties from the collection.
Definition for a property.
A store for object properties.
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool isNull() const
Test if the rectangle is null (holding no spatial information).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool isEmpty() const
Returns true if the rectangle has no area.
double height() const
Returns the height of the rectangle.
Contains information about the context of a rendering operation.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
void setTextureOrigin(const QPointF &origin)
Sets the texture origin, which should be used as a brush transform when rendering using QBrush object...
bool symbolLayerHasClipGeometries(const QString &symbolLayerId) const
Returns true if the symbol layer with matching ID has any associated clip geometries.
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
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.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsExpressionContext & expressionContext()
Gets the expression context.
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
long long currentFrame() const
Returns the current frame number of the map (in frames per second), for maps which are part of an ani...
void setIsGuiPreview(bool preview)
Sets GUI preview mode.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
double frameRate() const
Returns the frame rate of the map, for maps which are part of an animation.
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...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
bool isSymbolLayerEnabled(const QgsSymbolLayer *layer) const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
An interface for classes which provider custom handlers for features rendered as part of a map render...
Stores properties relating to a screen.
double devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels for the screen.
bool isValid() const
Returns true if the properties are valid.
void updateRenderContextForScreen(QgsRenderContext &context) const
Updates the settings in a render context to match the screen settings.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
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 (...
Contains settings relating to symbol animation.
bool isAnimated() const
Returns true if the symbol is animated.
double frameRate() const
Returns the symbol animation frame rate (in frames per second).
static void drawVertexMarker(double x, double y, QPainter &p, Qgis::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.
static QString encodeSldUom(Qgis::RenderUnit unit, double *scaleFactor)
Encodes a render unit into an SLD unit of measure string.
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
bool installMasks(QgsRenderContext &context, bool recursive, const QRectF &rect=QRectF())
When rendering, install masks on context painter.
@ LayerEnabled
Whether symbol layer is enabled.
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.
bool enabled() const
Returns true if symbol layer is enabled and will be drawn.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
QString id() const
Returns symbol layer identifier This id is unique in the whole project.
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
virtual Qgis::SymbolLayerFlags flags() const
Returns flags which control the symbol layer's behavior.
void setSelected(bool selected)
Sets whether symbols should be rendered using the selected symbol coloring and style.
void setOriginalGeometryType(Qgis::GeometryType type)
Sets the geometry type for the original feature geometry being rendered.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets 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.
void renderUsingLayer(QgsSymbolLayer *layer, QgsSymbolRenderContext &context, Qgis::GeometryType geometryType=Qgis::GeometryType::Unknown, const QPolygonF *points=nullptr, const QVector< QPolygonF > *rings=nullptr)
Renders a context using a particular symbol layer without passing in a geometry.
QgsSymbolLayerList cloneLayers() const
Retrieve a cloned list of all layers that make up this symbol.
void setOutputUnit(Qgis::RenderUnit unit) const
Sets the units to use for sizes and widths within the symbol.
Property
Data definable properties.
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the symbol.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, Qgis::VertexMarkerType currentVertexMarkerType=Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize=0.0)
Render a feature.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
static QPolygonF _getLineString(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent=true)
Creates a line string in screen coordinates from a QgsCurve in map coordinates.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
qreal mOpacity
Symbol opacity (in the range 0 - 1)
Q_DECL_DEPRECATED const QgsVectorLayer * mLayer
static QPolygonF _getPolygonRing(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing=false, bool correctRingOrientation=false)
Creates a polygon ring in screen coordinates from a QgsCurve in map coordinates.
QgsSymbolAnimationSettings & animationSettings()
Returns a reference to the symbol animation settings.
void renderVertexMarker(QPointF pt, QgsRenderContext &context, Qgis::VertexMarkerType currentVertexMarkerType, double currentVertexMarkerSize)
Render editing vertex marker at specified point.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
bool usesMapUnits() const
Returns true if the symbol has any components which use map unit based sizes.
Qgis::SymbolFlags flags() const
Returns flags for the symbol.
void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props) const
Converts the symbol to a SLD representation.
void setColor(const QColor &color) const
Sets the color for the symbol.
bool insertSymbolLayer(int index, QgsSymbolLayer *layer)
Inserts a symbol layer to specified index.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
static QString symbolTypeToString(Qgis::SymbolType type)
Returns a translated string version of the specified symbol type.
qreal opacity() const
Returns the opacity for the symbol.
bool canCauseArtifactsBetweenAdjacentTiles() const
Returns true if the symbol rendering can cause visible artifacts across a single feature when the fea...
static Qgis::SymbolType symbolTypeForGeometryType(Qgis::GeometryType type)
Returns the default symbol type required for the specified geometry type.
void setMapUnitScale(const QgsMapUnitScale &scale) const
Sets the map unit scale for the symbol.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=nullptr, Qgis::SymbolPreviewFlags flags=Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a large (roughly 100x100 pixel) preview image for the symbol.
QImage asImage(QSize size, QgsRenderContext *customContext=nullptr)
Returns an image of the symbol at the specified size.
static void _getPolygon(QPolygonF &pts, QVector< QPolygonF > &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent=true, bool correctRingOrientation=false)
Creates a polygon in screen coordinates from a QgsPolygonXYin map coordinates.
QString dump() const
Returns a string dump of the symbol's properties.
bool hasDataDefinedProperties() const
Returns whether the symbol utilizes any data defined properties.
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
QgsSymbolLayer * takeSymbolLayer(int index)
Removes a symbol layer from the list and returns a pointer to it.
Qgis::SymbolRenderHints mRenderHints
QgsSymbolLayerList mLayers
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *patchShape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Draws an icon of the symbol that occupies an area given by size using the specified painter.
Q_DECL_DEPRECATED const QgsVectorLayer * layer() const
QgsSymbolAnimationSettings mAnimationSettings
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context, int layer=-1)
Called before symbol layers will be rendered for a particular feature.
QColor color() const
Returns the symbol's color.
Qgis::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
QgsSymbol(Qgis::SymbolType type, const QgsSymbolLayerList &layers)
Constructor for a QgsSymbol of the specified type.
void setAnimationSettings(const QgsSymbolAnimationSettings &settings)
Sets a the symbol animation settings.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
Q_DECL_DEPRECATED void setLayer(const QgsVectorLayer *layer)
void exportImage(const QString &path, const QString &format, QSize size)
Export the symbol as an image format, to the specified path and with the given size.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context, int layer=-1)
Called after symbol layers have been rendered for a particular feature.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Represents a vector layer which manages a vector based data sets.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Qgis::VectorRenderingSimplificationFlags simplifyHints() const
Gets the simplification hints of the vector layer managed.
Qgis::VectorSimplificationAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
static QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
Contains geos related utilities and functions.
#define Q_NOWARN_DEPRECATED_POP
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList
Single variable definition for use within a QgsExpressionContextScope.
Utility class for identifying a unique vertex within a geometry.