43using namespace Qt::StringLiterals;
47void QgsCallout::initPropertyDefinitions()
49 const QString origin = u
"callouts"_s;
59 QgsPropertyDefinition(
"AnchorPointPosition",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Feature's anchor point position" ), QObject::tr(
"string " ) +
"[<b>pole_of_inaccessibility</b>|<b>point_on_exterior</b>|<b>point_on_surface</b>|<b>centroid</b>]", origin ) },
61 QgsPropertyDefinition(
62 "LabelAnchorPointPosition",
64 QObject::tr(
"Label's anchor point position" ),
65 QObject::tr(
"string " )
66 +
"[<b>point_on_exterior</b>|<b>centroid</b>|<b>top_left</b>=Top left|<b>top</b>=Top middle|"
67 "<b>top_right</b>=Top right|<br>"
68 "<b>left</b>=Left|<b>right</b>=Right|<br>"
69 "<b>bottom_left</b>=Bottom left|<b>bottom</b>=Bottom middle|"
70 "<b>bottom_right</b>=Bottom right]",
79 QgsPropertyDefinition(
"Orientation",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Callout curve orientation" ), QObject::tr(
"string " ) +
"[<b>auto</b>|<b>clockwise</b>|<b>counter_clockwise</b>]", origin ) },
81 QgsPropertyDefinition(
"Margins",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Margins" ), QObject::tr(
"string of four doubles '<b>top,right,bottom,left</b>' or array of doubles <b>[top, right, bottom, left]</b>" ) ) },
95 props.insert( u
"enabled"_s, mEnabled ?
"1" :
"0" );
99 props.insert( u
"ddProperties"_s, mDataDefinedProperties.toVariant(
propertyDefinitions() ) );
105 mEnabled = props.value( u
"enabled"_s, u
"0"_s ).toInt();
106 mAnchorPoint =
decodeAnchorPoint( props.value( u
"anchorPoint"_s, QString() ).toString() );
109 mDataDefinedProperties.loadVariant( props.value( u
"ddProperties"_s ),
propertyDefinitions() );
114 if ( element.isNull() )
121 QDomElement calloutElement = doc.createElement( u
"callout"_s );
122 calloutElement.setAttribute( u
"type"_s,
type() );
123 calloutElement.appendChild( calloutPropsElement );
125 element.appendChild( calloutElement );
158 QPainter *painter = context.
painter();
161 const QPainter::CompositionMode
blendMode = mBlendMode;
168 painter->setCompositionMode(
blendMode );
173 painter->setRenderHint( QPainter::Antialiasing,
false );
174 painter->translate( rect.center() );
175 painter->rotate( -angle );
177 painter->setBrush( QColor( 255, 0, 0, 100 ) );
178 painter->setPen( QColor( 255, 0, 0, 150 ) );
180 painter->drawRect( rect.width() * -0.5, rect.height() * -0.5, rect.width(), rect.height() );
183 painter->setBrush( QColor( 0, 255, 0, 100 ) );
184 painter->setPen( QColor( 0, 255, 0, 150 ) );
189 draw( context, rect, angle, anchor, calloutContext );
191 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
201 static std::once_flag initialized;
202 std::call_once( initialized, initPropertyDefinitions );
203 return sPropertyDefinitions;
218 auto evaluatedAnchor = ANCHOR_MAP.lookup( name );
219 if ( evaluatedAnchor )
221 return *evaluatedAnchor;
236 return u
"pole_of_inaccessibility"_s;
238 return u
"point_on_exterior"_s;
240 return u
"point_on_surface"_s;
242 return u
"centroid"_s;
252 return u
"point_on_exterior"_s;
254 return u
"centroid"_s;
302 auto evaluatedAnchor = ANCHOR_MAP.lookup( name );
303 if ( evaluatedAnchor )
305 return *evaluatedAnchor;
361 label.
rotate( angle, rect.topLeft() );
440 label.
rotate( angle, rect.topLeft() );
449 std::unique_ptr< QgsAbstractGeometry > tempPartAnchor;
462 evaluatedPartAnchor = tempPartAnchor.get();
470 evaluatedPartAnchor = partGeometry;
497 if ( labelGeos.
intersects( evaluatedPartAnchor ) )
536 if ( !mOriginalFeatureToMapTransform.isValid() )
541 return mOriginalFeatureToMapTransform;
558 , mLineSymbol( other.mLineSymbol ? other.mLineSymbol->
clone() : nullptr )
559 , mMinCalloutLength( other.mMinCalloutLength )
560 , mMinCalloutLengthUnit( other.mMinCalloutLengthUnit )
561 , mMinCalloutLengthScale( other.mMinCalloutLengthScale )
562 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
563 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
564 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
565 , mOffsetFromLabelDistance( other.mOffsetFromLabelDistance )
566 , mOffsetFromLabelUnit( other.mOffsetFromLabelUnit )
567 , mOffsetFromLabelScale( other.mOffsetFromLabelScale )
568 , mDrawCalloutToAllParts( other.mDrawCalloutToAllParts )
573 auto callout = std::make_unique< QgsSimpleLineCallout >();
574 callout->readProperties(
properties, context );
596 props[u
"minLength"_s] = mMinCalloutLength;
600 props[u
"offsetFromAnchor"_s] = mOffsetFromAnchorDistance;
603 props[u
"offsetFromLabel"_s] = mOffsetFromLabelDistance;
607 props[u
"drawToAllParts"_s] = mDrawCalloutToAllParts;
616 const QString lineSymbolDef = props.value( u
"lineSymbol"_s ).toString();
617 QDomDocument doc( u
"symbol"_s );
618 doc.setContent( lineSymbolDef );
619 const QDomElement symbolElem = doc.firstChildElement( u
"symbol"_s );
624 mMinCalloutLength = props.value( u
"minLength"_s, 0 ).toDouble();
628 mOffsetFromAnchorDistance = props.value( u
"offsetFromAnchor"_s, 0 ).toDouble();
631 mOffsetFromLabelDistance = props.value( u
"offsetFromLabel"_s, 0 ).toDouble();
635 mDrawCalloutToAllParts = props.value( u
"drawToAllParts"_s,
false ).toBool();
642 mLineSymbol->startRender( context );
649 mLineSymbol->stopRender( context );
656 fields.unite( mLineSymbol->usedAttributes( context ) );
662 return mLineSymbol.get();
667 mLineSymbol.reset( symbol );
680 bool originPinned =
false;
685 auto drawCalloutLine = [
this, &context, &calloutContext, &label, &rect, angle, &anchor, originPinned](
const QgsAbstractGeometry *partAnchor ) {
686 bool destinationPinned =
false;
691 const double lineLength = line.
length();
695 double minLength = mMinCalloutLength;
701 const double minLengthPixels = context.
convertToPainterUnits( minLength, mMinCalloutLengthUnit, mMinCalloutLengthScale );
702 if ( minLengthPixels > 0 && lineLength < minLengthPixels )
705 std::unique_ptr< QgsCurve > calloutCurve(
724 if ( offsetFromAnchorPixels > 0 || offsetFromLabelPixels > 0 )
726 calloutCurve.reset( calloutCurve->curveSubstring( offsetFromLabelPixels, calloutCurve->length() - offsetFromAnchorPixels ) );
729 const QPolygonF points = calloutCurve->asQPolygonF();
731 if ( points.empty() )
741 mLineSymbol->renderPolyline( points,
nullptr, context );
744 bool toAllParts = mDrawCalloutToAllParts;
752 drawCalloutLine( anchor.
constGet() );
756 drawCalloutLine( *it );
779 auto callout = std::make_unique< QgsManhattanLineCallout >();
780 callout->readProperties(
properties, context );
786 return u
"manhattan"_s;
797 return new QgsLineString( QVector< QgsPoint >() << start << mid1 << end );
810 , mOrientation( other.mOrientation )
811 , mCurvature( other.mCurvature )
816 auto callout = std::make_unique< QgsCurvedLineCallout >();
817 callout->readProperties(
properties, context );
819 callout->setCurvature(
properties.value( u
"curvature"_s, 0.1 ).toDouble() );
820 callout->setOrientation( decodeOrientation(
properties.value( u
"orientation"_s, u
"auto"_s ).toString() ) );
838 props.insert( u
"curvature"_s, mCurvature );
839 props.insert( u
"orientation"_s, encodeOrientation( mOrientation ) );
861 orientation = decodeOrientation( orientationString );
876 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
881 else if ( end.
x() > start.
x() )
889 if ( end.
x() < start.
x() )
891 else if ( end.
y() < start.
y() )
893 else if ( end.
x() - start.
x() < end.
y() - start.
y() )
904 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
909 else if ( end.
y() < start.
y() )
917 if ( end.
x() < start.
x() )
919 else if ( end.
y() > start.
y() )
921 else if ( end.
x() - start.
x() < start.
y() - end.
y() )
932 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
937 else if ( end.
x() < start.
x() )
945 if ( end.
x() > start.
x() )
947 else if ( end.
y() > start.
y() )
949 else if ( start.
x() - end.
x() < start.
y() - end.
y() )
960 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
965 else if ( end.
y() > start.
y() )
973 if ( end.
x() > start.
x() )
975 else if ( end.
y() < start.
y() )
977 else if ( start.
x() - end.
x() < end.
y() - start.
y() )
1003 auto evaluatedAnchor = ORIENTATION_MAP.lookup(
string );
1004 if ( evaluatedAnchor )
1006 return *evaluatedAnchor;
1021 return u
"clockwise"_s;
1023 return u
"counterclockwise"_s;
1030 return mOrientation;
1062 , mFillSymbol( other.mFillSymbol ? other.mFillSymbol->
clone() : nullptr )
1063 , mMarkerSymbol( other.mMarkerSymbol ? other.mMarkerSymbol->
clone() : nullptr )
1064 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
1065 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
1066 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
1067 , mMargins( other.mMargins )
1068 , mMarginUnit( other.mMarginUnit )
1069 , mWedgeWidth( other.mWedgeWidth )
1070 , mWedgeWidthUnit( other.mWedgeWidthUnit )
1071 , mWedgeWidthScale( other.mWedgeWidthScale )
1072 , mCornerRadius( other.mCornerRadius )
1073 , mCornerRadiusUnit( other.mCornerRadiusUnit )
1074 , mCornerRadiusScale( other.mCornerRadiusScale )
1079 auto callout = std::make_unique< QgsBalloonCallout >();
1080 callout->readProperties(
properties, context );
1086 return u
"balloon"_s;
1103 if ( mMarkerSymbol )
1108 props[u
"offsetFromAnchor"_s] = mOffsetFromAnchorDistance;
1112 props[u
"margins"_s] = mMargins.toString();
1115 props[u
"wedgeWidth"_s] = mWedgeWidth;
1119 props[u
"cornerRadius"_s] = mCornerRadius;
1131 const QString fillSymbolDef = props.value( u
"fillSymbol"_s ).toString();
1132 QDomDocument doc( u
"symbol"_s );
1133 doc.setContent( fillSymbolDef );
1134 const QDomElement symbolElem = doc.firstChildElement( u
"symbol"_s );
1141 const QString markerSymbolDef = props.value( u
"markerSymbol"_s ).toString();
1142 QDomDocument doc( u
"symbol"_s );
1143 doc.setContent( markerSymbolDef );
1144 const QDomElement symbolElem = doc.firstChildElement( u
"symbol"_s );
1150 mOffsetFromAnchorDistance = props.value( u
"offsetFromAnchor"_s, 0 ).toDouble();
1157 mWedgeWidth = props.value( u
"wedgeWidth"_s, 2.64 ).toDouble();
1161 mCornerRadius = props.value( u
"cornerRadius"_s, 0 ).toDouble();
1170 mFillSymbol->startRender( context );
1171 if ( mMarkerSymbol )
1172 mMarkerSymbol->startRender( context );
1179 mFillSymbol->stopRender( context );
1180 if ( mMarkerSymbol )
1181 mMarkerSymbol->stopRender( context );
1188 fields.unite( mFillSymbol->usedAttributes( context ) );
1189 if ( mMarkerSymbol )
1190 fields.unite( mMarkerSymbol->usedAttributes( context ) );
1196 return mFillSymbol.get();
1201 mFillSymbol.reset( symbol );
1206 return mMarkerSymbol.get();
1211 mMarkerSymbol.reset( symbol );
1216 bool destinationIsPinned =
false;
1219 if ( mMarkerSymbol )
1224 mMarkerSymbol->renderPoint(
anchorPoint.toQPointF(),
nullptr, context );
1236 if ( offsetFromAnchorPixels > 0 )
1240 line =
QgsGeometry( ls->curveSubstring( 0, ls->length() - offsetFromAnchorPixels ) );
1248 origin = ls->startPoint();
1249 destination = ls->endPoint();
1256 const QPolygonF points = getPoints( context, destination, rect );
1257 if ( points.empty() )
1270 mFillSymbol->renderPolygon( points,
nullptr,
nullptr, context );
1275 double segmentPointWidth = mWedgeWidth;
1281 segmentPointWidth = context.
convertToPainterUnits( segmentPointWidth, mWedgeWidthUnit, mWedgeWidthScale );
1291 double left = mMargins.left();
1292 double right = mMargins.right();
1293 double top = mMargins.top();
1294 double bottom = mMargins.bottom();
1301 if ( value.userType() == QMetaType::Type::QVariantList )
1303 const QVariantList list = value.toList();
1304 if ( list.size() == 4 )
1307 bool rightOk =
false;
1308 bool bottomOk =
false;
1309 bool leftOk =
false;
1310 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1311 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1312 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1313 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1314 if ( topOk && rightOk && bottomOk && leftOk )
1316 left = evaluatedLeft;
1318 right = evaluatedRight;
1319 bottom = evaluatedBottom;
1325 const QStringList list = value.toString().trimmed().split(
',' );
1326 if ( list.count() == 4 )
1329 bool rightOk =
false;
1330 bool bottomOk =
false;
1331 bool leftOk =
false;
1332 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1333 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1334 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1335 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1336 if ( topOk && rightOk && bottomOk && leftOk )
1338 left = evaluatedLeft;
1340 right = evaluatedRight;
1341 bottom = evaluatedBottom;
1353 const QRectF expandedRect = rect.height() < 0 ? QRectF( rect.left() - marginLeft, rect.top() + marginBottom, rect.width() + marginLeft + marginRight, rect.height() - marginTop - marginBottom )
1354 : QRectF( rect.left() - marginLeft, rect.top() - marginTop, rect.width() + marginLeft + marginRight, rect.height() + marginTop + marginBottom );
1358 if ( expandedRect.width() <= 0 || ( rect.height() < 0 && expandedRect.height() >= 0 ) || ( rect.height() > 0 && expandedRect.height() <= 0 ) )
1362 const QTransform t = QTransform::fromScale( 100, 100 );
1363 const QTransform ti = t.inverted();
1364 const QPolygonF poly = path.toFillPolygon( t );
1365 return ti.map( poly );
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Abstract base class for all geometries.
virtual QgsRectangle boundingBox() const
Returns the minimal bounding box for the geometry.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
QgsFillSymbol * fillSymbol()
Returns the fill symbol used to render the callout.
double cornerRadius() const
Returns the corner radius of the balloon shapes.
QString type() const override
Returns a unique string representing the callout type.
QgsMarkerSymbol * markerSymbol()
Returns the marker symbol used to render the callout endpoint.
void startRender(QgsRenderContext &context) override
Prepares the callout for rendering on the specified render context.
QSet< QString > referencedFields(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the callout.
void stopRender(QgsRenderContext &context) override
Finalises the callout after a set of rendering operations on the specified render context.
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the callout.
static std::unique_ptr< QgsCallout > create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsBalloonCallout, using the settings serialized in the properties map (corresponding t...
void draw(QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCallout::QgsCalloutContext &calloutContext) override
Performs the actual rendering of the callout implementation onto the specified render context.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the marker symbol used to render the callout endpoint.
~QgsBalloonCallout() override
QgsBalloonCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
double offsetFromAnchor() const
Returns the offset distance from the anchor point at which to start the line.
void readProperties(const QVariantMap &props, const QgsReadWriteContext &context) override
Reads a string map of an callout's properties and restores the callout to the state described by the ...
Represents the calculated placement of a map label callout line.
void setDestination(const QPointF &destination)
Sets the destination of the callout line, in map coordinates.
void setOrigin(const QPointF &origin)
Sets the origin of the callout line, in map coordinates.
void setDestinationIsPinned(bool pinned)
Sets whether the destination of the callout has pinned (manually placed).
void setOriginIsPinned(bool pinned)
Sets whether the origin of the callout has pinned (manually placed).
Contains additional contextual information about the context in which a callout is being rendered.
QgsCoordinateTransform originalFeatureToMapTransform(const QgsRenderContext &renderContext) const
Returns the coordinate transform to convert from the original layer associated with the callout to th...
void addCalloutPosition(const QgsCalloutPosition &position)
Adds a rendered callout position.
bool allFeaturePartsLabeled
true if all parts of associated feature were labeled
QgsCoordinateReferenceSystem originalFeatureCrs
Contains the CRS of the original feature associated with this callout.
static QString encodeAnchorPoint(AnchorPoint anchor)
Encodes an anchor point to its string representation.
bool containsAdvancedEffects() const
Returns true if the callout requires advanced effects such as blend modes, which require output in ra...
virtual bool saveProperties(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const
Saves the current state of the callout to a DOM element.
virtual void stopRender(QgsRenderContext &context)
Finalises the callout after a set of rendering operations on the specified render context.
QgsGeometry calloutLineToPart(const QgsGeometry &labelGeometry, const QgsAbstractGeometry *partGeometry, QgsRenderContext &context, const QgsCalloutContext &calloutContext, bool &pinned) const
Calculates the direct line from a label geometry to an anchor geometry part, respecting the various c...
void setEnabled(bool enabled)
Sets whether the callout is enabled.
virtual QString type() const =0
Returns a unique string representing the callout type.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the callout's property collection, used for data defined overrides.
QgsGeometry calloutLabelPoint(const QRectF &bodyBoundingBox, double angle, LabelAnchorPoint anchor, QgsRenderContext &context, const QgsCalloutContext &calloutContext, bool &pinned) const
Returns the anchor point geometry for a label with the given bounding box and anchor point mode.
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in callouts.
AnchorPoint anchorPoint() const
Returns the feature's anchor point position.
LabelAnchorPoint labelAnchorPoint() const
Returns the label's anchor point position.
AnchorPoint
Feature's anchor point position.
@ PointOnExterior
A point on the surface's outline closest to the label is used as anchor for polygon geometries.
@ Centroid
The surface's centroid is used as anchor for polygon geometries.
@ PointOnSurface
A point guaranteed to be on the surface is used as anchor for polygon geometries.
@ PoleOfInaccessibility
The surface's pole of inaccessibility used as anchor for polygon geometries.
void render(QgsRenderContext &context, const QRectF &rect, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext)
Renders the callout onto the specified render context.
virtual void restoreProperties(const QDomElement &element, const QgsReadWriteContext &context)
Restores the callout's properties from a DOM element.
virtual void draw(QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext)=0
Performs the actual rendering of the callout implementation onto the specified render context.
static QString encodeLabelAnchorPoint(LabelAnchorPoint anchor)
Encodes a label anchor point to its string representation.
virtual void startRender(QgsRenderContext &context)
Prepares the callout for rendering on the specified render context.
static QgsCallout::LabelAnchorPoint decodeLabelAnchorPoint(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a label anchor point name to the corresponding anchor p...
Q_DECL_DEPRECATED QgsGeometry labelAnchorGeometry(const QRectF &bodyBoundingBox, const double angle, LabelAnchorPoint anchor) const
Returns the anchor point geometry for a label with the given bounding box and anchor point mode.
QgsCallout()
Constructor for QgsCallout.
DrawOrder
Options for draw order (stacking) of callouts.
@ OrderBelowAllLabels
Render callouts below all labels.
virtual DrawOrder drawOrder() const
Returns the desired drawing order (stacking) to use while rendering this callout.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing callouts.
LabelAnchorPoint
Label's anchor point position.
@ LabelPointOnExterior
The point on the label's boundary closest to the feature.
@ LabelBottomLeft
Bottom left corner of the label's boundary.
@ LabelBottomMiddle
Bottom middle of the label's boundary.
@ LabelMiddleLeft
Middle left of the label's boundary.
@ LabelBottomRight
Bottom right corner of the label's boundary.
@ LabelMiddleRight
Middle right of the label's boundary.
@ LabelTopMiddle
Top middle of the label's boundary.
@ LabelTopLeft
Top left corner of the label's boundary.
@ LabelCentroid
The labe's centroid.
@ LabelTopRight
Top right corner of the label's boundary.
static QgsCallout::AnchorPoint decodeAnchorPoint(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of an anchor point name to the corresponding anchor point.
virtual void readProperties(const QVariantMap &props, const QgsReadWriteContext &context)
Reads a string map of an callout's properties and restores the callout to the state described by the ...
virtual QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns the set of attributes referenced by the callout.
@ MinimumCalloutLength
Minimum length of callouts.
@ LabelAnchorPointPosition
Label's anchor point position.
@ CornerRadius
Balloon callout corner radius.
@ OffsetFromAnchor
Distance to offset lines from anchor points.
@ OffsetFromLabel
Distance to offset lines from label area.
@ DestinationX
X-coordinate of callout destination (feature anchor).
@ DestinationY
Y-coordinate of callout destination (feature anchor).
@ WedgeWidth
Balloon callout wedge width.
@ AnchorPointPosition
Feature's anchor point position.
@ OriginX
X-coordinate of callout origin (label anchor).
@ OriginY
Y-coordinate of callout origin (label anchor).
@ Curvature
Curvature of curved line callouts.
@ BlendMode
Callout blend mode.
@ Orientation
Orientation of curved line callouts.
@ Margins
Margin from text.
@ DrawCalloutToAllParts
Whether callout lines should be drawn to all feature parts.
virtual QVariantMap properties(const QgsReadWriteContext &context) const
Returns the properties describing the callout encoded in a string format.
bool enabled() const
Returns true if the callout is enabled.
Circular string geometry type.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
QgsCurvedLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
QgsCurve * createCalloutLine(const QgsPoint &start, const QgsPoint &end, QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext) const override
Creates a callout line between start and end in the desired style.
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
void setOrientation(Orientation orientation)
Sets the callout line's curve orientation.
static std::unique_ptr< QgsCallout > create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsCurvedLineCallout, using the settings serialized in the properties map (correspondin...
void setCurvature(double curvature)
Sets the callout line's curvature.
QString type() const override
Returns a unique string representing the callout type.
double curvature() const
Returns the callout line's curvature.
Orientation
Curve orientation.
@ Clockwise
Curve lines in a clockwise direction.
@ CounterClockwise
Curve lines in a counter-clockwise direction.
@ Automatic
Automatically choose most cartographically pleasing orientation based on label and callout arrangemen...
Orientation orientation() const
Returns the callout line's curve orientation.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static int closestSideOfRectangle(double right, double bottom, double left, double top, double x, double y)
Returns a number representing the closest side of a rectangle defined by /a right,...
static void perpendicularOffsetPointAlongSegment(double x1, double y1, double x2, double y2, double proportion, double offset, double *x, double *y)
Calculates a point a certain proportion of the way along the segment from (x1, y1) to (x2,...
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsGeometry poleOfInaccessibility(double precision, double *distanceToBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
bool intersects(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const override
Checks if geom intersects this.
std::unique_ptr< QgsAbstractGeometry > shortestLine(const QgsGeometry &other, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const
Returns the shortest line joining this geometry to the other geometry.
Line string geometry type, with support for z-dimension and m-values.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsManhattanLineCallout()
QString type() const override
Returns a unique string representing the callout type.
static std::unique_ptr< QgsCallout > create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsManhattanLineCallout, using the settings serialized in the properties map (correspon...
QgsCurve * createCalloutLine(const QgsPoint &start, const QgsPoint &end, QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCallout::QgsCalloutContext &calloutContext) const override
Creates a callout line between start and end in the desired style.
QgsManhattanLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
static QgsMargins fromString(const QString &string)
Returns a QgsMargins object decoded from a string, or a null QgsMargins if the string could not be in...
A marker symbol type, for rendering Point and MultiPoint geometries.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
bool isEmpty() const
Returns true if the geometry is empty.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
double distance(double x, double y) const
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
@ Double
Double value (including negative values).
@ DoublePositive
Positive double value (including 0).
@ DataTypeString
Property requires a string value.
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
A container for the context for various read/write operations on objects.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
Contains information about the context of a rendering operation.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
static QPolygonF createBalloon(const QgsPointXY &origin, const QRectF &rect, double wedgeWidth)
Generates a "balloon"/"talking bubble" style shape (as a QPolygonF).
Renders polygons using a single fill and stroke color.
void startRender(QgsRenderContext &context) override
Prepares the callout for rendering on the specified render context.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the callout line.
void stopRender(QgsRenderContext &context) override
Finalises the callout after a set of rendering operations on the specified render context.
QSet< QString > referencedFields(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the callout.
double offsetFromLabel() const
Returns the offset distance from label area at which to end the line.
void readProperties(const QVariantMap &props, const QgsReadWriteContext &context) override
Reads a string map of an callout's properties and restores the callout to the state described by the ...
static std::unique_ptr< QgsCallout > create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsSimpleLineCallout, using the settings serialized in the properties map (correspondin...
void draw(QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCallout::QgsCalloutContext &calloutContext) override
Performs the actual rendering of the callout implementation onto the specified render context.
QString type() const override
Returns a unique string representing the callout type.
double offsetFromAnchor() const
Returns the offset distance from the anchor point at which to start the line.
~QgsSimpleLineCallout() override
virtual QgsCurve * createCalloutLine(const QgsPoint &start, const QgsPoint &end, QgsRenderContext &context, const QRectF &bodyBoundingBox, const double angle, const QgsGeometry &anchor, QgsCallout::QgsCalloutContext &calloutContext) const
Creates a callout line between start and end in the desired style.
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
QgsSimpleLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
QgsLineSymbol * lineSymbol()
Returns the line symbol used to render the callout line.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
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.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
constexpr QgsDataDefinedStringDecoder< V, N > makeDataDefinedStringDecoder(const DataDefinedDecoderEntry< V >(&values)[N])
Creates a QgsDataDefinedStringDecoder from a hardcoded lookup table.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList