20#include <QSvgGenerator>
65 for (
int i = 0; i <
mLayers.count(); i++ )
71 else if ( !
mLayers.at( i )->isCompatibleWithSymbol(
this ) )
83 return _getLineString3d( context, curve, clipToExtent );
85 return _getLineString2d( context, curve, clipToExtent );
90 const unsigned int nPoints = curve.
numPoints();
94 QVector< double > pointsX;
95 QVector< double > pointsY;
96 QVector< double > pointsZ;
102 const double cw = e.
width() / 10;
103 const double ch = e.
height() / 10;
107 if (
const QgsLineString *ls = qgsgeometry_cast< const QgsLineString * >( &curve ) )
113 std::unique_ptr< QgsLineString > segmentized;
114 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
115 lineString = segmentized.get();
123 if (
const QgsLineString *ls = qgsgeometry_cast<const QgsLineString *>( &curve ) )
125 pointsX = ls->xVector();
126 pointsY = ls->yVector();
127 pointsZ = ls->zVector();
131 std::unique_ptr< QgsLineString > segmentized;
132 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
134 pointsX = segmentized->xVector();
135 pointsY = segmentized->yVector();
136 pointsZ = segmentized->zVector();
141 const QVector< double > preTransformPointsZ = pointsZ;
142 bool wasTransformed =
false;
146 const int nVertices = pointsX.size();
147 wasTransformed =
true;
151 ct.
transformCoords( nVertices, pointsX.data(), pointsY.data(), pointsZ.data(), Qgis::TransformDirection::Forward );
161 const int size = pointsX.size();
163 const double *xIn = pointsX.data();
164 const double *yIn = pointsY.data();
165 const double *zIn = pointsZ.data();
167 const double *preTransformZIn = wasTransformed ? preTransformPointsZ.constData() :
nullptr;
169 double *xOut = pointsX.data();
170 double *yOut = pointsY.data();
171 double *zOut = pointsZ.data();
173 for (
int i = 0; i < size; ++i )
175 bool pointOk = std::isfinite( *xIn ) && std::isfinite( *yIn );
182 pointOk &= !wasTransformed || std::isfinite( *zIn ) || !std::isfinite( *preTransformZIn );
198 if ( preTransformZIn )
201 pointsX.resize( outSize );
202 pointsY.resize( outSize );
203 pointsZ.resize( outSize );
210 const double cw = e.
width() / 10;
211 const double ch = e.
height() / 10;
214 QVector< double > tempX;
215 QVector< double > tempY;
216 QVector< double > tempZ;
223 const int polygonSize = pointsX.size();
224 QPolygonF out( polygonSize );
225 const double *x = pointsX.constData();
226 const double *y = pointsY.constData();
227 QPointF *dest = out.data();
228 for (
int i = 0; i < polygonSize; ++i )
230 double screenX = *x++;
231 double screenY = *y++;
233 *dest++ = QPointF( screenX, screenY );
241 const unsigned int nPoints = curve.
numPoints();
251 const double cw = e.
width() / 10;
252 const double ch = e.
height() / 10;
275 pts.erase( std::remove_if( pts.begin(), pts.end(),
276 [](
const QPointF point )
278 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
285 const double cw = e.
width() / 10;
286 const double ch = e.
height() / 10;
291 QPointF *ptr = pts.data();
292 for (
int i = 0; i < pts.size(); ++i, ++ptr )
304 return _getPolygonRing3d( context, curve, clipToExtent, isExteriorRing, correctRingOrientation );
306 return _getPolygonRing2d( context, curve, clipToExtent, isExteriorRing, correctRingOrientation );
309QPolygonF QgsSymbol::_getPolygonRing3d(
QgsRenderContext &context,
const QgsCurve &curve,
const bool clipToExtent,
const bool isExteriorRing,
const bool correctRingOrientation )
314 QVector< double > pointsX;
315 QVector< double > pointsY;
316 QVector< double > pointsZ;
321 bool reverseRing =
false;
322 if ( correctRingOrientation )
335 const double cw = e.
width() / 10;
336 const double ch = e.
height() / 10;
340 std::unique_ptr< QgsLineString > segmentized;
341 if (
const QgsLineString *ls = qgsgeometry_cast< const QgsLineString * >( &curve ) )
347 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
348 lineString = segmentized.get();
351 pointsX = lineString->
xVector();
352 pointsY = lineString->
yVector();
353 pointsZ = lineString->
zVector();
360 if (
const QgsLineString *ls = qgsgeometry_cast<const QgsLineString *>( &curve ) )
362 pointsX = ls->xVector();
363 pointsY = ls->yVector();
364 pointsZ = ls->zVector();
368 std::unique_ptr< QgsLineString > segmentized;
369 segmentized.reset( qgsgeometry_cast< QgsLineString * >( curve.
segmentize( ) ) );
371 pointsX = segmentized->xVector();
372 pointsY = segmentized->yVector();
373 pointsZ = segmentized->zVector();
379 std::reverse( pointsX.begin(), pointsX.end() );
380 std::reverse( pointsY.begin(), pointsY.end() );
381 std::reverse( pointsZ.begin(), pointsZ.end() );
385 const QVector< double > preTransformPointsZ = pointsZ;
386 bool wasTransformed =
false;
389 const int nVertices = pointsX.size();
390 wasTransformed =
true;
393 ct.
transformCoords( nVertices, pointsX.data(), pointsY.data(), pointsZ.data(), Qgis::TransformDirection::Forward );
403 const int size = pointsX.size();
405 const double *xIn = pointsX.data();
406 const double *yIn = pointsY.data();
407 const double *zIn = pointsZ.data();
409 const double *preTransformZIn = wasTransformed ? preTransformPointsZ.constData() :
nullptr;
411 double *xOut = pointsX.data();
412 double *yOut = pointsY.data();
413 double *zOut = pointsZ.data();
415 for (
int i = 0; i < size; ++i )
417 bool pointOk = std::isfinite( *xIn ) && std::isfinite( *yIn );
423 pointOk &= !wasTransformed || std::isfinite( *zIn ) || !std::isfinite( *preTransformZIn );
439 if ( preTransformZIn )
442 pointsX.resize( outSize );
443 pointsY.resize( outSize );
444 pointsZ.resize( outSize );
451 const double cw = e.
width() / 10;
452 const double ch = e.
height() / 10;
458 const int polygonSize = pointsX.size();
459 QPolygonF out( polygonSize );
460 const double *x = pointsX.constData();
461 const double *y = pointsY.constData();
462 QPointF *dest = out.data();
463 for (
int i = 0; i < polygonSize; ++i )
465 double screenX = *x++;
466 double screenY = *y++;
468 *dest++ = QPointF( screenX, screenY );
471 if ( !out.empty() && !out.isClosed() )
478QPolygonF QgsSymbol::_getPolygonRing2d(
QgsRenderContext &context,
const QgsCurve &curve,
const bool clipToExtent,
const bool isExteriorRing,
const bool correctRingOrientation )
488 if ( correctRingOrientation )
492 std::reverse( poly.begin(), poly.end() );
494 std::reverse( poly.begin(), poly.end() );
501 const double cw = e.
width() / 10;
502 const double ch = e.
height() / 10;
521 poly.erase( std::remove_if( poly.begin(), poly.end(),
522 [](
const QPointF point )
524 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
531 const double cw = e.
width() / 10;
532 const double ch = e.
height() / 10;
537 QPointF *ptr = poly.data();
538 for (
int i = 0; i < poly.size(); ++i, ++ptr )
543 if ( !poly.empty() && !poly.isClosed() )
544 poly << poly.at( 0 );
555 holes.reserve( ringCount );
556 for (
int idx = 0; idx < ringCount; idx++ )
559 if ( !hole.isEmpty() )
560 holes.append( hole );
569 return QObject::tr(
"Marker" );
571 return QObject::tr(
"Line" );
573 return QObject::tr(
"Fill" );
575 return QObject::tr(
"Hybrid" );
584 case Qgis::GeometryType::Point:
586 case Qgis::GeometryType::Line:
588 case Qgis::GeometryType::Polygon:
590 case Qgis::GeometryType::Unknown:
591 case Qgis::GeometryType::Null:
599 QgsSymbol::initPropertyDefinitions();
600 return sPropertyDefinitions;
613 return Qgis::RenderUnit::Unknown;
616 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
620 for ( ; it !=
mLayers.constEnd(); ++it )
622 if ( ( *it )->outputUnit() != unit )
624 return Qgis::RenderUnit::Unknown;
639 if (
layer->usesMapUnits() )
654 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
655 if ( it ==
mLayers.constEnd() )
661 for ( ; it !=
mLayers.constEnd(); ++it )
663 if ( ( *it )->mapUnitScale() != scale )
673 const auto constMLayers =
mLayers;
676 layer->setOutputUnit( u );
682 const auto constMLayers =
mLayers;
685 layer->setMapUnitScale( scale );
706 std::unique_ptr< QgsSymbol > s;
711 case Qgis::GeometryType::Point:
714 case Qgis::GeometryType::Line:
717 case Qgis::GeometryType::Polygon:
729 case Qgis::GeometryType::Point:
730 s = std::make_unique< QgsMarkerSymbol >();
732 case Qgis::GeometryType::Line:
733 s = std::make_unique< QgsLineSymbol >();
735 case Qgis::GeometryType::Polygon:
736 s = std::make_unique< QgsFillSymbol >();
739 QgsDebugMsg( QStringLiteral(
"unknown layer's geometry type" ) );
768 if ( index < 0 || index >
mLayers.count() )
771 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
781 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
791 if ( index < 0 || index >=
mLayers.count() )
802 if ( index < 0 || index >=
mLayers.count() )
805 return mLayers.takeAt( index );
813 if ( oldLayer ==
layer )
816 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
827 Q_ASSERT_X( !mStarted,
"startRender",
"Rendering has already been started for this symbol instance!" );
840 const long long mapFrameNumber = context.
currentFrame();
841 double animationTimeSeconds = 0;
842 if ( mapFrameNumber >= 0 && context.
frameRate() > 0 )
845 animationTimeSeconds = mapFrameNumber / context.
frameRate();
850 animationTimeSeconds = QDateTime::currentMSecsSinceEpoch() / 1000.0;
854 scope->setVariable( QStringLiteral(
"symbol_frame" ), symbolFrame, true );
857 mSymbolRenderContext->setExpressionContextScope( scope.release() );
861 const auto constMLayers =
mLayers;
867 layer->prepareExpressions( symbolContext );
868 layer->prepareMasks( symbolContext );
869 layer->startRender( symbolContext );
875 Q_ASSERT_X( mStarted,
"startRender",
"startRender was not called for this symbol instance!" );
879 if ( mSymbolRenderContext )
881 const auto constMLayers =
mLayers;
887 layer->stopRender( *mSymbolRenderContext );
891 mSymbolRenderContext.reset(
nullptr );
900 const auto constMLayers =
mLayers;
903 if ( !
layer->isLocked() )
913 if ( !
layer->isLocked() )
915 const QColor layerColor =
layer->color();
916 if ( layerColor.isValid() )
920 return QColor( 0, 0, 0 );
926 std::unique_ptr< QgsRenderContext > tempContext;
930 context = tempContext.get();
960 if ( !customContext && expressionContext )
964 else if ( !customContext )
988 const QSizeF targetSize = QSizeF( size.width() - 1, size.height() - 1 );
996 std::unique_ptr< QgsEffectPainter > effectPainter;
997 if ( effect && effect->
enabled() )
998 effectPainter = std::make_unique< QgsEffectPainter >( symbolContext.
renderContext(), effect );
1000 for (
const QList< QPolygonF > &poly : polys )
1002 QVector< QPolygonF > rings;
1003 rings.reserve( poly.size() );
1004 for (
int i = 1; i < poly.size(); ++i )
1005 rings << poly.at( i );
1009 effectPainter.reset();
1014 layer->drawPreviewIcon( symbolContext, size );
1022 if ( format.compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
1024 QSvgGenerator generator;
1025 generator.setFileName( path );
1026 generator.setSize( size );
1027 generator.setViewBox( QRect( 0, 0, size.height(), size.height() ) );
1029 QPainter painter( &generator );
1035 QImage image =
asImage( size );
1042 QImage image( size, QImage::Format_ARGB32_Premultiplied );
1045 QPainter p( &image );
1046 p.setRenderHint( QPainter::Antialiasing );
1047 p.setRenderHint( QPainter::SmoothPixmapTransform );
1057 QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
1060 QPainter p( &preview );
1061 p.setRenderHint( QPainter::Antialiasing );
1062 p.translate( 0.5, 0.5 );
1066 p.setPen( QPen( Qt::gray ) );
1067 p.drawLine( 0, 50, 100, 50 );
1068 p.drawLine( 50, 0, 50, 100 );
1076 if ( expressionContext )
1085 poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
1086 static_cast<QgsLineSymbol *
>( this )->renderPolyline( poly,
nullptr, context );
1091 polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
1092 static_cast<QgsFillSymbol *
>( this )->renderPolygon( polygon,
nullptr,
nullptr, context );
1096 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( QPointF( 50, 50 ),
nullptr, context );
1114 t = QStringLiteral(
"MARKER" );
1117 t = QStringLiteral(
"LINE" );
1120 t = QStringLiteral(
"FILL" );
1123 Q_ASSERT(
false &&
"unknown symbol type" );
1127 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1136 props[ QStringLiteral(
"alpha" )] = QString::number(
opacity() );
1137 double scaleFactor = 1.0;
1141 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1143 ( *it )->toSld( doc, element, props );
1150 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1153 layer->setLocked( ( *it )->isLocked() );
1154 layer->setRenderingPass( ( *it )->renderingPass() );
1155 layer->setEnabled( ( *it )->enabled() );
1156 layer->setId( ( *it )->id() );
1157 lst.append(
layer );
1172 if ( effect && effect->
enabled() )
1175 generatorLayer->
render( context, geometryType, points, rings );
1179 generatorLayer->
render( context, geometryType, points, rings );
1189 QgsSymbolLayerList::const_iterator sIt =
mLayers.constBegin();
1190 for ( ; sIt !=
mLayers.constEnd(); ++sIt )
1194 attributes.unite( ( *sIt )->usedAttributes( context ) );
1202 mDataDefinedProperties.
setProperty( key, property );
1212 if (
layer->hasDataDefinedProperties() )
1222 if (
layer->canCauseArtifactsBetweenAdjacentTiles() )
1247class ExpressionContextScopePopper
1251 ExpressionContextScopePopper() =
default;
1253 ~ExpressionContextScopePopper()
1256 context->popScope();
1265class GeometryRestorer
1269 : mContext( context ),
1270 mGeometry( context.geometry() )
1275 mContext.setGeometry( mGeometry );
1295 GeometryRestorer geomRestorer( context );
1297 bool usingSegmentizedGeometry =
false;
1305 if ( std::isfinite( boundsOrigin.x() ) && std::isfinite( boundsOrigin.y() ) )
1320 clippingEnabled =
false;
1331 clippingEnabled =
false;
1335 clippingEnabled =
false;
1338 mSymbolRenderContext->setGeometryPartNum( 1 );
1341 ExpressionContextScopePopper scopePopper;
1342 if ( mSymbolRenderContext->expressionContextScope() )
1344 if ( needsExpressionContext )
1370 QPointF renderPoint;
1371 const QgsPoint *originalGeometry =
nullptr;
1373 QVector< PointInfo > pointsToRender;
1377 QPolygonF renderLine;
1378 const QgsCurve *originalGeometry =
nullptr;
1380 QVector< LineInfo > linesToRender;
1384 QPolygonF renderExterior;
1385 QVector< QPolygonF > renderRings;
1387 int originalPartIndex = 0;
1389 QVector< PolygonInfo > polygonsToRender;
1392 getPartGeometry = [&pointsToRender, &linesToRender, &polygonsToRender, &getPartGeometry, &context, &clippingEnabled, &markers, &feature, &usingSegmentizedGeometry,
this](
const QgsAbstractGeometry * part,
int partIndex = 0 )
1403 const bool isMultiPart = qgsgeometry_cast< const QgsGeometryCollection * >( part ) && qgsgeometry_cast< const QgsGeometryCollection * >( part )->numGeometries() > 1;
1409 if ( needsSegmentizing )
1412 if ( !segmentizedPart )
1416 temporaryGeometryContainer.
set( segmentizedPart.release() );
1417 processedGeometry = temporaryGeometryContainer.
constGet();
1418 usingSegmentizedGeometry =
true;
1423 processedGeometry = part;
1433 std::unique_ptr< QgsAbstractGeometry > simplified( simplifier.
simplify( processedGeometry ) );
1436 temporaryGeometryContainer.
set( simplified.release() );
1437 processedGeometry = temporaryGeometryContainer.
constGet();
1452 temporaryGeometryContainer.
set( clippedGeom.release() );
1453 processedGeometry = temporaryGeometryContainer.
constGet();
1460 processedGeometry = part;
1463 if ( !processedGeometry )
1466 QgsDebugMsg( QStringLiteral(
"No processed geometry to render for part!" ) );
1476 QgsDebugMsgLevel( QStringLiteral(
"point can be drawn only with marker symbol!" ), 2 );
1481 info.originalGeometry = qgsgeometry_cast< const QgsPoint * >( part );
1482 info.renderPoint =
_getPoint( context, *info.originalGeometry );
1483 pointsToRender << info;
1491 QgsDebugMsgLevel( QStringLiteral(
"linestring can be drawn only with line symbol!" ), 2 );
1496 info.originalGeometry = qgsgeometry_cast<const QgsCurve *>( part );
1497 info.renderLine =
_getLineString( context, *qgsgeometry_cast<const QgsCurve *>( processedGeometry ), clippingEnabled );
1498 linesToRender << info;
1508 QgsDebugMsgLevel( QStringLiteral(
"polygon can be drawn only with fill symbol!" ), 2 );
1513 info.originalGeometry = qgsgeometry_cast<const QgsCurvePolygon *>( part );
1514 info.originalPartIndex = partIndex;
1515 if ( !qgsgeometry_cast<const QgsPolygon *>( processedGeometry )->exteriorRing() )
1517 QgsDebugMsg( QStringLiteral(
"cannot render polygon with no exterior ring" ) );
1521 _getPolygon( info.renderExterior, info.renderRings, context, *qgsgeometry_cast<const QgsPolygon *>( processedGeometry ), clippingEnabled,
mForceRHR );
1522 polygonsToRender << info;
1528 const QgsMultiPoint *mp = qgsgeometry_cast< const QgsMultiPoint * >( processedGeometry );
1536 const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( processedGeometry );
1539 for (
unsigned int i = 0; i < num; ++i )
1544 getPartGeometry( geomCollection->
geometryN( i ), i );
1554 QgsDebugMsgLevel( QStringLiteral(
"multi-polygon can be drawn only with fill symbol!" ), 2 );
1565 std::map<double, QList<unsigned int> > thisAreaToPartNum;
1566 for (
unsigned int i = 0; i < num; ++i )
1575 std::map<double, QList<unsigned int> >::const_reverse_iterator iter = thisAreaToPartNum.rbegin();
1576 for ( ; iter != thisAreaToPartNum.rend(); ++iter )
1578 const QList<unsigned int> &listPartIndex = iter->second;
1579 for (
int idx = 0; idx < listPartIndex.size(); ++idx )
1581 const unsigned i = listPartIndex[idx];
1582 getPartGeometry( geomCollection->
geometryN( i ), i );
1589 QgsDebugMsg( QStringLiteral(
"feature %1: unsupported wkb type %2/%3 for rendering" )
1590 .arg( feature.
id() )
1592 .arg(
static_cast< quint32
>( part->wkbType() ), 0, 16 ) );
1602 std::vector< int > layers;
1605 layers.reserve(
mLayers.count() );
1606 for (
int i = 0; i <
mLayers.count(); ++i )
1607 layers.emplace_back( i );
1611 layers.emplace_back(
layer );
1616 if ( needsExpressionContext )
1619 for (
const int symbolLayerIndex : layers )
1625 if ( needsExpressionContext )
1634 int geometryPartNumber = 0;
1635 for (
const PointInfo &point : std::as_const( pointsToRender ) )
1640 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1641 if ( needsExpressionContext )
1644 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( point.renderPoint, &feature, context, symbolLayerIndex, selected );
1645 geometryPartNumber++;
1653 if ( linesToRender.empty() )
1656 int geometryPartNumber = 0;
1657 for (
const LineInfo &line : std::as_const( linesToRender ) )
1662 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1663 if ( needsExpressionContext )
1667 static_cast<QgsLineSymbol *
>( this )->renderPolyline( line.renderLine, &feature, context, symbolLayerIndex, selected );
1668 geometryPartNumber++;
1675 for (
const PolygonInfo &info : std::as_const( polygonsToRender ) )
1680 mSymbolRenderContext->setGeometryPartNum( info.originalPartIndex + 1 );
1681 if ( needsExpressionContext )
1685 static_cast<QgsFillSymbol *
>( this )->renderPolygon( info.renderExterior, ( !info.renderRings.isEmpty() ? &info.renderRings : nullptr ), &feature, context, symbolLayerIndex, selected );
1703 markers.reserve( pointsToRender.size() );
1704 for (
const PointInfo &info : std::as_const( pointsToRender ) )
1708 const QRectF bounds =
static_cast<QgsMarkerSymbol *
>( this )->bounds( info.renderPoint, context, feature );
1717 context.
painter()->setPen( Qt::red );
1718 context.
painter()->setBrush( QColor( 255, 0, 0, 100 ) );
1719 context.
painter()->drawRect( bounds );
1723 if ( drawVertexMarker && !usingSegmentizedGeometry )
1725 markers.append( info.renderPoint );
1733 for (
const LineInfo &info : std::as_const( linesToRender ) )
1741 if ( drawVertexMarker && !usingSegmentizedGeometry )
1743 markers << info.renderLine;
1751 for (
const PolygonInfo &info : std::as_const( polygonsToRender ) )
1760 if ( drawVertexMarker && !usingSegmentizedGeometry )
1762 markers << info.renderExterior;
1764 for (
const QPolygonF &hole : info.renderRings )
1782 handler->handleRenderedFeature( feature, renderedBoundsGeom, featureContext );
1785 if ( drawVertexMarker )
1789 const auto constMarkers = markers;
1790 for ( QPointF marker : constMarkers )
1792 renderVertexMarker( marker, context, currentVertexMarkerType, currentVertexMarkerSize );
1807 x = vertexPoint.
x();
1808 y = vertexPoint.
y();
1817 renderVertexMarker( mapPoint, context, currentVertexMarkerType, currentVertexMarkerSize );
1825 return mSymbolRenderContext.get();
1830 int markerSize = context.
convertToPainterUnits( currentVertexMarkerSize, Qgis::RenderUnit::Millimeters );
1834void QgsSymbol::initPropertyDefinitions()
1836 if ( !sPropertyDefinitions.isEmpty() )
1839 QString origin = QStringLiteral(
"symbol" );
1860 const QList< QgsSymbolLayer * > layers =
mLayers;
1884 const QList< QgsSymbolLayer * > layers =
mLayers;
@ CounterClockwise
Counter-clockwise direction.
@ Clockwise
Clockwise direction.
@ DisableFeatureClipping
If present, indicates that features should never be clipped to the map extent during rendering.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
RenderUnit
Rendering size 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.
@ 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.
Abstract base class for all geometries.
bool is3D() const SIP_HOLDGIL
Returns true if the geometry is 3D and contains a z-value.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const SIP_HOLDGIL
Returns a reference to the simplest lossless representation of this geometry, e.g.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
Qgis::WkbType wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
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.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
Abstract base class for curved geometry type.
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
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 SIP_HOLDGIL
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.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
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.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
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.
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 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.
A store for object properties.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
bool isEmpty() const
Returns true if the rectangle is empty.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other 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 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...
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...
static QgsStyle * defaultStyle()
Returns 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.
static QString encodeColor(const QColor &color)
@ PropertyLayerEnabled
Whether symbol layer is enabled.
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
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.
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
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.
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Property
Data definable properties.
@ PropertyOpacity
Opacity.
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the symbol.
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 drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *patchShape=nullptr)
Draws an icon of the symbol that occupies an area given by size using the specified painter.
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 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.
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=nullptr, Qgis::SymbolPreviewFlags flags=Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols)
Returns a large (roughly 100x100 pixel) preview image for the symbol.
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
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.
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) SIP_THROW(QgsCsException)
Render a 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,...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
static QString displayString(Qgis::WkbType type) SIP_HOLDGIL
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) SIP_HOLDGIL
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type) SIP_HOLDGIL
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)
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.