39 #include <QSvgRenderer> 40 #include <QDomDocument> 41 #include <QDomElement> 45 Qt::PenJoinStyle penJoinStyle )
46 : mBrushStyle( style )
47 , mStrokeColor( strokeColor )
48 , mStrokeStyle( strokeStyle )
49 , mStrokeWidth( strokeWidth )
50 , mPenJoinStyle( penJoinStyle )
86 void QgsSimpleFillSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context, QBrush &brush, QPen &pen, QPen &selPen )
102 if ( exprVal.isValid() )
114 double width = exprVal.toDouble( &ok );
118 pen.setWidthF( width );
119 selPen.setWidthF( width );
155 if ( props.contains( QStringLiteral(
"color" ) ) )
157 if ( props.contains( QStringLiteral(
"style" ) ) )
159 if ( props.contains( QStringLiteral(
"color_border" ) ) )
164 else if ( props.contains( QStringLiteral(
"outline_color" ) ) )
168 else if ( props.contains( QStringLiteral(
"line_color" ) ) )
173 if ( props.contains( QStringLiteral(
"style_border" ) ) )
178 else if ( props.contains( QStringLiteral(
"outline_style" ) ) )
182 else if ( props.contains( QStringLiteral(
"line_style" ) ) )
186 if ( props.contains( QStringLiteral(
"width_border" ) ) )
189 strokeWidth = props[QStringLiteral(
"width_border" )].toDouble();
191 else if ( props.contains( QStringLiteral(
"outline_width" ) ) )
193 strokeWidth = props[QStringLiteral(
"outline_width" )].toDouble();
195 else if ( props.contains( QStringLiteral(
"line_width" ) ) )
197 strokeWidth = props[QStringLiteral(
"line_width" )].toDouble();
199 if ( props.contains( QStringLiteral(
"offset" ) ) )
201 if ( props.contains( QStringLiteral(
"joinstyle" ) ) )
205 sl->setOffset( offset );
206 if ( props.contains( QStringLiteral(
"border_width_unit" ) ) )
210 else if ( props.contains( QStringLiteral(
"outline_width_unit" ) ) )
214 else if ( props.contains( QStringLiteral(
"line_width_unit" ) ) )
218 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
221 if ( props.contains( QStringLiteral(
"border_width_map_unit_scale" ) ) )
223 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
226 sl->restoreOldDataDefinedProperties( props );
234 return QStringLiteral(
"SimpleFill" );
254 mPen = QPen( strokeColor );
284 p->translate( offset );
291 p->translate( -offset );
302 map[QStringLiteral(
"outline_width" )] = QString::number(
mStrokeWidth );
330 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
331 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
332 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
333 element.appendChild( symbolizerElem );
341 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
342 symbolizerElem.appendChild( fillElem );
349 QDomElement strokeElem = doc.createElement( QStringLiteral(
"se:Stroke" ) );
350 symbolizerElem.appendChild( strokeElem );
365 symbolStyle.append(
';' );
374 Qt::BrushStyle fillStyle;
378 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
381 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
387 QString uom = element.attribute( QStringLiteral(
"uom" ), QString() );
393 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
394 sl->setOffset( offset );
402 return penBleed + offsetBleed;
463 : mGradientColorType( colorType )
464 , mGradientType( gradientType )
465 , mCoordinateMode( coordinateMode )
466 , mGradientSpread( spread )
467 , mReferencePoint1( QPointF( 0.5, 0 ) )
468 , mReferencePoint2( QPointF( 0.5, 1 ) )
489 bool refPoint1IsCentroid =
false;
491 bool refPoint2IsCentroid =
false;
496 if ( props.contains( QStringLiteral(
"type" ) ) )
497 type = static_cast< GradientType >( props[QStringLiteral(
"type" )].toInt() );
498 if ( props.contains( QStringLiteral(
"coordinate_mode" ) ) )
499 coordinateMode = static_cast< GradientCoordinateMode >( props[QStringLiteral(
"coordinate_mode" )].toInt() );
500 if ( props.contains( QStringLiteral(
"spread" ) ) )
501 gradientSpread = static_cast< GradientSpread >( props[QStringLiteral(
"spread" )].toInt() );
502 if ( props.contains( QStringLiteral(
"color_type" ) ) )
503 colorType = static_cast< GradientColorType >( props[QStringLiteral(
"color_type" )].toInt() );
504 if ( props.contains( QStringLiteral(
"gradient_color" ) ) )
509 else if ( props.contains( QStringLiteral(
"color" ) ) )
513 if ( props.contains( QStringLiteral(
"gradient_color2" ) ) )
518 if ( props.contains( QStringLiteral(
"reference_point1" ) ) )
520 if ( props.contains( QStringLiteral(
"reference_point1_iscentroid" ) ) )
521 refPoint1IsCentroid = props[QStringLiteral(
"reference_point1_iscentroid" )].toInt();
522 if ( props.contains( QStringLiteral(
"reference_point2" ) ) )
524 if ( props.contains( QStringLiteral(
"reference_point2_iscentroid" ) ) )
525 refPoint2IsCentroid = props[QStringLiteral(
"reference_point2_iscentroid" )].toInt();
526 if ( props.contains( QStringLiteral(
"angle" ) ) )
527 angle = props[QStringLiteral(
"angle" )].toDouble();
529 if ( props.contains( QStringLiteral(
"offset" ) ) )
534 if ( props.contains( QStringLiteral(
"rampType" ) ) && props[QStringLiteral(
"rampType" )] == QStringLiteral(
"cpt-city" ) )
545 sl->setOffset( offset );
546 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
548 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
550 sl->setReferencePoint1( referencePoint1 );
551 sl->setReferencePoint1IsCentroid( refPoint1IsCentroid );
552 sl->setReferencePoint2( referencePoint2 );
553 sl->setReferencePoint2IsCentroid( refPoint2IsCentroid );
554 sl->setAngle( angle );
556 sl->setColorRamp( gradientRamp );
558 sl->restoreOldDataDefinedProperties( props );
571 return QStringLiteral(
"GradientFill" );
574 void QgsGradientFillSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context,
const QPolygonF &points )
617 if ( currentType == QObject::tr(
"linear" ) )
621 else if ( currentType == QObject::tr(
"radial" ) )
625 else if ( currentType == QObject::tr(
"conical" ) )
639 if ( currentCoordMode == QObject::tr(
"feature" ) )
643 else if ( currentCoordMode == QObject::tr(
"viewport" ) )
657 if ( currentSpread == QObject::tr(
"pad" ) )
661 else if ( currentSpread == QObject::tr(
"repeat" ) )
665 else if ( currentSpread == QObject::tr(
"reflect" ) )
712 if ( refPoint1IsCentroid || refPoint2IsCentroid )
717 QRectF bbox = points.boundingRect();
718 double centroidX = ( centroid.x() - bbox.left() ) / bbox.width();
719 double centroidY = ( centroid.y() - bbox.top() ) / bbox.height();
721 if ( refPoint1IsCentroid )
723 refPoint1X = centroidX;
724 refPoint1Y = centroidY;
726 if ( refPoint2IsCentroid )
728 refPoint2X = centroidX;
729 refPoint2Y = centroidY;
735 spread, QPointF( refPoint1X, refPoint1Y ), QPointF( refPoint2X, refPoint2Y ), angle );
738 QPointF QgsGradientFillSymbolLayer::rotateReferencePoint( QPointF refPoint,
double angle )
743 QLineF refLine = QLineF( QPointF( 0.5, 0.5 ), refPoint );
745 refLine.setAngle( refLine.angle() +
angle );
747 QPointF rotatedReferencePoint = refLine.p2();
749 if ( rotatedReferencePoint.x() > 1 )
750 rotatedReferencePoint.setX( 1 );
751 if ( rotatedReferencePoint.x() < 0 )
752 rotatedReferencePoint.setX( 0 );
753 if ( rotatedReferencePoint.y() > 1 )
754 rotatedReferencePoint.setY( 1 );
755 if ( rotatedReferencePoint.y() < 0 )
756 rotatedReferencePoint.setY( 0 );
758 return rotatedReferencePoint;
769 fillColor.setAlphaF( context.
opacity() * fillColor.alphaF() );
770 QColor fillColor2 =
color2;
771 fillColor2.setAlphaF( context.
opacity() * fillColor2.alphaF() );
782 gradient = QLinearGradient( rotatedReferencePoint1, rotatedReferencePoint2 );
785 gradient = QRadialGradient( rotatedReferencePoint1, QLineF( rotatedReferencePoint1, rotatedReferencePoint2 ).length() );
788 gradient = QConicalGradient( rotatedReferencePoint1, QLineF( rotatedReferencePoint1, rotatedReferencePoint2 ).
angle() );
794 gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
797 gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
803 gradient.setSpread( QGradient::PadSpread );
806 gradient.setSpread( QGradient::ReflectSpread );
809 gradient.setSpread( QGradient::RepeatSpread );
815 ( gradientRamp->
type() == QLatin1String(
"gradient" ) || gradientRamp->
type() == QLatin1String(
"cpt-city" ) ) )
824 gradient.setColorAt( 0.0, fillColor );
825 gradient.setColorAt( 1.0, fillColor2 );
829 brush = QBrush( gradient );
836 selColor.setAlphaF( context.
opacity() );
853 applyDataDefinedSymbology( context, points );
856 p->setPen( Qt::NoPen );
863 p->translate( offset );
870 p->translate( -offset );
880 map[QStringLiteral(
"type" )] = QString::number(
mGradientType );
881 map[QStringLiteral(
"coordinate_mode" )] = QString::number(
mCoordinateMode );
887 map[QStringLiteral(
"angle" )] = QString::number(
mAngle );
945 int blurRadius,
bool useWholeShape,
double maxDistance )
946 : mBlurRadius( blurRadius )
947 , mUseWholeShape( useWholeShape )
948 , mMaxDistance( maxDistance )
949 , mColorType( colorType )
968 if ( props.contains( QStringLiteral(
"color_type" ) ) )
970 colorType =
static_cast< ShapeburstColorType >( props[QStringLiteral(
"color_type" )].toInt() );
972 if ( props.contains( QStringLiteral(
"shapeburst_color" ) ) )
977 else if ( props.contains( QStringLiteral(
"color" ) ) )
982 if ( props.contains( QStringLiteral(
"shapeburst_color2" ) ) )
987 else if ( props.contains( QStringLiteral(
"gradient_color2" ) ) )
991 if ( props.contains( QStringLiteral(
"blur_radius" ) ) )
993 blurRadius = props[QStringLiteral(
"blur_radius" )].toInt();
995 if ( props.contains( QStringLiteral(
"use_whole_shape" ) ) )
997 useWholeShape = props[QStringLiteral(
"use_whole_shape" )].toInt();
999 if ( props.contains( QStringLiteral(
"max_distance" ) ) )
1001 maxDistance = props[QStringLiteral(
"max_distance" )].toDouble();
1003 if ( props.contains( QStringLiteral(
"offset" ) ) )
1010 if ( props.contains( QStringLiteral(
"rampType" ) ) && props[QStringLiteral(
"rampType" )] == QStringLiteral(
"cpt-city" ) )
1021 sl->setOffset( offset );
1022 if ( props.contains( QStringLiteral(
"offset_unit" ) ) )
1026 if ( props.contains( QStringLiteral(
"distance_unit" ) ) )
1030 if ( props.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
1034 if ( props.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
1038 if ( props.contains( QStringLiteral(
"ignore_rings" ) ) )
1040 sl->setIgnoreRings( props[QStringLiteral(
"ignore_rings" )].toInt() );
1044 sl->setColorRamp( gradientRamp );
1047 sl->restoreOldDataDefinedProperties( props );
1049 return sl.release();
1054 return QStringLiteral(
"ShapeburstFill" );
1059 if ( mGradientRamp.get() == ramp )
1062 mGradientRamp.reset( ramp );
1109 ignoreRings = mIgnoreRings;
1123 selColor.setAlphaF( context.
opacity() );
1124 mSelBrush = QBrush( selColor );
1143 p->setBrush( mSelBrush );
1145 if ( !mOffset.isNull() )
1149 p->translate( offset );
1152 if ( !mOffset.isNull() )
1154 p->translate( -offset );
1165 applyDataDefinedSymbology( context, color1, color2, blurRadius, useWholeShape, maxDistance, ignoreRings );
1168 int outputPixelMaxDist = 0;
1176 std::unique_ptr< QgsGradientColorRamp > twoColorGradientRamp;
1179 twoColorGradientRamp = qgis::make_unique< QgsGradientColorRamp >( color1,
color2 );
1183 p->setPen( QPen( Qt::NoPen ) );
1186 int sideBuffer = 4 + ( blurRadius + 2 ) * 4;
1188 int pointsWidth =
static_cast< int >( std::round( points.boundingRect().width() ) );
1189 int pointsHeight =
static_cast< int >( std::round( points.boundingRect().height() ) );
1190 int imWidth = pointsWidth + ( sideBuffer * 2 );
1191 int imHeight = pointsHeight + ( sideBuffer * 2 );
1192 std::unique_ptr< QImage > fillImage = qgis::make_unique< QImage >( imWidth,
1193 imHeight, QImage::Format_ARGB32_Premultiplied );
1194 if ( fillImage->isNull() )
1201 std::unique_ptr< QImage > alphaImage = qgis::make_unique< QImage >( fillImage->width(), fillImage->height(), QImage::Format_ARGB32_Premultiplied );
1202 if ( alphaImage->isNull() )
1211 fillImage->fill( Qt::black );
1214 alphaImage->fill( Qt::transparent );
1217 QPainter imgPainter;
1218 imgPainter.begin( alphaImage.get() );
1219 imgPainter.setRenderHint( QPainter::Antialiasing,
true );
1220 imgPainter.setBrush( QBrush( Qt::white ) );
1221 imgPainter.setPen( QPen( Qt::black ) );
1222 imgPainter.translate( -points.boundingRect().left() + sideBuffer, - points.boundingRect().top() + sideBuffer );
1228 imgPainter.begin( fillImage.get() );
1231 imgPainter.drawImage( 0, 0, *alphaImage );
1238 imgPainter.setBrush( QBrush( Qt::white ) );
1239 imgPainter.setPen( QPen( Qt::black ) );
1240 imgPainter.translate( -points.boundingRect().left() + sideBuffer, - points.boundingRect().top() + sideBuffer );
1246 double *dtArray = distanceTransform( fillImage.get(), context.
renderContext() );
1260 if ( blurRadius > 0 )
1266 imgPainter.begin( fillImage.get() );
1267 imgPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
1268 imgPainter.drawImage( 0, 0, *alphaImage );
1277 if ( !mOffset.isNull() )
1281 p->translate( offset );
1284 p->drawImage( points.boundingRect().left() - sideBuffer, points.boundingRect().top() - sideBuffer, *fillImage );
1286 if ( !mOffset.isNull() )
1288 p->translate( -offset );
1297 void QgsShapeburstFillSymbolLayer::distanceTransform1d(
double *f,
int n,
int *v,
double *z,
double *d )
1303 for (
int q = 1; q <= n - 1; q++ )
1305 double s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1309 s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1318 for (
int q = 0; q <= n - 1; q++ )
1320 while ( z[k + 1] < q )
1322 d[q] = ( q - v[k] ) * ( q - v[k] ) + f[v[k]];
1327 void QgsShapeburstFillSymbolLayer::distanceTransform2d(
double *im,
int width,
int height,
QgsRenderContext &context )
1329 int maxDimension = std::max( width, height );
1330 double *f =
new double[ maxDimension ];
1331 int *v =
new int[ maxDimension ];
1332 double *z =
new double[ maxDimension + 1 ];
1333 double *d =
new double[ maxDimension ];
1336 for (
int x = 0; x < width; x++ )
1341 for (
int y = 0; y < height; y++ )
1343 f[y] = im[ x + y * width ];
1345 distanceTransform1d( f, height, v, z, d );
1346 for (
int y = 0; y < height; y++ )
1348 im[ x + y * width ] = d[y];
1353 for (
int y = 0; y < height; y++ )
1358 for (
int x = 0; x < width; x++ )
1360 f[x] = im[ x + y * width ];
1362 distanceTransform1d( f, width, v, z, d );
1363 for (
int x = 0; x < width; x++ )
1365 im[ x + y * width ] = d[x];
1376 double *QgsShapeburstFillSymbolLayer::distanceTransform( QImage *im,
QgsRenderContext &context )
1378 int width = im->width();
1379 int height = im->height();
1381 double *dtArray =
new double[width * height];
1386 for (
int heightIndex = 0; heightIndex < height; ++heightIndex )
1391 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( im->constScanLine( heightIndex ) );
1392 for (
int widthIndex = 0; widthIndex < width; ++widthIndex )
1394 tmpRgb = scanLine[widthIndex];
1395 if ( qRed( tmpRgb ) == 0 )
1403 dtArray[ idx ] =
INF;
1410 distanceTransform2d( dtArray, width, height, context );
1417 int width = im->width();
1418 int height = im->height();
1421 double maxDistanceValue;
1426 double dtMaxValue = array[0];
1427 for (
int i = 1; i < ( width * height ); ++i )
1429 if ( array[i] > dtMaxValue )
1431 dtMaxValue = array[i];
1436 maxDistanceValue = std::sqrt( dtMaxValue );
1441 maxDistanceValue = maxPixelDistance;
1446 double squaredVal = 0;
1449 for (
int heightIndex = 0; heightIndex < height; ++heightIndex )
1454 QRgb *scanLine =
reinterpret_cast< QRgb *
>( im->scanLine( heightIndex ) );
1455 for (
int widthIndex = 0; widthIndex < width; ++widthIndex )
1458 squaredVal = array[idx];
1461 if ( maxDistanceValue > 0 )
1463 pixVal = squaredVal > 0 ? std::min( ( std::sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
1472 scanLine[widthIndex] = qPremultiply( ramp->
color( pixVal ).rgba() );
1483 map[QStringLiteral(
"color_type" )] = QString::number( mColorType );
1484 map[QStringLiteral(
"blur_radius" )] = QString::number( mBlurRadius );
1485 map[QStringLiteral(
"use_whole_shape" )] = QString::number( mUseWholeShape );
1486 map[QStringLiteral(
"max_distance" )] = QString::number( mMaxDistance );
1489 map[QStringLiteral(
"ignore_rings" )] = QString::number( mIgnoreRings );
1493 if ( mGradientRamp )
1495 map.unite( mGradientRamp->properties() );
1503 std::unique_ptr< QgsShapeburstFillSymbolLayer > sl = qgis::make_unique< QgsShapeburstFillSymbolLayer >(
mColor, mColor2, mColorType, mBlurRadius, mUseWholeShape, mMaxDistance );
1504 if ( mGradientRamp )
1508 sl->setDistanceUnit( mDistanceUnit );
1509 sl->setDistanceMapUnitScale( mDistanceMapUnitScale );
1510 sl->setIgnoreRings( mIgnoreRings );
1511 sl->setOffset( mOffset );
1512 sl->setOffsetUnit( mOffsetUnit );
1513 sl->setOffsetMapUnitScale( mOffsetMapUnitScale );
1516 return sl.release();
1521 double offsetBleed = context.
convertToPainterUnits( std::max( std::fabs( mOffset.x() ), std::fabs( mOffset.y() ) ), mOffsetUnit, mOffsetMapUnitScale );
1527 mDistanceUnit = unit;
1533 if ( mDistanceUnit == mOffsetUnit )
1535 return mDistanceUnit;
1542 mDistanceMapUnitScale = scale;
1543 mOffsetMapUnitScale = scale;
1548 if ( mDistanceMapUnitScale == mOffsetMapUnitScale )
1550 return mDistanceMapUnitScale;
1572 applyDataDefinedSettings( context );
1574 p->setPen( QPen( Qt::NoPen ) );
1576 QTransform bkTransform = mBrush.transform();
1580 QPointF leftCorner = points.boundingRect().topLeft();
1581 QTransform t = mBrush.transform();
1582 t.translate( leftCorner.x(), leftCorner.y() );
1583 mBrush.setTransform( t );
1592 p->setBrush( QBrush( selColor ) );
1598 QTransform t = mBrush.transform();
1599 t.rotate( mNextAngle );
1600 mBrush.setTransform( t );
1602 p->setBrush( mBrush );
1609 QList<QPolygonF>::const_iterator ringIt = rings->constBegin();
1610 for ( ; ringIt != rings->constEnd(); ++ringIt )
1617 mBrush.setTransform( bkTransform );
1624 mStroke.reset(
nullptr );
1637 mStroke.reset( lineSymbol );
1647 mStrokeWidthUnit = unit;
1652 return mStrokeWidthUnit;
1657 mStrokeWidthMapUnitScale = scale;
1662 return mStrokeWidthMapUnitScale;
1667 if ( mStroke && mStroke->symbolLayer( 0 ) )
1669 double subLayerBleed = mStroke->symbolLayer( 0 )->estimateMaxBleed( context );
1670 return subLayerBleed;
1677 double width = mStrokeWidth;
1691 return QColor( Qt::black );
1693 return mStroke->color();
1698 return Qt::SolidLine;
1702 return Qt::SolidLine;
1706 return mStroke->dxfPenStyle();
1715 attr.unite( mStroke->usedAttributes( context ) );
1723 if ( mStroke && mStroke->hasDataDefinedProperties() )
1733 , mPatternWidth( width )
1737 mColor = QColor( 255, 255, 255 );
1743 , mPatternWidth( width )
1744 , mSvgData( svgData )
1749 mColor = QColor( 255, 255, 255 );
1751 setDefaultSvgParams();
1757 mPatternWidthUnit = unit;
1758 mSvgStrokeWidthUnit = unit;
1760 mStroke->setOutputUnit( unit );
1766 if ( mPatternWidthUnit != unit || mSvgStrokeWidthUnit != unit ||
mStrokeWidthUnit != unit )
1776 mPatternWidthMapUnitScale = scale;
1777 mSvgStrokeWidthMapUnitScale = scale;
1784 mPatternWidthMapUnitScale == mSvgStrokeWidthMapUnitScale &&
1787 return mPatternWidthMapUnitScale;
1797 mSvgFilePath = svgPath;
1798 setDefaultSvgParams();
1808 if ( properties.contains( QStringLiteral(
"width" ) ) )
1810 width = properties[QStringLiteral(
"width" )].toDouble();
1812 if ( properties.contains( QStringLiteral(
"svgFile" ) ) )
1814 svgFilePath = properties[QStringLiteral(
"svgFile" )];
1816 if ( properties.contains( QStringLiteral(
"angle" ) ) )
1818 angle = properties[QStringLiteral(
"angle" )].toDouble();
1821 std::unique_ptr< QgsSVGFillSymbolLayer > symbolLayer;
1822 if ( !svgFilePath.isEmpty() )
1824 symbolLayer = qgis::make_unique< QgsSVGFillSymbolLayer >(
svgFilePath, width,
angle );
1828 if ( properties.contains( QStringLiteral(
"data" ) ) )
1830 data = QByteArray::fromHex( properties[QStringLiteral(
"data" )].toLocal8Bit() );
1832 symbolLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( data, width,
angle );
1836 if ( properties.contains( QStringLiteral(
"svgFillColor" ) ) )
1841 else if ( properties.contains( QStringLiteral(
"color" ) ) )
1845 if ( properties.contains( QStringLiteral(
"svgOutlineColor" ) ) )
1850 else if ( properties.contains( QStringLiteral(
"outline_color" ) ) )
1854 else if ( properties.contains( QStringLiteral(
"line_color" ) ) )
1858 if ( properties.contains( QStringLiteral(
"svgOutlineWidth" ) ) )
1861 symbolLayer->setSvgStrokeWidth( properties[QStringLiteral(
"svgOutlineWidth" )].toDouble() );
1863 else if ( properties.contains( QStringLiteral(
"outline_width" ) ) )
1865 symbolLayer->setSvgStrokeWidth( properties[QStringLiteral(
"outline_width" )].toDouble() );
1867 else if ( properties.contains( QStringLiteral(
"line_width" ) ) )
1869 symbolLayer->setSvgStrokeWidth( properties[QStringLiteral(
"line_width" )].toDouble() );
1873 if ( properties.contains( QStringLiteral(
"pattern_width_unit" ) ) )
1877 if ( properties.contains( QStringLiteral(
"pattern_width_map_unit_scale" ) ) )
1881 if ( properties.contains( QStringLiteral(
"svg_outline_width_unit" ) ) )
1885 if ( properties.contains( QStringLiteral(
"svg_outline_width_map_unit_scale" ) ) )
1889 if ( properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
1893 if ( properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
1898 symbolLayer->restoreOldDataDefinedProperties( properties );
1900 return symbolLayer.release();
1905 QgsStringMap::iterator it = properties.find( QStringLiteral(
"svgFile" ) );
1906 if ( it != properties.end() )
1917 return QStringLiteral(
"SVGFill" );
1925 if ( mSvgViewBox.isNull() )
1932 if ( static_cast< int >( size ) < 1.0 || 10000.0 < size )
1934 brush.setTextureImage( QImage() );
1938 bool fitsInCache =
true;
1946 double hwRatio = 1.0;
1947 if ( patternPict.width() > 0 )
1949 hwRatio =
static_cast< double >( patternPict.height() ) / static_cast< double >( patternPict.width() );
1951 patternImage = QImage( static_cast< int >( size ), static_cast< int >( size * hwRatio ), QImage::Format_ARGB32_Premultiplied );
1952 patternImage.fill( 0 );
1954 QPainter p( &patternImage );
1955 p.drawPicture( QPointF( size / 2, size * hwRatio / 2 ), patternPict );
1958 QTransform brushTransform;
1961 QImage transparentImage = patternImage.copy();
1963 brush.setTextureImage( transparentImage );
1967 brush.setTextureImage( patternImage );
1969 brush.setTransform( brushTransform );
1976 applyPattern(
mBrush, mSvgFilePath, mPatternWidth, mPatternWidthUnit,
mColor, mSvgStrokeColor, mSvgStrokeWidth, mSvgStrokeWidthUnit, context, mPatternWidthMapUnitScale, mSvgStrokeWidthMapUnitScale );
1995 if ( !mSvgFilePath.isEmpty() )
1997 map.insert( QStringLiteral(
"svgFile" ), mSvgFilePath );
2001 map.insert( QStringLiteral(
"data" ), QString( mSvgData.toHex() ) );
2004 map.insert( QStringLiteral(
"width" ), QString::number( mPatternWidth ) );
2005 map.insert( QStringLiteral(
"angle" ), QString::number(
mAngle ) );
2010 map.insert( QStringLiteral(
"outline_width" ), QString::number( mSvgStrokeWidth ) );
2024 std::unique_ptr< QgsSVGFillSymbolLayer > clonedLayer;
2025 if ( !mSvgFilePath.isEmpty() )
2027 clonedLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( mSvgFilePath, mPatternWidth,
mAngle );
2029 clonedLayer->setSvgStrokeColor( mSvgStrokeColor );
2030 clonedLayer->setSvgStrokeWidth( mSvgStrokeWidth );
2034 clonedLayer = qgis::make_unique< QgsSVGFillSymbolLayer >( mSvgData, mPatternWidth,
mAngle );
2037 clonedLayer->setPatternWidthUnit( mPatternWidthUnit );
2038 clonedLayer->setPatternWidthMapUnitScale( mPatternWidthMapUnitScale );
2039 clonedLayer->setSvgStrokeWidthUnit( mSvgStrokeWidthUnit );
2040 clonedLayer->setSvgStrokeWidthMapUnitScale( mSvgStrokeWidthMapUnitScale );
2046 clonedLayer->setSubSymbol(
mStroke->clone() );
2050 return clonedLayer.release();
2055 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
2056 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
2057 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
2058 element.appendChild( symbolizerElem );
2062 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
2063 symbolizerElem.appendChild( fillElem );
2065 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
2066 fillElem.appendChild( graphicFillElem );
2068 QDomElement graphicElem = doc.createElement( QStringLiteral(
"se:Graphic" ) );
2069 graphicFillElem.appendChild( graphicElem );
2071 if ( !mSvgFilePath.isEmpty() )
2082 symbolizerElem.appendChild( doc.createComment( QStringLiteral(
"SVG from data not implemented yet" ) ) );
2088 double angle = props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toDouble( &ok );
2091 angleFunc = QStringLiteral(
"%1 + %2" ).arg( props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ) ).arg(
mAngle );
2095 angleFunc = QString::number( angle +
mAngle );
2104 mStroke->toSld( doc, element, props );
2110 QString path, mimeType;
2112 Qt::PenStyle penStyle;
2113 double size, strokeWidth;
2115 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
2116 if ( fillElem.isNull() )
2119 QDomElement graphicFillElem = fillElem.firstChildElement( QStringLiteral(
"GraphicFill" ) );
2120 if ( graphicFillElem.isNull() )
2123 QDomElement graphicElem = graphicFillElem.firstChildElement( QStringLiteral(
"Graphic" ) );
2124 if ( graphicElem.isNull() )
2130 if ( mimeType != QLatin1String(
"image/svg+xml" ) )
2135 QString uom = element.attribute( QStringLiteral(
"uom" ) );
2144 double d = angleFunc.toDouble( &ok );
2149 std::unique_ptr< QgsSVGFillSymbolLayer > sl = qgis::make_unique< QgsSVGFillSymbolLayer >( path, size,
angle );
2150 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
2151 sl->setSvgFillColor( fillColor );
2152 sl->setSvgStrokeColor( strokeColor );
2153 sl->setSvgStrokeWidth( strokeWidth );
2156 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
2157 if ( !strokeElem.isNull() )
2168 return sl.release();
2186 double width = mPatternWidth;
2192 QString svgFile = mSvgFilePath;
2211 double strokeWidth = mSvgStrokeWidth;
2217 applyPattern(
mBrush, svgFile, width, mPatternWidthUnit, svgFillColor, svgStrokeColor, strokeWidth,
2218 mSvgStrokeWidthUnit, context, mPatternWidthMapUnitScale, mSvgStrokeWidthMapUnitScale );
2222 void QgsSVGFillSymbolLayer::storeViewBox()
2224 if ( !mSvgData.isEmpty() )
2226 QSvgRenderer r( mSvgData );
2229 mSvgViewBox = r.viewBoxF();
2234 mSvgViewBox = QRectF();
2237 void QgsSVGFillSymbolLayer::setDefaultSvgParams()
2239 if ( mSvgFilePath.isEmpty() )
2244 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
2245 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
2246 QColor defaultFillColor, defaultStrokeColor;
2247 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
2249 hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2250 hasStrokeParam, hasDefaultStrokeColor, defaultStrokeColor,
2251 hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
2252 hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
2254 double newFillOpacity = hasFillOpacityParam ?
mColor.alphaF() : 1.0;
2255 double newStrokeOpacity = hasStrokeOpacityParam ? mSvgStrokeColor.alphaF() : 1.0;
2257 if ( hasDefaultFillColor )
2259 mColor = defaultFillColor;
2260 mColor.setAlphaF( newFillOpacity );
2262 if ( hasDefaultFillOpacity )
2264 mColor.setAlphaF( defaultFillOpacity );
2266 if ( hasDefaultStrokeColor )
2268 mSvgStrokeColor = defaultStrokeColor;
2269 mSvgStrokeColor.setAlphaF( newStrokeOpacity );
2271 if ( hasDefaultStrokeOpacity )
2273 mSvgStrokeColor.setAlphaF( defaultStrokeOpacity );
2275 if ( hasDefaultStrokeWidth )
2277 mSvgStrokeWidth = defaultStrokeWidth;
2303 return mFillLineSymbol ? mFillLineSymbol->
color() :
mColor;
2308 delete mFillLineSymbol;
2323 delete mFillLineSymbol;
2324 mFillLineSymbol = lineSymbol;
2335 return mFillLineSymbol;
2341 if ( mFillLineSymbol )
2363 mDistanceUnit = unit;
2364 mLineWidthUnit = unit;
2371 if ( mDistanceUnit != unit || mLineWidthUnit != unit || mOffsetUnit != unit )
2381 mDistanceMapUnitScale = scale;
2382 mLineWidthMapUnitScale = scale;
2383 mOffsetMapUnitScale = scale;
2389 mDistanceMapUnitScale == mLineWidthMapUnitScale &&
2390 mLineWidthMapUnitScale == mOffsetMapUnitScale )
2392 return mDistanceMapUnitScale;
2399 std::unique_ptr< QgsLinePatternFillSymbolLayer > patternLayer = qgis::make_unique< QgsLinePatternFillSymbolLayer >();
2405 QColor
color( Qt::black );
2408 if ( properties.contains( QStringLiteral(
"lineangle" ) ) )
2411 lineAngle = properties[QStringLiteral(
"lineangle" )].toDouble();
2413 else if ( properties.contains( QStringLiteral(
"angle" ) ) )
2415 lineAngle = properties[QStringLiteral(
"angle" )].toDouble();
2417 patternLayer->setLineAngle( lineAngle );
2419 if ( properties.contains( QStringLiteral(
"distance" ) ) )
2421 distance = properties[QStringLiteral(
"distance" )].toDouble();
2423 patternLayer->setDistance( distance );
2425 if ( properties.contains( QStringLiteral(
"linewidth" ) ) )
2428 lineWidth = properties[QStringLiteral(
"linewidth" )].toDouble();
2430 else if ( properties.contains( QStringLiteral(
"outline_width" ) ) )
2432 lineWidth = properties[QStringLiteral(
"outline_width" )].toDouble();
2434 else if ( properties.contains( QStringLiteral(
"line_width" ) ) )
2436 lineWidth = properties[QStringLiteral(
"line_width" )].toDouble();
2438 patternLayer->setLineWidth( lineWidth );
2440 if ( properties.contains( QStringLiteral(
"color" ) ) )
2444 else if ( properties.contains( QStringLiteral(
"outline_color" ) ) )
2448 else if ( properties.contains( QStringLiteral(
"line_color" ) ) )
2452 patternLayer->setColor( color );
2454 if ( properties.contains( QStringLiteral(
"offset" ) ) )
2456 offset = properties[QStringLiteral(
"offset" )].toDouble();
2458 patternLayer->setOffset( offset );
2461 if ( properties.contains( QStringLiteral(
"distance_unit" ) ) )
2465 if ( properties.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
2469 if ( properties.contains( QStringLiteral(
"line_width_unit" ) ) )
2473 else if ( properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
2477 if ( properties.contains( QStringLiteral(
"line_width_map_unit_scale" ) ) )
2481 if ( properties.contains( QStringLiteral(
"offset_unit" ) ) )
2485 if ( properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
2489 if ( properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
2493 if ( properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
2498 patternLayer->restoreOldDataDefinedProperties( properties );
2500 return patternLayer.release();
2505 return QStringLiteral(
"LinePatternFill" );
2510 mBrush.setTextureImage( QImage() );
2512 if ( !mFillLineSymbol )
2517 std::unique_ptr< QgsLineSymbol > fillLineSymbol( mFillLineSymbol->
clone() );
2518 if ( !fillLineSymbol )
2525 double outputPixelDist = ctx.
convertToPainterUnits( distance, mDistanceUnit, mDistanceMapUnitScale );
2533 outputPixelOffset = std::fmod( outputPixelOffset, outputPixelDist );
2534 if ( outputPixelOffset > outputPixelDist / 2.0 )
2535 outputPixelOffset -= outputPixelDist;
2539 double outputPixelBleed = 0;
2540 double outputPixelInterval = 0;
2541 for (
int i = 0; i < fillLineSymbol->symbolLayerCount(); i++ )
2545 outputPixelBleed = std::max( outputPixelBleed, outputPixelLayerBleed );
2548 if ( markerLineLayer )
2557 outputPixelInterval = std::max( outputPixelInterval, outputPixelLayerInterval );
2561 if ( outputPixelInterval > 0 )
2565 double intervalScale = std::round( outputPixelInterval ) / outputPixelInterval;
2566 outputPixelInterval = std::round( outputPixelInterval );
2568 for (
int i = 0; i < fillLineSymbol->symbolLayerCount(); i++ )
2573 if ( markerLineLayer )
2587 height = outputPixelDist;
2588 width = outputPixelInterval > 0 ? outputPixelInterval : height;
2592 width = outputPixelDist;
2593 height = outputPixelInterval > 0 ? outputPixelInterval : width;
2597 height = outputPixelDist / std::cos(
lineAngle * M_PI / 180 );
2598 width = outputPixelDist / std::sin(
lineAngle * M_PI / 180 );
2601 lineAngle = 180 * std::atan2( static_cast< double >( height ), static_cast< double >( width ) ) / M_PI;
2607 height = std::abs( height );
2608 width = std::abs( width );
2610 outputPixelDist = std::abs( height * std::cos(
lineAngle * M_PI / 180 ) );
2614 int offsetHeight =
static_cast< int >( std::round( outputPixelOffset / std::cos(
lineAngle * M_PI / 180 ) ) );
2615 outputPixelOffset = offsetHeight * std::cos(
lineAngle * M_PI / 180 );
2624 int bufferMulti =
static_cast< int >( std::max( std::ceil( outputPixelBleed / width ), std::ceil( outputPixelBleed / width ) ) );
2628 bufferMulti = std::max( bufferMulti, 1 );
2630 int xBuffer = width * bufferMulti;
2631 int yBuffer = height * bufferMulti;
2632 int innerWidth = width;
2633 int innerHeight = height;
2634 width += 2 * xBuffer;
2635 height += 2 * yBuffer;
2638 if ( width > 10000 || height > 10000 || width == 0 || height == 0 )
2643 QImage patternImage( width, height, QImage::Format_ARGB32 );
2644 patternImage.fill( 0 );
2646 QPointF p1, p2, p3, p4, p5, p6;
2649 p1 = QPointF( 0, yBuffer );
2650 p2 = QPointF( width, yBuffer );
2651 p3 = QPointF( 0, yBuffer + innerHeight );
2652 p4 = QPointF( width, yBuffer + innerHeight );
2656 p1 = QPointF( xBuffer, height );
2657 p2 = QPointF( xBuffer, 0 );
2658 p3 = QPointF( xBuffer + innerWidth, height );
2659 p4 = QPointF( xBuffer + innerWidth, 0 );
2663 dx = outputPixelDist * std::cos( ( 90 -
lineAngle ) * M_PI / 180.0 );
2664 dy = outputPixelDist * std::sin( ( 90 -
lineAngle ) * M_PI / 180.0 );
2665 p1 = QPointF( 0, height );
2666 p2 = QPointF( width, 0 );
2667 p3 = QPointF( -dx, height - dy );
2668 p4 = QPointF( width - dx, -dy );
2669 p5 = QPointF( dx, height + dy );
2670 p6 = QPointF( width + dx, dy );
2674 dx = outputPixelDist * std::cos( ( 90 -
lineAngle ) * M_PI / 180.0 );
2675 dy = outputPixelDist * std::sin( ( 90 -
lineAngle ) * M_PI / 180.0 );
2676 p1 = QPointF( width, 0 );
2677 p2 = QPointF( 0, height );
2678 p3 = QPointF( width - dx, -dy );
2679 p4 = QPointF( -dx, height - dy );
2680 p5 = QPointF( width + dx, dy );
2681 p6 = QPointF( dx, height + dy );
2685 dy = outputPixelDist * std::cos( ( 180 -
lineAngle ) * M_PI / 180 );
2686 dx = outputPixelDist * std::sin( ( 180 -
lineAngle ) * M_PI / 180 );
2687 p1 = QPointF( 0, 0 );
2688 p2 = QPointF( width, height );
2689 p5 = QPointF( dx, -dy );
2690 p6 = QPointF( width + dx, height - dy );
2691 p3 = QPointF( -dx, dy );
2692 p4 = QPointF( width - dx, height + dy );
2696 dy = outputPixelDist * std::cos( ( 180 -
lineAngle ) * M_PI / 180 );
2697 dx = outputPixelDist * std::sin( ( 180 -
lineAngle ) * M_PI / 180 );
2698 p1 = QPointF( width, height );
2699 p2 = QPointF( 0, 0 );
2700 p5 = QPointF( width + dx, height - dy );
2701 p6 = QPointF( dx, -dy );
2702 p3 = QPointF( width - dx, height + dy );
2703 p4 = QPointF( -dx, dy );
2710 p3 = QPointF( tempPt.x(), tempPt.y() );
2712 p4 = QPointF( tempPt.x(), tempPt.y() );
2714 p5 = QPointF( tempPt.x(), tempPt.y() );
2716 p6 = QPointF( tempPt.x(), tempPt.y() );
2720 p1 = QPointF( tempPt.x(), tempPt.y() );
2722 p2 = QPointF( tempPt.x(), tempPt.y() );
2725 QPainter p( &patternImage );
2729 p.setRenderHint( QPainter::Antialiasing,
false );
2730 QPen pen( QColor( Qt::black ) );
2731 pen.setWidthF( 0.1 );
2732 pen.setCapStyle( Qt::FlatCap );
2737 QPolygon polygon = QPolygon() << QPoint( 0, 0 ) << QPoint( width - 1, 0 ) << QPoint( width - 1, height - 1 ) << QPoint( 0, height - 1 ) << QPoint( 0, 0 );
2738 p.drawPolygon( polygon );
2740 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 );
2741 p.drawPolygon( polygon );
2747 p.setRenderHint( QPainter::Antialiasing,
true );
2758 fillLineSymbol->startRender( lineRenderContext, context.
fields() );
2760 QVector<QPolygonF> polygons;
2761 polygons.append( QPolygonF() << p1 << p2 );
2762 polygons.append( QPolygonF() << p3 << p4 );
2765 polygons.append( QPolygonF() << p5 << p6 );
2768 for (
const QPolygonF &polygon : qgis::as_const( polygons ) )
2770 fillLineSymbol->renderPolyline( polygon, context.
feature(), lineRenderContext, -1, context.
selected() );
2773 fillLineSymbol->stopRender( lineRenderContext );
2777 patternImage = patternImage.copy( xBuffer, yBuffer, patternImage.width() - 2 * xBuffer, patternImage.height() - 2 * yBuffer );
2782 QImage transparentImage = patternImage.copy();
2784 brush.setTextureImage( transparentImage );
2788 brush.setTextureImage( patternImage );
2791 QTransform brushTransform;
2792 brush.setTransform( brushTransform );
2797 applyPattern( context,
mBrush, mLineAngle, mDistance );
2799 if ( mFillLineSymbol )
2807 if ( mFillLineSymbol )
2816 map.insert( QStringLiteral(
"angle" ), QString::number( mLineAngle ) );
2817 map.insert( QStringLiteral(
"distance" ), QString::number( mDistance ) );
2818 map.insert( QStringLiteral(
"line_width" ), QString::number( mLineWidth ) );
2820 map.insert( QStringLiteral(
"offset" ), QString::number( mOffset ) );
2835 if ( mFillLineSymbol )
2846 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
2847 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
2848 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
2849 element.appendChild( symbolizerElem );
2854 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
2855 symbolizerElem.appendChild( fillElem );
2857 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
2858 fillElem.appendChild( graphicFillElem );
2860 QDomElement graphicElem = doc.createElement( QStringLiteral(
"se:Graphic" ) );
2861 graphicFillElem.appendChild( graphicElem );
2864 QColor lineColor = mFillLineSymbol ? mFillLineSymbol->
color() : QColor();
2865 double lineWidth = mFillLineSymbol ? mFillLineSymbol->
width() : 0.0;
2873 double angle = props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ).toDouble( &ok );
2876 angleFunc = QStringLiteral(
"%1 + %2" ).arg( props.value( QStringLiteral(
"angle" ), QStringLiteral(
"0" ) ) ).arg( mLineAngle );
2880 angleFunc = QString::number( angle + mLineAngle );
2885 QPointF lineOffset( std::sin( mLineAngle ) * mOffset, std::cos( mLineAngle ) * mOffset );
2892 QString featureStyle;
2893 featureStyle.append(
"Brush(" );
2894 featureStyle.append( QStringLiteral(
"fc:%1" ).arg(
mColor.name() ) );
2895 featureStyle.append( QStringLiteral(
",bc:%1" ).arg( QStringLiteral(
"#00000000" ) ) );
2896 featureStyle.append(
",id:\"ogr-brush-2\"" );
2897 featureStyle.append( QStringLiteral(
",a:%1" ).arg( mLineAngle ) );
2898 featureStyle.append( QStringLiteral(
",s:%1" ).arg( mLineWidth * widthScaleFactor ) );
2899 featureStyle.append(
",dx:0mm" );
2900 featureStyle.append( QStringLiteral(
",dy:%1mm" ).arg( mDistance * widthScaleFactor ) );
2901 featureStyle.append(
')' );
2902 return featureStyle;
2925 applyPattern( context,
mBrush, lineAngle, distance );
2933 Qt::PenStyle lineStyle;
2935 QDomElement fillElem = element.firstChildElement( QStringLiteral(
"Fill" ) );
2936 if ( fillElem.isNull() )
2939 QDomElement graphicFillElem = fillElem.firstChildElement( QStringLiteral(
"GraphicFill" ) );
2940 if ( graphicFillElem.isNull() )
2943 QDomElement graphicElem = graphicFillElem.firstChildElement( QStringLiteral(
"Graphic" ) );
2944 if ( graphicElem.isNull() )
2950 if ( name != QLatin1String(
"horline" ) )
2958 double d = angleFunc.toDouble( &ok );
2967 offset = std::sqrt( std::pow( vectOffset.x(), 2 ) + std::pow( vectOffset.y(), 2 ) );
2970 QString uom = element.attribute( QStringLiteral(
"uom" ) );
2974 std::unique_ptr< QgsLinePatternFillSymbolLayer > sl = qgis::make_unique< QgsLinePatternFillSymbolLayer >();
2975 sl->setOutputUnit( QgsUnitTypes::RenderUnit::RenderPixels );
2976 sl->setColor( lineColor );
2977 sl->setLineWidth( lineWidth );
2978 sl->setLineAngle( angle );
2979 sl->setOffset( offset );
2980 sl->setDistance( size );
2983 QDomElement strokeElem = element.firstChildElement( QStringLiteral(
"Stroke" ) );
2984 if ( !strokeElem.isNull() )
2995 return sl.release();
3072 std::unique_ptr< QgsPointPatternFillSymbolLayer > layer = qgis::make_unique< QgsPointPatternFillSymbolLayer >();
3073 if ( properties.contains( QStringLiteral(
"distance_x" ) ) )
3075 layer->setDistanceX( properties[QStringLiteral(
"distance_x" )].toDouble() );
3077 if ( properties.contains( QStringLiteral(
"distance_y" ) ) )
3079 layer->setDistanceY( properties[QStringLiteral(
"distance_y" )].toDouble() );
3081 if ( properties.contains( QStringLiteral(
"displacement_x" ) ) )
3083 layer->setDisplacementX( properties[QStringLiteral(
"displacement_x" )].toDouble() );
3085 if ( properties.contains( QStringLiteral(
"displacement_y" ) ) )
3087 layer->setDisplacementY( properties[QStringLiteral(
"displacement_y" )].toDouble() );
3089 if ( properties.contains( QStringLiteral(
"offset_x" ) ) )
3091 layer->setOffsetX( properties[QStringLiteral(
"offset_x" )].toDouble() );
3093 if ( properties.contains( QStringLiteral(
"offset_y" ) ) )
3095 layer->setOffsetY( properties[QStringLiteral(
"offset_y" )].toDouble() );
3098 if ( properties.contains( QStringLiteral(
"distance_x_unit" ) ) )
3102 if ( properties.contains( QStringLiteral(
"distance_x_map_unit_scale" ) ) )
3106 if ( properties.contains( QStringLiteral(
"distance_y_unit" ) ) )
3110 if ( properties.contains( QStringLiteral(
"distance_y_map_unit_scale" ) ) )
3114 if ( properties.contains( QStringLiteral(
"displacement_x_unit" ) ) )
3118 if ( properties.contains( QStringLiteral(
"displacement_x_map_unit_scale" ) ) )
3122 if ( properties.contains( QStringLiteral(
"displacement_y_unit" ) ) )
3126 if ( properties.contains( QStringLiteral(
"displacement_y_map_unit_scale" ) ) )
3130 if ( properties.contains( QStringLiteral(
"offset_x_unit" ) ) )
3134 if ( properties.contains( QStringLiteral(
"offset_x_map_unit_scale" ) ) )
3138 if ( properties.contains( QStringLiteral(
"offset_y_unit" ) ) )
3142 if ( properties.contains( QStringLiteral(
"offset_y_map_unit_scale" ) ) )
3147 if ( properties.contains( QStringLiteral(
"outline_width_unit" ) ) )
3151 if ( properties.contains( QStringLiteral(
"outline_width_map_unit_scale" ) ) )
3158 return layer.release();
3163 return QStringLiteral(
"PointPatternFill" );
3177 if ( width > 10000 || height > 10000 )
3180 brush.setTextureImage( img );
3184 QImage patternImage( width, height, QImage::Format_ARGB32 );
3185 patternImage.fill( 0 );
3186 if ( patternImage.isNull() )
3188 brush.setTextureImage( QImage() );
3193 QPainter p( &patternImage );
3203 p.setRenderHint( QPainter::Antialiasing,
true );
3213 for (
double currentX = -width; currentX <= width * 2.0; currentX += width )
3215 for (
double currentY = -height; currentY <= height * 2.0; currentY += height )
3224 for (
double currentX = -width; currentX <= width * 2.0; currentX += width )
3226 for (
double currentY = -height / 2.0; currentY <= height * 2.0; currentY += height )
3232 for (
double currentX = -width / 2.0; currentX <= width * 2.0; currentX += width )
3234 for (
double currentY = -height; currentY <= height * 2.0; currentY += height / 2.0 )
3236 mMarkerSymbol->
renderPoint( QPointF( currentX + widthOffset + ( std::fmod( currentY, height ) != 0 ? displacementPixelX : 0 ), currentY + heightOffset - displacementPixelY ), context.
feature(), pointRenderContext );
3245 QImage transparentImage = patternImage.copy();
3247 brush.setTextureImage( transparentImage );
3251 brush.setTextureImage( patternImage );
3253 QTransform brushTransform;
3254 brush.setTransform( brushTransform );
3278 map.insert( QStringLiteral(
"distance_x" ), QString::number(
mDistanceX ) );
3279 map.insert( QStringLiteral(
"distance_y" ), QString::number(
mDistanceY ) );
3280 map.insert( QStringLiteral(
"displacement_x" ), QString::number(
mDisplacementX ) );
3281 map.insert( QStringLiteral(
"displacement_y" ), QString::number(
mDisplacementY ) );
3282 map.insert( QStringLiteral(
"offset_x" ), QString::number(
mOffsetX ) );
3283 map.insert( QStringLiteral(
"offset_y" ), QString::number(
mOffsetY ) );
3317 QDomElement symbolizerElem = doc.createElement( QStringLiteral(
"se:PolygonSymbolizer" ) );
3318 if ( !props.value( QStringLiteral(
"uom" ), QString() ).isEmpty() )
3319 symbolizerElem.setAttribute( QStringLiteral(
"uom" ), props.value( QStringLiteral(
"uom" ), QString() ) );
3320 element.appendChild( symbolizerElem );
3325 QDomElement fillElem = doc.createElement( QStringLiteral(
"se:Fill" ) );
3326 symbolizerElem.appendChild( fillElem );
3328 QDomElement graphicFillElem = doc.createElement( QStringLiteral(
"se:GraphicFill" ) );
3329 fillElem.appendChild( graphicFillElem );
3336 symbolizerElem.appendChild( distanceElem );
3342 QString errorMsg = QStringLiteral(
"MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( layer->
layerType() );
3343 graphicFillElem.appendChild( doc.createComment( errorMsg ) );
3419 applyPattern( context,
mBrush, distanceX, distanceY, displacementX, displacementY, offsetX, offsetY );
3468 std::unique_ptr< QgsCentroidFillSymbolLayer > sl = qgis::make_unique< QgsCentroidFillSymbolLayer >();
3470 if ( properties.contains( QStringLiteral(
"point_on_surface" ) ) )
3471 sl->setPointOnSurface( properties[QStringLiteral(
"point_on_surface" )].toInt() != 0 );
3472 if ( properties.contains( QStringLiteral(
"point_on_all_parts" ) ) )
3473 sl->setPointOnAllParts( properties[QStringLiteral(
"point_on_all_parts" )].toInt() != 0 );
3477 return sl.release();
3482 return QStringLiteral(
"CentroidFill" );
3487 mMarker->setColor( color );
3493 return mMarker ? mMarker->color() :
mColor;
3498 mMarker->setOpacity( context.
opacity() );
3501 mCurrentFeatureId = -1;
3502 mBiggestPartIndex = 0;
3512 if ( !mPointOnAllParts )
3517 if ( feature->
id() != mCurrentFeatureId )
3519 mCurrentFeatureId = feature->
id();
3520 mBiggestPartIndex = 1;
3528 double areaBiggest = 0;
3532 if ( area > areaBiggest )
3535 mBiggestPartIndex = i + 1;
3543 if ( mPointOnAllParts || ( context.
geometryPartNum() == mBiggestPartIndex ) )
3553 map[QStringLiteral(
"point_on_surface" )] = QString::number( mPointOnSurface );
3554 map[QStringLiteral(
"point_on_all_parts" )] = QString::number( mPointOnAllParts );
3560 std::unique_ptr< QgsCentroidFillSymbolLayer > x = qgis::make_unique< QgsCentroidFillSymbolLayer >();
3563 x->setSubSymbol( mMarker->clone() );
3564 x->setPointOnSurface( mPointOnSurface );
3565 x->setPointOnAllParts( mPointOnAllParts );
3576 mMarker->toSld( doc, element, props );
3587 std::unique_ptr< QgsMarkerSymbol > marker(
new QgsMarkerSymbol( layers ) );
3589 std::unique_ptr< QgsCentroidFillSymbolLayer > sl = qgis::make_unique< QgsCentroidFillSymbolLayer >();
3590 sl->setSubSymbol( marker.release() );
3591 sl->setPointOnAllParts(
false );
3592 return sl.release();
3598 return mMarker.get();
3609 mMarker.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
3610 mColor = mMarker->color();
3619 attributes.unite( mMarker->usedAttributes( context ) );
3628 if ( mMarker && mMarker->hasDataDefinedProperties() )
3637 mMarker->setOutputUnit( unit );
3645 return mMarker->outputUnit();
3654 mMarker->setMapUnitScale( scale );
3662 return mMarker->mapUnitScale();
3672 , mImageFilePath( imageFilePath )
3686 if ( properties.contains( QStringLiteral(
"imageFile" ) ) )
3688 imagePath = properties[QStringLiteral(
"imageFile" )];
3690 if ( properties.contains( QStringLiteral(
"coordinate_mode" ) ) )
3692 mode =
static_cast< FillCoordinateMode >( properties[QStringLiteral(
"coordinate_mode" )].toInt() );
3694 if ( properties.contains( QStringLiteral(
"alpha" ) ) )
3696 alpha = properties[QStringLiteral(
"alpha" )].toDouble();
3698 if ( properties.contains( QStringLiteral(
"offset" ) ) )
3702 if ( properties.contains( QStringLiteral(
"angle" ) ) )
3704 angle = properties[QStringLiteral(
"angle" )].toDouble();
3706 if ( properties.contains( QStringLiteral(
"width" ) ) )
3708 width = properties[QStringLiteral(
"width" )].toDouble();
3710 std::unique_ptr< QgsRasterFillSymbolLayer > symbolLayer = qgis::make_unique< QgsRasterFillSymbolLayer >( imagePath );
3711 symbolLayer->setCoordinateMode( mode );
3712 symbolLayer->setOpacity( alpha );
3713 symbolLayer->setOffset( offset );
3714 symbolLayer->setAngle( angle );
3715 symbolLayer->setWidth( width );
3716 if ( properties.contains( QStringLiteral(
"offset_unit" ) ) )
3720 if ( properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
3724 if ( properties.contains( QStringLiteral(
"width_unit" ) ) )
3728 if ( properties.contains( QStringLiteral(
"width_map_unit_scale" ) ) )
3733 symbolLayer->restoreOldDataDefinedProperties( properties );
3735 return symbolLayer.release();
3740 QgsStringMap::iterator it = properties.find( QStringLiteral(
"imageFile" ) );
3741 if ( it != properties.end() )
3744 it.value() = pathResolver.
writePath( it.value() );
3746 it.value() = pathResolver.
readPath( it.value() );
3758 return QStringLiteral(
"RasterFill" );
3770 if ( !mOffset.isNull() )
3774 p->translate( offset );
3776 if ( mCoordinateMode ==
Feature )
3778 QRectF boundingRect = points.boundingRect();
3779 mBrush.setTransform(
mBrush.transform().translate( boundingRect.left() -
mBrush.transform().dx(),
3780 boundingRect.top() -
mBrush.transform().dy() ) );
3784 if ( !mOffset.isNull() )
3786 p->translate( -offset );
3792 applyPattern(
mBrush, mImageFilePath, mWidth, mOpacity, context );
3803 map[QStringLiteral(
"imageFile" )] = mImageFilePath;
3804 map[QStringLiteral(
"coordinate_mode" )] = QString::number( mCoordinateMode );
3805 map[QStringLiteral(
"alpha" )] = QString::number( mOpacity );
3809 map[QStringLiteral(
"angle" )] = QString::number(
mAngle );
3810 map[QStringLiteral(
"width" )] = QString::number( mWidth );
3818 std::unique_ptr< QgsRasterFillSymbolLayer > sl = qgis::make_unique< QgsRasterFillSymbolLayer >( mImageFilePath );
3820 sl->setOpacity( mOpacity );
3821 sl->setOffset( mOffset );
3822 sl->setOffsetUnit( mOffsetUnit );
3823 sl->setOffsetMapUnitScale( mOffsetMapUnitScale );
3825 sl->setWidth( mWidth );
3826 sl->setWidthUnit( mWidthUnit );
3827 sl->setWidthMapUnitScale( mWidthMapUnitScale );
3830 return sl.release();
3835 return context.
convertToPainterUnits( std::max( std::fabs( mOffset.x() ), std::fabs( mOffset.y() ) ), mOffsetUnit, mOffsetMapUnitScale );
3840 mImageFilePath = imagePath;
3845 mCoordinateMode = mode;
3863 if ( !hasWidthExpression && !hasAngleExpression && !hasOpacityExpression && !hasFileExpression )
3869 if ( hasAngleExpression )
3877 if ( !hasWidthExpression && !hasOpacityExpression && !hasFileExpression )
3882 double width = mWidth;
3883 if ( hasWidthExpression )
3889 if ( hasOpacityExpression )
3894 QString file = mImageFilePath;
3895 if ( hasFileExpression )
3900 applyPattern(
mBrush, file, width, opacity, context );
3909 size.setHeight( 0 );
3917 brush.setTextureImage( img );
3926 : mCountMethod( method )
3927 , mPointCount( pointCount )
3928 , mDensityArea( densityArea )
3937 const int pointCount = properties.value( QStringLiteral(
"point_count" ), QStringLiteral(
"10" ) ).toInt();
3938 const double densityArea = properties.value( QStringLiteral(
"density_area" ), QStringLiteral(
"250.0" ) ).toDouble();
3940 unsigned long seed = 0;
3941 if ( properties.contains( QStringLiteral(
"seed" ) ) )
3942 seed = properties.value( QStringLiteral(
"seed" ) ).toULong();
3947 std::random_device rd;
3948 std::mt19937 mt( seed == 0 ? rd() : seed );
3949 std::uniform_int_distribution<> uniformDist( 1, 999999999 );
3950 seed = uniformDist( mt );
3955 if ( properties.contains( QStringLiteral(
"density_area_unit" ) ) )
3957 if ( properties.contains( QStringLiteral(
"density_area_unit_scale" ) ) )
3960 if ( properties.contains( QStringLiteral(
"clip_points" ) ) )
3962 sl->setClipPoints( properties[QStringLiteral(
"clip_points" )].toInt() );
3965 return sl.release();
3970 return QStringLiteral(
"RandomMarkerFill" );
3975 mMarker->setColor( color );
3981 return mMarker ? mMarker->color() :
mColor;
3986 mMarker->setOpacity( context.
opacity() );
3998 part.exterior = points;
4000 part.rings = *rings;
4002 if ( mRenderingFeature )
4006 mCurrentParts << part;
4015 void QgsRandomMarkerFillSymbolLayer::render(
QgsRenderContext &context,
const QVector<QgsRandomMarkerFillSymbolLayer::Part> &parts,
const QgsFeature &feature,
bool selected )
4024 QVector< QgsGeometry > geometryParts;
4025 geometryParts.reserve( parts.size() );
4028 for (
const Part &part : parts )
4031 if ( !geom.
isNull() && !part.rings.empty() )
4034 for (
const QPolygonF &ring : part.rings )
4041 geom = geom.
buffer( 0, 0 );
4043 geometryParts << geom;
4047 path.addPolygon( part.exterior );
4048 for (
const QPolygonF &ring : part.rings )
4050 path.addPolygon( ring );
4060 context.
painter()->setClipPath( path );
4064 int count = mPointCount;
4071 switch ( mCountMethod )
4081 densityArea = context.
convertToPainterUnits( std::sqrt( densityArea ), mDensityAreaUnit, mDensityAreaUnitScale );
4082 densityArea = std::pow( densityArea, 2 );
4083 count = std::max( 0.0, std::ceil( count * ( geom.
area() /
densityArea ) ) );
4090 unsigned long seed = mSeed;
4101 std::sort( randomPoints.begin(), randomPoints.end(), [](
const QgsPointXY & a,
const QgsPointXY & b )->
bool 4103 return a.
y() < b.y();
4106 for (
const QgsPointXY &p : qgis::as_const( randomPoints ) )
4108 mMarker->renderPoint( QPointF( p.x(), p.y() ), feature.
isValid() ? &feature :
nullptr, context, -1, selected );
4120 map.insert( QStringLiteral(
"count_method" ), QString::number( static_cast< int >( mCountMethod ) ) );
4121 map.insert( QStringLiteral(
"point_count" ), QString::number( mPointCount ) );
4122 map.insert( QStringLiteral(
"density_area" ), QString::number( mDensityArea ) );
4125 map.insert( QStringLiteral(
"seed" ), QString::number( mSeed ) );
4126 map.insert( QStringLiteral(
"clip_points" ), QString::number( mClipPoints ) );
4132 std::unique_ptr< QgsRandomMarkerFillSymbolLayer > res = qgis::make_unique< QgsRandomMarkerFillSymbolLayer >( mPointCount, mCountMethod, mDensityArea, mSeed );
4135 res->setDensityAreaUnit( mDensityAreaUnit );
4136 res->setDensityAreaUnitScale( mDensityAreaUnitScale );
4137 res->mClipPoints = mClipPoints;
4138 res->setSubSymbol( mMarker->clone() );
4141 return res.release();
4146 return mMarker.get();
4157 mMarker.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
4158 mColor = mMarker->color();
4167 attributes.unite( mMarker->usedAttributes( context ) );
4176 if ( mMarker && mMarker->hasDataDefinedProperties() )
4213 return mCountMethod;
4218 mCountMethod = method;
4223 return mDensityArea;
4228 mDensityArea = area;
4233 mRenderingFeature =
true;
4234 mCurrentParts.clear();
4239 mRenderingFeature =
false;
4240 render( context, mCurrentParts, feature,
false );
4248 mMarker->setOutputUnit( unit );
4256 return mMarker->outputUnit();
4265 mMarker->setMapUnitScale( scale );
4273 return mMarker->mapUnitScale();
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
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)
QgsMapUnitScale mapUnitScale() const override
QColor color2() const
Returns the color used for the endpoint of the shapeburst fill.
bool isValid() const
Returns the validity of this feature.
#define DEFAULT_SIMPLEFILL_BORDERCOLOR
QgsUnitTypes::RenderUnit mStrokeWidthUnit
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
QgsMapUnitScale mapUnitScale() const override
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
static QgsSymbolLayer * createFromSld(QDomElement &element)
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
QgsImageFillSymbolLayer()
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
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)
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...
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
Gradient reference point 1 is centroid.
QgsSimpleFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
double mStrokeWidth
Stroke width.
double rendererScale() const
Returns the renderer map scale.
Qt::BrushStyle mBrushStyle
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsUnitTypes::RenderUnit mDisplacementXUnit
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double symbologyScale() const
Returns the reference scale for output.
void setPointCount(int count)
Sets the count of random points to render in the fill.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used for the gradient fill.
QString svgFilePath() const
Returns the path to the SVG file used to render the fill.
QColor strokeColor() const override
Gets stroke color.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
static Qt::BrushStyle decodeBrushStyle(const QString &str)
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsMapUnitScale mOffsetYMapUnitScale
QgsSVGFillSymbolLayer(const QString &svgFilePath, double width=20, double rotation=0.0)
Constructor for QgsSVGFillSymbolLayer, using the SVG picture at the specified absolute file path...
#define DEFAULT_SIMPLEFILL_JOINSTYLE
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsCentroidFillSymbolLayer using the specified properties map containing symbol propert...
Gradient reference point 1 x.
QgsFields fields() const
Fields of the layer.
QgsMapUnitScale mStrokeWidthMapUnitScale
QColor color() const override
The fill color.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsRasterFillSymbolLayer from a properties map.
QgsRasterFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Qt::PenStyle mStrokeStyle
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
void setSvgFillColor(const QColor &c)
Sets the fill color used for rendering the SVG content.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QString layerType() const override
Returns a string that represents this layer type.
Abstract base class for all rendered symbols.
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...
void setColor(const QColor &c) override
The fill color.
QString imageFilePath() const
The path to the raster image used for the fill.
QPointF offset() const
Returns the offset for the shapeburst fill.
Use antialiasing while drawing.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
QgsMapUnitScale mapUnitScale() const override
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
GradientCoordinateMode coordinateMode() const
Coordinate mode for gradient. Controls how the gradient stops are positioned.
QColor dxfColor(QgsSymbolRenderContext &context) const override
Gets color.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsPointPatternFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Qt::PenJoinStyle penJoinStyle() const
GradientSpread gradientSpread() const
Gradient spread mode. Controls how the gradient behaves outside of the predefined stops...
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsRandomMarkerFillSymbolLayer using the specified properties map containing symbol pro...
A symbol fill consisting of repeated parallel lines.
QgsLinePatternFillSymbolLayer()
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)
Gets SVG as QImage.
QgsUnitTypes::RenderUnit mOffsetUnit
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.
QgsMapUnitScale mapUnitScale() const override
Base class for polygon renderers generating texture images.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used to draw the shapeburst fill.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images...
A class to represent a 2D point.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
QgsUnitTypes::RenderUnit patternWidthUnit() const
Returns the units for the width of the SVG images in the pattern.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
Abstract base class for color ramps.
static QString ogrFeatureStyleBrush(const QColor &fillColr)
Create ogr feature style string for brush.
QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const override
void setRendererScale(double scale)
Sets the renderer map scale.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
virtual QColor strokeColor() const
Gets stroke color.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
static bool displacementFromSldElement(QDomElement &element, QPointF &offset)
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
QString layerType() const override
Returns a string that represents this layer type.
Whether markers should be clipped to polygon boundaries.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsLinePatternFillSymbolLayer from a properties map.
QString layerType() const override
Returns a string that represents this layer type.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
ShapeburstColorType colorType() const
Returns the color mode used for the shapeburst fill.
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsMapUnitScale mapUnitScale() const override
static QPointF polygonPointOnSurface(const QPolygonF &points, QList< QPolygonF > *rings=nullptr)
Calculate a point on the surface of a QPolygonF.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
~QgsGradientFillSymbolLayer() override
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
A geometry is the spatial representation of a feature.
void restoreOldDataDefinedProperties(const QgsStringMap &stringMap)
Restores older data defined properties from string map.
static double sizeInPixelsFromSldUom(const QString &uom, double size)
Returns the size scaled in pixels according to the uom attribute.
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...
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSVGFillSymbolLayer from a properties map.
void _renderPolygon(QPainter *p, const QPolygonF &points, const QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
Default method to render polygon.
bool useWholeShape() const
Returns whether the shapeburst fill is set to cover the entire shape.
Flags flags() const
Returns combination of flags used for rendering.
static QgsSymbolLayer * createFromSld(QDomElement &element)
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
#define DEFAULT_SIMPLEFILL_COLOR
QgsUnitTypes::DistanceUnit mapUnits() const
Retrieve map units.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
A fill symbol layer which places markers at random locations within polygons.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
QColor color2() const
Color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.
QgsGradientFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsUnitTypes::RenderUnit intervalUnit() const
Returns the units for the interval between symbols.
GradientColorType mGradientColorType
double interval() const
Returns the interval between individual symbols.
const QgsMapUnitScale & svgStrokeWidthMapUnitScale() const
Returns the map unit scale for the pattern's stroke.
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
QColor color() const override
The fill color.
QgsMapUnitScale mDistanceYMapUnitScale
QPointF referencePoint1() const
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QString layerType() const override
Returns a string that represents this layer type.
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QMap< QString, QString > QgsStringMap
QgsMapUnitScale mapUnitScale() const override
Shapeburst use whole shape.
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
void setInterval(double interval)
Sets the interval between individual symbols.
static QgsSymbolLayer * createFromSld(QDomElement &element)
Creates a new QgsSVGFillSymbolLayer from a SLD element.
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
A marker symbol type, for rendering Point and MultiPoint geometries.
QColor color() const override
The fill color.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
A line symbol type, for rendering LineString and MultiLineString geometries.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
QgsUnitTypes::RenderUnit mStrokeWidthUnit
Gradient reference point 2 y.
double lineAngle() const
Returns the angle for the parallel lines used to fill the symbol.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsMapUnitScale mapUnitScale() const override
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void setMapUnitScale(const QgsMapUnitScale &scale) override
#define DEFAULT_SIMPLEFILL_STYLE
static QString encodeColor(const QColor &color)
QgsMapUnitScale mDisplacementYMapUnitScale
void setCoordinateMode(FillCoordinateMode mode)
Set the coordinate mode for fill.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
double offsetY() const
Returns the vertical offset values for points in the pattern.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
void setOffset(QPointF offset)
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
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
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...
void setMapUnitScale(const QgsMapUnitScale &scale) override
QPointF referencePoint2() const
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection...
void 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.
QString layerType() const override
Returns a string that represents this layer type.
QgsUnitTypes::RenderUnit mOffsetUnit
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
static QString encodePenStyle(Qt::PenStyle style)
Perform transforms between map coordinates and device coordinates.
double offset() const
Returns the offset distance for lines within the fill, which is the distance to offset the parallel l...
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
Writes the symbol layer definition as a SLD XML element.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership)
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
static double rescaleUom(double size, QgsUnitTypes::RenderUnit unit, const QgsStringMap &props)
Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
QgsLinePatternFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
CountMethod countMethod() const
Returns the count method used to randomly fill the polygon.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
double strokeWidth() const
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
std::unique_ptr< QgsLineSymbol > mStroke
Custom stroke.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
A class for filling symbols with a repeated raster image.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsMapUnitScale mDistanceXMapUnitScale
#define DEFAULT_SIMPLEFILL_BORDERWIDTH
QColor dxfBrushColor(QgsSymbolRenderContext &context) const override
Gets brush/fill color.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
bool isGeosValid(QgsGeometry::ValidityFlags flags=nullptr) const
Checks validity of the geometry using GEOS.
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void setCountMethod(CountMethod method)
Sets the count method used to randomly fill the polygon.
double offsetX() const
Returns the horizontal offset values for points in the pattern.
static const bool SELECT_FILL_STYLE
Whether fill styles for selected features uses symbol layer style.
void setColor(const QColor &color) override
The fill color.
bool clipPoints() const
Returns true if point markers should be clipped to the polygon boundary.
GradientType mGradientType
void setWidth(double width)
Sets the width for the whole line symbol.
qreal opacity() const
Returns the opacity for the symbol.
static QgsSymbolLayer * createFromSld(QDomElement &element)
void setDensityArea(double area)
Sets the density area used to count the number of points to randomly fill the polygon.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
double dxfWidth(const QgsDxfExport &e, QgsSymbolRenderContext &context) const override
Gets line width.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
Gradient coordinate mode.
bool mReferencePoint1IsCentroid
double densityArea() const
Returns the density area used to count the number of points to randomly fill the polygon.
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).
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol propert...
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
double displacementX() const
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsPointPatternFillSymbolLayer using the specified properties map containing symbol pro...
QByteArray getImageData(const QString &path, bool blocking=false) const
Gets the SVG content corresponding to the given path.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
static double mapUnitScaleFactor(double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits, double mapUnitsPerPixel=1.0)
Returns scale factor for conversion to map units.
virtual QColor color() const
The fill color.
static void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing...
static QgsSymbolLayer * createMarkerLayerFromSld(QDomElement &element)
static void createRotationElement(QDomDocument &doc, QDomElement &element, const QString &rotationFunc)
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Filename, eg for svg files.
QColor selectionColor() const
Returns the color to use when rendering selected features.
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
QgsUnitTypes::RenderUnit mOffsetYUnit
QgsGradientFillSymbolLayer(const QColor &color=DEFAULT_SIMPLEFILL_COLOR, const QColor &color2=Qt::white, GradientColorType gradientColorType=SimpleTwoColor, GradientType gradientType=Linear, GradientCoordinateMode coordinateMode=Feature, GradientSpread gradientSpread=Pad)
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QList< QgsSymbolLayer * > QgsSymbolLayerList
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
void setColor(const QColor &color) override
The fill color.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
CountMethod
Methods to define the number of points randomly filling the polygon.
QColor color() const
Returns the symbol's color.
Shapeburst fill from edge distance.
void setMapUnitScale(const QgsMapUnitScale &scale) override
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
QgsSymbol::SymbolType type() const
bool ignoreRings() const
Returns whether the shapeburst fill is set to ignore polygon interior rings.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
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...
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
virtual QString type() const =0
Returns a string representing the color ramp type.
QString layerType() const override
Returns a string that represents this layer type.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
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)
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
double mapUnitsPerPixel() const
Returns current map units per pixel.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QColor fillColor() const override
Gets fill color.
QgsUnitTypes::RenderUnit svgStrokeWidthUnit() const
Returns the units for the stroke width.
QColor svgStrokeColor() const
Returns the stroke color used for rendering the SVG content.
QgsMapUnitScale mDisplacementXMapUnitScale
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
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.
Tiling is based on feature bounding box.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
static Qt::PenStyle decodePenStyle(const QString &str)
static bool externalGraphicFromSld(QDomElement &element, QString &path, QString &mime, QColor &color, double &size)
bool mReferencePoint2IsCentroid
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...
int pointCount() const
Returns the count of random points to render in the fill.
static void resolvePaths(QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing...
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
virtual double estimateMaxBleed(const QgsRenderContext &context) const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style...
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
double lineWidth() const
Returns the width of the line subsymbol used to render the parallel lines in the fill.
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsMapUnitScale mOffsetXMapUnitScale
QgsShapeburstFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Gradient reference point 1 y.
~QgsPointPatternFillSymbolLayer() override
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsMapUnitScale mapUnitScale() const override
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
QgsMapUnitScale mapUnitScale() const override
double dxfAngle(QgsSymbolRenderContext &context) const override
Gets angle.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsExpressionContext & expressionContext()
Gets the expression context.
QString layerType() const override
Returns a string that represents this layer type.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
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.
int geometryPartNum() const
Part number of current geometry.
Line angle, or angle of hash lines for hash line symbols.
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...
GradientCoordinateMode mCoordinateMode
GradientType gradientType() const
Type of gradient, e.g., linear or radial.
QgsRasterFillSymbolLayer(const QString &imageFilePath=QString())
Constructor for QgsRasterFillSymbolLayer, using a raster fill from the specified imageFilePath.
GradientSpread mGradientSpread
void setLineWidth(double w)
Sets the width of the line subsymbol used to render the parallel lines in the fill.
void setMapUnitScale(const QgsMapUnitScale &scale) override
static QPointF polygonCentroid(const QPolygonF &points)
Calculate the centroid point of a QPolygonF.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
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...
A class for filling symbols with a repeated SVG file.
void setMapUnitScale(const QgsMapUnitScale &scale) override
Stroke style (eg solid, dashed)
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Contains information about the context of a rendering operation.
Abstract base class for marker symbol layers.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
const QgsMapUnitScale & intervalMapUnitScale() const
Returns the map unit scale for the interval between symbols.
QString layerType() const override
Returns a string that represents this layer type.
QgsCentroidFillSymbolLayer()
QgsCentroidFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Qt::BrushStyle dxfBrushStyle() const override
Gets brush/fill style.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsShapeburstFillSymbolLayer using the specified properties map containing symbol prope...
Line symbol layer type which draws repeating marker symbols along a line feature. ...
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
bool hasDataDefinedProperties() const
Returns whether the symbol utilizes any data defined properties.
QgsPointPatternFillSymbolLayer()
QColor svgFillColor() const
Returns the fill color used for rendering the SVG content.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
SymbolType type() const
Returns the symbol's type.
~QgsShapeburstFillSymbolLayer() override
Struct for storing maximum and minimum scales for measurements in map units.
static QString encodeBrushStyle(Qt::BrushStyle style)
The point count is part of a marker density count.
const QgsMapUnitScale & patternWidthMapUnitScale() const
Returns the map unit scale for the pattern's width.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false)
Performs a stack blur on an image.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
void setSvgFilePath(const QString &svgPath)
Sets the path to the SVG file to render in the fill.
virtual QgsStringMap properties() const =0
Returns a string map containing all the color ramp's properties.
QString ogrFeatureStyleWidth(double widthScaleFactor) const
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QgsRandomMarkerFillSymbolLayer(int pointCount=10, CountMethod method=AbsoluteCount, double densityArea=250.0, unsigned long seed=0)
Constructor for QgsRandomMarkerFillSymbolLayer, with the specified pointCount.
Qt::PenStyle strokeStyle() const
static const bool SELECTION_IS_OPAQUE
Whether styles for selected features ignore symbol alpha.
const QgsFeature * feature() const
Returns the current feature being rendered.
#define DEFAULT_SIMPLEFILL_BORDERSTYLE
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
GradientColorType gradientColorType() const
Gradient color mode, controls how gradient color stops are created.
Distance between lines, or length of lines for hash line symbols.
Qt::PenJoinStyle mPenJoinStyle
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
QgsColorRamp * mGradientRamp
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QColor dxfColor(QgsSymbolRenderContext &context) const override
Gets color.
double patternWidth() const
Returns the width of the rendered SVG content within the fill (i.e.
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 * createFromSld(QDomElement &element)
Creates a new QgsLinePatternFillSymbolLayer from a SLD element.
Secondary color (eg for gradient fills)
static bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &strokeColor, Qt::PenStyle &strokeStyle, double &strokeWidth, double &size)
QgsMarkerSymbol * mMarkerSymbol
double maxDistance() const
Returns the maximum distance from the shape's boundary which is shaded.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
void applyDataDefinedSettings(QgsSymbolRenderContext &context) override
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
double opacity() const
Returns the opacity for the raster image used in the fill.
The point count is used as an absolute count of markers.
QgsUnitTypes::RenderUnit mOffsetXUnit
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QgsSymbolLayer * createLineLayerFromSld(QDomElement &element)
QgsRandomMarkerFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setMapUnitScale(const QgsMapUnitScale &scale) override
static const bool SELECT_FILL_BORDER
Whether fill styles for selected features also highlight symbol stroke.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
void setMapUnitScale(const QgsMapUnitScale &scale) override
static void fillToSld(QDomDocument &doc, QDomElement &element, Qt::BrushStyle brushStyle, const QColor &color=QColor())
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)
void setColor(const QColor &c) override
The fill color.
Qt::PenStyle dxfPenStyle() const override
Gets pen style.
double svgStrokeWidth() const
Returns the stroke width used for rendering the SVG content.
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)
Gets SVG as QPicture&.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
QgsUnitTypes::RenderUnit mDistanceXUnit
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
double area() const
Returns the planar, 2-dimensional area of the geometry.
int blurRadius() const
Returns the blur radius, which controls the amount of blurring applied to the fill.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsUnitTypes::RenderUnit mDisplacementYUnit
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Resolves relative paths into absolute paths and vice versa.
Draw map such that there are no problems between adjacent tiles.
void setOpacity(double opacity)
Sets the opacity for the raster image used in the fill.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr) const
Returns a list of count random points generated inside a (multi)polygon geometry. ...
void addStopsToGradient(QGradient *gradient, double opacity=1)
Copy color ramp stops to a QGradient.
double distance() const
Returns the distance between lines in the fill pattern.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Fill style (eg solid, dots)
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false)
Returns the specified path rendered as an image.
double displacementY() const
virtual QColor fillColor() const
Gets fill 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...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
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 void multiplyImageOpacity(QImage *image, qreal opacity)
Multiplies opacity of image pixel values with a (global) transparency value.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
double width() const
Returns the width used for scaling the image used in the fill.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsSVGFillSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Gradient reference point 2 is centroid.
FillCoordinateMode
Fill coordinate modes, dictates fill tiling behavior.
void setMapUnitScale(const QgsMapUnitScale &scale) 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)
QgsMapUnitScale mOffsetMapUnitScale
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
Gradient reference point 2 x.
QgsPropertyCollection mDataDefinedProperties
QgsUnitTypes::RenderUnit mDistanceYUnit
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
int geometryPartCount() const
Part count of current geometry.
void setClipPoints(bool clipped)
Sets whether point markers should be clipped to the polygon boundary.
Qt::PenStyle dxfPenStyle() const override
Gets pen style.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
~QgsLinePatternFillSymbolLayer() override
RenderUnit
Rendering size units.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
static QColor decodeColor(const QString &str)
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
QgsMapUnitScale mStrokeWidthMapUnitScale
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Horizontal distance between points.
QPointF offset() const
Returns the offset for the fill.
virtual QString layerType() const =0
Returns a string that represents this layer type.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void setColor(const QColor &color)
Sets the color for the symbol.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
Vertical distance between points.
QgsMapUnitScale mOffsetMapUnitScale