QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
20 #include <QSvgGenerator>
74 ( !
qgsDoubleNear( scaleFactorX, 0.0 ) ?
"tostring(" + QString::number( scaleFactorX ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) +
76 ( !
qgsDoubleNear( scaleFactorY, 0.0 ) ?
"tostring(" + QString::number( scaleFactorY ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) );
89 for (
int i = 0; i <
mLayers.count(); i++ )
95 else if ( !
mLayers.at( i )->isCompatibleWithSymbol(
this ) )
106 const unsigned int nPoints = curve.
numPoints();
113 if ( clipToExtent && nPoints > 1 )
116 const double cw = e.
width() / 10;
117 const double ch = e.
height() / 10;
140 pts.erase( std::remove_if( pts.begin(), pts.end(),
141 [](
const QPointF point )
143 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
146 QPointF *ptr = pts.data();
147 for (
int i = 0; i < pts.size(); ++i, ++ptr )
160 const double cw = e.
width() / 10;
161 const double ch = e.
height() / 10;
169 if ( correctRingOrientation )
173 std::reverse( poly.begin(), poly.end() );
175 std::reverse( poly.begin(), poly.end() );
179 const QRectF ptsRect = poly.boundingRect();
199 poly.erase( std::remove_if( poly.begin(), poly.end(),
200 [](
const QPointF point )
202 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
205 QPointF *ptr = poly.data();
206 for (
int i = 0; i < poly.size(); ++i, ++ptr )
211 if ( !poly.empty() && !poly.isClosed() )
212 poly << poly.at( 0 );
223 holes.reserve( ringCount );
224 for (
int idx = 0; idx < ringCount; idx++ )
227 if ( !hole.isEmpty() )
228 holes.append( hole );
245 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
249 for ( ; it !=
mLayers.constEnd(); ++it )
251 if ( ( *it )->outputUnit() != unit )
266 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
267 if ( it ==
mLayers.constEnd() )
273 for ( ; it !=
mLayers.constEnd(); ++it )
275 if ( ( *it )->mapUnitScale() != scale )
285 const auto constMLayers =
mLayers;
288 layer->setOutputUnit( u );
294 const auto constMLayers =
mLayers;
297 layer->setMapUnitScale( scale );
303 std::unique_ptr< QgsSymbol > s;
330 s = qgis::make_unique< QgsMarkerSymbol >();
333 s = qgis::make_unique< QgsLineSymbol >();
336 s = qgis::make_unique< QgsFillSymbol >();
339 QgsDebugMsg( QStringLiteral(
"unknown layer's geometry type" ) );
378 if ( index < 0 || index >
mLayers.count() )
381 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
391 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
401 if ( index < 0 || index >=
mLayers.count() )
412 if ( index < 0 || index >=
mLayers.count() )
415 return mLayers.takeAt( index );
423 if ( oldLayer ==
layer )
426 if ( !
layer || !
layer->isCompatibleWithSymbol(
this ) )
437 Q_ASSERT_X( !mStarted,
"startRender",
"Rendering has already been started for this symbol instance!" );
447 mSymbolRenderContext->setExpressionContextScope( scope.release() );
449 const auto constMLayers =
mLayers;
455 layer->prepareExpressions( symbolContext );
456 layer->startRender( symbolContext );
462 Q_ASSERT_X( mStarted,
"startRender",
"startRender was not called for this symbol instance!" );
466 if ( mSymbolRenderContext )
468 const auto constMLayers =
mLayers;
474 layer->stopRender( *mSymbolRenderContext );
478 mSymbolRenderContext.reset(
nullptr );
487 const auto constMLayers =
mLayers;
490 if ( !
layer->isLocked() )
497 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
500 if ( !( *it )->isLocked() )
501 return ( *it )->color();
503 return QColor( 0, 0, 0 );
509 std::unique_ptr< QgsRenderContext > tempContext;
513 context = tempContext.get();
525 if ( !customContext && expressionContext )
529 else if ( !customContext )
553 const QSizeF targetSize = QSizeF( size.width() - 1, size.height() - 1 );
561 std::unique_ptr< QgsEffectPainter > effectPainter;
562 if ( effect && effect->
enabled() )
563 effectPainter = qgis::make_unique< QgsEffectPainter >( symbolContext.
renderContext(), effect );
565 for (
const QList< QPolygonF > &poly : polys )
567 QVector< QPolygonF > rings;
568 for (
int i = 1; i < poly.size(); ++i )
569 rings << poly.at( i );
573 effectPainter.reset();
578 layer->drawPreviewIcon( symbolContext, size );
586 if ( format.compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
588 QSvgGenerator generator;
589 generator.setFileName( path );
590 generator.setSize( size );
591 generator.setViewBox( QRect( 0, 0, size.height(), size.height() ) );
593 QPainter painter( &generator );
599 QImage image =
asImage( size );
606 QImage image( size, QImage::Format_ARGB32_Premultiplied );
609 QPainter p( &image );
610 p.setRenderHint( QPainter::Antialiasing );
620 QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
623 QPainter p( &preview );
624 p.setRenderHint( QPainter::Antialiasing );
625 p.translate( 0.5, 0.5 );
629 p.setPen( QPen( Qt::gray ) );
630 p.drawLine( 0, 50, 100, 50 );
631 p.drawLine( 50, 0, 50, 100 );
636 if ( expressionContext )
645 poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
646 static_cast<QgsLineSymbol *
>( this )->renderPolyline( poly,
nullptr, context );
651 polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
652 static_cast<QgsFillSymbol *
>( this )->renderPolygon( polygon,
nullptr,
nullptr, context );
656 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( QPointF( 50, 50 ),
nullptr, context );
670 t = QStringLiteral(
"MARKER" );
673 t = QStringLiteral(
"LINE" );
676 t = QStringLiteral(
"FILL" );
679 Q_ASSERT(
false &&
"unknown symbol type" );
683 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
692 props[ QStringLiteral(
"alpha" )] = QString::number(
opacity() );
693 double scaleFactor = 1.0;
697 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
699 ( *it )->toSld( doc, element, props );
706 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
709 layer->setLocked( ( *it )->isLocked() );
710 layer->setRenderingPass( ( *it )->renderingPass() );
711 layer->setEnabled( ( *it )->enabled() );
727 if ( effect && effect->
enabled() )
730 generatorLayer->
render( context );
734 generatorLayer->
render( context );
740 QSet<QString> attributes;
741 QgsSymbolLayerList::const_iterator sIt =
mLayers.constBegin();
742 for ( ; sIt !=
mLayers.constEnd(); ++sIt )
746 attributes.unite( ( *sIt )->usedAttributes( context ) );
754 const auto constMLayers =
mLayers;
757 if (
layer->hasDataDefinedProperties() )
782 class ExpressionContextScopePopper
786 ExpressionContextScopePopper() =
default;
788 ~ExpressionContextScopePopper()
800 class GeometryRestorer
804 : mContext( context ),
805 mGeometry( context.geometry() )
810 mContext.setGeometry( mGeometry );
830 GeometryRestorer geomRestorer( context );
832 bool usingSegmentizedGeometry =
false;
839 if ( !needsSegmentizing )
843 for (
int i = 0; i < collection->numGeometries(); ++i )
847 needsSegmentizing =
true;
854 if ( needsSegmentizing )
862 usingSegmentizedGeometry =
true;
865 mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.
constGet()->
partCount() );
866 mSymbolRenderContext->setGeometryPartNum( 1 );
869 ExpressionContextScopePopper scopePopper;
870 if ( mSymbolRenderContext->expressionContextScope() )
872 if ( needsExpressionContext )
897 segmentizedGeometry = simplifier.
simplify( segmentizedGeometry );
908 const QgsPoint *originalGeometry =
nullptr;
910 QVector< PointInfo > pointsToRender;
914 QPolygonF renderLine;
915 const QgsCurve *originalGeometry =
nullptr;
917 QVector< LineInfo > linesToRender;
921 QPolygonF renderExterior;
922 QVector< QPolygonF > renderRings;
925 QVector< PolygonInfo > polygonsToRender;
928 getPartGeometry = [&pointsToRender, &linesToRender, &polygonsToRender, &getPartGeometry, &context, &tileMapRendering, &markers, &feature,
this](
const QgsAbstractGeometry * part )
941 QgsDebugMsgLevel( QStringLiteral(
"point can be drawn only with marker symbol!" ), 2 );
946 info.originalGeometry = qgsgeometry_cast< const QgsPoint * >( part );
947 info.renderPoint =
_getPoint( context, *info.originalGeometry );
948 pointsToRender << info;
956 QgsDebugMsgLevel( QStringLiteral(
"linestring can be drawn only with line symbol!" ), 2 );
961 info.originalGeometry = qgsgeometry_cast<const QgsCurve *>( part );
963 linesToRender << info;
971 QVector<QPolygonF> holes;
974 QgsDebugMsgLevel( QStringLiteral(
"polygon can be drawn only with fill symbol!" ), 2 );
979 info.originalGeometry = qgsgeometry_cast<const QgsPolygon *>( part );
980 if ( !info.originalGeometry->exteriorRing() )
982 QgsDebugMsg( QStringLiteral(
"cannot render polygon with no exterior ring" ) );
987 polygonsToRender << info;
993 const QgsMultiPoint *mp = qgsgeometry_cast< const QgsMultiPoint * >( part );
1001 const QgsGeometryCollection *geomCollection = qgsgeometry_cast<const QgsGeometryCollection *>( part );
1004 for (
unsigned int i = 0; i < num; ++i )
1006 if ( context.renderingStopped() )
1009 getPartGeometry( geomCollection->
geometryN( i ) );
1019 QgsDebugMsgLevel( QStringLiteral(
"multi-polygon can be drawn only with fill symbol!" ), 2 );
1024 QVector<QPolygonF> holes;
1031 std::map<double, QList<unsigned int> > thisAreaToPartNum;
1032 for (
unsigned int i = 0; i < num; ++i )
1034 const QgsPolygon *polygon = qgsgeometry_cast<const QgsPolygon *>( geomCollection->
geometryN( i ) );
1042 std::map<double, QList<unsigned int> >::const_reverse_iterator iter = thisAreaToPartNum.rbegin();
1043 for ( ; iter != thisAreaToPartNum.rend(); ++iter )
1045 const QList<unsigned int> &listPartIndex = iter->second;
1046 for (
int idx = 0; idx < listPartIndex.size(); ++idx )
1048 const unsigned i = listPartIndex[idx];
1049 const QgsPolygon *polygon = qgsgeometry_cast<const QgsPolygon *>( geomCollection->
geometryN( i ) );
1050 getPartGeometry( polygon );
1057 QgsDebugMsg( QStringLiteral(
"feature %1: unsupported wkb type %2/%3 for rendering" )
1058 .arg( feature.id() )
1060 .arg( part->wkbType(), 0, 16 ) );
1064 getPartGeometry( segmentizedGeometry.
constGet() );
1067 std::vector< int > layers;
1070 layers.reserve(
mLayers.count() );
1071 for (
int i = 0; i <
mLayers.count(); ++i )
1072 layers.emplace_back( i );
1076 layers.emplace_back(
layer );
1081 if ( needsExpressionContext )
1084 for (
const int symbolLayerIndex : layers )
1090 if ( needsExpressionContext )
1099 int geometryPartNumber = 0;
1100 for (
const PointInfo &point : qgis::as_const( pointsToRender ) )
1102 if ( context.renderingStopped() )
1105 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1106 if ( needsExpressionContext )
1109 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( point.renderPoint, &feature, context, symbolLayerIndex, selected );
1110 geometryPartNumber++;
1118 if ( linesToRender.empty() )
1121 int geometryPartNumber = 0;
1122 for (
const LineInfo &line : linesToRender )
1124 if ( context.renderingStopped() )
1127 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1128 if ( needsExpressionContext )
1131 context.setGeometry( line.originalGeometry );
1132 static_cast<QgsLineSymbol *
>( this )->renderPolyline( line.renderLine, &feature, context, symbolLayerIndex, selected );
1133 geometryPartNumber++;
1140 int geometryPartNumber = 0;
1141 for (
const PolygonInfo &info : polygonsToRender )
1143 if ( context.renderingStopped() )
1146 mSymbolRenderContext->setGeometryPartNum( geometryPartNumber + 1 );
1147 if ( needsExpressionContext )
1150 context.setGeometry( info.originalGeometry );
1151 static_cast<QgsFillSymbol *
>( this )->renderPolygon( info.renderExterior, ( !info.renderRings.isEmpty() ? &info.renderRings : nullptr ), &feature, context, symbolLayerIndex, selected );
1152 geometryPartNumber++;
1170 markers.reserve( pointsToRender.size() );
1171 for (
const PointInfo &info : qgis::as_const( pointsToRender ) )
1175 const QRectF bounds =
static_cast<QgsMarkerSymbol *
>( this )->bounds( info.renderPoint, context, feature );
1176 if ( context.hasRenderedFeatureHandlers() )
1184 context.painter()->setPen( Qt::red );
1185 context.painter()->setBrush( QColor( 255, 0, 0, 100 ) );
1186 context.painter()->drawRect( bounds );
1190 if ( drawVertexMarker && !usingSegmentizedGeometry )
1192 markers.append( info.renderPoint );
1200 for (
const LineInfo &info : qgis::as_const( linesToRender ) )
1202 if ( context.hasRenderedFeatureHandlers() )
1208 if ( drawVertexMarker && !usingSegmentizedGeometry )
1210 markers << info.renderLine;
1219 for (
const PolygonInfo &info : qgis::as_const( polygonsToRender ) )
1221 if ( context.hasRenderedFeatureHandlers() )
1228 if ( drawVertexMarker && !usingSegmentizedGeometry )
1230 markers << info.renderExterior;
1232 for (
const QPolygonF &hole : info.renderRings )
1246 if ( context.hasRenderedFeatureHandlers() )
1249 const QList< QgsRenderedFeatureHandlerInterface * > handlers = context.renderedFeatureHandlers();
1251 handler->handleRenderedFeature( feature, renderedBoundsGeom, featureContext );
1254 if ( drawVertexMarker )
1256 if ( !markers.isEmpty() && !context.renderingStopped() )
1258 const auto constMarkers = markers;
1259 for ( QPointF marker : constMarkers )
1261 renderVertexMarker( marker, context, currentVertexMarkerType, currentVertexMarkerSize );
1276 x = vertexPoint.
x();
1277 y = vertexPoint.
y();
1286 renderVertexMarker( mapPoint, context, currentVertexMarkerType, currentVertexMarkerSize );
1294 return mSymbolRenderContext.get();
1316 const QList< QgsSymbolLayer * > layers =
mLayers;
1340 const QList< QgsSymbolLayer * > layers =
mLayers;
1355 : mRenderContext(
c )
1357 , mMapUnitScale( mapUnitScale )
1358 , mOpacity( opacity )
1359 , mSelected( selected )
1360 , mRenderHints( renderHints )
1363 , mGeometryPartCount( 0 )
1364 , mGeometryPartNum( 0 )
1398 return mExpressionContextScope.get();
1403 mExpressionContextScope.reset( contextScope );
1408 return mPatchShape.get();
1425 layers.append( sl );
1436 layers.append( sl );
1447 layers.append( sl );
1462 double origAngle =
angle();
1463 double angleDiff = symbolAngle - origAngle;
1464 const auto constMLayers =
mLayers;
1480 return markerLayer->
angle();
1487 const auto constMLayers =
mLayers;
1499 const double symbolRotation =
angle();
1528 const double symbolRotation =
angle();
1559 if ( !layerAngleDD || layerAngleDD != symbolDD )
1565 if ( !layerAngleDD || layerAngleDD != rotatedDD )
1575 double origSize =
size();
1577 const auto constMLayers =
mLayers;
1588 markerLayer->
setSize( markerLayer->
size() * s / origSize );
1592 markerLayer->
setOffset( QPointF( markerLayer->
offset().x() * s / origSize,
1593 markerLayer->
offset().y() * s / origSize ) );
1601 const auto constMLayers =
mLayers;
1607 double lsize = markerLayer->
size();
1608 if ( lsize > maxSize )
1624 maxSize = std::max( maxSize, layerSize );
1631 const auto constMLayers =
mLayers;
1647 const auto constMLayers =
mLayers;
1658 if ( unit != markerLayer->
sizeUnit() )
1669 const auto constMLayers =
mLayers;
1682 const auto constMLayers =
mLayers;
1696 const double symbolSize =
size();
1698 const auto constMLayers =
mLayers;
1724 markerLayer->
offset().x() / symbolSize,
1725 markerLayer->
offset().y() / symbolSize, property ) );
1733 const double symbolSize =
size();
1766 if ( !layerSizeDD || layerSizeDD != symbolDD )
1775 if ( !layerSizeDD || layerSizeDD != scaledDD )
1780 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
1789 const auto constMLayers =
mLayers;
1801 const auto constMLayers =
mLayers;
1816 static QPointF nullPoint( 0, 0 );
1822 if ( effect && effect->
enabled() )
1825 p->translate( point );
1826 p.setEffect( effect );
1827 layer->renderPoint( nullPoint, context );
1831 layer->renderPoint( point, context );
1841 if ( layerIdx != -1 )
1849 renderPointUsingLayer( markerLayer, point, symbolContext );
1869 renderPointUsingLayer( markerLayer, point, symbolContext );
1881 const auto constMLayers =
mLayers;
1887 if ( bound.isNull() )
1888 bound =
symbolLayer->bounds( point, symbolContext );
1890 bound = bound.united(
symbolLayer->bounds( point, symbolContext ) );
1921 double origWidth =
width();
1923 const auto constMLayers =
mLayers;
1948 double maxWidth = 0;
1952 const auto constMLayers =
mLayers;
1959 if (
width > maxWidth )
1969 double maxWidth = 0;
1975 const double layerWidth = lineLayer->
width( context );
1976 maxWidth = std::max( maxWidth, layerWidth );
1983 const double symbolWidth =
width();
1985 const auto constMLayers =
mLayers;
2019 const double symbolWidth =
width();
2024 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
2038 const auto constMLayers =
mLayers;
2050 if ( !layerWidthDD || layerWidthDD != symbolDD )
2059 if ( !layerWidthDD || layerWidthDD != scaledDD )
2064 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
2074 QPainter *renderPainter = context.
painter();
2080 if ( layerIdx != -1 )
2088 renderPolylineUsingLayer( lineLayer, points, symbolContext );
2096 const auto constMLayers =
mLayers;
2108 renderPolylineUsingLayer( lineLayer, points, symbolContext );
2125 if ( effect && effect->
enabled() )
2128 p->translate( points.boundingRect().topLeft() );
2129 p.setEffect( effect );
2130 layer->renderPolyline( points.translated( -points.boundingRect().topLeft() ), context );
2134 layer->renderPolyline( points, context );
2168 if ( layerIdx != -1 )
2174 renderPolygonUsingLayer(
symbolLayer, points, rings, symbolContext );
2181 const auto constMLayers =
mLayers;
2191 renderPolygonUsingLayer(
symbolLayer, points, rings, symbolContext );
2205 if ( effect && effect->
enabled() )
2207 QRectF bounds = polygonBounds( points, rings );
2208 QVector<QPolygonF> *translatedRings = translateRings( rings, -bounds.left(), -bounds.top() );
2211 p->translate( bounds.topLeft() );
2212 p.setEffect( effect );
2215 (
static_cast<QgsFillSymbolLayer *
>(
layer ) )->renderPolygon( points.translated( -bounds.topLeft() ), translatedRings, context );
2219 (
static_cast<QgsLineSymbolLayer *
>(
layer ) )->renderPolygonStroke( points.translated( -bounds.topLeft() ), translatedRings, context );
2221 delete translatedRings;
2236 QRectF QgsFillSymbol::polygonBounds(
const QPolygonF &points,
const QVector<QPolygonF> *rings )
const
2238 QRectF bounds = points.boundingRect();
2241 for (
auto it = rings->constBegin(); it != rings->constEnd(); ++it )
2243 bounds = bounds.united( ( *it ).boundingRect() );
2249 QVector<QPolygonF> *QgsFillSymbol::translateRings(
const QVector<QPolygonF> *rings,
double dx,
double dy )
const
2254 QVector<QPolygonF> *translatedRings =
new QVector<QPolygonF>;
2255 translatedRings->reserve( rings->size() );
2256 for (
auto it = rings->constBegin(); it != rings->constEnd(); ++it )
2258 translatedRings->append( ( *it ).translated( dx, dy ) );
2260 return translatedRings;
2277 const auto constMLayers =
mLayers;
Abstract base class for curved geometry type.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
Q_DECL_DEPRECATED void setLayer(const QgsVectorLayer *layer)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsSymbolLayerList cloneLayers() const
Retrieve a cloned list of all layers that make up this symbol.
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.
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
bool enabled() const
Returns true if symbol layer is enabled and will be drawn.
const Q_DECL_DEPRECATED QgsVectorLayer * mLayer
QgsFillSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsFillSymbol, with the specified list of initial symbol layers.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol's size.
QColor color() const
Returns the symbol's color.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QList< QList< QPolygonF > > toQPolygonF(QgsSymbol::SymbolType type, QSizeF size) const
Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for...
static QString encodeColor(const QColor &color)
static QPolygonF clippedLine(const QgsCurve &curve, const QgsRectangle &clipExtent)
Takes a linestring and clips it to clipExtent.
void setIsGuiPreview(bool preview)
Sets GUI preview mode.
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
double size() const
Returns the symbol size.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides.
A store for object properties.
RenderUnit
Rendering size units.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
virtual double width() const
Returns the estimated width for the line symbol layer.
A class to manager painter saving and restoring required for effect drawing.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the size units for the whole symbol (including all symbol layers).
Point geometry type, with support for z-dimension and m-values.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
int numGeometries() const
Returns the number of geometries within the collection.
#define QgsDebugMsgLevel(str, level)
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
void renderUsingLayer(QgsSymbolLayer *layer, QgsSymbolRenderContext &context)
Renders a context using a particular symbol layer without passing in a geometry.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
QgsSymbolLayer * takeSymbolLayer(int index)
Removes a symbol layer from the list and returns a pointer to it.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
const Q_DECL_DEPRECATED QgsVectorLayer * layer() const
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void setAngle(double angle)
Sets the rotation angle for the marker.
void setSelected(bool selected)
Sets whether symbols should be rendered using the selected symbol coloring and style.
void setGeometryPartNum(int num)
Sets the part number of current geometry.
QgsSymbol::ScaleMethod scaleMethod() const
Returns the method to use for scaling the marker's size.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
static QgsProject * instance()
Returns the QgsProject singleton instance.
bool hasDataDefinedProperties() const
Returns whether the symbol utilizes any data defined properties.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
@ RenderMillimeters
Millimeters.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Abstract base class for marker symbol layers.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
~QgsSymbolRenderContext()
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
double angle() const
Returns the marker angle for the whole symbol.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
bool insertSymbolLayer(int index, QgsSymbolLayer *layer)
Inserts a symbol layer to specified index.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleMarkerSymbolLayer.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
QgsSymbol(SymbolType type, const QgsSymbolLayerList &layers)
void setWidth(double width)
Sets the width for the whole line symbol.
const QgsLegendPatchShape * patchShape() const
Returns the symbol patch shape, to use if rendering symbol preview icons.
void setOffset(double offset)
Sets the line's offset.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool isSymbolLayerEnabled(const QgsSymbolLayer *layer) const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
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.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape, to use if rendering symbol preview icons.
QgsProperty rotateWholeSymbol(double additionalRotation, const QgsProperty &property)
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol's size.
static QgsStyle * defaultStyle()
Returns default application-wide style.
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol.
ScaleMethod scaleMethod()
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
#define Q_NOWARN_DEPRECATED_POP
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
qreal opacity() const
Returns the opacity for the symbol.
@ PropertyOffset
Symbol offset.
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=nullptr)
Returns a large (roughly 100x100 pixel) preview image for the symbol.
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void setAngle(double angle)
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
SimplifyAlgorithm
Types of simplification algorithms that can be used.
QgsSymbolLayerList mLayers
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.
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Converts the symbol to a SLD representation.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, double currentVertexMarkerSize=0.0) SIP_THROW(QgsCsException)
Render a feature.
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
@ Clockwise
Clockwise orientation.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.
QString dump() const
Returns a string dump of the symbol's properties.
@ PropertySize
Symbol size.
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.
void setGeometryPartCount(int count)
Sets the part count of current geometry.
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
@ CounterClockwise
Counter-clockwise orientation.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
Q_DECL_DEPRECATED double outputLineWidth(double width) const
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
Struct for storing maximum and minimum scales for measurements in map units.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
void renderVertexMarker(QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize)
Render editing vertex marker at specified point.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol using the given render context.
@ PropertyStrokeWidth
Stroke width.
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Multi point geometry collection.
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
Abstract base class for all geometries.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Single scope for storing variables and functions for use within a QgsExpressionContext....
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
QRectF bounds(QPointF point, QgsRenderContext &context, const QgsFeature &feature=QgsFeature()) const
Returns the approximate bounding box of the marker symbol, which includes the bounding box of all sym...
@ PropertyLayerEnabled
Whether symbol layer is enabled.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
qreal mOpacity
Symbol opacity (in the range 0 - 1)
void setOriginalGeometryType(QgsWkbTypes::GeometryType type)
Sets the geometry type for the original feature geometry being rendered.
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
QMap< QString, QString > QgsStringMap
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
Q_DECL_DEPRECATED double outputPixelSize(double size) const
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(QgsSymbol::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
QgsProperty scaleWholeSymbol(double scaleFactor, const QgsProperty &property)
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
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
void setColor(const QColor &color)
Sets the color for the symbol.
virtual void render(QgsSymbolRenderContext &context)
Will render this symbol layer using the context.
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.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
QList< QgsSymbolLayer * > QgsSymbolLayerList
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
QgsSymbolRenderContext(QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity=1.0, bool selected=false, QgsSymbol::RenderHints renderHints=nullptr, const QgsFeature *f=nullptr, const QgsFields &fields=QgsFields(), const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Constructor for QgsSymbolRenderContext.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
#define DEFAULT_SCALE_METHOD
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
Utility class for identifying a unique vertex within a geometry.
Base class for visual effects which can be applied to QPicture drawings.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
double height() const
Returns the height of the rectangle.
@ PropertyAngle
Symbol angle.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol along the line joining points, using the given render context.
QgsLineSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsLineSymbol, with the specified list of initial symbol layers.
@ RenderUnknownUnit
Mixed or unknown units.
VertexMarkerType
Editing vertex markers.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
SymbolType type() const
Returns the symbol's type.
void setExpressionContextScope(QgsExpressionContextScope *contextScope)
Set an expression scope for this symbol.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
static QString encodeSldUom(QgsUnitTypes::RenderUnit unit, double *scaleFactor)
Encodes a render unit into an SLD unit of measure string.
virtual void setSize(double size)
Sets the symbol size.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's size.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
QgsSymbol::SymbolType type() const
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
double offset() const
Returns the line's offset.
virtual int numPoints() const =0
Returns the number of points in the curve.
SymbolType
Type of the symbol.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the size units for the whole symbol (including all symbol layers).
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
QPainter * painter()
Returns the destination QPainter for the render operation.
bool enabled() const
Returns whether the effect is enabled.
QgsMarkerSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsMarkerSymbol, with the specified list of initial symbol layers.
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
QImage asImage(QSize size, QgsRenderContext *customContext=nullptr)
Returns an image of the symbol at the specified size.
Single variable definition for use within a QgsExpressionContextScope.
Orientation orientation() const
Returns the curve's orientation, e.g.
QgsMapUnitScale sizeMapUnitScale() const
Returns the size map unit scale for the whole symbol.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
#define Q_NOWARN_DEPRECATED_PUSH
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 renderPoint(QPointF point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol at the specified point, using the given render context.
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)
void setAngle(double angle)
QgsMapLayerType type() const
Returns the type of the layer.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
double width() const
Returns the width of the rectangle.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
bool mClipFeaturesToExtent
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static Type flatType(Type type)
Returns the flat type for a WKB type.
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Sets the method to use for scaling the marker's size.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
void setSize(double size)
Sets the size for the whole symbol.
static void drawVertexMarker(double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the size map unit scale for the whole symbol (including all symbol layers).
QgsSymbolRenderContext & operator=(const QgsSymbolRenderContext &)
const QgsMapUnitScale & sizeMapUnitScale() const
Returns the map unit scale for the symbol's size.