40 #include <QSvgRenderer>
41 #include <QDomDocument>
42 #include <QDomElement>
50 Qt::PenJoinStyle penJoinStyle )
51 : mBrushStyle( style )
52 , mStrokeColor( strokeColor )
53 , mStrokeStyle( strokeStyle )
54 , mStrokeWidth( strokeWidth )
55 , mPenJoinStyle( penJoinStyle )
97 void QgsSimpleFillSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context, QBrush &brush, QPen &pen, QPen &selPen )
115 if ( exprVal.isValid() )
122 penColor.setAlphaF( context.
opacity() * penColor.alphaF() );
123 pen.setColor( penColor );
129 double width = exprVal.toDouble( &ok );
133 pen.setWidthF( width );
134 selPen.setWidthF( width );
170 if ( props.contains( QStringLiteral(
"color" ) ) )
172 if ( props.contains( QStringLiteral(
"style" ) ) )
174 if ( props.contains( QStringLiteral(
"color_border" ) ) )
179 else if ( props.contains( QStringLiteral(
"outline_color" ) ) )
183 else if ( props.contains( QStringLiteral(
"line_color" ) ) )
188 if ( props.contains( QStringLiteral(
"style_border" ) ) )
193 else if ( props.contains( QStringLiteral(
"outline_style" ) ) )
197 else if ( props.contains( QStringLiteral(
"line_style" ) ) )
201 if ( props.contains( QStringLiteral(
"width_border" ) ) )
204 strokeWidth = props[QStringLiteral(
"width_border" )].toDouble();
206 else if ( props.contains( QStringLiteral(
"outline_width" ) ) )
208 strokeWidth = props[QStringLiteral(
"outline_width" )].toDouble();
210 else if ( props.contains( QStringLiteral(
"line_width" ) ) )
212 strokeWidth = props[QStringLiteral(
"line_width" )].toDouble();
214 if ( props.contains( QStringLiteral(
"offset" ) ) )
216 if ( props.contains( QStringLiteral(
"joinstyle" ) ) )
221 if ( props.contains( QStringLiteral(
"border_width_unit" ) ) )
225 else if ( props.contains( QStringLiteral(
"outline_width_unit" ) ) )
229 else if ( props.contains( QStringLiteral(
"line_width_unit" ) ) )
233 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
236 if ( props.contains( QStringLiteral(
"border_width_map_unit_scale" ) ) )
238 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
241 sl->restoreOldDataDefinedProperties( props );
249 return QStringLiteral(
"SimpleFill" );
261 selColor.setAlphaF( context.
opacity() );
318 #ifndef QT_NO_PRINTER
319 if (
mBrush.style() == Qt::SolidPattern ||
mBrush.style() == Qt::NoBrush || !
dynamic_cast<QPrinter *
>( p->device() ) )
326 #ifndef QT_NO_PRINTER
333 p->setPen( Qt::NoPen );
337 p->setBrush( Qt::NoBrush );
355 map[QStringLiteral(
"outline_width" )] = QString::number(
mStrokeWidth );
383 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
384 if ( !props.value( QStringLiteral(
"uom" ), QString() ).toString().isEmpty() )
385 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ).toString() );
386 element.appendChild( symbolizerElem );
394 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
395 symbolizerElem.appendChild( fillElem );
402 QDomElement strokeElem = doc.createElement( QStringLiteral(
"se:Stroke" ) );
403 symbolizerElem.appendChild( strokeElem );
418 symbolStyle.append(
';' );
427 Qt::BrushStyle fillStyle;
431 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
434 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
440 QString uom = element.attribute( QStringLiteral(
"uom" ), QString() );
446 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
455 return penBleed + offsetBleed;
516 : mGradientColorType( colorType )
517 , mGradientType( gradientType )
518 , mCoordinateMode( coordinateMode )
519 , mGradientSpread( spread )
520 , mReferencePoint1( QPointF( 0.5, 0 ) )
521 , mReferencePoint2( QPointF( 0.5, 1 ) )
542 bool refPoint1IsCentroid =
false;
544 bool refPoint2IsCentroid =
false;
549 if ( props.contains( QStringLiteral(
"type" ) ) )
550 type =
static_cast< GradientType >( props[QStringLiteral(
"type" )].toInt() );
551 if ( props.contains( QStringLiteral(
"coordinate_mode" ) ) )
553 if ( props.contains( QStringLiteral(
"spread" ) ) )
555 if ( props.contains( QStringLiteral(
"color_type" ) ) )
556 colorType =
static_cast< GradientColorType >( props[QStringLiteral(
"color_type" )].toInt() );
557 if ( props.contains( QStringLiteral(
"gradient_color" ) ) )
562 else if ( props.contains( QStringLiteral(
"color" ) ) )
566 if ( props.contains( QStringLiteral(
"gradient_color2" ) ) )
571 if ( props.contains( QStringLiteral(
"reference_point1" ) ) )
573 if ( props.contains( QStringLiteral(
"reference_point1_iscentroid" ) ) )
574 refPoint1IsCentroid = props[QStringLiteral(
"reference_point1_iscentroid" )].toInt();
575 if ( props.contains( QStringLiteral(
"reference_point2" ) ) )
577 if ( props.contains( QStringLiteral(
"reference_point2_iscentroid" ) ) )
578 refPoint2IsCentroid = props[QStringLiteral(
"reference_point2_iscentroid" )].toInt();
579 if ( props.contains( QStringLiteral(
"angle" ) ) )
580 angle = props[QStringLiteral(
"angle" )].toDouble();
582 if ( props.contains( QStringLiteral(
"offset" ) ) )
599 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
601 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
604 sl->setReferencePoint1IsCentroid( refPoint1IsCentroid );
606 sl->setReferencePoint2IsCentroid( refPoint2IsCentroid );
607 sl->setAngle(
angle );
609 sl->setColorRamp( gradientRamp );
611 sl->restoreOldDataDefinedProperties( props );
624 return QStringLiteral(
"GradientFill" );
627 void QgsGradientFillSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context,
const QPolygonF &points )
672 if ( currentType == QObject::tr(
"linear" ) )
676 else if ( currentType == QObject::tr(
"radial" ) )
680 else if ( currentType == QObject::tr(
"conical" ) )
694 if ( currentCoordMode == QObject::tr(
"feature" ) )
698 else if ( currentCoordMode == QObject::tr(
"viewport" ) )
712 if ( currentSpread == QObject::tr(
"pad" ) )
716 else if ( currentSpread == QObject::tr(
"repeat" ) )
720 else if ( currentSpread == QObject::tr(
"reflect" ) )
767 if ( refPoint1IsCentroid || refPoint2IsCentroid )
772 QRectF bbox = points.boundingRect();
773 double centroidX = ( centroid.x() - bbox.left() ) / bbox.width();
774 double centroidY = ( centroid.y() - bbox.top() ) / bbox.height();
776 if ( refPoint1IsCentroid )
778 refPoint1X = centroidX;
779 refPoint1Y = centroidY;
781 if ( refPoint2IsCentroid )
783 refPoint2X = centroidX;
784 refPoint2Y = centroidY;
790 spread, QPointF( refPoint1X, refPoint1Y ), QPointF( refPoint2X, refPoint2Y ),
angle );
793 QPointF QgsGradientFillSymbolLayer::rotateReferencePoint( QPointF refPoint,
double angle )
798 QLineF refLine = QLineF( QPointF( 0.5, 0.5 ), refPoint );
800 refLine.setAngle( refLine.angle() +
angle );
802 QPointF rotatedReferencePoint = refLine.p2();
804 if ( rotatedReferencePoint.x() > 1 )
805 rotatedReferencePoint.setX( 1 );
806 if ( rotatedReferencePoint.x() < 0 )
807 rotatedReferencePoint.setX( 0 );
808 if ( rotatedReferencePoint.y() > 1 )
809 rotatedReferencePoint.setY( 1 );
810 if ( rotatedReferencePoint.y() < 0 )
811 rotatedReferencePoint.setY( 0 );
813 return rotatedReferencePoint;
817 const QColor &color,
const QColor &color2, GradientColorType gradientColorType,
819 GradientCoordinateMode coordinateMode, GradientSpread gradientSpread,
820 QPointF referencePoint1, QPointF referencePoint2,
const double angle )
825 QColor fillColor2 =
color2;
826 fillColor2.setAlphaF( context.
opacity() * fillColor2.alphaF() );
837 gradient = QLinearGradient( rotatedReferencePoint1, rotatedReferencePoint2 );
840 gradient = QRadialGradient( rotatedReferencePoint1, QLineF( rotatedReferencePoint1, rotatedReferencePoint2 ).length() );
843 gradient = QConicalGradient( rotatedReferencePoint1, QLineF( rotatedReferencePoint1, rotatedReferencePoint2 ).
angle() );
849 gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
852 gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
858 gradient.setSpread( QGradient::PadSpread );
861 gradient.setSpread( QGradient::ReflectSpread );
864 gradient.setSpread( QGradient::RepeatSpread );
880 gradient.setColorAt( 1.0, fillColor2 );
884 brush = QBrush( gradient );
891 selColor.setAlphaF( context.
opacity() );
908 applyDataDefinedSymbology( context, points );
911 p->setPen( Qt::NoPen );
945 map[QStringLiteral(
"type" )] = QString::number(
mGradientType );
946 map[QStringLiteral(
"coordinate_mode" )] = QString::number(
mCoordinateMode );
952 map[QStringLiteral(
"angle" )] = QString::number(
mAngle );
958 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1024 int blurRadius,
bool useWholeShape,
double maxDistance )
1025 : mBlurRadius( blurRadius )
1026 , mUseWholeShape( useWholeShape )
1027 , mMaxDistance( maxDistance )
1028 , mColorType( colorType )
1047 if ( props.contains( QStringLiteral(
"color_type" ) ) )
1051 if ( props.contains( QStringLiteral(
"shapeburst_color" ) ) )
1056 else if ( props.contains( QStringLiteral(
"color" ) ) )
1061 if ( props.contains( QStringLiteral(
"shapeburst_color2" ) ) )
1066 else if ( props.contains( QStringLiteral(
"gradient_color2" ) ) )
1070 if ( props.contains( QStringLiteral(
"blur_radius" ) ) )
1072 blurRadius = props[QStringLiteral(
"blur_radius" )].toInt();
1074 if ( props.contains( QStringLiteral(
"use_whole_shape" ) ) )
1076 useWholeShape = props[QStringLiteral(
"use_whole_shape" )].toInt();
1078 if ( props.contains( QStringLiteral(
"max_distance" ) ) )
1080 maxDistance = props[QStringLiteral(
"max_distance" )].toDouble();
1082 if ( props.contains( QStringLiteral(
"offset" ) ) )
1101 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
1105 if ( props.contains( QStringLiteral(
"distance_unit" ) ) )
1109 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
1113 if ( props.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
1117 if ( props.contains( QStringLiteral(
"ignore_rings" ) ) )
1119 sl->setIgnoreRings( props[QStringLiteral(
"ignore_rings" )].toInt() );
1123 sl->setColorRamp( gradientRamp );
1126 sl->restoreOldDataDefinedProperties( props );
1128 return sl.release();
1133 return QStringLiteral(
"ShapeburstFill" );
1138 if ( mGradientRamp.get() == ramp )
1141 mGradientRamp.reset( ramp );
1144 void QgsShapeburstFillSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context, QColor &color, QColor &color2,
int &blurRadius,
bool &useWholeShape,
1145 double &maxDistance,
bool &ignoreRings )
1202 selColor.setAlphaF( context.
opacity() );
1203 mSelBrush = QBrush( selColor );
1222 p->setBrush( mSelBrush );
1223 QPointF
offset = mOffset;
1258 int outputPixelMaxDist = 0;
1266 std::unique_ptr< QgsGradientColorRamp > twoColorGradientRamp;
1269 twoColorGradientRamp = qgis::make_unique< QgsGradientColorRamp >( color1,
color2 );
1273 p->setPen( QPen( Qt::NoPen ) );
1278 int pointsWidth =
static_cast< int >( std::round( points.boundingRect().width() ) );
1279 int pointsHeight =
static_cast< int >( std::round( points.boundingRect().height() ) );
1280 int imWidth = pointsWidth + ( sideBuffer * 2 );
1281 int imHeight = pointsHeight + ( sideBuffer * 2 );
1282 std::unique_ptr< QImage > fillImage = qgis::make_unique< QImage >( imWidth,
1283 imHeight, QImage::Format_ARGB32_Premultiplied );
1284 if ( fillImage->isNull() )
1291 std::unique_ptr< QImage > alphaImage = qgis::make_unique< QImage >( fillImage->width(), fillImage->height(), QImage::Format_ARGB32_Premultiplied );
1292 if ( alphaImage->isNull() )
1301 fillImage->fill( Qt::black );
1304 alphaImage->fill( Qt::transparent );
1307 QPainter imgPainter;
1308 imgPainter.begin( alphaImage.get() );
1309 imgPainter.setRenderHint( QPainter::Antialiasing,
true );
1310 imgPainter.setBrush( QBrush( Qt::white ) );
1311 imgPainter.setPen( QPen( Qt::black ) );
1312 imgPainter.translate( -points.boundingRect().left() + sideBuffer, - points.boundingRect().top() + sideBuffer );
1318 imgPainter.begin( fillImage.get() );
1321 imgPainter.drawImage( 0, 0, *alphaImage );
1328 imgPainter.setBrush( QBrush( Qt::white ) );
1329 imgPainter.setPen( QPen( Qt::black ) );
1330 imgPainter.translate( -points.boundingRect().left() + sideBuffer, - points.boundingRect().top() + sideBuffer );
1336 double *dtArray = distanceTransform( fillImage.get(), context.
renderContext() );
1356 imgPainter.begin( fillImage.get() );
1357 imgPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
1358 imgPainter.drawImage( 0, 0, *alphaImage );
1366 QPointF
offset = mOffset;
1383 p->drawImage( points.boundingRect().left() - sideBuffer, points.boundingRect().top() - sideBuffer, *fillImage );
1394 void QgsShapeburstFillSymbolLayer::distanceTransform1d(
double *f,
int n,
int *v,
double *z,
double *d )
1400 for (
int q = 1; q <= n - 1; q++ )
1402 double s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1406 s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1415 for (
int q = 0; q <= n - 1; q++ )
1417 while ( z[k + 1] < q )
1419 d[q] = ( q - v[k] ) * ( q - v[k] ) + f[v[k]];
1424 void QgsShapeburstFillSymbolLayer::distanceTransform2d(
double *im,
int width,
int height,
QgsRenderContext &context )
1426 int maxDimension = std::max( width, height );
1427 double *f =
new double[ maxDimension ];
1428 int *v =
new int[ maxDimension ];
1429 double *z =
new double[ maxDimension + 1 ];
1430 double *d =
new double[ maxDimension ];
1433 for (
int x = 0; x < width; x++ )
1438 for (
int y = 0; y < height; y++ )
1440 f[y] = im[ x + y * width ];
1442 distanceTransform1d( f, height, v, z, d );
1443 for (
int y = 0; y < height; y++ )
1445 im[ x + y * width ] = d[y];
1450 for (
int y = 0; y < height; y++ )
1455 for (
int x = 0; x < width; x++ )
1457 f[x] = im[ x + y * width ];
1459 distanceTransform1d( f, width, v, z, d );
1460 for (
int x = 0; x < width; x++ )
1462 im[ x + y * width ] = d[x];
1473 double *QgsShapeburstFillSymbolLayer::distanceTransform( QImage *im,
QgsRenderContext &context )
1475 int width = im->width();
1476 int height = im->height();
1478 double *dtArray =
new double[width * height];
1483 for (
int heightIndex = 0; heightIndex < height; ++heightIndex )
1488 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( im->constScanLine( heightIndex ) );
1489 for (
int widthIndex = 0; widthIndex < width; ++widthIndex )
1491 tmpRgb = scanLine[widthIndex];
1492 if ( qRed( tmpRgb ) == 0 )
1500 dtArray[ idx ] =
INF;
1507 distanceTransform2d( dtArray, width, height, context );
1512 void QgsShapeburstFillSymbolLayer::dtArrayToQImage(
double *array, QImage *im,
QgsColorRamp *ramp,
QgsRenderContext &context,
bool useWholeShape,
int maxPixelDistance )
1514 int width = im->width();
1515 int height = im->height();
1518 double maxDistanceValue;
1523 double dtMaxValue = array[0];
1524 for (
int i = 1; i < ( width * height ); ++i )
1526 if ( array[i] > dtMaxValue )
1528 dtMaxValue = array[i];
1533 maxDistanceValue = std::sqrt( dtMaxValue );
1538 maxDistanceValue = maxPixelDistance;
1543 double squaredVal = 0;
1546 for (
int heightIndex = 0; heightIndex < height; ++heightIndex )
1551 QRgb *scanLine =
reinterpret_cast< QRgb *
>( im->scanLine( heightIndex ) );
1552 for (
int widthIndex = 0; widthIndex < width; ++widthIndex )
1555 squaredVal = array[idx];
1558 if ( maxDistanceValue > 0 )
1560 pixVal = squaredVal > 0 ? std::min( ( std::sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
1569 scanLine[widthIndex] = qPremultiply( ramp->
color( pixVal ).rgba() );
1580 map[QStringLiteral(
"color_type" )] = QString::number( mColorType );
1581 map[QStringLiteral(
"blur_radius" )] = QString::number( mBlurRadius );
1582 map[QStringLiteral(
"use_whole_shape" )] = QString::number( mUseWholeShape );
1583 map[QStringLiteral(
"max_distance" )] = QString::number( mMaxDistance );
1586 map[QStringLiteral(
"ignore_rings" )] = QString::number( mIgnoreRings );
1590 if ( mGradientRamp )
1592 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
1593 map.unite( mGradientRamp->properties() );
1595 map.insert( mGradientRamp->properties() );
1604 std::unique_ptr< QgsShapeburstFillSymbolLayer > sl = qgis::make_unique< QgsShapeburstFillSymbolLayer >(
mColor, mColor2, mColorType, mBlurRadius, mUseWholeShape, mMaxDistance );
1605 if ( mGradientRamp )
1607 sl->setColorRamp( mGradientRamp->clone() );
1609 sl->setDistanceUnit( mDistanceUnit );
1610 sl->setDistanceMapUnitScale( mDistanceMapUnitScale );
1611 sl->setIgnoreRings( mIgnoreRings );
1612 sl->setOffset( mOffset );
1613 sl->setOffsetUnit( mOffsetUnit );
1614 sl->setOffsetMapUnitScale( mOffsetMapUnitScale );
1617 return sl.release();
1622 double offsetBleed = context.
convertToPainterUnits( std::max( std::fabs( mOffset.x() ), std::fabs( mOffset.y() ) ), mOffsetUnit, mOffsetMapUnitScale );
1633 mDistanceUnit = unit;
1639 if ( mDistanceUnit == mOffsetUnit )
1641 return mDistanceUnit;
1654 mDistanceMapUnitScale = scale;
1655 mOffsetMapUnitScale = scale;
1660 if ( mDistanceMapUnitScale == mOffsetMapUnitScale )
1662 return mDistanceMapUnitScale;
1686 p->setPen( QPen( Qt::NoPen ) );
1688 QTransform bkTransform =
mBrush.transform();
1692 QTransform t =
mBrush.transform();
1693 t.translate( leftCorner.x(), leftCorner.y() );
1694 mBrush.setTransform( t );
1700 p->setBrush( QBrush( selColor ) );
1706 QTransform t =
mBrush.transform();
1708 mBrush.setTransform( t );
1717 for (
auto ringIt = rings->constBegin(); ringIt != rings->constEnd(); ++ringIt )
1724 mBrush.setTransform( bkTransform );
1776 double subLayerBleed =
mStroke->symbolLayer( 0 )->estimateMaxBleed( context );
1777 return subLayerBleed;
1798 return QColor( Qt::black );
1805 return Qt::SolidLine;
1809 return Qt::SolidLine;
1813 return mStroke->dxfPenStyle();
1822 attr.unite(
mStroke->usedAttributes( context ) );
1845 , mPatternWidth( width )
1849 mColor = QColor( 255, 255, 255 );
1855 , mPatternWidth( width )
1856 , mSvgData( svgData )
1861 mColor = QColor( 255, 255, 255 );
1863 setDefaultSvgParams();
1869 mPatternWidthUnit = unit;
1870 mSvgStrokeWidthUnit = unit;
1872 mStroke->setOutputUnit( unit );
1878 if ( mPatternWidthUnit != unit || mSvgStrokeWidthUnit != unit ||
mStrokeWidthUnit != unit )
1888 mPatternWidthMapUnitScale = scale;
1889 mSvgStrokeWidthMapUnitScale = scale;
1896 mPatternWidthMapUnitScale == mSvgStrokeWidthMapUnitScale &&
1899 return mPatternWidthMapUnitScale;
1909 mSvgFilePath = svgPath;
1910 setDefaultSvgParams();
1920 if (
properties.contains( QStringLiteral(
"width" ) ) )
1922 width =
properties[QStringLiteral(
"width" )].toDouble();
1924 if (
properties.contains( QStringLiteral(
"svgFile" ) ) )
1928 if (
properties.contains( QStringLiteral(
"angle" ) ) )
1933 std::unique_ptr< QgsSVGFillSymbolLayer > symbolLayer;
1936 symbolLayer = qgis::make_unique< QgsSVGFillSymbolLayer >(
svgFilePath, width,
angle );
1940 if (
properties.contains( QStringLiteral(
"data" ) ) )
1942 data = QByteArray::fromHex(
properties[QStringLiteral(
"data" )].toString().toLocal8Bit() );
1944 symbolLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( data, width,
angle );
1948 if (
properties.contains( QStringLiteral(
"svgFillColor" ) ) )
1953 else if (
properties.contains( QStringLiteral(
"color" ) ) )
1957 if (
properties.contains( QStringLiteral(
"svgOutlineColor" ) ) )
1962 else if (
properties.contains( QStringLiteral(
"outline_color" ) ) )
1966 else if (
properties.contains( QStringLiteral(
"line_color" ) ) )
1970 if (
properties.contains( QStringLiteral(
"svgOutlineWidth" ) ) )
1973 symbolLayer->setSvgStrokeWidth(
properties[QStringLiteral(
"svgOutlineWidth" )].toDouble() );
1975 else if (
properties.contains( QStringLiteral(
"outline_width" ) ) )
1977 symbolLayer->setSvgStrokeWidth(
properties[QStringLiteral(
"outline_width" )].toDouble() );
1979 else if (
properties.contains( QStringLiteral(
"line_width" ) ) )
1981 symbolLayer->setSvgStrokeWidth(
properties[QStringLiteral(
"line_width" )].toDouble() );
1985 if (
properties.contains( QStringLiteral(
"pattern_width_unit" ) ) )
1989 if (
properties.contains( QStringLiteral(
"pattern_width_map_unit_scale" ) ) )
1993 if (
properties.contains( QStringLiteral(
"svg_outline_width_unit" ) ) )
1997 if (
properties.contains( QStringLiteral(
"svg_outline_width_map_unit_scale" ) ) )
2001 if (
properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
2005 if (
properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
2010 if (
properties.contains( QStringLiteral(
"parameters" ) ) )
2013 QMap<QString, QgsProperty> parametersProperties;
2014 QVariantMap::const_iterator it =
parameters.constBegin();
2019 parametersProperties.insert( it.key(), property );
2022 symbolLayer->setParameters( parametersProperties );
2025 symbolLayer->restoreOldDataDefinedProperties(
properties );
2027 return symbolLayer.release();
2032 QVariantMap::iterator it =
properties.find( QStringLiteral(
"svgFile" ) );
2044 return QStringLiteral(
"SVGFill" );
2047 void QgsSVGFillSymbolLayer::applyPattern( QBrush &brush,
const QString &svgFilePath,
double patternWidth,
QgsUnitTypes::RenderUnit patternWidthUnit,
2048 const QColor &svgFillColor,
const QColor &svgStrokeColor,
double svgStrokeWidth,
2052 if ( mSvgViewBox.isNull() )
2059 if (
static_cast< int >( size ) < 1.0 || 10000.0 < size )
2061 brush.setTextureImage( QImage() );
2065 bool fitsInCache =
true;
2073 double hwRatio = 1.0;
2074 if ( patternPict.width() > 0 )
2076 hwRatio =
static_cast< double >( patternPict.height() ) /
static_cast< double >( patternPict.width() );
2078 patternImage = QImage(
static_cast< int >( size ),
static_cast< int >( size * hwRatio ), QImage::Format_ARGB32_Premultiplied );
2079 patternImage.fill( 0 );
2081 QPainter p( &patternImage );
2082 p.drawPicture( QPointF( size / 2, size * hwRatio / 2 ), patternPict );
2085 QTransform brushTransform;
2088 QImage transparentImage = patternImage.copy();
2090 brush.setTextureImage( transparentImage );
2094 brush.setTextureImage( patternImage );
2096 brush.setTransform( brushTransform );
2104 applyPattern(
mBrush, mSvgFilePath, mPatternWidth, mPatternWidthUnit,
mColor, mSvgStrokeColor, mSvgStrokeWidth, mSvgStrokeWidthUnit, context, mPatternWidthMapUnitScale, mSvgStrokeWidthMapUnitScale, evaluatedParameters );
2123 if ( !mSvgFilePath.isEmpty() )
2125 map.insert( QStringLiteral(
"svgFile" ), mSvgFilePath );
2129 map.insert( QStringLiteral(
"data" ), QString( mSvgData.toHex() ) );
2132 map.insert( QStringLiteral(
"width" ), QString::number( mPatternWidth ) );
2133 map.insert( QStringLiteral(
"angle" ), QString::number(
mAngle ) );
2138 map.insert( QStringLiteral(
"outline_width" ), QString::number( mSvgStrokeWidth ) );
2149 QMap<QString, QgsProperty>::const_iterator it = mParameters.constBegin();
2150 for ( ; it != mParameters.constEnd(); ++it )
2151 parameters.insert( it.key(), it.value().toVariant() );
2152 map[QStringLiteral(
"parameters" )] =
parameters;
2159 std::unique_ptr< QgsSVGFillSymbolLayer > clonedLayer;
2160 if ( !mSvgFilePath.isEmpty() )
2162 clonedLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( mSvgFilePath, mPatternWidth,
mAngle );
2163 clonedLayer->setSvgFillColor(
mColor );
2164 clonedLayer->setSvgStrokeColor( mSvgStrokeColor );
2165 clonedLayer->setSvgStrokeWidth( mSvgStrokeWidth );
2169 clonedLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( mSvgData, mPatternWidth,
mAngle );
2172 clonedLayer->setPatternWidthUnit( mPatternWidthUnit );
2173 clonedLayer->setPatternWidthMapUnitScale( mPatternWidthMapUnitScale );
2174 clonedLayer->setSvgStrokeWidthUnit( mSvgStrokeWidthUnit );
2175 clonedLayer->setSvgStrokeWidthMapUnitScale( mSvgStrokeWidthMapUnitScale );
2179 clonedLayer->setParameters( mParameters );
2183 clonedLayer->setSubSymbol(
mStroke->clone() );
2187 return clonedLayer.release();
2192 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
2193 if ( !props.value( QStringLiteral(
"uom" ), QString() ).toString().isEmpty() )
2194 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ).toString() );
2195 element.appendChild( symbolizerElem );
2199 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
2200 symbolizerElem.appendChild( fillElem );
2202 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
2203 fillElem.appendChild( graphicFillElem );
2205 QDomElement graphicElem = doc.createElement( QStringLiteral(
"se:Graphic" ) );
2206 graphicFillElem.appendChild( graphicElem );
2208 if ( !mSvgFilePath.isEmpty() )
2219 symbolizerElem.appendChild( doc.createComment( QStringLiteral(
"SVG from data not implemented yet" ) ) );
2225 double angle = props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toDouble( &ok );
2228 angleFunc = QStringLiteral(
"%1 + %2" ).arg( props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toString() ).arg(
mAngle );
2241 mStroke->toSld( doc, element, props );
2253 QString path, mimeType;
2255 Qt::PenStyle penStyle;
2256 double size, strokeWidth;
2258 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
2259 if ( fillElem.isNull() )
2262 QDomElement graphicFillElem = fillElem.firstChildElement( QStringLiteral(
"GraphicFill" ) );
2263 if ( graphicFillElem.isNull() )
2266 QDomElement graphicElem = graphicFillElem.firstChildElement( QStringLiteral(
"Graphic" ) );
2267 if ( graphicElem.isNull() )
2273 if ( mimeType != QLatin1String(
"image/svg+xml" ) )
2278 QString uom = element.attribute( QStringLiteral(
"uom" ) );
2287 double d = angleFunc.toDouble( &ok );
2292 std::unique_ptr< QgsSVGFillSymbolLayer > sl = qgis::make_unique< QgsSVGFillSymbolLayer >( path, size,
angle );
2293 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
2296 sl->setSvgStrokeWidth( strokeWidth );
2299 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
2300 if ( !strokeElem.isNull() )
2311 return sl.release();
2329 double width = mPatternWidth;
2335 QString svgFile = mSvgFilePath;
2354 double strokeWidth = mSvgStrokeWidth;
2363 mSvgStrokeWidthUnit, context, mPatternWidthMapUnitScale, mSvgStrokeWidthMapUnitScale, evaluatedParameters );
2367 void QgsSVGFillSymbolLayer::storeViewBox()
2369 if ( !mSvgData.isEmpty() )
2371 QSvgRenderer r( mSvgData );
2374 mSvgViewBox = r.viewBoxF();
2379 mSvgViewBox = QRectF();
2382 void QgsSVGFillSymbolLayer::setDefaultSvgParams()
2384 if ( mSvgFilePath.isEmpty() )
2389 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
2390 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
2391 QColor defaultFillColor, defaultStrokeColor;
2392 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
2394 hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2395 hasStrokeParam, hasDefaultStrokeColor, defaultStrokeColor,
2396 hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
2397 hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
2399 double newFillOpacity = hasFillOpacityParam ?
mColor.alphaF() : 1.0;
2400 double newStrokeOpacity = hasStrokeOpacityParam ? mSvgStrokeColor.alphaF() : 1.0;
2402 if ( hasDefaultFillColor )
2404 mColor = defaultFillColor;
2405 mColor.setAlphaF( newFillOpacity );
2407 if ( hasDefaultFillOpacity )
2409 mColor.setAlphaF( defaultFillOpacity );
2411 if ( hasDefaultStrokeColor )
2413 mSvgStrokeColor = defaultStrokeColor;
2414 mSvgStrokeColor.setAlphaF( newStrokeOpacity );
2416 if ( hasDefaultStrokeOpacity )
2418 mSvgStrokeColor.setAlphaF( defaultStrokeOpacity );
2420 if ( hasDefaultStrokeWidth )
2422 mSvgStrokeWidth = defaultStrokeWidth;
2453 return mFillLineSymbol ? mFillLineSymbol->
color() :
mColor;
2458 delete mFillLineSymbol;
2473 delete mFillLineSymbol;
2474 mFillLineSymbol = lineSymbol;
2485 return mFillLineSymbol;
2491 if ( mFillLineSymbol )
2513 mDistanceUnit = unit;
2514 mLineWidthUnit = unit;
2521 if ( mDistanceUnit != unit || mLineWidthUnit != unit || mOffsetUnit != unit )
2538 mDistanceMapUnitScale = scale;
2539 mLineWidthMapUnitScale = scale;
2540 mOffsetMapUnitScale = scale;
2546 mDistanceMapUnitScale == mLineWidthMapUnitScale &&
2547 mLineWidthMapUnitScale == mOffsetMapUnitScale )
2549 return mDistanceMapUnitScale;
2556 std::unique_ptr< QgsLinePatternFillSymbolLayer > patternLayer = qgis::make_unique< QgsLinePatternFillSymbolLayer >();
2562 QColor
color( Qt::black );
2565 if (
properties.contains( QStringLiteral(
"lineangle" ) ) )
2570 else if (
properties.contains( QStringLiteral(
"angle" ) ) )
2574 patternLayer->setLineAngle(
lineAngle );
2576 if (
properties.contains( QStringLiteral(
"distance" ) ) )
2580 patternLayer->setDistance(
distance );
2582 if (
properties.contains( QStringLiteral(
"linewidth" ) ) )
2587 else if (
properties.contains( QStringLiteral(
"outline_width" ) ) )
2591 else if (
properties.contains( QStringLiteral(
"line_width" ) ) )
2595 patternLayer->setLineWidth(
lineWidth );
2597 if (
properties.contains( QStringLiteral(
"color" ) ) )
2601 else if (
properties.contains( QStringLiteral(
"outline_color" ) ) )
2605 else if (
properties.contains( QStringLiteral(
"line_color" ) ) )
2609 patternLayer->setColor(
color );
2611 if (
properties.contains( QStringLiteral(
"offset" ) ) )
2615 patternLayer->setOffset(
offset );
2618 if (
properties.contains( QStringLiteral(
"distance_unit" ) ) )
2622 if (
properties.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
2626 if (
properties.contains( QStringLiteral(
"line_width_unit" ) ) )
2630 else if (
properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
2634 if (
properties.contains( QStringLiteral(
"line_width_map_unit_scale" ) ) )
2638 if (
properties.contains( QStringLiteral(
"offset_unit" ) ) )
2642 if (
properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
2646 if (
properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
2650 if (
properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
2655 patternLayer->restoreOldDataDefinedProperties(
properties );
2657 return patternLayer.release();
2662 return QStringLiteral(
"LinePatternFill" );
2665 void QgsLinePatternFillSymbolLayer::applyPattern(
const QgsSymbolRenderContext &context, QBrush &brush,
double lineAngle,
double distance )
2667 mBrush.setTextureImage( QImage() );
2669 if ( !mFillLineSymbol )
2674 std::unique_ptr< QgsLineSymbol > fillLineSymbol( mFillLineSymbol->
clone() );
2675 if ( !fillLineSymbol )
2690 outputPixelOffset = std::fmod( outputPixelOffset, outputPixelDist );
2691 if ( outputPixelOffset > outputPixelDist / 2.0 )
2692 outputPixelOffset -= outputPixelDist;
2696 double outputPixelBleed = 0;
2697 double outputPixelInterval = 0;
2698 for (
int i = 0; i < fillLineSymbol->symbolLayerCount(); i++ )
2702 outputPixelBleed = std::max( outputPixelBleed, outputPixelLayerBleed );
2705 if ( markerLineLayer )
2714 outputPixelInterval = std::max( outputPixelInterval, outputPixelLayerInterval );
2718 if ( outputPixelInterval > 0 )
2722 double intervalScale = std::round( outputPixelInterval ) / outputPixelInterval;
2723 outputPixelInterval = std::round( outputPixelInterval );
2725 for (
int i = 0; i < fillLineSymbol->symbolLayerCount(); i++ )
2730 if ( markerLineLayer )
2744 height = outputPixelDist;
2745 width = outputPixelInterval > 0 ? outputPixelInterval : height;
2749 width = outputPixelDist;
2750 height = outputPixelInterval > 0 ? outputPixelInterval : width;
2754 height = outputPixelDist / std::cos(
lineAngle * M_PI / 180 );
2755 width = outputPixelDist / std::sin(
lineAngle * M_PI / 180 );
2758 lineAngle = 180 * std::atan2(
static_cast< double >( height ),
static_cast< double >( width ) ) / M_PI;
2764 height = std::abs( height );
2765 width = std::abs( width );
2767 outputPixelDist = std::abs( height * std::cos(
lineAngle * M_PI / 180 ) );
2771 int offsetHeight =
static_cast< int >( std::round( outputPixelOffset / std::cos(
lineAngle * M_PI / 180 ) ) );
2772 outputPixelOffset = offsetHeight * std::cos(
lineAngle * M_PI / 180 );
2781 int bufferMulti =
static_cast< int >( std::max( std::ceil( outputPixelBleed / width ), std::ceil( outputPixelBleed / width ) ) );
2785 bufferMulti = std::max( bufferMulti, 1 );
2787 int xBuffer = width * bufferMulti;
2788 int yBuffer = height * bufferMulti;
2789 int innerWidth = width;
2790 int innerHeight = height;
2791 width += 2 * xBuffer;
2792 height += 2 * yBuffer;
2795 if ( width > 10000 || height > 10000 || width == 0 || height == 0 )
2800 QImage patternImage( width, height, QImage::Format_ARGB32 );
2801 patternImage.fill( 0 );
2803 QPointF p1, p2, p3, p4, p5, p6;
2806 p1 = QPointF( 0, yBuffer );
2807 p2 = QPointF( width, yBuffer );
2808 p3 = QPointF( 0, yBuffer + innerHeight );
2809 p4 = QPointF( width, yBuffer + innerHeight );
2813 p1 = QPointF( xBuffer, height );
2814 p2 = QPointF( xBuffer, 0 );
2815 p3 = QPointF( xBuffer + innerWidth, height );
2816 p4 = QPointF( xBuffer + innerWidth, 0 );
2820 dx = outputPixelDist * std::cos( ( 90 -
lineAngle ) * M_PI / 180.0 );
2821 dy = outputPixelDist * std::sin( ( 90 -
lineAngle ) * M_PI / 180.0 );
2822 p1 = QPointF( 0, height );
2823 p2 = QPointF( width, 0 );
2824 p3 = QPointF( -dx, height - dy );
2825 p4 = QPointF( width - dx, -dy );
2826 p5 = QPointF( dx, height + dy );
2827 p6 = QPointF( width + dx, dy );
2831 dx = outputPixelDist * std::cos( ( 90 -
lineAngle ) * M_PI / 180.0 );
2832 dy = outputPixelDist * std::sin( ( 90 -
lineAngle ) * M_PI / 180.0 );
2833 p1 = QPointF( width, 0 );
2834 p2 = QPointF( 0, height );
2835 p3 = QPointF( width - dx, -dy );
2836 p4 = QPointF( -dx, height - dy );
2837 p5 = QPointF( width + dx, dy );
2838 p6 = QPointF( dx, height + dy );
2842 dy = outputPixelDist * std::cos( ( 180 -
lineAngle ) * M_PI / 180 );
2843 dx = outputPixelDist * std::sin( ( 180 -
lineAngle ) * M_PI / 180 );
2844 p1 = QPointF( 0, 0 );
2845 p2 = QPointF( width, height );
2846 p5 = QPointF( dx, -dy );
2847 p6 = QPointF( width + dx, height - dy );
2848 p3 = QPointF( -dx, dy );
2849 p4 = QPointF( width - dx, height + dy );
2853 dy = outputPixelDist * std::cos( ( 180 -
lineAngle ) * M_PI / 180 );
2854 dx = outputPixelDist * std::sin( ( 180 -
lineAngle ) * M_PI / 180 );
2855 p1 = QPointF( width, height );
2856 p2 = QPointF( 0, 0 );
2857 p5 = QPointF( width + dx, height - dy );
2858 p6 = QPointF( dx, -dy );
2859 p3 = QPointF( width - dx, height + dy );
2860 p4 = QPointF( -dx, dy );
2867 p3 = QPointF( tempPt.x(), tempPt.y() );
2869 p4 = QPointF( tempPt.x(), tempPt.y() );
2871 p5 = QPointF( tempPt.x(), tempPt.y() );
2873 p6 = QPointF( tempPt.x(), tempPt.y() );
2877 p1 = QPointF( tempPt.x(), tempPt.y() );
2879 p2 = QPointF( tempPt.x(), tempPt.y() );
2882 QPainter p( &patternImage );
2886 p.setRenderHint( QPainter::Antialiasing,
false );
2887 QPen pen( QColor( Qt::black ) );
2888 pen.setWidthF( 0.1 );
2889 pen.setCapStyle( Qt::FlatCap );
2894 QPolygon polygon = QPolygon() << QPoint( 0, 0 ) << QPoint( width - 1, 0 ) << QPoint( width - 1, height - 1 ) << QPoint( 0, height - 1 ) << QPoint( 0, 0 );
2895 p.drawPolygon( polygon );
2897 polygon = QPolygon() << QPoint( xBuffer, yBuffer ) << QPoint( width - xBuffer - 1, yBuffer ) << QPoint( width - xBuffer - 1, height - yBuffer - 1 ) << QPoint( xBuffer, height - yBuffer - 1 ) << QPoint( xBuffer, yBuffer );
2898 p.drawPolygon( polygon );
2904 p.setRenderHint( QPainter::Antialiasing,
true );
2915 fillLineSymbol->startRender( lineRenderContext, context.
fields() );
2917 QVector<QPolygonF> polygons;
2918 polygons.append( QPolygonF() << p1 << p2 );
2919 polygons.append( QPolygonF() << p3 << p4 );
2922 polygons.append( QPolygonF() << p5 << p6 );
2925 for (
const QPolygonF &polygon : qgis::as_const( polygons ) )
2927 fillLineSymbol->renderPolyline( polygon, context.
feature(), lineRenderContext, -1, context.
selected() );
2930 fillLineSymbol->stopRender( lineRenderContext );
2934 patternImage = patternImage.copy( xBuffer, yBuffer, patternImage.width() - 2 * xBuffer, patternImage.height() - 2 * yBuffer );
2939 QImage transparentImage = patternImage.copy();
2941 brush.setTextureImage( transparentImage );
2945 brush.setTextureImage( patternImage );
2948 QTransform brushTransform;
2949 brush.setTransform( brushTransform );
2954 applyPattern( context,
mBrush, mLineAngle, mDistance );
2956 if ( mFillLineSymbol )
2964 if ( mFillLineSymbol )
2973 map.insert( QStringLiteral(
"angle" ), QString::number( mLineAngle ) );
2974 map.insert( QStringLiteral(
"distance" ), QString::number( mDistance ) );
2975 map.insert( QStringLiteral(
"line_width" ), QString::number( mLineWidth ) );
2977 map.insert( QStringLiteral(
"offset" ), QString::number( mOffset ) );
2992 if ( mFillLineSymbol )
3003 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
3004 if ( !props.value( QStringLiteral(
"uom" ), QString() ).toString().isEmpty() )
3005 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ).toString() );
3006 element.appendChild( symbolizerElem );
3011 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
3012 symbolizerElem.appendChild( fillElem );
3014 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
3015 fillElem.appendChild( graphicFillElem );
3017 QDomElement graphicElem = doc.createElement( QStringLiteral(
"se:Graphic" ) );
3018 graphicFillElem.appendChild( graphicElem );
3021 QColor lineColor = mFillLineSymbol ? mFillLineSymbol->
color() : QColor();
3022 double lineWidth = mFillLineSymbol ? mFillLineSymbol->
width() : 0.0;
3030 double angle = props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toDouble( &ok );
3033 angleFunc = QStringLiteral(
"%1 + %2" ).arg( props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toString() ).arg( mLineAngle );
3037 angleFunc = QString::number(
angle + mLineAngle );
3042 QPointF lineOffset( std::sin( mLineAngle ) * mOffset, std::cos( mLineAngle ) * mOffset );
3049 QString featureStyle;
3050 featureStyle.append(
"Brush(" );
3051 featureStyle.append( QStringLiteral(
"fc:%1" ).arg(
mColor.name() ) );
3052 featureStyle.append( QStringLiteral(
",bc:%1" ).arg( QLatin1String(
"#00000000" ) ) );
3053 featureStyle.append(
",id:\"ogr-brush-2\"" );
3054 featureStyle.append( QStringLiteral(
",a:%1" ).arg( mLineAngle ) );
3055 featureStyle.append( QStringLiteral(
",s:%1" ).arg( mLineWidth * widthScaleFactor ) );
3056 featureStyle.append(
",dx:0mm" );
3057 featureStyle.append( QStringLiteral(
",dy:%1mm" ).arg( mDistance * widthScaleFactor ) );
3058 featureStyle.append(
')' );
3059 return featureStyle;
3090 Qt::PenStyle lineStyle;
3092 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
3093 if ( fillElem.isNull() )
3096 QDomElement graphicFillElem = fillElem.firstChildElement( QStringLiteral(
"GraphicFill" ) );
3097 if ( graphicFillElem.isNull() )
3100 QDomElement graphicElem = graphicFillElem.firstChildElement( QStringLiteral(
"Graphic" ) );
3101 if ( graphicElem.isNull() )
3107 if ( name != QLatin1String(
"horline" ) )
3115 double d = angleFunc.toDouble( &ok );
3124 offset = std::sqrt( std::pow( vectOffset.x(), 2 ) + std::pow( vectOffset.y(), 2 ) );
3127 QString uom = element.attribute( QStringLiteral(
"uom" ) );
3131 std::unique_ptr< QgsLinePatternFillSymbolLayer > sl = qgis::make_unique< QgsLinePatternFillSymbolLayer >();
3132 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
3133 sl->setColor( lineColor );
3135 sl->setLineAngle(
angle );
3137 sl->setDistance( size );
3140 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
3141 if ( !strokeElem.isNull() )
3152 return sl.release();
3239 std::unique_ptr< QgsPointPatternFillSymbolLayer > layer = qgis::make_unique< QgsPointPatternFillSymbolLayer >();
3240 if (
properties.contains( QStringLiteral(
"distance_x" ) ) )
3242 layer->setDistanceX(
properties[QStringLiteral(
"distance_x" )].toDouble() );
3244 if (
properties.contains( QStringLiteral(
"distance_y" ) ) )
3246 layer->setDistanceY(
properties[QStringLiteral(
"distance_y" )].toDouble() );
3248 if (
properties.contains( QStringLiteral(
"displacement_x" ) ) )
3250 layer->setDisplacementX(
properties[QStringLiteral(
"displacement_x" )].toDouble() );
3252 if (
properties.contains( QStringLiteral(
"displacement_y" ) ) )
3254 layer->setDisplacementY(
properties[QStringLiteral(
"displacement_y" )].toDouble() );
3256 if (
properties.contains( QStringLiteral(
"offset_x" ) ) )
3258 layer->setOffsetX(
properties[QStringLiteral(
"offset_x" )].toDouble() );
3260 if (
properties.contains( QStringLiteral(
"offset_y" ) ) )
3262 layer->setOffsetY(
properties[QStringLiteral(
"offset_y" )].toDouble() );
3265 if (
properties.contains( QStringLiteral(
"distance_x_unit" ) ) )
3269 if (
properties.contains( QStringLiteral(
"distance_x_map_unit_scale" ) ) )
3273 if (
properties.contains( QStringLiteral(
"distance_y_unit" ) ) )
3277 if (
properties.contains( QStringLiteral(
"distance_y_map_unit_scale" ) ) )
3281 if (
properties.contains( QStringLiteral(
"displacement_x_unit" ) ) )
3285 if (
properties.contains( QStringLiteral(
"displacement_x_map_unit_scale" ) ) )
3289 if (
properties.contains( QStringLiteral(
"displacement_y_unit" ) ) )
3293 if (
properties.contains( QStringLiteral(
"displacement_y_map_unit_scale" ) ) )
3297 if (
properties.contains( QStringLiteral(
"offset_x_unit" ) ) )
3301 if (
properties.contains( QStringLiteral(
"offset_x_map_unit_scale" ) ) )
3305 if (
properties.contains( QStringLiteral(
"offset_y_unit" ) ) )
3309 if (
properties.contains( QStringLiteral(
"offset_y_map_unit_scale" ) ) )
3314 if (
properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
3318 if (
properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
3323 layer->restoreOldDataDefinedProperties(
properties );
3325 return layer.release();
3330 return QStringLiteral(
"PointPatternFill" );
3333 void QgsPointPatternFillSymbolLayer::applyPattern(
const QgsSymbolRenderContext &context, QBrush &brush,
double distanceX,
double distanceY,
3334 double displacementX,
double displacementY,
double offsetX,
double offsetY )
3344 if ( width > 10000 || height > 10000 )
3347 brush.setTextureImage( img );
3351 QImage patternImage( width, height, QImage::Format_ARGB32 );
3352 patternImage.fill( 0 );
3353 if ( patternImage.isNull() )
3355 brush.setTextureImage( QImage() );
3360 QPainter p( &patternImage );
3381 for (
double currentX = -width; currentX <= width * 2.0; currentX += width )
3383 for (
double currentY = -height; currentY <= height * 2.0; currentY += height )
3392 for (
double currentX = -width; currentX <= width * 2.0; currentX += width )
3394 for (
double currentY = -height / 2.0; currentY <= height * 2.0; currentY += height )
3400 for (
double currentX = -width / 2.0; currentX <= width * 2.0; currentX += width )
3402 for (
double currentY = -height; currentY <= height * 2.0; currentY += height / 2.0 )
3404 mMarkerSymbol->
renderPoint( QPointF( currentX + widthOffset + ( std::fmod( currentY, height ) != 0 ? displacementPixelX : 0 ), currentY + heightOffset - displacementPixelY ), context.
feature(), pointRenderContext );
3413 QImage transparentImage = patternImage.copy();
3415 brush.setTextureImage( transparentImage );
3419 brush.setTextureImage( patternImage );
3421 QTransform brushTransform;
3422 brush.setTransform( brushTransform );
3431 if ( mRenderUsingMarkers )
3449 if ( mRenderUsingMarkers )
3462 if ( !mRenderUsingMarkers )
3524 p->setPen( QPen( Qt::NoPen ) );
3529 p->setBrush( QBrush( selColor ) );
3536 path.addPolygon( points );
3539 for (
const QPolygonF &ring : *rings )
3541 path.addPolygon( ring );
3544 p->setClipPath( path, Qt::IntersectClip );
3546 const double left = points.boundingRect().left();
3547 const double top = points.boundingRect().top();
3548 const double right = points.boundingRect().right();
3549 const double bottom = points.boundingRect().bottom();
3556 bool alternateColumn =
false;
3557 int currentCol = -3;
3558 for (
double currentX = ( std::floor( left / width ) - 2 ) * width; currentX <= right + 2 * width; currentX += width, alternateColumn = !alternateColumn )
3560 if ( needsExpressionContext )
3563 bool alternateRow =
false;
3564 const double columnX = currentX + widthOffset;
3565 int currentRow = -3;
3566 for (
double currentY = ( std::floor( top / height ) - 2 ) * height; currentY <= bottom + 2 * height; currentY += height, alternateRow = !alternateRow )
3568 double y = currentY + heightOffset;
3571 x += displacementPixelX;
3573 if ( !alternateColumn )
3574 y -= displacementPixelY;
3576 if ( needsExpressionContext )
3593 for (
auto ringIt = rings->constBegin(); ringIt != rings->constEnd(); ++ringIt )
3604 map.insert( QStringLiteral(
"distance_x" ), QString::number(
mDistanceX ) );
3605 map.insert( QStringLiteral(
"distance_y" ), QString::number(
mDistanceY ) );
3606 map.insert( QStringLiteral(
"displacement_x" ), QString::number(
mDisplacementX ) );
3607 map.insert( QStringLiteral(
"displacement_y" ), QString::number(
mDisplacementY ) );
3608 map.insert( QStringLiteral(
"offset_x" ), QString::number(
mOffsetX ) );
3609 map.insert( QStringLiteral(
"offset_y" ), QString::number(
mOffsetY ) );
3643 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
3644 if ( !props.value( QStringLiteral(
"uom" ), QString() ).toString().isEmpty() )
3645 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ).toString() );
3646 element.appendChild( symbolizerElem );
3651 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
3652 symbolizerElem.appendChild( fillElem );
3654 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
3655 fillElem.appendChild( graphicFillElem );
3662 symbolizerElem.appendChild( distanceElem );
3668 QString errorMsg = QStringLiteral(
"MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( layer->
layerType() );
3669 graphicFillElem.appendChild( doc.createComment( errorMsg ) );
3795 std::unique_ptr< QgsCentroidFillSymbolLayer > sl = qgis::make_unique< QgsCentroidFillSymbolLayer >();
3797 if (
properties.contains( QStringLiteral(
"point_on_surface" ) ) )
3798 sl->setPointOnSurface(
properties[QStringLiteral(
"point_on_surface" )].toInt() != 0 );
3799 if (
properties.contains( QStringLiteral(
"point_on_all_parts" ) ) )
3800 sl->setPointOnAllParts(
properties[QStringLiteral(
"point_on_all_parts" )].toInt() != 0 );
3801 if (
properties.contains( QStringLiteral(
"clip_points" ) ) )
3802 sl->setClipPoints(
properties[QStringLiteral(
"clip_points" )].toInt() != 0 );
3803 if (
properties.contains( QStringLiteral(
"clip_on_current_part_only" ) ) )
3804 sl->setClipOnCurrentPartOnly(
properties[QStringLiteral(
"clip_on_current_part_only" )].toInt() != 0 );
3806 sl->restoreOldDataDefinedProperties(
properties );
3808 return sl.release();
3813 return QStringLiteral(
"CentroidFill" );
3843 part.exterior = points;
3845 part.rings = *rings;
3852 mCurrentParts << part;
3857 const double prevOpacity =
mMarker->opacity();
3860 mMarker->setOpacity( prevOpacity );
3867 mCurrentParts.clear();
3874 const double prevOpacity =
mMarker->opacity();
3877 render( context, mCurrentParts, feature,
false );
3879 mMarker->setOpacity( prevOpacity );
3882 void QgsCentroidFillSymbolLayer::render(
QgsRenderContext &context,
const QVector<QgsCentroidFillSymbolLayer::Part> &parts,
const QgsFeature &feature,
bool selected )
3891 QVector< QgsGeometry > geometryParts;
3892 geometryParts.reserve( parts.size() );
3893 QPainterPath globalPath;
3896 int maxAreaPartIdx = 0;
3898 for (
int i = 0; i < parts.size(); i++ )
3900 const Part part = parts[i];
3903 if ( !geom.
isNull() && !part.rings.empty() )
3905 QgsPolygon *poly = qgsgeometry_cast< QgsPolygon * >( geom.
get() );
3909 int area = poly->
area();
3911 if ( area > maxArea )
3921 globalPath.addPolygon( part.exterior );
3922 for (
const QPolygonF &ring : part.rings )
3924 globalPath.addPolygon( ring );
3929 for (
int i = 0; i < parts.size(); i++ )
3934 const Part part = parts[i];
3942 path.addPolygon( part.exterior );
3943 for (
const QPolygonF &ring : part.rings )
3945 path.addPolygon( ring );
3954 context.
painter()->setClipPath( path );
3958 mMarker->renderPoint( centroid, feature.
isValid() ? &feature :
nullptr, context, -1, selected );
3970 map[QStringLiteral(
"point_on_surface" )] = QString::number(
mPointOnSurface );
3971 map[QStringLiteral(
"point_on_all_parts" )] = QString::number(
mPointOnAllParts );
3972 map[QStringLiteral(
"clip_points" )] = QString::number(
mClipPoints );
3979 std::unique_ptr< QgsCentroidFillSymbolLayer > x = qgis::make_unique< QgsCentroidFillSymbolLayer >();
3982 x->setSubSymbol(
mMarker->clone() );
3997 mMarker->toSld( doc, element, props );
4008 std::unique_ptr< QgsMarkerSymbol > marker(
new QgsMarkerSymbol( layers ) );
4010 std::unique_ptr< QgsCentroidFillSymbolLayer > sl = qgis::make_unique< QgsCentroidFillSymbolLayer >();
4011 sl->setSubSymbol( marker.release() );
4012 sl->setPointOnAllParts(
false );
4013 return sl.release();
4040 attributes.unite(
mMarker->usedAttributes( context ) );
4063 mMarker->setOutputUnit( unit );
4080 return mMarker->usesMapUnits();
4089 mMarker->setMapUnitScale( scale );
4097 return mMarker->mapUnitScale();
4107 , mImageFilePath( imageFilePath )
4121 if (
properties.contains( QStringLiteral(
"imageFile" ) ) )
4123 imagePath =
properties[QStringLiteral(
"imageFile" )].toString();
4125 if (
properties.contains( QStringLiteral(
"coordinate_mode" ) ) )
4129 if (
properties.contains( QStringLiteral(
"alpha" ) ) )
4131 alpha =
properties[QStringLiteral(
"alpha" )].toDouble();
4133 if (
properties.contains( QStringLiteral(
"offset" ) ) )
4137 if (
properties.contains( QStringLiteral(
"angle" ) ) )
4141 if (
properties.contains( QStringLiteral(
"width" ) ) )
4145 std::unique_ptr< QgsRasterFillSymbolLayer > symbolLayer = qgis::make_unique< QgsRasterFillSymbolLayer >( imagePath );
4146 symbolLayer->setCoordinateMode( mode );
4147 symbolLayer->setOpacity( alpha );
4148 symbolLayer->setOffset(
offset );
4149 symbolLayer->setAngle(
angle );
4150 symbolLayer->setWidth(
width );
4151 if (
properties.contains( QStringLiteral(
"offset_unit" ) ) )
4155 if (
properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
4159 if (
properties.contains( QStringLiteral(
"width_unit" ) ) )
4163 if (
properties.contains( QStringLiteral(
"width_map_unit_scale" ) ) )
4168 symbolLayer->restoreOldDataDefinedProperties(
properties );
4170 return symbolLayer.release();
4175 QVariantMap::iterator it =
properties.find( QStringLiteral(
"imageFile" ) );
4179 it.value() = pathResolver.
writePath( it.value().toString() );
4181 it.value() = pathResolver.
readPath( it.value().toString() );
4193 return QStringLiteral(
"RasterFill" );
4204 QPointF
offset = mOffset;
4220 if ( mCoordinateMode ==
Feature )
4222 QRectF boundingRect = points.boundingRect();
4223 mBrush.setTransform(
mBrush.transform().translate( boundingRect.left() -
mBrush.transform().dx(),
4224 boundingRect.top() -
mBrush.transform().dy() ) );
4236 applyPattern(
mBrush, mImageFilePath, mWidth, mOpacity * context.
opacity(), context );
4247 map[QStringLiteral(
"imageFile" )] = mImageFilePath;
4248 map[QStringLiteral(
"coordinate_mode" )] = QString::number( mCoordinateMode );
4249 map[QStringLiteral(
"alpha" )] = QString::number( mOpacity );
4253 map[QStringLiteral(
"angle" )] = QString::number(
mAngle );
4254 map[QStringLiteral(
"width" )] = QString::number( mWidth );
4262 std::unique_ptr< QgsRasterFillSymbolLayer > sl = qgis::make_unique< QgsRasterFillSymbolLayer >( mImageFilePath );
4263 sl->setCoordinateMode( mCoordinateMode );
4264 sl->setOpacity( mOpacity );
4265 sl->setOffset( mOffset );
4266 sl->setOffsetUnit( mOffsetUnit );
4267 sl->setOffsetMapUnitScale( mOffsetMapUnitScale );
4269 sl->setWidth( mWidth );
4270 sl->setWidthUnit( mWidthUnit );
4271 sl->setWidthMapUnitScale( mWidthMapUnitScale );
4274 return sl.release();
4279 return context.
convertToPainterUnits( std::max( std::fabs( mOffset.x() ), std::fabs( mOffset.y() ) ), mOffsetUnit, mOffsetMapUnitScale );
4290 mImageFilePath = imagePath;
4295 mCoordinateMode = mode;
4313 if ( !hasWidthExpression && !hasAngleExpression && !hasOpacityExpression && !hasFileExpression )
4319 if ( hasAngleExpression )
4327 if ( !hasWidthExpression && !hasOpacityExpression && !hasFileExpression )
4332 double width = mWidth;
4333 if ( hasWidthExpression )
4339 if ( hasOpacityExpression )
4344 QString file = mImageFilePath;
4345 if ( hasFileExpression )
4358 void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush,
const QString &imageFilePath,
const double width,
const double alpha,
const QgsSymbolRenderContext &context )
4371 if ( size.isEmpty() )
4374 size.setWidth( (
width * size.width() ) / 100.0 );
4377 if (
static_cast< int >( size.width() ) < 1 || 10000.0 < size.width() )
4381 size.setHeight( 0 );
4389 brush.setTextureImage( img );
4398 : mCountMethod( method )
4399 , mPointCount( pointCount )
4400 , mDensityArea( densityArea )
4409 const int pointCount =
properties.value( QStringLiteral(
"point_count" ), QStringLiteral(
"10" ) ).toInt();
4410 const double densityArea =
properties.value( QStringLiteral(
"density_area" ), QStringLiteral(
"250.0" ) ).toDouble();
4412 unsigned long seed = 0;
4413 if (
properties.contains( QStringLiteral(
"seed" ) ) )
4419 std::random_device rd;
4420 std::mt19937 mt(
seed == 0 ? rd() :
seed );
4421 std::uniform_int_distribution<> uniformDist( 1, 999999999 );
4422 seed = uniformDist( mt );
4427 if (
properties.contains( QStringLiteral(
"density_area_unit" ) ) )
4429 if (
properties.contains( QStringLiteral(
"density_area_unit_scale" ) ) )
4432 if (
properties.contains( QStringLiteral(
"clip_points" ) ) )
4434 sl->setClipPoints(
properties[QStringLiteral(
"clip_points" )].toInt() );
4437 return sl.release();
4442 return QStringLiteral(
"RandomMarkerFill" );
4447 mMarker->setColor(
color );
4453 return mMarker ? mMarker->color() :
mColor;
4469 part.exterior = points;
4471 part.rings = *rings;
4473 if ( mRenderingFeature )
4477 mFeatureSymbolOpacity = context.
opacity();
4478 mCurrentParts << part;
4483 const double prevOpacity = mMarker->opacity();
4484 mMarker->setOpacity( mMarker->opacity() * context.
opacity() );
4486 mMarker->setOpacity( prevOpacity );
4490 void QgsRandomMarkerFillSymbolLayer::render(
QgsRenderContext &context,
const QVector<QgsRandomMarkerFillSymbolLayer::Part> &parts,
const QgsFeature &feature,
bool selected )
4499 QVector< QgsGeometry > geometryParts;
4500 geometryParts.reserve( parts.size() );
4503 for (
const Part &part : parts )
4506 if ( !geom.
isNull() && !part.rings.empty() )
4508 QgsPolygon *poly = qgsgeometry_cast< QgsPolygon * >( geom.
get() );
4509 for (
const QPolygonF &ring : part.rings )
4516 geom = geom.
buffer( 0, 0 );
4518 geometryParts << geom;
4522 path.addPolygon( part.exterior );
4523 for (
const QPolygonF &ring : part.rings )
4525 path.addPolygon( ring );
4535 context.
painter()->setClipPath( path );
4539 int count = mPointCount;
4546 switch ( mCountMethod )
4558 count = std::max( 0.0, std::ceil( count * ( geom.
area() /
densityArea ) ) );
4565 unsigned long seed = mSeed;
4576 std::sort( randomPoints.begin(), randomPoints.end(), [](
const QgsPointXY & a,
const QgsPointXY & b )->bool
4578 return a.y() < b.y();
4586 for (
const QgsPointXY &p : qgis::as_const( randomPoints ) )
4588 if ( needsExpressionContext )
4590 mMarker->renderPoint( QPointF( p.x(), p.y() ), feature.
isValid() ? &feature :
nullptr, context, -1, selected );
4602 map.insert( QStringLiteral(
"count_method" ), QString::number(
static_cast< int >( mCountMethod ) ) );
4603 map.insert( QStringLiteral(
"point_count" ), QString::number( mPointCount ) );
4604 map.insert( QStringLiteral(
"density_area" ), QString::number( mDensityArea ) );
4607 map.insert( QStringLiteral(
"seed" ), QString::number( mSeed ) );
4608 map.insert( QStringLiteral(
"clip_points" ), QString::number( mClipPoints ) );
4614 std::unique_ptr< QgsRandomMarkerFillSymbolLayer > res = qgis::make_unique< QgsRandomMarkerFillSymbolLayer >( mPointCount, mCountMethod, mDensityArea, mSeed );
4617 res->setDensityAreaUnit( mDensityAreaUnit );
4618 res->setDensityAreaUnitScale( mDensityAreaUnitScale );
4619 res->mClipPoints = mClipPoints;
4620 res->setSubSymbol( mMarker->clone() );
4623 return res.release();
4633 return mMarker.get();
4645 mColor = mMarker->color();
4654 attributes.unite( mMarker->usedAttributes( context ) );
4663 if ( mMarker && mMarker->hasDataDefinedProperties() )
4700 return mCountMethod;
4705 mCountMethod = method;
4710 return mDensityArea;
4715 mDensityArea = area;
4720 mRenderingFeature =
true;
4721 mCurrentParts.clear();
4726 mRenderingFeature =
false;
4728 const double prevOpacity = mMarker->opacity();
4729 mMarker->setOpacity( mMarker->opacity() * mFeatureSymbolOpacity );
4731 render( context, mCurrentParts, feature,
false );
4733 mFeatureSymbolOpacity = 1;
4734 mMarker->setOpacity( prevOpacity );
4742 mMarker->setOutputUnit( unit );
4750 return mMarker->outputUnit();
4759 return mMarker->usesMapUnits();
4768 mMarker->setMapUnitScale( scale );
4776 return mMarker->mapUnitScale();
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
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.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
static QgsSymbolLayer * createFromSld(QDomElement &element)
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
void setMapUnitScale(const QgsMapUnitScale &scale) override
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
bool pointOnSurface() const
QgsMapUnitScale mapUnitScale() const override
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
std::unique_ptr< QgsMarkerSymbol > mMarker
QString layerType() const override
Returns a string that represents this layer type.
void setColor(const QColor &color) override
The fill color.
bool pointOnAllParts() const
Returns whether a point is drawn for all parts or only on the biggest part of multi-part features.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
QgsFeatureId mCurrentFeatureId
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
bool clipPoints() const
Returns true if point markers should be clipped to the polygon boundary.
QgsCentroidFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
double mFeatureSymbolOpacity
QgsCentroidFillSymbolLayer()
QColor color() const override
The fill color.
bool clipOnCurrentPartOnly() const
Returns true if point markers should be clipped to the current part boundary only.
bool mClipOnCurrentPartOnly
Abstract base class for color ramps.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
virtual QVariantMap properties() const =0
Returns a string map containing all the color ramp's properties.
virtual QString type() const =0
Returns a string representing the color ramp type.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
static QgsColorRamp * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
double area() const override SIP_HOLDGIL
Returns the planar, 2-dimensional area of the geometry.
Exports QGIS layers to the DXF format.
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
double symbologyScale() const
Returns the reference scale for output.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isValid() const
Returns the validity of this feature.
void _renderPolygon(QPainter *p, const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context)
Default method to render polygon.
A geometry is the spatial representation of a feature.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0) const
Returns a list of count random points generated inside a (multi)polygon geometry (if acceptPoint is s...
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
static QgsColorRamp * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsColorRamp from a map of properties.
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
void addStopsToGradient(QGradient *gradient, double opacity=1)
Copy color ramp stops to a QGradient.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used for the gradient fill.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsUnitTypes::RenderUnit mOffsetUnit
GradientCoordinateMode coordinateMode() const
Coordinate mode for gradient. Controls how the gradient stops are positioned.
QColor color2() const
Color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
QgsGradientFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
GradientColorType mGradientColorType
QgsMapUnitScale mapUnitScale() const override
bool mReferencePoint1IsCentroid
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
GradientSpread gradientSpread() const
Gradient spread mode. Controls how the gradient behaves outside of the predefined stops.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
GradientColorType gradientColorType() const
Gradient color mode, controls how gradient color stops are created.
GradientType mGradientType
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
void setMapUnitScale(const QgsMapUnitScale &scale) override
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
GradientCoordinateMode mCoordinateMode
~QgsGradientFillSymbolLayer() override
QgsColorRamp * mGradientRamp
GradientSpread mGradientSpread
QPointF referencePoint1() const
bool mReferencePoint2IsCentroid
QgsMapUnitScale mOffsetMapUnitScale
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QPointF offset() const
Returns the offset by which polygons will be translated during rendering.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QString layerType() const override
Returns a string that represents this layer type.
QgsGradientFillSymbolLayer(const QColor &color=DEFAULT_SIMPLEFILL_COLOR, const QColor &color2=Qt::white, GradientColorType gradientColorType=SimpleTwoColor, GradientType gradientType=Linear, GradientCoordinateMode coordinateMode=Feature, GradientSpread gradientSpread=Pad)
GradientType gradientType() const
Type of gradient, e.g., linear or radial.
QPointF referencePoint2() const
QSize originalSize(const QString &path, bool blocking=false) const
Returns the original size (in pixels) of the image at the specified path.
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false, bool *isMissing=nullptr)
Returns the specified path rendered as an image.
Base class for polygon renderers generating texture images.
std::unique_ptr< QgsLineSymbol > mStroke
Custom stroke.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
QgsMapUnitScale mStrokeWidthMapUnitScale
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
QgsImageFillSymbolLayer()
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
double mStrokeWidth
Stroke width.
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsMapUnitScale mapUnitScale() const override
Qt::PenStyle dxfPenStyle() const override
Gets pen style.
void setMapUnitScale(const QgsMapUnitScale &scale) override
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
virtual void applyDataDefinedSettings(QgsSymbolRenderContext &context)
virtual bool applyBrushTransformFromContext() const
Returns true if the image brush should be transformed using the render context's texture origin.
QColor dxfColor(QgsSymbolRenderContext &context) const override
Gets color.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
QgsUnitTypes::RenderUnit mStrokeWidthUnit
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false)
Performs a stack blur on an image.
A symbol fill consisting of repeated parallel lines.
QgsMapUnitScale mapUnitScale() const override
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QString layerType() const override
Returns a string that represents this layer type.
QgsLinePatternFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QColor color() const override
The fill color.
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
double lineWidth() const
Returns the width of the line subsymbol used to render the parallel lines in the fill.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void setMapUnitScale(const QgsMapUnitScale &scale) override
double lineAngle() const
Returns the angle for the parallel lines used to fill the symbol.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setLineWidth(double w)
Sets the width of the line subsymbol used to render the parallel lines in the fill.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void setColor(const QColor &c) override
The fill color.
double offset() const
Returns the offset distance for lines within the fill, which is the distance to offset the parallel l...
QgsLinePatternFillSymbolLayer()
double distance() const
Returns the distance between lines in the fill pattern.
QString ogrFeatureStyleWidth(double widthScaleFactor) const
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
~QgsLinePatternFillSymbolLayer() override
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
void setWidth(double width)
Sets the width for the whole line symbol.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns current map units per pixel.
Struct for storing maximum and minimum scales for measurements in map units.
Line symbol layer type which draws repeating marker symbols along a line feature.
Abstract base class for marker symbol layers.
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const
Writes the symbol layer definition as a SLD XML element.
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Resolves relative paths into absolute paths and vice versa.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
QgsMapUnitScale mapUnitScale() const override
QgsMarkerSymbol * mMarkerSymbol
QgsMapUnitScale mDisplacementYMapUnitScale
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsMapUnitScale mDisplacementXMapUnitScale
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsMapUnitScale mDistanceYMapUnitScale
QgsUnitTypes::RenderUnit mDisplacementXUnit
double displacementY() const
QgsUnitTypes::RenderUnit mDistanceYUnit
void setColor(const QColor &c) override
The fill color.
QgsUnitTypes::RenderUnit mOffsetXUnit
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
double offsetY() const
Returns the vertical offset values for points in the pattern.
QgsMapUnitScale mDistanceXMapUnitScale
void setMapUnitScale(const QgsMapUnitScale &scale) override
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QString layerType() const override
Returns a string that represents this layer type.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsMapUnitScale mOffsetXMapUnitScale
QColor color() const override
The fill color.
QgsPointPatternFillSymbolLayer()
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
double offsetX() const
Returns the horizontal offset values for points in the pattern.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
QgsPointPatternFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsUnitTypes::RenderUnit mDistanceXUnit
QgsUnitTypes::RenderUnit mOffsetYUnit
double displacementX() const
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
~QgsPointPatternFillSymbolLayer() override
QgsMapUnitScale mOffsetYMapUnitScale
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QgsUnitTypes::RenderUnit mDisplacementYUnit
static QgsSymbolLayer * createFromSld(QDomElement &element)
A class to represent a 2D point.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership)
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
A store for object properties.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
A fill symbol layer which places markers at random locations within polygons.
int pointCount() const
Returns the count of random points to render in the fill.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
unsigned long seed() const
Returns the random number seed to use when generating points, or 0 if a truly random sequence will be...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setCountMethod(CountMethod method)
Sets the count method used to randomly fill the polygon.
QString layerType() const override
Returns a string that represents this layer type.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsRandomMarkerFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setMapUnitScale(const QgsMapUnitScale &scale) override
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
bool clipPoints() const
Returns true if point markers should be clipped to the polygon boundary.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
void setClipPoints(bool clipped)
Sets whether point markers should be clipped to the polygon boundary.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QColor color() const override
The fill color.
void setSeed(unsigned long seed)
Sets the random number seed to use when generating points, or 0 if a truly random sequence will be us...
QgsRandomMarkerFillSymbolLayer(int pointCount=10, CountMethod method=AbsoluteCount, double densityArea=250.0, unsigned long seed=0)
Constructor for QgsRandomMarkerFillSymbolLayer, with the specified pointCount.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
void setPointCount(int count)
Sets the count of random points to render in the fill.
CountMethod
Methods to define the number of points randomly filling the polygon.
@ AbsoluteCount
The point count is used as an absolute count of markers.
@ DensityBasedCount
The point count is part of a marker density count.
double densityArea() const
Returns the density area used to count the number of points to randomly fill the polygon.
void setColor(const QColor &color) override
The fill color.
void setDensityArea(double area)
Sets the density area used to count the number of points to randomly fill the polygon.
QgsMapUnitScale mapUnitScale() const override
CountMethod countMethod() const
Returns the count method used to randomly fill the polygon.
A class for filling symbols with a repeated raster image.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
double width() const
Returns the width used for scaling the image used in the fill.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterFillSymbolLayer from a properties map.
FillCoordinateMode
Fill coordinate modes, dictates fill tiling behavior.
@ Feature
Tiling is based on feature bounding box.
QString layerType() const override
Returns a string that represents this layer type.
QgsRasterFillSymbolLayer(const QString &imageFilePath=QString())
Constructor for QgsRasterFillSymbolLayer, using a raster fill from the specified imageFilePath.
double opacity() const
Returns the opacity for the raster image used in the fill.
void setOpacity(double opacity)
Sets the opacity for the raster image used in the fill.
bool applyBrushTransformFromContext() const override
Returns true if the image brush should be transformed using the render context's texture origin.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QString imageFilePath() const
The path to the raster image used for the fill.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
void setCoordinateMode(FillCoordinateMode mode)
Set the coordinate mode for fill.
QPointF offset() const
Returns the offset for the fill.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QgsRasterFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
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...
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
double rendererScale() const
Returns the renderer map scale.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
QColor selectionColor() const
Returns the color to use when rendering selected features.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
@ Antialiasing
Use antialiasing while drawing.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Flags flags() const
Returns combination of flags used for rendering.
QPointF textureOrigin() const
Returns the texture origin, which should be used as a brush transform when rendering using QBrush obj...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void setRendererScale(double scale)
Sets the renderer map scale.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
A class for filling symbols with a repeated SVG file.
QMap< QString, QgsProperty > parameters() const
Returns the dynamic SVG parameters.
void setParameters(const QMap< QString, QgsProperty > ¶meters)
Sets the dynamic SVG parameters.
QString svgFilePath() const
Returns the path to the SVG file used to render the fill.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QColor svgStrokeColor() const
Returns the stroke color used for rendering the SVG content.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
const QgsMapUnitScale & svgStrokeWidthMapUnitScale() const
Returns the map unit scale for the pattern's stroke.
QgsUnitTypes::RenderUnit svgStrokeWidthUnit() const
Returns the units for the stroke width.
double svgStrokeWidth() const
Returns the stroke width used for rendering the SVG content.
QString layerType() const override
Returns a string that represents this layer type.
QgsSVGFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSVGFillSymbolLayer(const QString &svgFilePath, double width=20, double rotation=0.0)
Constructor for QgsSVGFillSymbolLayer, using the SVG picture at the specified absolute file path.
void setSvgFilePath(const QString &svgPath)
Sets the path to the SVG file to render in the fill.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
QColor svgFillColor() const
Returns the fill color used for rendering the SVG content.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
const QgsMapUnitScale & patternWidthMapUnitScale() const
Returns the map unit scale for the pattern's width.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
double patternWidth() const
Returns the width of the rendered SVG content within the fill (i.e.
QgsUnitTypes::RenderUnit patternWidthUnit() const
Returns the units for the width of the SVG images in the pattern.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
QgsMapUnitScale mapUnitScale() const override
Scoped object for saving and restoring a QPainter object's state.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QgsShapeburstFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
~QgsShapeburstFillSymbolLayer() override
int blurRadius() const
Returns the blur radius, which controls the amount of blurring applied to the fill.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QColor color2() const
Returns the color used for the endpoint of the shapeburst fill.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsMapUnitScale mapUnitScale() const override
QgsShapeburstFillSymbolLayer(const QColor &color=DEFAULT_SIMPLEFILL_COLOR, const QColor &color2=Qt::white, ShapeburstColorType colorType=SimpleTwoColor, int blurRadius=0, bool useWholeShape=true, double maxDistance=5)
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
QPointF offset() const
Returns the offset for the shapeburst fill.
bool useWholeShape() const
Returns whether the shapeburst fill is set to cover the entire shape.
ShapeburstColorType colorType() const
Returns the color mode used for the shapeburst fill.
bool ignoreRings() const
Returns whether the shapeburst fill is set to ignore polygon interior rings.
double maxDistance() const
Returns the maximum distance from the shape's boundary which is shaded.
QString layerType() const override
Returns a string that represents this layer type.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used to draw the shapeburst fill.
QgsSimpleFillSymbolLayer(const QColor &color=DEFAULT_SIMPLEFILL_COLOR, Qt::BrushStyle style=DEFAULT_SIMPLEFILL_STYLE, const QColor &strokeColor=DEFAULT_SIMPLEFILL_BORDERCOLOR, Qt::PenStyle strokeStyle=DEFAULT_SIMPLEFILL_BORDERSTYLE, double strokeWidth=DEFAULT_SIMPLEFILL_BORDERWIDTH, Qt::PenJoinStyle penJoinStyle=DEFAULT_SIMPLEFILL_JOINSTYLE)
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
Qt::PenJoinStyle penJoinStyle() const
QColor strokeColor() const override
Gets stroke color.
QColor dxfBrushColor(QgsSymbolRenderContext &context) const override
Gets brush/fill color.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
Qt::BrushStyle dxfBrushStyle() const override
Gets brush/fill style.
QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const override
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QgsUnitTypes::RenderUnit mOffsetUnit
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QColor dxfColor(QgsSymbolRenderContext &context) const override
Gets color.
QColor fillColor() const override
Gets fill color.
Qt::PenStyle strokeStyle() const
QString layerType() const override
Returns a string that represents this layer type.
double dxfAngle(QgsSymbolRenderContext &context) const override
Gets angle.
QgsMapUnitScale mOffsetMapUnitScale
double strokeWidth() const
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Qt::PenStyle dxfPenStyle() const override
Gets pen style.
QgsMapUnitScale mStrokeWidthMapUnitScale
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the fill symbol layer for the polygon whose outer ring is defined by points,...
QgsSimpleFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QPointF offset()
Returns the offset by which polygons will be translated during rendering.
Qt::PenStyle mStrokeStyle
QgsMapUnitScale mapUnitScale() const override
Qt::PenJoinStyle mPenJoinStyle
Qt::BrushStyle mBrushStyle
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
static QgsSymbolLayer * createFromSld(QDomElement &element)
QgsUnitTypes::RenderUnit mStrokeWidthUnit
QByteArray getImageData(const QString &path, bool blocking=false) const
Gets the SVG content corresponding to the given path.
QPicture svgAsPicture(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool forceVectorOutput=false, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Returns an SVG drawing as a QPicture.
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const
Tests if an SVG file contains parameters for fill, stroke color, stroke width.
QImage svgAsImage(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Returns an SVG drawing as a QImage.
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
static QString encodePenStyle(Qt::PenStyle style)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsStringMap evaluatePropertiesMap(const QMap< QString, QgsProperty > &propertiesMap, const QgsExpressionContext &context)
Evaluates a map of properties using the given context and returns a variant map with evaluated expres...
static bool displacementFromSldElement(QDomElement &element, QPointF &offset)
static QColor decodeColor(const QString &str)
static QPointF polygonCentroid(const QPolygonF &points)
Calculate the centroid point of a QPolygonF.
static QString encodeBrushStyle(Qt::BrushStyle style)
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
static QPointF polygonPointOnSurface(const QPolygonF &points, const QVector< QPolygonF > *rings=nullptr)
Calculate a point on the surface of a QPolygonF.
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
static double rescaleUom(double size, QgsUnitTypes::RenderUnit unit, const QVariantMap &props)
Rescales the given size based on the uomScale found in the props, if any is found,...
static void multiplyImageOpacity(QImage *image, qreal opacity)
Multiplies opacity of image pixel values with a (global) transparency value.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QString ogrFeatureStylePen(double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor &c, Qt::PenJoinStyle joinStyle=Qt::MiterJoin, Qt::PenCapStyle capStyle=Qt::FlatCap, double offset=0.0, const QVector< qreal > *dashPattern=nullptr)
Create ogr feature style string for pen.
static bool externalGraphicFromSld(QDomElement &element, QString &path, QString &mime, QColor &color, double &size)
static void parametricSvgToSld(QDomDocument &doc, QDomElement &graphicElem, const QString &path, const QColor &fillColor, double size, const QColor &strokeColor, double strokeWidth)
Encodes a reference to a parametric SVG into SLD, as a succession of parametric SVG using URL paramet...
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=nullptr, Qt::PenCapStyle *penCapStyle=nullptr, QVector< qreal > *customDashPattern=nullptr, double *dashOffset=nullptr)
static QString ogrFeatureStyleBrush(const QColor &fillColr)
Create ogr feature style string for brush.
static QPointF pointOnLineWithDistance(QPointF startPoint, QPointF directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
static Qt::BrushStyle decodeBrushStyle(const QString &str)
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, const QColor &color, double width=-1, const Qt::PenJoinStyle *penJoinStyle=nullptr, const Qt::PenCapStyle *penCapStyle=nullptr, const QVector< qreal > *customDashPattern=nullptr, double dashOffset=0.0)
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
static double sizeInPixelsFromSldUom(const QString &uom, double size)
Returns the size scaled in pixels according to the uom attribute.
static bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle, double &strokeWidth, double &size)
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodeColor(const QColor &color)
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
static void fillToSld(QDomDocument &doc, QDomElement &element, Qt::BrushStyle brushStyle, const QColor &color=QColor())
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
static void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, const QString &name, const QColor &color, const QColor &strokeColor, Qt::PenStyle strokeStyle, double strokeWidth=-1, double size=-1)
static Qt::PenStyle decodePenStyle(const QString &str)
static void createRotationElement(QDomDocument &doc, QDomElement &element, const QString &rotationFunc)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
static QgsSymbolLayer * createMarkerLayerFromSld(QDomElement &element)
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
static QgsSymbolLayer * createLineLayerFromSld(QDomElement &element)
@ PropertyGradientReference1X
Gradient reference point 1 x.
@ PropertyShapeburstIgnoreRings
Shapeburst ignore rings.
@ PropertyGradientReference2X
Gradient reference point 2 x.
@ PropertyStrokeStyle
Stroke style (eg solid, dashed)
@ PropertyDistanceX
Horizontal distance between points.
@ PropertyFile
Filename, eg for svg files.
@ PropertyGradientType
Gradient fill type.
@ PropertyAngle
Symbol angle.
@ PropertyDistanceY
Vertical distance between points.
@ PropertyDisplacementX
Horizontal displacement.
@ PropertyGradientSpread
Gradient spread mode.
@ PropertyOffsetY
Vertical offset.
@ PropertyGradientReference1Y
Gradient reference point 1 y.
@ PropertyLineDistance
Distance between lines, or length of lines for hash line symbols.
@ PropertyBlurRadius
Shapeburst blur radius.
@ PropertyGradientReference2Y
Gradient reference point 2 y.
@ PropertyDensityArea
Density area.
@ PropertyGradientReference1IsCentroid
Gradient reference point 1 is centroid.
@ PropertyShapeburstUseWholeShape
Shapeburst use whole shape.
@ PropertyOffsetX
Horizontal offset.
@ PropertyJoinStyle
Line join style.
@ PropertyOpacity
Opacity.
@ PropertySecondaryColor
Secondary color (eg for gradient fills)
@ PropertyCoordinateMode
Gradient coordinate mode.
@ PropertyLineAngle
Line angle, or angle of hash lines for hash line symbols.
@ PropertyShapeburstMaxDistance
Shapeburst fill from edge distance.
@ PropertyOffset
Symbol offset.
@ PropertyStrokeWidth
Stroke width.
@ PropertyFillColor
Fill color.
@ PropertyClipPoints
Whether markers should be clipped to polygon boundaries.
@ PropertyPointCount
Point count.
@ PropertyRandomSeed
Random number seed.
@ PropertyFillStyle
Fill style (eg solid, dots)
@ PropertyDisplacementY
Vertical displacement.
@ PropertyStrokeColor
Stroke color.
@ PropertyGradientReference2IsCentroid
Gradient reference point 2 is centroid.
@ PropertyWidth
Symbol width.
static const bool SELECTION_IS_OPAQUE
Whether styles for selected features ignore symbol alpha.
virtual QColor color() const
The fill color.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
virtual double estimateMaxBleed(const QgsRenderContext &context) const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
static const bool SELECT_FILL_BORDER
Whether fill styles for selected features also highlight symbol stroke.
virtual QColor fillColor() const
Gets fill color.
virtual QString layerType() const =0
Returns a string that represents this layer type.
QgsSymbol::SymbolType type() const
virtual QColor strokeColor() const
Gets stroke color.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides.
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
QgsPropertyCollection mDataDefinedProperties
static const bool SELECT_FILL_STYLE
Whether fill styles for selected features uses symbol layer style.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
QgsFields fields() const
Fields of the layer.
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
const QgsFeature * feature() const
Returns the current feature being rendered.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
qreal opacity() const
Returns the opacity for the symbol.
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
SymbolType type() const
Returns the symbol's type.
bool hasDataDefinedProperties() const
Returns whether the symbol utilizes any data defined properties.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
void setColor(const QColor &color)
Sets the color for the symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
QColor color() const
Returns the symbol's color.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
const QgsMapUnitScale & intervalMapUnitScale() const
Returns the map unit scale for the interval between symbols.
double interval() const
Returns the interval between individual symbols.
void setInterval(double interval)
Sets the interval between individual symbols.
QgsUnitTypes::RenderUnit intervalUnit() const
Returns the units for the interval between symbols.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
RenderUnit
Rendering size units.
@ RenderUnknownUnit
Mixed or unknown units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
@ RenderMapUnits
Map units.
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)
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
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QMap< QString, QString > QgsStringMap
#define DEFAULT_SIMPLEFILL_JOINSTYLE
#define DEFAULT_SIMPLEFILL_COLOR
#define DEFAULT_SIMPLEFILL_STYLE
#define DEFAULT_SIMPLEFILL_BORDERSTYLE
#define DEFAULT_SIMPLEFILL_BORDERCOLOR
#define DEFAULT_SIMPLEFILL_BORDERWIDTH
QList< QgsSymbolLayer * > QgsSymbolLayerList
Single variable definition for use within a QgsExpressionContextScope.