49#include <QDomDocument>
54using namespace Qt::StringLiterals;
61 mCustomDashVector << 5 << 2;
71 mCustomDashPatternUnit = unit;
72 mDashPatternOffsetUnit = unit;
73 mTrimDistanceStartUnit = unit;
74 mTrimDistanceEndUnit = unit;
97 mCustomDashPatternMapUnitScale = scale;
115 if ( props.contains( u
"line_color"_s ) )
119 else if ( props.contains( u
"outline_color"_s ) )
123 else if ( props.contains( u
"color"_s ) )
128 if ( props.contains( u
"line_width"_s ) )
130 width = props[u
"line_width"_s].toDouble();
132 else if ( props.contains( u
"outline_width"_s ) )
134 width = props[u
"outline_width"_s].toDouble();
136 else if ( props.contains( u
"width"_s ) )
139 width = props[u
"width"_s].toDouble();
141 if ( props.contains( u
"line_style"_s ) )
145 else if ( props.contains( u
"outline_style"_s ) )
149 else if ( props.contains( u
"penstyle"_s ) )
155 if ( props.contains( u
"line_width_unit"_s ) )
159 else if ( props.contains( u
"outline_width_unit"_s ) )
163 else if ( props.contains( u
"width_unit"_s ) )
168 if ( props.contains( u
"width_map_unit_scale"_s ) )
170 if ( props.contains( u
"offset"_s ) )
171 l->setOffset( props[u
"offset"_s].toDouble() );
172 if ( props.contains( u
"offset_unit"_s ) )
174 if ( props.contains( u
"offset_map_unit_scale"_s ) )
176 if ( props.contains( u
"joinstyle"_s ) )
178 if ( props.contains( u
"capstyle"_s ) )
181 if ( props.contains( u
"use_custom_dash"_s ) )
183 l->setUseCustomDashPattern( props[u
"use_custom_dash"_s].toInt() );
185 if ( props.contains( u
"customdash"_s ) )
189 if ( props.contains( u
"customdash_unit"_s ) )
193 if ( props.contains( u
"customdash_map_unit_scale"_s ) )
198 if ( props.contains( u
"draw_inside_polygon"_s ) )
200 l->setDrawInsidePolygon( props[u
"draw_inside_polygon"_s].toInt() );
203 if ( props.contains( u
"ring_filter"_s ) )
205 l->setRingFilter(
static_cast< RenderRingFilter>( props[u
"ring_filter"_s].toInt() ) );
208 if ( props.contains( u
"dash_pattern_offset"_s ) )
209 l->setDashPatternOffset( props[u
"dash_pattern_offset"_s].toDouble() );
210 if ( props.contains( u
"dash_pattern_offset_unit"_s ) )
212 if ( props.contains( u
"dash_pattern_offset_map_unit_scale"_s ) )
215 if ( props.contains( u
"trim_distance_start"_s ) )
216 l->setTrimDistanceStart( props[u
"trim_distance_start"_s].toDouble() );
217 if ( props.contains( u
"trim_distance_start_unit"_s ) )
219 if ( props.contains( u
"trim_distance_start_map_unit_scale"_s ) )
221 if ( props.contains( u
"trim_distance_end"_s ) )
222 l->setTrimDistanceEnd( props[u
"trim_distance_end"_s].toDouble() );
223 if ( props.contains( u
"trim_distance_end_unit"_s ) )
225 if ( props.contains( u
"trim_distance_end_map_unit_scale"_s ) )
228 if ( props.contains( u
"align_dash_pattern"_s ) )
229 l->setAlignDashPattern( props[u
"align_dash_pattern"_s].toInt() );
231 if ( props.contains( u
"tweak_dash_pattern_on_corners"_s ) )
232 l->setTweakDashPatternOnCorners( props[u
"tweak_dash_pattern_on_corners"_s].toInt() );
234 l->restoreOldDataDefinedProperties( props );
241 return u
"SimpleLine"_s;
253 mPen.setColor( penColor );
255 mPen.setWidthF( scaledWidth );
259 const double dashWidthDiv = std::max( 1.0, scaledWidth );
260 if ( mUseCustomDashPattern )
262 mPen.setStyle( Qt::CustomDashLine );
266 QVector<qreal> scaledVector;
267 QVector<qreal>::const_iterator it = mCustomDashVector.constBegin();
268 for ( ; it != mCustomDashVector.constEnd(); ++it )
273 mPen.setDashPattern( scaledVector );
277 mPen.setStyle( mPenStyle );
280 if ( mDashPatternOffset && mPen.style() != Qt::SolidLine )
285 mPen.setJoinStyle( mPenJoinStyle );
286 mPen.setCapStyle( mPenCapStyle );
291 selColor.setAlphaF( context.
opacity() );
292 mSelPen.setColor( selColor );
309 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
317 if ( mDrawInsidePolygon )
327 if ( mDrawInsidePolygon )
330 QPainterPath clipPath;
331 clipPath.addPolygon( points );
336 for (
auto it = rings->constBegin(); it != rings->constEnd(); ++it )
338 QPolygonF ring = *it;
339 clipPath.addPolygon( ring );
344 p->setClipPath( clipPath, Qt::IntersectClip );
367 for (
const QPolygonF &ring : std::as_const( *rings ) )
412 double totalLength = -1;
416 startTrim = startTrim * 0.01 * totalLength;
424 if ( totalLength < 0 )
426 endTrim = endTrim * 0.01 * totalLength;
447 QPolygonF points = pts;
448 trimPoints( points, mTrimDistanceStart, mTrimDistanceEnd, mTrimDistanceStartUnit, mTrimDistanceEndUnit, mTrimDistanceStartMapUnitScale, mTrimDistanceEndMapUnitScale,
mDataDefinedProperties, context );
452 mPen.setColor( penColor );
455 applyDataDefinedSymbology( context, mPen, mSelPen,
offset );
458 const QPen pen = useSelectedColor ? mSelPen : mPen;
460 if ( !pen.dashPattern().isEmpty() )
463 const QVector<double> pattern = pen.dashPattern();
464 bool foundNonNull =
false;
465 for (
int i = 0; i < pattern.size(); ++i )
477 p->setBrush( Qt::NoBrush );
481 if ( points.size() <= 2
484 && ( p->renderHints() & QPainter::Antialiasing ) )
487 p->setRenderHint( QPainter::Antialiasing,
false );
490 const bool applyPatternTweaks = mAlignDashPattern && ( pen.style() != Qt::SolidLine || !pen.dashPattern().empty() ) && pen.dashOffset() == 0;
494 if ( applyPatternTweaks )
496 drawPathWithDashPatternTweaks( p, points, pen );
502 path.addPolygon( points );
518 for (
const QPolygonF &part : mline )
520 if ( applyPatternTweaks )
522 drawPathWithDashPatternTweaks( p, part, pen );
528 path.addPolygon( part );
539 map[u
"line_width"_s] = QString::number(
mWidth );
545 map[u
"offset"_s] = QString::number(
mOffset );
548 map[u
"use_custom_dash"_s] = ( mUseCustomDashPattern ? u
"1"_s : u
"0"_s );
552 map[u
"dash_pattern_offset"_s] = QString::number( mDashPatternOffset );
555 map[u
"trim_distance_start"_s] = QString::number( mTrimDistanceStart );
558 map[u
"trim_distance_end"_s] = QString::number( mTrimDistanceEnd );
561 map[u
"draw_inside_polygon"_s] = ( mDrawInsidePolygon ? u
"1"_s : u
"0"_s );
562 map[u
"ring_filter"_s] = QString::number(
static_cast< int >(
mRingFilter ) );
563 map[u
"align_dash_pattern"_s] = mAlignDashPattern ? u
"1"_s : u
"0"_s;
564 map[u
"tweak_dash_pattern_on_corners"_s] = mPatternCartographicTweakOnSharpCorners ? u
"1"_s : u
"0"_s;
604 toSld( doc, element, context );
609 if ( mPenStyle == Qt::NoPen )
613 QDomElement symbolizerElem = doc.createElement( u
"se:LineSymbolizer"_s );
614 if ( !props.value( u
"uom"_s, QString() ).toString().isEmpty() )
615 symbolizerElem.setAttribute( u
"uom"_s, props.value( u
"uom"_s, QString() ).toString() );
616 element.appendChild( symbolizerElem );
622 QDomElement strokeElem = doc.createElement( u
"se:Stroke"_s );
623 symbolizerElem.appendChild( strokeElem );
625 Qt::PenStyle
penStyle = mUseCustomDashPattern ? Qt::CustomDashLine : mPenStyle;
633 QDomElement perpOffsetElem = doc.createElement( u
"se:PerpendicularOffset"_s );
636 symbolizerElem.appendChild( perpOffsetElem );
643 if ( mUseCustomDashPattern )
657 QDomElement strokeElem = element.firstChildElement( u
"Stroke"_s );
658 if ( strokeElem.isNull() )
672 QDomElement perpOffsetElem = element.firstChildElement( u
"PerpendicularOffset"_s );
673 if ( !perpOffsetElem.isNull() )
676 double d = perpOffsetElem.firstChild().nodeValue().toDouble( &ok );
681 double scaleFactor = 1.0;
682 const QString uom = element.attribute( u
"uom"_s );
688 l->setOutputUnit( sldUnitSize );
692 l->setUseCustomDashPattern(
penStyle == Qt::CustomDashLine );
697void QgsSimpleLineSymbolLayer::applyDataDefinedSymbology(
QgsSymbolRenderContext &context, QPen &pen, QPen &selPen,
double &offset )
703 bool hasStrokeWidthExpression =
false;
710 pen.setWidthF( scaledWidth );
711 selPen.setWidthF( scaledWidth );
712 hasStrokeWidthExpression =
true;
721 penColor.setAlphaF( context.
opacity() * penColor.alphaF() );
722 pen.setColor( penColor );
736 const double dashWidthDiv = std::max( hasStrokeWidthExpression ? pen.widthF() : mPen.widthF(), 1.0 );
740 const QString customDashString
742 const QStringList dashList = customDashString.split(
';' );
743 QVector<qreal> dashVector;
744 for (
const QString &dash : dashList )
748 pen.setDashPattern( dashVector );
754 QVector<qreal> scaledVector;
755 for (
double v : std::as_const( mCustomDashVector ) )
760 mPen.setDashPattern( scaledVector );
764 double patternOffset = mDashPatternOffset;
776 const QString lineStyleString
785 const QString joinStyleString
794 const QString capStyleString
800void QgsSimpleLineSymbolLayer::drawPathWithDashPatternTweaks( QPainter *painter,
const QPolygonF &points, QPen pen )
const
802 if ( pen.dashPattern().empty() || points.size() < 2 )
805 if ( pen.widthF() <= 1.0 )
807 pen.setWidthF( 1.0001 );
810 QVector< qreal > sourcePattern = pen.dashPattern();
811 const double dashWidthDiv = pen.widthF();
813 for (
int i = 0; i < sourcePattern.size(); ++i )
814 sourcePattern[i] *= pen.widthF();
816 QVector< qreal > buffer;
817 QPolygonF bufferedPoints;
818 QPolygonF previousSegmentBuffer;
823 auto ptIt = points.constBegin();
824 double totalBufferLength = 0;
825 int patternIndex = 0;
826 double currentRemainingDashLength = 0;
827 double currentRemainingGapLength = 0;
829 auto compressPattern = [](
const QVector< qreal > &buffer ) -> QVector< qreal > {
830 QVector< qreal > result;
831 result.reserve( buffer.size() );
832 for (
auto it = buffer.begin(); it != buffer.end(); )
836 while ( dash == 0 && !result.empty() )
838 result.last() += gap;
840 if ( it == buffer.end() )
845 while ( gap == 0 && it != buffer.end() )
850 result << dash << gap;
855 double currentBufferLineLength = 0;
857 [pen, painter, &buffer, &bufferedPoints, &previousSegmentBuffer, ¤tRemainingDashLength, ¤tRemainingGapLength, ¤tBufferLineLength, &totalBufferLength, dashWidthDiv, &compressPattern](
860 if ( buffer.empty() || bufferedPoints.size() < 2 )
865 if ( currentRemainingDashLength )
868 buffer << currentRemainingDashLength << 0.0;
869 totalBufferLength += currentRemainingDashLength;
871 QVector< qreal > compressed = compressPattern( buffer );
872 if ( !currentRemainingDashLength )
875 totalBufferLength -= compressed.last();
876 compressed.last() = 0;
880 const double scaleFactor = currentBufferLineLength / totalBufferLength;
882 bool shouldFlushPreviousSegmentBuffer =
false;
884 if ( !previousSegmentBuffer.empty() )
888 if ( !firstDashSubstring.empty() )
894 compressed = compressed.mid( 2 );
895 shouldFlushPreviousSegmentBuffer = !compressed.empty();
898 if ( !previousSegmentBuffer.empty() && ( shouldFlushPreviousSegmentBuffer || !nextPoint ) )
900 QPen adjustedPen = pen;
901 adjustedPen.setStyle( Qt::SolidLine );
902 painter->setPen( adjustedPen );
904 path.addPolygon( previousSegmentBuffer );
905 painter->drawPath( path );
906 previousSegmentBuffer.clear();
909 double finalDash = 0;
916 if ( !compressed.empty() )
918 finalDash = compressed.at( compressed.size() - 2 );
919 const double finalGap = compressed.size() > 2 ? compressed.at( compressed.size() - 3 ) : 0;
921 const QPolygonF thisPoints = bufferedPoints;
927 previousSegmentBuffer << bufferedPoints;
931 currentBufferLineLength = 0;
932 currentRemainingDashLength = 0;
933 currentRemainingGapLength = 0;
934 totalBufferLength = 0;
937 if ( !bufferedPoints.empty() && ( !compressed.empty() || !nextPoint ) )
939 QPen adjustedPen = pen;
940 if ( !compressed.empty() )
943 compressed = compressed.mid( 0, 32 );
944 std::for_each( compressed.begin(), compressed.end(), [scaleFactor, dashWidthDiv]( qreal &element ) { element *= scaleFactor / dashWidthDiv; } );
945 adjustedPen.setDashPattern( compressed );
949 adjustedPen.setStyle( Qt::SolidLine );
952 painter->setPen( adjustedPen );
954 path.addPolygon( bufferedPoints );
955 painter->drawPath( path );
958 bufferedPoints.clear();
964 bufferedPoints << p2;
965 for ( ; ptIt != points.constEnd(); ++ptIt )
973 double remainingSegmentDistance = std::sqrt( std::pow( p2.x() - p1.x(), 2.0 ) + std::pow( p2.y() - p1.y(), 2.0 ) );
974 currentBufferLineLength += remainingSegmentDistance;
978 if ( currentRemainingDashLength > 0 )
981 if ( remainingSegmentDistance >= currentRemainingDashLength )
984 buffer << currentRemainingDashLength << 0.0;
985 totalBufferLength += currentRemainingDashLength;
986 remainingSegmentDistance -= currentRemainingDashLength;
988 currentRemainingDashLength = 0.0;
989 currentRemainingGapLength = sourcePattern.at( patternIndex );
990 if ( currentRemainingGapLength == 0.0 )
998 buffer << remainingSegmentDistance << 0.0;
999 totalBufferLength += remainingSegmentDistance;
1000 currentRemainingDashLength -= remainingSegmentDistance;
1004 if ( currentRemainingGapLength > 0 )
1007 if ( remainingSegmentDistance >= currentRemainingGapLength )
1010 buffer << 0.0 << currentRemainingGapLength;
1011 totalBufferLength += currentRemainingGapLength;
1012 remainingSegmentDistance -= currentRemainingGapLength;
1013 currentRemainingGapLength = 0.0;
1019 buffer << 0.0 << remainingSegmentDistance;
1020 totalBufferLength += remainingSegmentDistance;
1021 currentRemainingGapLength -= remainingSegmentDistance;
1026 if ( patternIndex + 1 >= sourcePattern.size() )
1031 const double nextPatternDashLength = sourcePattern.at( patternIndex );
1032 const double nextPatternGapLength = sourcePattern.at( patternIndex + 1 );
1033 if ( nextPatternDashLength + nextPatternGapLength <= remainingSegmentDistance )
1035 buffer << nextPatternDashLength << nextPatternGapLength;
1036 remainingSegmentDistance -= nextPatternDashLength + nextPatternGapLength;
1037 totalBufferLength += nextPatternDashLength + nextPatternGapLength;
1040 else if ( nextPatternDashLength <= remainingSegmentDistance )
1043 buffer << nextPatternDashLength << remainingSegmentDistance - nextPatternDashLength;
1044 totalBufferLength += remainingSegmentDistance;
1045 currentRemainingGapLength = nextPatternGapLength - ( remainingSegmentDistance - nextPatternDashLength );
1046 currentRemainingDashLength = 0;
1053 buffer << remainingSegmentDistance << 0.0;
1054 totalBufferLength += remainingSegmentDistance;
1055 currentRemainingGapLength = 0;
1056 currentRemainingDashLength = nextPatternDashLength - remainingSegmentDistance;
1061 bufferedPoints << p1;
1062 if ( mPatternCartographicTweakOnSharpCorners && ptIt + 1 != points.constEnd() )
1064 QPointF nextPoint = *( ptIt + 1 );
1070 flushBuffer( &nextPoint );
1071 bufferedPoints << p1;
1074 if ( patternIndex % 2 == 1 )
1078 currentRemainingDashLength = sourcePattern.at( patternIndex );
1085 flushBuffer(
nullptr );
1086 if ( !previousSegmentBuffer.empty() )
1088 QPen adjustedPen = pen;
1089 adjustedPen.setStyle( Qt::SolidLine );
1090 painter->setPen( adjustedPen );
1092 path.addPolygon( previousSegmentBuffer );
1093 painter->drawPath( path );
1094 previousSegmentBuffer.clear();
1100 if ( mDrawInsidePolygon )
1113 unit = mCustomDashPatternUnit;
1114 return mUseCustomDashPattern ? mCustomDashVector : QVector<qreal>();
1146 return mPenStyle != Qt::SolidLine || mUseCustomDashPattern;
1151 return mAlignDashPattern;
1161 return mPatternCartographicTweakOnSharpCorners;
1166 mPatternCartographicTweakOnSharpCorners =
enabled;
1187 : mRotateSymbols( rotateSymbol )
1223 if ( mRenderingFeature )
1227 mFeatureSymbolOpacity = context.
opacity();
1228 mCurrentFeatureIsSelected = useSelectedColor;
1246 QString placementString = exprVal.toString();
1259 auto evaluatedPlacement = PLACEMENT_MAP.lookup( placementString );
1260 if ( evaluatedPlacement )
1273 double averageOver = mAverageAngleLength;
1281 QgsSymbolLayerUtils::BlankSegments blankSegments;
1286 QList<QList<QgsSymbolLayerUtils::BlankSegments>> allBlankSegments = QgsSymbolLayerUtils::parseBlankSegments( strBlankSegments, context.
renderContext(),
blankSegmentsUnit(), error );
1288 if ( !error.isEmpty() )
1290 QgsDebugError( u
"Badly formatted blank segment '%1', skip it: %2"_s.arg( strBlankSegments ).arg( error ) );
1296 if ( iPart >= 0 &&
mRingIndex >= 0 && iPart < allBlankSegments.count() &&
mRingIndex < allBlankSegments.at( iPart ).count() )
1298 blankSegments = allBlankSegments.at( iPart ).at(
mRingIndex );
1303 QPolygonF points = pts;
1304 trimPoints( points, mTrimDistanceStart, mTrimDistanceEnd, mTrimDistanceStartUnit, mTrimDistanceEndUnit, mTrimDistanceStartMapUnitScale, mTrimDistanceEndMapUnitScale,
mDataDefinedProperties, context );
1309 renderPolylineInterval( points, context, averageOver, blankSegments );
1311 renderPolylineCentral( points, context, averageOver, blankSegments );
1317 mHasRenderedFirstPart = mRenderingFeature;
1331 QList<QPolygonF> mline =
::
1334 for (
int part = 0; part < mline.count(); ++part )
1336 const QPolygonF &points2 = mline[part];
1339 renderPolylineInterval( points2, context, averageOver, blankSegments );
1341 renderPolylineCentral( points2, context, averageOver, blankSegments );
1351 mHasRenderedFirstPart = mRenderingFeature;
1360 QgsSymbolLayerUtils::ExtraItems extraItems;
1365 extraItems = QgsSymbolLayerUtils::parseExtraItems( strExtraItems, error );
1367 if ( !error.isEmpty() )
1369 QgsDebugError( u
"Badly formatted extra items '%1', skip it: %2"_s.arg( strExtraItems ).arg( error ) );
1374 for ( std::pair<QPointF, double> &extraItem : extraItems )
1396 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper;
1412 mBlockExtraItemsRendering =
true;
1427 for (
int i = 0; i < rings->size(); ++i )
1438 mBlockExtraItemsRendering =
true;
1449 mBlockExtraItemsRendering =
false;
1465 mIntervalUnit = unit;
1466 mOffsetAlongLineUnit = unit;
1467 mAverageAngleLengthUnit = unit;
1491 map[u
"interval"_s] = QString::number(
interval() );
1492 map[u
"offset"_s] = QString::number(
mOffset );
1500 map[u
"average_angle_length"_s] = QString::number( mAverageAngleLength );
1503 map[u
"trim_distance_start"_s] = QString::number( mTrimDistanceStart );
1506 map[u
"trim_distance_end"_s] = QString::number( mTrimDistanceEnd );
1513 map[u
"ring_filter"_s] = QString::number(
static_cast< int >(
mRingFilter ) );
1514 map[u
"place_on_every_part"_s] = mPlaceOnEveryPart;
1520 return mPlaceOnEveryPart
1530 mRenderingFeature =
true;
1531 mHasRenderedFirstPart =
false;
1536 mRenderingFeature =
false;
1547 renderSymbol( mFinalVertex, &feature, context, -1, mCurrentFeatureIsSelected );
1548 mFeatureSymbolOpacity = 1;
1588 if (
properties.contains( u
"offset_unit"_s ) )
1592 if (
properties.contains( u
"interval_unit"_s ) )
1596 if (
properties.contains( u
"offset_along_line"_s ) )
1600 if (
properties.contains( u
"offset_along_line_unit"_s ) )
1604 if (
properties.contains( ( u
"offset_along_line_map_unit_scale"_s ) ) )
1609 if (
properties.contains( u
"offset_map_unit_scale"_s ) )
1613 if (
properties.contains( u
"interval_map_unit_scale"_s ) )
1618 if (
properties.contains( u
"average_angle_length"_s ) )
1622 if (
properties.contains( u
"average_angle_unit"_s ) )
1626 if (
properties.contains( ( u
"average_angle_map_unit_scale"_s ) ) )
1630 if (
properties.contains( u
"blank_segments_unit"_s ) )
1635 if (
properties.contains( u
"trim_distance_start"_s ) )
1637 if (
properties.contains( u
"trim_distance_start_unit"_s ) )
1639 if (
properties.contains( u
"trim_distance_start_map_unit_scale"_s ) )
1641 if (
properties.contains( u
"trim_distance_end"_s ) )
1643 if (
properties.contains( u
"trim_distance_end_unit"_s ) )
1645 if (
properties.contains( u
"trim_distance_end_map_unit_scale"_s ) )
1650 if (
properties[u
"placement"_s] ==
"vertex"_L1 )
1652 else if (
properties[u
"placement"_s] ==
"lastvertex"_L1 )
1654 else if (
properties[u
"placement"_s] ==
"firstvertex"_L1 )
1656 else if (
properties[u
"placement"_s] ==
"centralpoint"_L1 )
1658 else if (
properties[u
"placement"_s] ==
"curvepoint"_L1 )
1660 else if (
properties[u
"placement"_s] ==
"segmentcenter"_L1 )
1665 else if (
properties.contains( u
"placements"_s ) )
1671 if (
properties.contains( u
"ring_filter"_s ) )
1687class BlankSegmentsWalker
1690 BlankSegmentsWalker(
const QPolygonF &points,
const QgsSymbolLayerUtils::BlankSegments &blankSegments )
1691 : mBlankSegments( blankSegments )
1693 , mItBlankSegment( blankSegments.cbegin() )
1695 mDistances.reserve( mPoints.count() );
1699 bool insideBlankSegment(
double distance )
1701 while ( mItBlankSegment != mBlankSegments.cend() && distance > mItBlankSegment->second )
1706 return ( mItBlankSegment != mBlankSegments.cend() && distance >= mItBlankSegment->first );
1711 bool insideBlankSegment(
const QPointF &point,
int pointIndex )
1713 if ( pointIndex < 0 || pointIndex >= mPoints.count() )
1717 if ( pointIndex >= mDistances.count() )
1719 for (
int i =
static_cast<int>( mDistances.count() ); i < pointIndex + 1; i++ )
1721 const QPointF diff = mPoints.at( i ) - mPoints.at( i - 1 );
1722 const double distance = std::sqrt( std::pow( diff.x(), 2 ) + std::pow( diff.y(), 2 ) );
1723 const double totalDistance = distance + mDistances.last();
1724 mDistances << totalDistance;
1728 const QPointF diff = mPoints.at( pointIndex ) - point;
1729 const double distance = std::sqrt( std::pow( diff.x(), 2 ) + std::pow( diff.y(), 2 ) );
1730 const double currentDistance = mDistances.at( pointIndex ) + distance;
1732 return insideBlankSegment( currentDistance );
1736 const QgsSymbolLayerUtils::BlankSegments &mBlankSegments;
1737 const QPolygonF &mPoints;
1738 QList<double> mDistances;
1739 QgsSymbolLayerUtils::BlankSegments::const_iterator mItBlankSegment;
1746void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval(
const QPolygonF &points,
QgsSymbolRenderContext &context,
double averageOver,
const QgsSymbolLayerUtils::BlankSegments &blankSegments )
1748 if ( points.isEmpty() )
1752 double lengthLeft = 0;
1757 QgsExpressionContextScope *scope =
new QgsExpressionContextScope();
1784 constexpr double EPSILON = 1e-5;
1785 if ( painterUnitInterval <
EPSILON )
1788 double painterUnitOffsetAlongLine = 0;
1791 double totalLength = -1;
1812 if ( points.isClosed() )
1814 if ( painterUnitOffsetAlongLine > 0 )
1816 if ( totalLength < 0 )
1818 painterUnitOffsetAlongLine = std::fmod( painterUnitOffsetAlongLine, totalLength );
1820 else if ( painterUnitOffsetAlongLine < 0 )
1822 if ( totalLength < 0 )
1824 painterUnitOffsetAlongLine = totalLength - std::fmod( -painterUnitOffsetAlongLine, totalLength );
1836 lengthLeft = painterUnitInterval - painterUnitOffsetAlongLine;
1838 if ( averageOver > 0 && !
qgsDoubleNear( averageOver, 0.0 ) )
1840 QVector< QPointF > angleStartPoints;
1841 QVector< QPointF > symbolPoints;
1842 QVector< QPointF > angleEndPoints;
1851 QList<int> pointIndices;
1852 collectOffsetPoints( points, symbolPoints, painterUnitInterval, lengthLeft, blankSegments.isEmpty() ?
nullptr : &pointIndices );
1854 if ( symbolPoints.empty() )
1860 if ( symbolPoints.count() > 1 && symbolPoints.constFirst() == symbolPoints.constLast() )
1863 symbolPoints.pop_back();
1866 angleEndPoints.reserve( symbolPoints.size() );
1867 angleStartPoints.reserve( symbolPoints.size() );
1868 if ( averageOver <= painterUnitOffsetAlongLine )
1870 collectOffsetPoints( points, angleStartPoints, painterUnitInterval, lengthLeft + averageOver,
nullptr, 0, symbolPoints.size() );
1874 collectOffsetPoints( points, angleStartPoints, painterUnitInterval, 0,
nullptr, averageOver - painterUnitOffsetAlongLine, symbolPoints.size() );
1876 collectOffsetPoints( points, angleEndPoints, painterUnitInterval, lengthLeft - averageOver,
nullptr, 0, symbolPoints.size() );
1879 BlankSegmentsWalker blankSegmentsWalker( points, blankSegments );
1880 for (
int i = 0; i < symbolPoints.size(); ++i )
1885 const QPointF pt = symbolPoints[i];
1886 if ( i < pointIndices.count() && blankSegmentsWalker.insideBlankSegment( pt, pointIndices.at( i ) ) )
1890 const QPointF startPt = angleStartPoints[i];
1891 const QPointF endPt = angleEndPoints[i];
1893 Line l( startPt, endPt );
1908 QPointF lastPt = points[0];
1909 BlankSegmentsWalker itBlankSegment( points, blankSegments );
1910 for (
int i = 1; i < points.count(); ++i )
1915 const QPointF &pt = points[i];
1921 Line l( lastPt, pt );
1922 QPointF diff = l.diffForInterval( painterUnitInterval );
1927 double c = 1 - lengthLeft / painterUnitInterval;
1929 lengthLeft += l.length();
1938 while ( lengthLeft > painterUnitInterval )
1945 if ( !itBlankSegment.insideBlankSegment( lastPt, i - 1 ) )
1951 lengthLeft -= painterUnitInterval;
1959static double _averageAngle( QPointF prevPt, QPointF pt, QPointF nextPt )
1962 double a1 = Line( prevPt, pt ).angle();
1963 double a2 = Line( pt, nextPt ).angle();
1964 double unitX = std::cos( a1 ) + std::cos( a2 ), unitY = std::sin( a1 ) + std::sin( a2 );
1966 return std::atan2( unitY, unitX );
1969void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex(
1973 if ( points.isEmpty() )
1978 int i = -1, maxCount = 0;
1979 bool isRing =
false;
1981 QgsExpressionContextScope *scope =
new QgsExpressionContextScope();
1993 double totalLength = -1;
2013 if ( points.isClosed() )
2017 if ( totalLength < 0 )
2023 if ( totalLength < 0 )
2097 i = points.count() - 1;
2099 maxCount = points.count();
2107 maxCount = points.count() - 1;
2115 maxCount = points.count();
2116 if ( points.first() == points.last() )
2133 renderOffsetVertexAlongLine( points, i, distance, context,
placement, blankSegments );
2140 prevPoint = points.at( 0 );
2142 QPointF symbolPoint;
2143 BlankSegmentsWalker blankSegmentsWalker( points, blankSegments );
2144 for ( ; i < maxCount; ++i )
2155 QPointF currentPoint = points.at( i );
2156 symbolPoint = QPointF( 0.5 * ( currentPoint.x() + prevPoint.x() ), 0.5 * ( currentPoint.y() + prevPoint.y() ) );
2159 double angle = std::atan2( currentPoint.y() - prevPoint.y(), currentPoint.x() - prevPoint.x() );
2162 prevPoint = currentPoint;
2166 symbolPoint = points.at( i );
2170 double angle = markerAngle( points, isRing, i );
2175 mFinalVertex = symbolPoint;
2181double QgsTemplatedLineSymbolLayerBase::markerAngle(
const QPolygonF &points,
bool isRing,
int vertex )
2184 const QPointF &pt = points[vertex];
2186 if ( isRing || ( vertex > 0 && vertex < points.count() - 1 ) )
2188 int prevIndex = vertex - 1;
2189 int nextIndex = vertex + 1;
2191 if ( isRing && ( vertex == 0 || vertex == points.count() - 1 ) )
2193 prevIndex = points.count() - 2;
2197 QPointF prevPoint, nextPoint;
2198 while ( prevIndex >= 0 )
2200 prevPoint = points[prevIndex];
2201 if ( prevPoint != pt )
2208 while ( nextIndex < points.count() )
2210 nextPoint = points[nextIndex];
2211 if ( nextPoint != pt )
2218 if ( prevIndex >= 0 && nextIndex < points.count() )
2220 angle = _averageAngle( prevPoint, pt, nextPoint );
2227 while ( vertex < points.size() - 1 )
2229 const QPointF &nextPt = points[vertex + 1];
2232 angle = Line( pt, nextPt ).angle();
2241 while ( vertex >= 1 )
2243 const QPointF &prevPt = points[vertex - 1];
2246 angle = Line( prevPt, pt ).angle();
2256void QgsTemplatedLineSymbolLayerBase::renderOffsetVertexAlongLine(
2260 if ( points.isEmpty() )
2270 bool isRing =
false;
2271 if ( points.first() == points.last() )
2273 double angle = markerAngle( points, isRing, vertex );
2276 mFinalVertex = points[vertex];
2282 int pointIncrement = distance > 0 ? 1 : -1;
2283 QPointF previousPoint = points[vertex];
2284 int startPoint = distance > 0 ? std::min( vertex + 1,
static_cast<int>( points.count() ) - 1 ) : std::max( vertex - 1, 0 );
2285 int endPoint = distance > 0 ? points.count() - 1 : 0;
2286 double distanceLeft = std::fabs( distance );
2287 BlankSegmentsWalker blankSegmentsWalker( points, blankSegments );
2289 for (
int i = startPoint; pointIncrement > 0 ? i <= endPoint : i >= endPoint; i += pointIncrement )
2291 const QPointF &pt = points[i];
2293 if ( previousPoint == pt )
2297 Line l( previousPoint, pt );
2299 if ( distanceLeft < l.length() )
2302 QPointF markerPoint = previousPoint + l.diffForInterval( distanceLeft );
2308 mFinalVertex = markerPoint;
2314 distanceLeft -= l.length();
2321void QgsTemplatedLineSymbolLayerBase::collectOffsetPoints(
2322 const QVector<QPointF> &p, QVector<QPointF> &dest,
double intervalPainterUnits,
double initialOffset, QList<int> *pointIndices,
double initialLag,
int numberPointsRequired
2328 QVector< QPointF > points = p;
2329 const bool closedRing = points.first() == points.last();
2331 double lengthLeft = initialOffset;
2333 double initialLagLeft = initialLag > 0 ? -initialLag : 1;
2334 if ( initialLagLeft < 0 && closedRing )
2337 QPointF lastPt = points.constLast();
2338 QVector< QPointF > pseudoPoints;
2339 for (
int i = points.count() - 2; i > 0; --i )
2341 if ( initialLagLeft >= 0 )
2346 const QPointF &pt = points[i];
2351 Line l( lastPt, pt );
2352 initialLagLeft += l.length();
2357 std::reverse( pseudoPoints.begin(), pseudoPoints.end() );
2359 points = pseudoPoints;
2364 while ( initialLagLeft < 0 )
2366 dest << points.constFirst();
2367 initialLagLeft += intervalPainterUnits;
2370 if ( initialLag > 0 )
2372 lengthLeft += intervalPainterUnits - initialLagLeft;
2375 QPointF lastPt = points[0];
2376 for (
int i = 1; i < points.count(); ++i )
2378 const QPointF &pt = points[i];
2382 if ( closedRing && i == points.count() - 1 && numberPointsRequired > 0 && dest.size() < numberPointsRequired )
2391 Line l( lastPt, pt );
2392 QPointF diff = l.diffForInterval( intervalPainterUnits );
2396 double c = 1 - lengthLeft / intervalPainterUnits;
2398 lengthLeft += l.length();
2401 while ( lengthLeft > intervalPainterUnits ||
qgsDoubleNear( lengthLeft, intervalPainterUnits, 0.000000001 ) )
2405 lengthLeft -= intervalPainterUnits;
2408 *pointIndices << i - 1;
2411 if ( numberPointsRequired > 0 && dest.size() >= numberPointsRequired )
2416 if ( numberPointsRequired > 0 && dest.size() >= numberPointsRequired )
2420 if ( closedRing && i == points.count() - 1 && numberPointsRequired > 0 && dest.size() < numberPointsRequired )
2427 if ( !closedRing && numberPointsRequired > 0 && dest.size() < numberPointsRequired )
2430 while ( dest.size() < numberPointsRequired )
2431 dest << points.constLast();
2435void QgsTemplatedLineSymbolLayerBase::renderPolylineCentral(
const QPolygonF &points,
QgsSymbolRenderContext &context,
double averageAngleOver,
const QgsSymbolLayerUtils::BlankSegments &blankSegments )
2437 if ( !points.isEmpty() )
2441 QPolygonF::const_iterator it = points.constBegin();
2443 for ( ++it; it != points.constEnd(); ++it )
2445 length += std::sqrt( ( last.x() - it->x() ) * ( last.x() - it->x() ) + ( last.y() - it->y() ) * ( last.y() - it->y() ) );
2451 const double midPoint = length / 2;
2453 BlankSegmentsWalker blankSegmentsWalker( points, blankSegments );
2454 if ( blankSegmentsWalker.insideBlankSegment( midPoint ) )
2458 double thisSymbolAngle = 0;
2460 if ( averageAngleOver > 0 && !
qgsDoubleNear( averageAngleOver, 0.0 ) )
2462 QVector< QPointF > angleStartPoints;
2463 QVector< QPointF > symbolPoints;
2464 QVector< QPointF > angleEndPoints;
2468 collectOffsetPoints( points, symbolPoints, midPoint, midPoint,
nullptr, 0.0, 2 );
2469 collectOffsetPoints( points, angleStartPoints, midPoint, 0,
nullptr, averageAngleOver, 2 );
2470 collectOffsetPoints( points, angleEndPoints, midPoint, midPoint - averageAngleOver,
nullptr, 0, 2 );
2472 pt = symbolPoints.at( 1 );
2473 Line l( angleStartPoints.at( 1 ), angleEndPoints.at( 1 ) );
2474 thisSymbolAngle = l.angle();
2479 it = points.constBegin();
2481 qreal last_at = 0, next_at = 0;
2483 for ( ++it; it != points.constEnd(); ++it )
2486 next_at += std::sqrt( ( last.x() - it->x() ) * ( last.x() - it->x() ) + ( last.y() - it->y() ) * ( last.y() - it->y() ) );
2487 if ( next_at >= midPoint )
2494 Line l( last, next );
2495 qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
2496 pt = last + ( next - last ) * k;
2497 thisSymbolAngle = l.angle();
2548 if ( props.contains( u
"interval"_s ) )
2549 interval = props[u
"interval"_s].toDouble();
2550 if ( props.contains( u
"rotate"_s ) )
2551 rotate = ( props[u
"rotate"_s].toString() ==
"1"_L1 );
2553 auto x = std::make_unique< QgsMarkerLineSymbolLayer >( rotate,
interval );
2560 return u
"MarkerLine"_s;
2580 mMarker->setRenderHints( hints );
2602 toSld( doc, element, context );
2608 for (
int i = 0; i <
mMarker->symbolLayerCount(); i++ )
2610 QDomElement symbolizerElem = doc.createElement( u
"se:LineSymbolizer"_s );
2611 if ( !props.value( u
"uom"_s, QString() ).toString().isEmpty() )
2612 symbolizerElem.setAttribute( u
"uom"_s, props.value( u
"uom"_s, QString() ).toString() );
2613 element.appendChild( symbolizerElem );
2643 QDomElement strokeElem = doc.createElement( u
"se:Stroke"_s );
2644 symbolizerElem.appendChild( strokeElem );
2647 QDomElement graphicStrokeElem = doc.createElement( u
"se:GraphicStroke"_s );
2648 strokeElem.appendChild( graphicStrokeElem );
2653 markerLayer->writeSldMarker( doc, graphicStrokeElem, context );
2661 QgsDebugError( u
"Missing marker line symbol layer. Skip it."_s );
2664 if ( !gap.isEmpty() )
2666 QDomElement gapElem = doc.createElement( u
"se:Gap"_s );
2668 graphicStrokeElem.appendChild( gapElem );
2673 QDomElement perpOffsetElem = doc.createElement( u
"se:PerpendicularOffset"_s );
2676 symbolizerElem.appendChild( perpOffsetElem );
2686 QDomElement strokeElem = element.firstChildElement( u
"Stroke"_s );
2687 if ( strokeElem.isNull() )
2690 QDomElement graphicStrokeElem = strokeElem.firstChildElement( u
"GraphicStroke"_s );
2691 if ( graphicStrokeElem.isNull() )
2699 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
2701 if ( it.key() ==
"placement"_L1 )
2703 if ( it.value() ==
"points"_L1 )
2705 else if ( it.value() ==
"firstPoint"_L1 )
2707 else if ( it.value() ==
"lastPoint"_L1 )
2709 else if ( it.value() ==
"centralPoint"_L1 )
2712 else if ( it.value() ==
"rotateMarker"_L1 )
2718 std::unique_ptr< QgsMarkerSymbol > marker;
2724 layers.append( l.release() );
2725 marker = std::make_unique<QgsMarkerSymbol>( layers );
2732 QDomElement gapElem = graphicStrokeElem.firstChildElement( u
"Gap"_s );
2733 if ( !gapElem.isNull() )
2736 double d = gapElem.firstChild().firstChild().nodeValue().toDouble( &ok );
2742 QDomElement perpOffsetElem = graphicStrokeElem.firstChildElement( u
"PerpendicularOffset"_s );
2743 if ( !perpOffsetElem.isNull() )
2746 double d = perpOffsetElem.firstChild().nodeValue().toDouble( &ok );
2751 double scaleFactor = 1.0;
2752 const QString uom = element.attribute( u
"uom"_s );
2757 auto x = std::make_unique<QgsMarkerLineSymbolLayer>(
rotateMarker );
2758 x->setOutputUnit( sldUnitSize );
2761 x->setSubSymbol( marker.release() );
2775 mMarker->setDataDefinedSize( property );
2782 const double prevOpacity =
mMarker->opacity();
2785 mMarker->setOpacity( prevOpacity );
2790 mMarker->setLineAngle( angle );
2808 mMarker->renderPoint( point, feature, context, layer, selected );
2820 return mMarker->size( context );
2826 mMarker->setOutputUnit( unit );
2849 attr.unite(
mMarker->usedAttributes( context ) );
2885 if ( props.contains( u
"interval"_s ) )
2886 interval = props[u
"interval"_s].toDouble();
2887 if ( props.contains( u
"rotate"_s ) )
2888 rotate = ( props[u
"rotate"_s] ==
"1"_L1 );
2890 auto x = std::make_unique< QgsHashedLineSymbolLayer >( rotate,
interval );
2892 if ( props.contains( u
"hash_angle"_s ) )
2894 x->setHashAngle( props[u
"hash_angle"_s].toDouble() );
2897 if ( props.contains( u
"hash_length"_s ) )
2898 x->setHashLength( props[u
"hash_length"_s].toDouble() );
2900 if ( props.contains( u
"hash_length_unit"_s ) )
2903 if ( props.contains( u
"hash_length_map_unit_scale"_s ) )
2911 return u
"HashLine"_s;
2920 mHashSymbol->setRenderHints( hints );
2933 map[u
"hash_angle"_s] = QString::number( mHashAngle );
2935 map[u
"hash_length"_s] = QString::number( mHashLength );
2946 x->setHashAngle( mHashAngle );
2947 x->setHashLength( mHashLength );
2948 x->setHashLengthUnit( mHashLengthUnit );
2949 x->setHashLengthMapUnitScale( mHashLengthMapUnitScale );
2955 mHashSymbol->setColor(
color );
2961 return mHashSymbol ? mHashSymbol->color() :
mColor;
2966 return mHashSymbol.get();
2977 mHashSymbol.reset(
static_cast<QgsLineSymbol *
>( symbol ) );
2978 mColor = mHashSymbol->color();
2984 mHashLength =
width;
2999 return ( mHashSymbol->width( context ) / 2.0 )
3007 mHashSymbol->setOutputUnit( unit );
3014 attr.unite( mHashSymbol->usedAttributes( context ) );
3022 if ( mHashSymbol && mHashSymbol->hasDataDefinedProperties() )
3031 mHashSymbol->setDataDefinedWidth( property );
3051 || ( mHashSymbol && mHashSymbol->usesMapUnits() );
3056 mSymbolLineAngle = angle;
3061 return mSymbolAngle;
3066 mSymbolAngle = angle;
3071 double lineLength = mHashLength;
3077 const double w = context.
convertToPainterUnits( lineLength, mHashLengthUnit, mHashLengthMapUnitScale ) / 2.0;
3091 points << QPointF( start.
x(), start.
y() ) << QPointF( end.
x(), end.
y() );
3096 mHashSymbol->renderPolyline( points, feature, context, layer, selected );
3113 const double prevOpacity = mHashSymbol->opacity();
3114 mHashSymbol->setOpacity( mHashSymbol->opacity() * context.
opacity() );
3116 mHashSymbol->setOpacity( prevOpacity );
3135 QPolygonF offsetPoints;
3138 renderLine( points, context, patternThickness, patternLength, brush );
3147 renderLine( part, context, patternThickness, patternLength, brush );
3152void QgsAbstractBrushedLineSymbolLayer::renderLine(
const QPolygonF &points,
QgsSymbolRenderContext &context,
const double lineThickness,
const double patternLength,
const QBrush &sourceBrush )
3158 QBrush brush = sourceBrush;
3163 QPolygonF inputPoints;
3164 inputPoints.reserve( points.size() );
3166 double minX = std::numeric_limits< double >::max();
3167 double minY = std::numeric_limits< double >::max();
3168 double maxX = std::numeric_limits< double >::lowest();
3169 double maxY = std::numeric_limits< double >::lowest();
3171 for (
const QPointF &pt : std::as_const( points ) )
3178 minX = std::min( minX, pt.x() );
3179 minY = std::min( minY, pt.y() );
3180 maxX = std::max( maxX, pt.x() );
3181 maxY = std::max( maxY, pt.y() );
3184 if ( inputPoints.size() < 2 )
3188 constexpr int ANTIALIAS_ALLOWANCE_PIXELS = 10;
3190 constexpr double ANTIALIAS_OVERLAP_PIXELS = 0.5;
3193 const int imageWidth =
static_cast< int >( std::ceil( maxX - minX ) + lineThickness * 2 ) + ANTIALIAS_ALLOWANCE_PIXELS * 2;
3194 const int imageHeight =
static_cast< int >( std::ceil( maxY - minY ) + lineThickness * 2 ) + ANTIALIAS_ALLOWANCE_PIXELS * 2;
3196 const bool isClosedLine =
qgsDoubleNear( points.at( 0 ).x(), points.constLast().x(), 0.01 ) &&
qgsDoubleNear( points.at( 0 ).y(), points.constLast().y(), 0.01 );
3198 QImage temporaryImage( imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied );
3199 if ( temporaryImage.isNull() )
3208 temporaryImage.fill( Qt::transparent );
3231 QPainterPathStroker stroker;
3232 stroker.setWidth( lineThickness );
3233 stroker.setCapStyle( cap );
3234 stroker.setJoinStyle( join );
3237 path.addPolygon( inputPoints );
3238 const QPainterPath stroke = stroker.createStroke( path ).simplified();
3241 QPainter imagePainter;
3242 imagePainter.begin( &temporaryImage );
3244 imagePainter.translate( -minX + lineThickness + ANTIALIAS_ALLOWANCE_PIXELS, -minY + lineThickness + ANTIALIAS_ALLOWANCE_PIXELS );
3246 imagePainter.setClipPath( stroke, Qt::IntersectClip );
3247 imagePainter.setPen( Qt::NoPen );
3249 QPointF segmentStartPoint = inputPoints.at( 0 );
3252 double progressThroughImage = 0;
3254 QgsPoint prevSegmentPolygonEndLeft;
3255 QgsPoint prevSegmentPolygonEndRight;
3258 QgsPoint startLinePolygonLeft;
3259 QgsPoint startLinePolygonRight;
3261 for (
int i = 1; i < inputPoints.size(); ++i )
3266 const QPointF segmentEndPoint = inputPoints.at( i );
3267 const double segmentAngleDegrees = 180.0 / M_PI *
QgsGeometryUtilsBase::lineAngle( segmentStartPoint.x(), segmentStartPoint.y(), segmentEndPoint.x(), segmentEndPoint.y() ) - 90;
3270 QgsPoint thisSegmentPolygonEndLeft;
3271 QgsPoint thisSegmentPolygonEndRight;
3273 QgsPoint thisSegmentPolygonEndLeftForPainter;
3274 QgsPoint thisSegmentPolygonEndRightForPainter;
3282 const QgsPoint startPointLeft = QgsPoint( segmentStartPoint ).project( lineThickness / 2, segmentAngleDegrees );
3283 const QgsPoint endPointLeft = QgsPoint( segmentEndPoint ).project( lineThickness / 2, segmentAngleDegrees );
3284 const QgsPoint startPointRight = QgsPoint( segmentStartPoint ).project( -lineThickness / 2, segmentAngleDegrees );
3285 const QgsPoint endPointRight = QgsPoint( segmentEndPoint ).project( -lineThickness / 2, segmentAngleDegrees );
3289 const double lastSegmentAngleDegrees = 180.0
3291 *
QgsGeometryUtilsBase::lineAngle( points.at( points.size() - 2 ).x(), points.at( points.size() - 2 ).y(), segmentStartPoint.x(), segmentStartPoint.y() )
3295 const QgsPoint lastSegmentStartPointLeft = QgsPoint( points.at( points.size() - 2 ) ).project( lineThickness / 2, lastSegmentAngleDegrees );
3296 const QgsPoint lastSegmentEndPointLeft = QgsPoint( segmentStartPoint ).project( lineThickness / 2, lastSegmentAngleDegrees );
3297 const QgsPoint lastSegmentStartPointRight = QgsPoint( points.at( points.size() - 2 ) ).project( -lineThickness / 2, lastSegmentAngleDegrees );
3298 const QgsPoint lastSegmentEndPointRight = QgsPoint( segmentStartPoint ).project( -lineThickness / 2, lastSegmentAngleDegrees );
3303 QgsPoint intersectionPoint;
3304 bool isIntersection =
false;
3306 if ( !isIntersection )
3307 prevSegmentPolygonEndLeft = startPointLeft;
3308 isIntersection =
false;
3309 QgsGeometryUtils::segmentIntersection( lastSegmentStartPointRight, lastSegmentEndPointRight, startPointRight, endPointRight, prevSegmentPolygonEndRight, isIntersection, 1e-8,
true );
3310 if ( !isIntersection )
3311 prevSegmentPolygonEndRight = startPointRight;
3313 startLinePolygonLeft = prevSegmentPolygonEndLeft;
3314 startLinePolygonRight = prevSegmentPolygonEndRight;
3318 prevSegmentPolygonEndLeft = QgsPoint( segmentStartPoint ).
project( lineThickness / 2, segmentAngleDegrees );
3319 if ( cap != Qt::PenCapStyle::FlatCap )
3320 prevSegmentPolygonEndLeft = prevSegmentPolygonEndLeft.
project( lineThickness / 2, segmentAngleDegrees - 90 );
3321 prevSegmentPolygonEndRight = QgsPoint( segmentStartPoint ).
project( -lineThickness / 2, segmentAngleDegrees );
3322 if ( cap != Qt::PenCapStyle::FlatCap )
3323 prevSegmentPolygonEndRight = prevSegmentPolygonEndRight.
project( lineThickness / 2, segmentAngleDegrees - 90 );
3327 if ( i < inputPoints.size() - 1 )
3332 const QgsPoint startPointLeft = QgsPoint( segmentStartPoint ).
project( lineThickness / 2, segmentAngleDegrees );
3333 const QgsPoint endPointLeft = QgsPoint( segmentEndPoint ).
project( lineThickness / 2, segmentAngleDegrees );
3334 const QgsPoint startPointRight = QgsPoint( segmentStartPoint ).
project( -lineThickness / 2, segmentAngleDegrees );
3335 const QgsPoint endPointRight = QgsPoint( segmentEndPoint ).
project( -lineThickness / 2, segmentAngleDegrees );
3339 const double nextSegmentAngleDegrees = 180.0 / M_PI *
QgsGeometryUtilsBase::lineAngle( segmentEndPoint.x(), segmentEndPoint.y(), inputPoints.at( i + 1 ).x(), inputPoints.at( i + 1 ).y() ) - 90;
3342 const QgsPoint nextSegmentStartPointLeft = QgsPoint( segmentEndPoint ).
project( lineThickness / 2, nextSegmentAngleDegrees );
3343 const QgsPoint nextSegmentEndPointLeft = QgsPoint( inputPoints.at( i + 1 ) ).
project( lineThickness / 2, nextSegmentAngleDegrees );
3344 const QgsPoint nextSegmentStartPointRight = QgsPoint( segmentEndPoint ).
project( -lineThickness / 2, nextSegmentAngleDegrees );
3345 const QgsPoint nextSegmentEndPointRight = QgsPoint( inputPoints.at( i + 1 ) ).
project( -lineThickness / 2, nextSegmentAngleDegrees );
3350 QgsPoint intersectionPoint;
3351 bool isIntersection =
false;
3353 if ( !isIntersection )
3354 thisSegmentPolygonEndLeft = endPointLeft;
3355 isIntersection =
false;
3356 QgsGeometryUtils::segmentIntersection( startPointRight, endPointRight, nextSegmentStartPointRight, nextSegmentEndPointRight, thisSegmentPolygonEndRight, isIntersection, 1e-8,
true );
3357 if ( !isIntersection )
3358 thisSegmentPolygonEndRight = endPointRight;
3360 thisSegmentPolygonEndLeftForPainter = thisSegmentPolygonEndLeft.
project( ANTIALIAS_OVERLAP_PIXELS, segmentAngleDegrees + 90 );
3361 thisSegmentPolygonEndRightForPainter = thisSegmentPolygonEndRight.
project( ANTIALIAS_OVERLAP_PIXELS, segmentAngleDegrees + 90 );
3369 thisSegmentPolygonEndLeft = startLinePolygonLeft;
3370 thisSegmentPolygonEndRight = startLinePolygonRight;
3372 thisSegmentPolygonEndLeftForPainter = thisSegmentPolygonEndLeft.
project( ANTIALIAS_OVERLAP_PIXELS, segmentAngleDegrees + 90 );
3373 thisSegmentPolygonEndRightForPainter = thisSegmentPolygonEndRight.
project( ANTIALIAS_OVERLAP_PIXELS, segmentAngleDegrees + 90 );
3377 thisSegmentPolygonEndLeft = QgsPoint( segmentEndPoint ).
project( lineThickness / 2, segmentAngleDegrees );
3378 if ( cap != Qt::PenCapStyle::FlatCap )
3379 thisSegmentPolygonEndLeft = thisSegmentPolygonEndLeft.
project( lineThickness / 2, segmentAngleDegrees + 90 );
3380 thisSegmentPolygonEndRight = QgsPoint( segmentEndPoint ).
project( -lineThickness / 2, segmentAngleDegrees );
3381 if ( cap != Qt::PenCapStyle::FlatCap )
3382 thisSegmentPolygonEndRight = thisSegmentPolygonEndRight.
project( lineThickness / 2, segmentAngleDegrees + 90 );
3384 thisSegmentPolygonEndLeftForPainter = thisSegmentPolygonEndLeft;
3385 thisSegmentPolygonEndRightForPainter = thisSegmentPolygonEndRight;
3391 QTransform brushTransform;
3392 brushTransform.translate( segmentStartPoint.x(), segmentStartPoint.y() );
3393 brushTransform.rotate( -segmentAngleDegrees );
3394 if ( i == 1 && cap != Qt::PenCapStyle::FlatCap )
3398 brushTransform.translate( -( lineThickness / 2 ), 0 );
3400 brushTransform.translate( -progressThroughImage, -lineThickness / 2 );
3402 brush.setTransform( brushTransform );
3403 imagePainter.setBrush( brush );
3406 imagePainter.drawPolygon(
3408 << prevSegmentPolygonEndLeft.
toQPointF()
3409 << thisSegmentPolygonEndLeftForPainter.
toQPointF()
3410 << thisSegmentPolygonEndRightForPainter.
toQPointF()
3411 << prevSegmentPolygonEndRight.
toQPointF()
3412 << prevSegmentPolygonEndLeft.
toQPointF()
3416 imagePainter.setPen( QPen( QColor( 0, 255, 255 ), 2 ) );
3417 imagePainter.setBrush( Qt::NoBrush );
3418 imagePainter.drawPolygon( QPolygonF() << prevSegmentPolygonEndLeft.
toQPointF()
3419 << thisSegmentPolygonEndLeftForPainter.
toQPointF()
3420 << thisSegmentPolygonEndRightForPainter.
toQPointF()
3421 << prevSegmentPolygonEndRight.
toQPointF()
3422 << prevSegmentPolygonEndLeft.
toQPointF() );
3423 imagePainter.setPen( Qt::NoPen );
3428 progressThroughImage += sqrt( std::pow( segmentStartPoint.x() - segmentEndPoint.x(), 2 ) + std::pow( segmentStartPoint.y() - segmentEndPoint.y(), 2 ) )
3429 + ( i == 1 && cap != Qt::PenCapStyle::FlatCap ? lineThickness / 2 : 0 );
3430 progressThroughImage = fmod( progressThroughImage, patternLength );
3433 segmentStartPoint = segmentEndPoint;
3434 prevSegmentPolygonEndLeft = thisSegmentPolygonEndLeft;
3435 prevSegmentPolygonEndRight = thisSegmentPolygonEndRight;
3443 p->drawImage( QPointF( minX - lineThickness - ANTIALIAS_ALLOWANCE_PIXELS, minY - lineThickness - ANTIALIAS_ALLOWANCE_PIXELS ), temporaryImage );
3459 auto res = std::make_unique<QgsRasterLineSymbolLayer>();
3461 if (
properties.contains( u
"line_width"_s ) )
3463 res->setWidth(
properties[u
"line_width"_s].toDouble() );
3465 if (
properties.contains( u
"line_width_unit"_s ) )
3469 if (
properties.contains( u
"width_map_unit_scale"_s ) )
3475 res->setPath(
properties[u
"imageFile"_s].toString() );
3479 res->setOffset(
properties[u
"offset"_s].toDouble() );
3481 if (
properties.contains( u
"offset_unit"_s ) )
3485 if (
properties.contains( u
"offset_map_unit_scale"_s ) )
3497 res->setOpacity(
properties[u
"alpha"_s].toDouble() );
3507 map[u
"imageFile"_s] =
mPath;
3509 map[u
"line_width"_s] = QString::number(
mWidth );
3516 map[u
"offset"_s] = QString::number(
mOffset );
3520 map[u
"alpha"_s] = QString::number(
mOpacity );
3527 auto res = std::make_unique< QgsRasterLineSymbolLayer >(
mPath );
3538 return res.release();
3543 const QVariantMap::iterator it =
properties.find( u
"imageFile"_s );
3544 if ( it !=
properties.end() && it.value().userType() == QMetaType::Type::QString )
3560 return u
"RasterLine"_s;
3575 bool cached =
false;
3578 QSize(
static_cast< int >( std::round( originalSize.width() / originalSize.height() * std::max( 1.0, scaledHeight ) ) ),
static_cast< int >( std::ceil( scaledHeight ) ) ),
3606 double strokeWidth =
mWidth;
3623 bool cached =
false;
3626 QSize(
static_cast< int >( std::round( originalSize.width() / originalSize.height() * std::max( 1.0, scaledHeight ) ) ),
static_cast< int >( std::ceil( scaledHeight ) ) ),
3635 if ( useSelectedColor )
3640 const QBrush brush( sourceImage );
3708 auto res = std::make_unique<QgsLineburstSymbolLayer>();
3710 if (
properties.contains( u
"line_width"_s ) )
3712 res->setWidth(
properties[u
"line_width"_s].toDouble() );
3714 if (
properties.contains( u
"line_width_unit"_s ) )
3718 if (
properties.contains( u
"width_map_unit_scale"_s ) )
3725 res->setOffset(
properties[u
"offset"_s].toDouble() );
3727 if (
properties.contains( u
"offset_unit"_s ) )
3731 if (
properties.contains( u
"offset_map_unit_scale"_s ) )
3741 if (
properties.contains( u
"color_type"_s ) )
3748 if (
properties.contains( u
"gradient_color2"_s ) )
3770 map[u
"line_width"_s] = QString::number(
mWidth );
3777 map[u
"offset"_s] = QString::number(
mOffset );
3794 auto res = std::make_unique< QgsLineburstSymbolLayer >();
3809 return res.release();
3814 return u
"Lineburst"_s;
3833 double strokeWidth =
mWidth;
3849 if ( useSelectedColor )
3853 color1.setAlphaF( context.
opacity() * color1.alphaF() );
3864 QGradient gradient = QLinearGradient( QPointF( 0, 0 ), QPointF( 0, scaledWidth ) );
3877 gradient.setColorAt( 0.0, color1 );
3878 gradient.setColorAt( 1.0,
color2 );
3880 const QBrush brush( gradient );
3957 if ( props.contains( u
"line_width"_s ) )
3959 width = props[u
"line_width"_s].toDouble();
3961 else if ( props.contains( u
"outline_width"_s ) )
3963 width = props[u
"outline_width"_s].toDouble();
3965 else if ( props.contains( u
"width"_s ) )
3967 width = props[u
"width"_s].toDouble();
3972 if ( props.contains( u
"line_width_unit"_s ) )
3976 else if ( props.contains( u
"outline_width_unit"_s ) )
3980 else if ( props.contains( u
"width_unit"_s ) )
3985 if ( props.contains( u
"width_map_unit_scale"_s ) )
3987 if ( props.contains( u
"offset"_s ) )
3988 l->setOffset( props[u
"offset"_s].toDouble() );
3989 if ( props.contains( u
"offset_unit"_s ) )
3991 if ( props.contains( u
"offset_map_unit_scale"_s ) )
3993 if ( props.contains( u
"joinstyle"_s ) )
3995 if ( props.contains( u
"capstyle"_s ) )
3998 l->restoreOldDataDefinedProperties( props );
4005 return u
"FilledLine"_s;
4054 Qt::PenJoinStyle join = mPenJoinStyle;
4063 Qt::PenCapStyle cap = mPenCapStyle;
4079 const double prevOpacity = mFill->opacity();
4080 mFill->setOpacity( mFill->opacity() * context.
opacity() );
4087 if ( points.count() >= 2 )
4106 auto inputPoly = std::make_unique< QgsPolygon >(
static_cast< QgsLineString *
>( ls.release() ) );
4112 if ( !parts.empty() )
4139 std::unique_ptr< QgsAbstractGeometry > bufferedGeom =
QgsGeos::fromGeos( buffered.get() );
4141 for (
const QList< QPolygonF > &polygon : parts )
4143 QVector< QPolygonF > rings;
4144 for (
int i = 1; i < polygon.size(); ++i )
4145 rings << polygon.at( i );
4146 mFill->renderPolygon( polygon.value( 0 ), &rings, context.
feature(), context.
renderContext(), -1, useSelectedColor );
4154 mFill->setOpacity( prevOpacity );
4161 map[u
"line_width"_s] = QString::number(
mWidth );
4166 map[u
"offset"_s] = QString::number(
mOffset );
4180 res->setSubSymbol( mFill->clone() );
4181 return res.release();
4216 attr.unite( mFill->usedAttributes( context ) );
4224 if ( mFill && mFill->hasDataDefinedProperties() )
4233 mFill->setColor(
c );
4238 return mFill ? mFill->color() :
mColor;
4247 || ( mFill && mFill->usesMapUnits() );
4254 mFill->setMapUnitScale( scale );
4261 return mFill->mapUnitScale();
4270 mFill->setOutputUnit( unit );
4277 return mFill->outputUnit();
MarkerLinePlacement
Defines how/where the symbols should be placed on a line.
@ CurvePoint
Place symbols at every virtual curve point in the line (used when rendering curved geometry types onl...
@ InnerVertices
Inner vertices (i.e. all vertices except the first and last vertex).
@ LastVertex
Place symbols on the last vertex in the line.
@ CentralPoint
Place symbols at the mid point of the line.
@ SegmentCenter
Place symbols at the center of every line segment.
@ Vertex
Place symbols on every vertex in the line.
@ Interval
Place symbols at regular intervals.
@ FirstVertex
Place symbols on the first vertex in the line.
@ DynamicRotation
Rotation of symbol may be changed during rendering and symbol should not be cached.
@ IsSymbolLayerSubSymbol
Symbol is being rendered as a sub-symbol of a QgsSymbolLayer.
@ AntialiasingSimplification
The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'.
GradientColorSource
Gradient color sources.
@ ColorRamp
Gradient color ramp.
@ CanCalculateMaskGeometryPerFeature
If present, indicates that mask geometry can safely be calculated per feature for the symbol layer....
@ Curve
An intermediate point on a segment defining the curvature of the segment.
@ Segment
The actual start or end point of a segment.
QFlags< SymbolLayerFlag > SymbolLayerFlags
Symbol layer flags.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Miter
Use mitered joins.
RenderUnit
Rendering size units.
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size).
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ Unknown
Mixed or unknown units.
@ MetersInMapUnits
Meters value as Map units.
@ Flat
Flat cap (in line with start/end of line).
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
@ RenderLayerTree
The render is for a layer tree display where map based properties are not available and where avoidan...
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
QFlags< SymbolRenderHint > SymbolRenderHints
Symbol render hints.
@ MultiLineString
MultiLineString.
QFlags< MarkerLinePlacement > MarkerLinePlacements
Base class for line symbol layer types which draws line sections using a QBrush.
Qt::PenCapStyle mPenCapStyle
Qt::PenJoinStyle mPenJoinStyle
void renderPolylineUsingBrush(const QPolygonF &points, QgsSymbolRenderContext &context, const QBrush &brush, double patternThickness, double patternLength)
Renders a polyline of points using the specified brush.
static bool isGeneralizableByDeviceBoundingBox(const QgsRectangle &envelope, float mapToPixelTol=1.0f)
Returns whether the device-envelope can be replaced by its BBOX when is applied the specified toleran...
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
Abstract base class for color ramps.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
static std::unique_ptr< QgsColorRamp > create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
Curve polygon geometry type.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const
Tells whether the operation has been canceled already.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QVariantMap 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.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
void setOutputUnit(Qgis::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.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsFilledLineSymbolLayer, using the settings serialized in the properties map (correspo...
~QgsFilledLineSymbolLayer() override
QgsFilledLineSymbolLayer(double width=DEFAULT_SIMPLELINE_WIDTH, QgsFillSymbol *fillSymbol=nullptr)
Constructor for QgsFilledLineSymbolLayer.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setColor(const QColor &c) override
Sets the "representative" color for the symbol layer.
QColor color() const override
Returns the "representative" color of the symbol layer.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
QgsFilledLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsMapUnitScale mapUnitScale() const override
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
static double lineAngle(double x1, double y1, double x2, double y2)
Calculates the direction of line joining two points in radians, clockwise from the north direction.
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
A geometry is the spatial representation of a feature.
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0, bool avoidDuplicates=true) const
Attempts to coerce this geometry into the specified destination type.
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlags())
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
static geos::unique_ptr offsetCurve(const GEOSGeometry *geometry, double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr)
Directly calculates the offset curve for a GEOS geometry object and returns a GEOS geometry result.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const override
Buffers the geometry.
static std::unique_ptr< QgsAbstractGeometry > fromGeos(const GEOSGeometry *geos)
Create a geometry from a GEOSGeometry.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
static std::unique_ptr< QgsColorRamp > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsColorRamp from a map of properties.
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
void addStopsToGradient(QGradient *gradient, double opacity=1) const
Copy color ramp stops to a QGradient.
double hashAngle() const
Returns the angle to use when drawing the hashed lines sections, in degrees clockwise.
QgsHashedLineSymbolLayer(bool rotateSymbol=true, double interval=3)
Constructor for QgsHashedLineSymbolLayer.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void setWidth(double width) override
Sets the width of the line symbol layer.
double symbolAngle() const override
Returns the symbol's current angle, in degrees clockwise.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
double width() const override
Returns the estimated width for the line symbol layer.
void setDataDefinedProperty(QgsSymbolLayer::Property key, const QgsProperty &property) override
Sets a data defined property for the layer.
void setSymbolLineAngle(double angle) override
Sets the line angle modification for the symbol's angle.
void setSymbolAngle(double angle) override
Sets the symbol's angle, in degrees clockwise.
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
QgsHashedLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
~QgsHashedLineSymbolLayer() override
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QColor color() const override
Returns the "representative" color of the symbol layer.
void renderSymbol(const QPointF &point, const QgsFeature *feature, QgsRenderContext &context, int layer=-1, bool selected=false) override
Renders the templated symbol at the specified point, using the given render context.
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsHashedLineSymbolLayer, using the settings serialized in the properties map (correspo...
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void setOutputUnit(Qgis::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.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void setHashAngle(double angle)
Sets the angle to use when drawing the hashed lines sections, in degrees clockwise.
QSize originalSize(const QString &path, bool blocking=false) const
Returns the original size (in pixels) of the image at the specified path.
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false, double targetDpi=96, int frameNumber=-1, bool *isMissing=nullptr)
Returns the specified path rendered as an image.
static void overlayColor(QImage &image, const QColor &color)
Overlays a color onto an image.
Line string geometry type, with support for z-dimension and m-values.
static std::unique_ptr< QgsLineString > fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
Qgis::RenderUnit mOffsetUnit
RenderRingFilter
Options for filtering rings when the line symbol layer is being used to render a polygon's rings.
@ ExteriorRingOnly
Render the exterior ring only.
@ InteriorRingsOnly
Render the interior rings only.
@ AllRings
Render both exterior and interior rings.
QgsMapUnitScale mWidthMapUnitScale
QgsLineSymbolLayer(const QgsLineSymbolLayer &other)=delete
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
Qgis::RenderUnit mWidthUnit
void setOffset(double offset)
Sets the line's offset.
RenderRingFilter mRingFilter
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the line's offset.
void setWidthUnit(Qgis::RenderUnit unit)
Sets the units for the line's width.
virtual double width() const
Returns the estimated width for the line symbol layer.
QgsMapUnitScale mOffsetMapUnitScale
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the line's offset.
QgsMapUnitScale mapUnitScale() const override
void setRingFilter(QgsLineSymbolLayer::RenderRingFilter filter)
Sets the line symbol layer's ring filter, which controls which rings are rendered when the line symbo...
void setMapUnitScale(const QgsMapUnitScale &scale) override
double offset() const
Returns the line's offset.
Qgis::RenderUnit offsetUnit() const
Returns the units for the line's offset.
Qgis::RenderUnit widthUnit() const
Returns the units for the line's width.
A line symbol type, for rendering LineString and MultiLineString geometries.
std::unique_ptr< QgsColorRamp > mGradientRamp
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used for the gradient line.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsLineburstSymbolLayer, using the settings serialized in the properties map (correspon...
QColor color2() const
Returns the color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoC...
Qgis::GradientColorSource mGradientColorType
QString layerType() const override
Returns a string that represents this layer type.
~QgsLineburstSymbolLayer() override
QgsLineburstSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsMapUnitScale mapUnitScale() const override
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
Qgis::SymbolLayerFlags flags() const override
Returns flags which control the symbol layer's behavior.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QgsLineburstSymbolLayer(const QColor &color=DEFAULT_SIMPLELINE_COLOR, const QColor &color2=Qt::white)
Constructor for QgsLineburstSymbolLayer, with the specified start and end gradient colors.
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsColorRamp * colorRamp()
Returns the color ramp used for the gradient line.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
Perform transforms between map coordinates and device coordinates.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
Q_DECL_DEPRECATED bool rotateMarker() const
Shall the marker be rotated.
std::unique_ptr< QgsMarkerSymbol > mMarker
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM element.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
QgsMarkerLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsMarkerLineSymbolLayer, using the settings serialized in the properties map (correspo...
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void setDataDefinedProperty(QgsSymbolLayer::Property key, const QgsProperty &property) override
Sets a data defined property for the layer.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
double symbolAngle() const override
Returns the symbol's current angle, in degrees clockwise.
double width() const override
Returns the estimated width for the line symbol layer.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
QgsMarkerLineSymbolLayer(bool rotateMarker=DEFAULT_MARKERLINE_ROTATE, double interval=DEFAULT_MARKERLINE_INTERVAL)
Constructor for QgsMarkerLineSymbolLayer.
void setWidth(double width) override
Sets the width of the line symbol layer.
QColor color() const override
Returns the "representative" color of the symbol layer.
void setSymbolLineAngle(double angle) override
Sets the line angle modification for the symbol's angle.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
~QgsMarkerLineSymbolLayer() override
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
QString layerType() const override
Returns a string that represents this layer type.
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
void setSymbolAngle(double angle) override
Sets the symbol's angle, in degrees clockwise.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
void renderSymbol(const QPointF &point, const QgsFeature *feature, QgsRenderContext &context, int layer=-1, bool selected=false) override
Renders the templated symbol at the specified point, using the given render context.
Abstract base class for marker symbol layers.
A marker symbol type, for rendering Point and MultiPoint geometries.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Resolves relative paths into absolute paths and vice versa.
QgsPointXY project(double distance, double bearing) const
Returns a new point which corresponds to this point projected by a specified distance in a specified ...
QPointF toQPointF() const
Returns the point as a QPointF.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which corresponds to this point projected by a specified distance with specified ...
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
A store for object properties.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsRasterLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
double opacity() const
Returns the line opacity.
QString path() const
Returns the raster image path.
void setPath(const QString &path)
Set the raster image path.
QString layerType() const override
Returns a string that represents this layer type.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsRasterLineSymbolLayer, using the settings serialized in the properties map (correspo...
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
static void resolvePaths(QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving)
Turns relative paths in properties map to absolute when reading and vice versa when writing.
QgsRasterLineSymbolLayer(const QString &path=QString())
Constructor for QgsRasterLineSymbolLayer, with the specified raster image path.
Qgis::SymbolLayerFlags flags() const override
Returns flags which control the symbol layer's behavior.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
QColor color() const override
Returns the "representative" color of the symbol layer.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
~QgsRasterLineSymbolLayer() override
void setMapUnitScale(const QgsMapUnitScale &scale) override
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsMapUnitScale mapUnitScale() const override
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Contains information about the context of a rendering operation.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
QgsVectorSimplifyMethod & vectorSimplifyMethod()
Returns the simplification settings to use when rendering vector layers.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsExpressionContext & expressionContext()
Gets the expression context.
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QColor selectionColor() const
Returns the color to use when rendering selected features.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
Scoped object for saving and restoring a QPainter object's state.
@ NoSave
Do not save the current painter state.
void save()
Performs a manual save on the painter state, pushing another saved state to the painter.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
void setDrawInsidePolygon(bool drawInsidePolygon)
Sets whether the line should only be drawn inside polygons, and any portion of the line which falls o...
bool tweakDashPatternOnCorners() const
Returns true if dash patterns tweaks should be applied on sharp corners, to ensure that a double-leng...
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
Qgis::SymbolLayerFlags flags() const override
Returns flags which control the symbol layer's behavior.
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
QgsMapUnitScale mapUnitScale() const override
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QVector< qreal > customDashVector() const
Returns the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ...
Qt::PenJoinStyle penJoinStyle() const
Returns the pen join style used to render the line (e.g.
void renderPolygonStroke(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the outline of polygon, using the given render context.
double dxfWidth(QgsSymbolRenderContext &context) const override
Gets line width.
double dxfOffset(QgsSymbolRenderContext &context) const override
Gets offset.
Qt::PenStyle dxfPenStyle() const override
Gets pen style.
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for lengths used in the custom dash pattern.
void setTrimDistanceEndMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the trim distance for the end of the line.
double estimateMaxBleed(const QgsRenderContext &context) const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape when ...
void setTrimDistanceEnd(double distance)
Sets the trim distance for the end of the line, which dictates a length from the end of the line at w...
QgsSimpleLineSymbolLayer(const QColor &color=DEFAULT_SIMPLELINE_COLOR, double width=DEFAULT_SIMPLELINE_WIDTH, Qt::PenStyle penStyle=DEFAULT_SIMPLELINE_PENSTYLE)
Constructor for QgsSimpleLineSymbolLayer.
~QgsSimpleLineSymbolLayer() override
void setUseCustomDashPattern(bool b)
Sets whether the line uses a custom dash pattern.
void setTweakDashPatternOnCorners(bool enabled)
Sets whether dash patterns tweaks should be applied on sharp corners, to ensure that a double-length ...
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
void setCustomDashVector(const QVector< qreal > &vector)
Sets the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ren...
void setDashPatternOffset(double offset)
Sets the dash pattern offset, which dictates how far along the dash pattern the pattern should start ...
QColor dxfColor(QgsSymbolRenderContext &context) const override
Gets color.
QString layerType() const override
Returns a string that represents this layer type.
void setDashPatternOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the dash pattern offset.
QgsSimpleLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Qt::PenStyle penStyle() const
Returns the pen style used to render the line (e.g.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
void setAlignDashPattern(bool enabled)
Sets whether dash patterns should be aligned to the start and end of lines, by applying subtle tweaks...
void setTrimDistanceStartMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the trim distance for the start of the line.
QVector< qreal > dxfCustomDashPattern(Qgis::RenderUnit &unit) const override
Gets dash pattern.
static std::unique_ptr< QgsSymbolLayer > create(const QVariantMap &properties=QVariantMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
Qt::PenCapStyle penCapStyle() const
Returns the pen cap style used to render the line (e.g.
void setTrimDistanceEndUnit(Qgis::RenderUnit unit)
Sets the unit for the trim distance for the end of the line.
void setDashPatternOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the dash pattern offset.
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
static std::unique_ptr< QgsSymbolLayer > createFromSld(QDomElement &element)
Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM element.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setTrimDistanceStart(double distance)
Sets the trim distance for the start of the line, which dictates a length from the start of the line ...
QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const override
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void setTrimDistanceStartUnit(Qgis::RenderUnit unit)
Sets the unit for the trim distance for the start of the line.
bool alignDashPattern() const
Returns true if dash patterns should be aligned to the start and end of lines, by applying subtle twe...
void setCustomDashPatternUnit(Qgis::RenderUnit unit)
Sets the unit for lengths used in the custom dash pattern.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
QVariantMap extraProperties() const
Returns the open ended set of properties that can drive/inform the SLD encoding.
static QString encodePenStyle(Qt::PenStyle style)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static Q_DECL_DEPRECATED bool createExpressionElement(QDomDocument &doc, QDomElement &element, const QString &function)
Creates a OGC Expression element based on the provided function expression.
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static double rescaleUom(double size, Qgis::RenderUnit unit, const QVariantMap &props)
Rescales the given size based on the uomScale found in the props, if any is found,...
static std::unique_ptr< QgsSymbolLayer > createMarkerLayerFromSld(QDomElement &element)
Creates a new marker layer from a SLD DOM element.
static bool isSharpCorner(QPointF p1, QPointF p2, QPointF p3)
Returns true if the angle formed by the line p1 - p2 - p3 forms a "sharp" corner.
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 Qt::PenCapStyle decodePenCapStyle(const QString &str)
static QList< QList< QPolygonF > > toQPolygonF(const QgsGeometry &geometry, Qgis::SymbolType type)
Converts a geometry to a set of QPolygonF objects representing how the geometry should be drawn for a...
static QVector< qreal > decodeRealVector(const QString &s)
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=nullptr, Qt::PenCapStyle *penCapStyle=nullptr, QVector< qreal > *customDashPattern=nullptr, double *dashOffset=nullptr)
static QString encodePenCapStyle(Qt::PenCapStyle style)
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
static void appendPolyline(QPolygonF &target, const QPolygonF &line)
Appends a polyline line to an existing target polyline.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodeColor(const QColor &color)
Lossy-encodes a color to a string.
static Qgis::EndCapStyle penCapStyleToEndCapStyle(Qt::PenCapStyle style)
Converts a Qt pen cap style to a QGIS end cap style.
static double polylineLength(const QPolygonF &polyline)
Returns the total length of a polyline.
static Qgis::RenderUnit decodeSldUom(const QString &str, double *scaleFactor=nullptr)
Decodes a SLD unit of measure string to a render unit.
static Q_DECL_DEPRECATED void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
Creates an SLD geometry element.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
static Qt::PenStyle decodePenStyle(const QString &str)
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
static QgsStringMap getVendorOptionList(QDomElement &element)
static Qgis::JoinStyle penJoinStyleToJoinStyle(Qt::PenJoinStyle style)
Converts a Qt pen joinstyle to a QGIS join style.
static QPolygonF polylineSubstring(const QPolygonF &polyline, double startOffset, double endOffset)
Returns the substring of a polyline which starts at startOffset from the beginning of the line and en...
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, const QColor &color, QgsSldExportContext &context, double width=-1, const Qt::PenJoinStyle *penJoinStyle=nullptr, const Qt::PenCapStyle *penCapStyle=nullptr, const QVector< qreal > *customDashPattern=nullptr, double dashOffset=0.0)
static QString encodeRealVector(const QVector< qreal > &v)
void copyCommonProperties(QgsSymbolLayer *destLayer) const
Copies all common base class properties from this layer to another symbol layer.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
bool shouldRenderUsingSelectionColor(const QgsSymbolRenderContext &context) const
Returns true if the symbol layer should be rendered using the selection color from the render context...
static const bool SELECTION_IS_OPAQUE
Whether styles for selected features ignore symbol alpha.
bool installMasks(QgsRenderContext &context, bool recursive, const QRectF &rect=QRectF())
When rendering, install masks on context painter.
void removeMasks(QgsRenderContext &context, bool recursive)
When rendering, remove previously installed masks from context painter if recursive is true masks are...
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Property
Data definable properties.
@ SecondaryColor
Secondary color (eg for gradient fills).
@ File
Filename, eg for svg files.
@ BlankSegments
String list of distance to define blank segments along line for templated line symbol layers.
@ DashPatternOffset
Dash pattern offset,.
@ OffsetAlongLine
Offset along line.
@ CustomDash
Custom dash pattern.
@ StrokeStyle
Stroke style (eg solid, dashed).
@ StrokeColor
Stroke color.
@ TrimStart
Trim distance from start of line.
@ CapStyle
Line cap style.
@ Placement
Line marker placement.
@ LineAngle
Line angle, or angle of hash lines for hash line symbols.
@ JoinStyle
Line join style.
@ AverageAngleLength
Length to average symbol angles over.
@ Interval
Line marker interval.
@ StrokeWidth
Stroke width.
@ LineDistance
Distance between lines, or length of lines for hash line symbols.
@ ExtraItems
String list of tuple (x, y and rotation angle) to define extra items to be rendered for templated lin...
@ TrimEnd
Trim distance from end of line.
void restoreOldDataDefinedProperties(const QVariantMap &stringMap)
Restores older data defined properties from string map.
bool enabled() const
Returns true if symbol layer is enabled and will be drawn.
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
virtual QColor color() const
Returns the "representative" color of the symbol layer.
virtual Qgis::SymbolLayerFlags flags() const
Returns flags which control the symbol layer's behavior.
QgsPropertyCollection mDataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
QgsSymbolLayer(const QgsSymbolLayer &other)
Encapsulates the context in which a symbol is being rendered.
const QgsFeature * feature() const
Returns the current feature being rendered.
Qgis::GeometryType originalGeometryType() const
Returns the geometry type for the original feature geometry being rendered.
QgsFields fields() const
Fields of the layer.
int geometryPartNum() const
Part number of current geometry.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
qreal opacity() const
Returns the opacity for the symbol.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
qreal opacity() const
Returns the opacity for the symbol.
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
bool rotateSymbols() const
Returns true if the repeating symbols be rotated to match their line segment orientation.
void setTrimDistanceStartMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the trim distance for the start of the line.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
static void setCommonProperties(QgsTemplatedLineSymbolLayerBase *destLayer, const QVariantMap &properties)
Sets all common symbol properties in the destLayer, using the settings serialized in the properties m...
void setMapUnitScale(const QgsMapUnitScale &scale) final
void renderPolygonStroke(const QPolygonF &points, const QVector< QPolygonF > *rings, QgsSymbolRenderContext &context) final
Renders the line symbol layer along the outline of polygon, using the given render context.
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
void renderPolyline(const QPolygonF &pts, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void setIntervalUnit(Qgis::RenderUnit unit)
Sets the units for the interval between symbols.
void setAverageAngleUnit(Qgis::RenderUnit unit)
Sets the unit for the length over which the line's direction is averaged when calculating individual ...
double interval() const
Returns the interval between individual symbols.
void setOffsetAlongLineUnit(Qgis::RenderUnit unit)
Sets the unit used for calculating the offset along line for symbols.
void setAverageAngleMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the length over which the line's direction is averaged when calculating i...
const QgsMapUnitScale & intervalMapUnitScale() const
Returns the map unit scale for the interval between symbols.
double offsetAlongLine() const
Returns the offset along the line for the symbol placement.
~QgsTemplatedLineSymbolLayerBase() override
void copyTemplateSymbolProperties(QgsTemplatedLineSymbolLayerBase *destLayer) const
Copies all common properties of this layer to another templated symbol layer destLayer.
Qgis::MarkerLinePlacements placements() const
Returns the placement of the symbols.
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the symbol placement.
void setTrimDistanceEndMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the trim distance for the end of the line.
Qgis::RenderUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for symbols.
Qgis::RenderUnit outputUnit() const final
Returns the units to use for sizes and widths within the symbol layer.
QgsTemplatedLineSymbolLayerBase(bool rotateSymbol=true, double interval=3)
Constructor for QgsTemplatedLineSymbolLayerBase.
virtual void setSymbolLineAngle(double angle)=0
Sets the line angle modification for the symbol's angle.
QgsMapUnitScale mapUnitScale() const final
Qgis::RenderUnit intervalUnit() const
Returns the units for the interval between symbols.
Q_DECL_DEPRECATED Qgis::MarkerLinePlacement placement() const
Returns the placement of the symbols.
void setTrimDistanceStartUnit(Qgis::RenderUnit unit)
Sets the unit for the trim distance for the start of the line.
void setPlaceOnEveryPart(bool respect)
Sets whether the placement applies for every part of multi-part feature geometries.
void setPlacements(Qgis::MarkerLinePlacements placements)
Sets the placement of the symbols.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setTrimDistanceStart(double distance)
Sets the trim distance for the start of the line, which dictates a length from the start of the line ...
Qgis::RenderUnit averageAngleUnit() const
Returns the unit for the length over which the line's direction is averaged when calculating individu...
Q_DECL_DEPRECATED void setPlacement(Qgis::MarkerLinePlacement placement)
Sets the placement of the symbols.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
Qgis::RenderUnit blankSegmentsUnit() const
Returns the unit for for blank segments start and end distances.
void setBlankSegmentsUnit(Qgis::RenderUnit unit)
Sets the unit for blank segments start and end distances.
void setTrimDistanceEnd(double distance)
Sets the trim distance for the end of the line, which dictates a length from the end of the line at w...
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for symbols.
void setTrimDistanceEndUnit(Qgis::RenderUnit unit)
Sets the unit for the trim distance for the end of the line.
virtual void renderSymbol(const QPointF &point, const QgsFeature *feature, QgsRenderContext &context, int layer=-1, bool selected=false)=0
Renders the templated symbol at the specified point, using the given render context.
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the interval between symbols.
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for symbols.
void setAverageAngleLength(double length)
Sets the length of line over which the line's direction is averaged when calculating individual symbo...
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Qgis::VectorRenderingSimplificationFlags simplifyHints() const
Gets the simplification hints of the vector layer managed.
float threshold() const
Gets the simplification threshold of the vector layer managed.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored).
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsFlagValueToKeys(const T &value, bool *returnOk=nullptr)
Returns the value for the given keys of a flag.
T qgsFlagKeysToValue(const QString &keys, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given keys of a flag.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QMap< QString, QString > QgsStringMap
constexpr QgsDataDefinedStringDecoder< V, N > makeDataDefinedStringDecoder(const DataDefinedDecoderEntry< V >(&values)[N])
Creates a QgsDataDefinedStringDecoder from a hardcoded lookup table.
void trimPoints(QPolygonF &points, double startTrim, double endTrim, Qgis::RenderUnit trimDistanceStartUnit, Qgis::RenderUnit trimDistanceEndUnit, const QgsMapUnitScale &trimDistanceStartMapUnitScale, const QgsMapUnitScale &trimDistanceEndMapUnitScale, const QgsPropertyCollection &mDataDefinedProperties, QgsSymbolRenderContext &context)
trim points according to start and end trim distance based on data defined properties and render cont...
#define DEFAULT_MARKERLINE_INTERVAL
#define DEFAULT_SIMPLELINE_WIDTH
#define DEFAULT_MARKERLINE_ROTATE
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_SIMPLELINE_COLOR
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QList< QgsSymbolLayer * > QgsSymbolLayerList
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, Qgis::GeometryType geometryType)
calculate geometry shifted by a specified distance
Single variable definition for use within a QgsExpressionContextScope.
Qgis::VertexType type
Vertex type.