QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
39 void QgsCallout::initPropertyDefinitions()
41 const QString origin = QStringLiteral(
"callouts" );
52 "<b>TR</b>=Top right|<br>"
53 "<b>L</b>=Left|<b>R</b>=Right|<br>"
54 "<b>BL</b>=Bottom left|<b>B</b>=Bottom middle|"
55 "<b>BR</b>=Bottom right]", origin )
66 QgsCallout::Margins,
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>" ) )
82 props.insert( QStringLiteral(
"enabled" ), mEnabled ?
"1" :
"0" );
83 props.insert( QStringLiteral(
"anchorPoint" ),
encodeAnchorPoint( mAnchorPoint ) );
92 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt();
93 mAnchorPoint =
decodeAnchorPoint( props.value( QStringLiteral(
"anchorPoint" ), QString() ).toString() );
94 mLabelAnchorPoint =
decodeLabelAnchorPoint( props.value( QStringLiteral(
"labelAnchorPoint" ), QString() ).toString() );
102 if ( element.isNull() )
109 QDomElement calloutElement = doc.createElement( QStringLiteral(
"callout" ) );
110 calloutElement.setAttribute( QStringLiteral(
"type" ),
type() );
111 calloutElement.appendChild( calloutPropsElement );
113 element.appendChild( calloutElement );
150 QPainter *painter = context.
painter();
154 const QPainter::CompositionMode
blendMode = mBlendMode;
161 painter->setCompositionMode(
blendMode );
164 #if 0 // for debugging
166 painter->setRenderHint( QPainter::Antialiasing,
false );
167 painter->translate( rect.center() );
168 painter->rotate( -
angle );
170 painter->setBrush( QColor( 255, 0, 0, 100 ) );
171 painter->setPen( QColor( 255, 0, 0, 150 ) );
173 painter->drawRect( rect.width() * -0.5, rect.height() * -0.5, rect.width(), rect.height() );
176 painter->setBrush( QColor( 0, 255, 0, 100 ) );
177 painter->setPen( QColor( 0, 255, 0, 150 ) );
182 draw( context, rect,
angle, anchor, calloutContext );
184 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
194 static std::once_flag initialized;
195 std::call_once( initialized, [ = ]( )
197 initPropertyDefinitions();
199 return sPropertyDefinitions;
206 const QString cleaned = name.toLower().trimmed();
208 if ( cleaned == QLatin1String(
"pole_of_inaccessibility" ) )
210 else if ( cleaned == QLatin1String(
"point_on_exterior" ) )
212 else if ( cleaned == QLatin1String(
"point_on_surface" ) )
214 else if ( cleaned == QLatin1String(
"centroid" ) )
227 return QStringLiteral(
"pole_of_inaccessibility" );
229 return QStringLiteral(
"point_on_exterior" );
231 return QStringLiteral(
"point_on_surface" );
233 return QStringLiteral(
"centroid" );
243 return QStringLiteral(
"point_on_exterior" );
245 return QStringLiteral(
"centroid" );
247 return QStringLiteral(
"tl" );
249 return QStringLiteral(
"t" );
251 return QStringLiteral(
"tr" );
253 return QStringLiteral(
"l" );
255 return QStringLiteral(
"r" );
257 return QStringLiteral(
"bl" );
259 return QStringLiteral(
"b" );
261 return QStringLiteral(
"br" );
271 const QString cleaned = name.toLower().trimmed();
273 if ( cleaned == QLatin1String(
"point_on_exterior" ) )
275 else if ( cleaned == QLatin1String(
"centroid" ) )
277 else if ( cleaned == QLatin1String(
"tl" ) )
279 else if ( cleaned == QLatin1String(
"t" ) )
281 else if ( cleaned == QLatin1String(
"tr" ) )
283 else if ( cleaned == QLatin1String(
"l" ) )
285 else if ( cleaned == QLatin1String(
"r" ) )
287 else if ( cleaned == QLatin1String(
"bl" ) )
289 else if ( cleaned == QLatin1String(
"b" ) )
291 else if ( cleaned == QLatin1String(
"br" ) )
431 std::unique_ptr< QgsAbstractGeometry > tempPartAnchor;
444 evaluatedPartAnchor = tempPartAnchor.get();
452 evaluatedPartAnchor = partGeometry;
479 if ( labelGeos.
intersects( evaluatedPartAnchor ) )
516 if ( !mOriginalFeatureToMapTransform.
isValid() )
521 return mOriginalFeatureToMapTransform;
539 , mLineSymbol( other.mLineSymbol ? other.mLineSymbol->
clone() : nullptr )
540 , mMinCalloutLength( other.mMinCalloutLength )
541 , mMinCalloutLengthUnit( other.mMinCalloutLengthUnit )
542 , mMinCalloutLengthScale( other.mMinCalloutLengthScale )
543 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
544 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
545 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
546 , mOffsetFromLabelDistance( other.mOffsetFromLabelDistance )
547 , mOffsetFromLabelUnit( other.mOffsetFromLabelUnit )
548 , mOffsetFromLabelScale( other.mOffsetFromLabelScale )
549 , mDrawCalloutToAllParts( other.mDrawCalloutToAllParts )
556 std::unique_ptr< QgsSimpleLineCallout > callout = std::make_unique< QgsSimpleLineCallout >();
557 callout->readProperties(
properties, context );
558 return callout.release();
563 return QStringLiteral(
"simple" );
579 props[ QStringLiteral(
"minLength" ) ] = mMinCalloutLength;
583 props[ QStringLiteral(
"offsetFromAnchor" ) ] = mOffsetFromAnchorDistance;
586 props[ QStringLiteral(
"offsetFromLabel" ) ] = mOffsetFromLabelDistance;
590 props[ QStringLiteral(
"drawToAllParts" ) ] = mDrawCalloutToAllParts;
599 const QString lineSymbolDef = props.value( QStringLiteral(
"lineSymbol" ) ).toString();
600 QDomDocument doc( QStringLiteral(
"symbol" ) );
601 doc.setContent( lineSymbolDef );
602 const QDomElement symbolElem = doc.firstChildElement( QStringLiteral(
"symbol" ) );
603 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( symbolElem, context ) );
607 mMinCalloutLength = props.value( QStringLiteral(
"minLength" ), 0 ).toDouble();
611 mOffsetFromAnchorDistance = props.value( QStringLiteral(
"offsetFromAnchor" ), 0 ).toDouble();
614 mOffsetFromLabelDistance = props.value( QStringLiteral(
"offsetFromLabel" ), 0 ).toDouble();
618 mDrawCalloutToAllParts = props.value( QStringLiteral(
"drawToAllParts" ),
false ).toBool();
625 mLineSymbol->startRender( context );
632 mLineSymbol->stopRender( context );
639 fields.unite( mLineSymbol->usedAttributes( context ) );
645 return mLineSymbol.get();
650 mLineSymbol.reset( symbol );
663 bool originPinned =
false;
668 auto drawCalloutLine = [
this, &context, &calloutContext, &label, &rect,
angle, &anchor, originPinned](
const QgsAbstractGeometry * partAnchor )
670 bool destinationPinned =
false;
675 const double lineLength = line.
length();
679 double minLength = mMinCalloutLength;
685 const double minLengthPixels = context.
convertToPainterUnits( minLength, mMinCalloutLengthUnit, mMinCalloutLengthScale );
686 if ( minLengthPixels > 0 && lineLength < minLengthPixels )
689 std::unique_ptr< QgsCurve > calloutCurve(
createCalloutLine( qgsgeometry_cast< const QgsLineString * >( line.
constGet() )->startPoint(),
690 qgsgeometry_cast< const QgsLineString * >( line.
constGet() )->endPoint(), context, rect,
angle, anchor, calloutContext ) );
707 if ( offsetFromAnchorPixels > 0 || offsetFromLabelPixels > 0 )
709 calloutCurve.reset( calloutCurve->curveSubstring( offsetFromLabelPixels, calloutCurve->length() - offsetFromAnchorPixels ) );
712 const QPolygonF points = calloutCurve->asQPolygonF();
714 if ( points.empty() )
722 calloutContext.addCalloutPosition( position );
724 mLineSymbol->renderPolyline( points,
nullptr, context );
727 bool toAllParts = mDrawCalloutToAllParts;
734 if ( calloutContext.allFeaturePartsLabeled || !toAllParts )
735 drawCalloutLine( anchor.constGet() );
738 for (
auto it = anchor.const_parts_begin(); it != anchor.const_parts_end(); ++it )
739 drawCalloutLine( *it );
765 std::unique_ptr< QgsManhattanLineCallout > callout = std::make_unique< QgsManhattanLineCallout >();
766 callout->readProperties(
properties, context );
767 return callout.release();
772 return QStringLiteral(
"manhattan" );
783 return new QgsLineString( QVector< QgsPoint >() << start << mid1 << end );
797 , mOrientation( other.mOrientation )
798 , mCurvature( other.mCurvature )
805 std::unique_ptr< QgsCurvedLineCallout > callout = std::make_unique< QgsCurvedLineCallout >();
806 callout->readProperties(
properties, context );
808 callout->setCurvature(
properties.value( QStringLiteral(
"curvature" ), 0.1 ).toDouble() );
809 callout->setOrientation( decodeOrientation(
properties.value( QStringLiteral(
"orientation" ), QStringLiteral(
"auto" ) ).toString() ) );
811 return callout.release();
816 return QStringLiteral(
"curved" );
827 props.insert( QStringLiteral(
"curvature" ), mCurvature );
828 props.insert( QStringLiteral(
"orientation" ), encodeOrientation( mOrientation ) );
848 orientation = decodeOrientation( orientationString );
863 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
868 else if ( end.
x() > start.
x() )
876 if ( end.
x() < start.
x() )
878 else if ( end.
y() < start.
y() )
880 else if ( end.
x() - start.
x() < end.
y() - start.
y() )
891 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
896 else if ( end.
y() < start.
y() )
904 if ( end.
x() < start.
x() )
906 else if ( end.
y() > start.
y() )
908 else if ( end.
x() - start.
x() < start.
y() - end.
y() )
919 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
924 else if ( end.
x() < start.
x() )
932 if ( end.
x() > start.
x() )
934 else if ( end.
y() > start.
y() )
936 else if ( start.
x() - end.
x() < start.
y() - end.
y() )
947 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
952 else if ( end.
y() > start.
y() )
960 if ( end.
x() > start.
x() )
962 else if ( end.
y() < start.
y() )
964 else if ( start.
x() - end.
x() < end.
y() - start.
y() )
984 const QString cleaned =
string.toLower().trimmed();
985 if ( cleaned == QLatin1String(
"auto" ) )
987 if ( cleaned == QLatin1String(
"clockwise" ) )
989 if ( cleaned == QLatin1String(
"counterclockwise" ) )
999 return QStringLiteral(
"auto" );
1001 return QStringLiteral(
"clockwise" );
1003 return QStringLiteral(
"counterclockwise" );
1010 return mOrientation;
1043 , mFillSymbol( other.mFillSymbol ? other.mFillSymbol->clone() : nullptr )
1044 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
1045 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
1046 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
1047 , mMargins( other.mMargins )
1048 , mMarginUnit( other.mMarginUnit )
1049 , mWedgeWidth( other.mWedgeWidth )
1050 , mWedgeWidthUnit( other.mWedgeWidthUnit )
1051 , mWedgeWidthScale( other.mWedgeWidthScale )
1052 , mCornerRadius( other.mCornerRadius )
1053 , mCornerRadiusUnit( other.mCornerRadiusUnit )
1054 , mCornerRadiusScale( other.mCornerRadiusScale )
1061 std::unique_ptr< QgsBalloonCallout > callout = std::make_unique< QgsBalloonCallout >();
1062 callout->readProperties(
properties, context );
1063 return callout.release();
1068 return QStringLiteral(
"balloon" );
1085 props[ QStringLiteral(
"offsetFromAnchor" ) ] = mOffsetFromAnchorDistance;
1089 props[ QStringLiteral(
"margins" ) ] = mMargins.
toString();
1092 props[ QStringLiteral(
"wedgeWidth" ) ] = mWedgeWidth;
1096 props[ QStringLiteral(
"cornerRadius" ) ] = mCornerRadius;
1107 const QString fillSymbolDef = props.value( QStringLiteral(
"fillSymbol" ) ).toString();
1108 QDomDocument doc( QStringLiteral(
"symbol" ) );
1109 doc.setContent( fillSymbolDef );
1110 const QDomElement symbolElem = doc.firstChildElement( QStringLiteral(
"symbol" ) );
1111 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElem, context ) );
1115 mOffsetFromAnchorDistance = props.value( QStringLiteral(
"offsetFromAnchor" ), 0 ).toDouble();
1122 mWedgeWidth = props.value( QStringLiteral(
"wedgeWidth" ), 2.64 ).toDouble();
1126 mCornerRadius = props.value( QStringLiteral(
"cornerRadius" ), 0 ).toDouble();
1135 mFillSymbol->startRender( context );
1142 mFillSymbol->stopRender( context );
1149 fields.unite( mFillSymbol->usedAttributes( context ) );
1155 return mFillSymbol.get();
1160 mFillSymbol.reset( symbol );
1165 bool destinationIsPinned =
false;
1176 if ( offsetFromAnchorPixels > 0 )
1180 line =
QgsGeometry( ls->curveSubstring( 0, ls->length() - offsetFromAnchorPixels ) );
1188 origin = ls->startPoint();
1189 destination = ls->endPoint();
1196 const QPolygonF points = getPoints( context, destination, rect );
1197 if ( points.empty() )
1210 mFillSymbol->renderPolygon( points,
nullptr,
nullptr, context );
1215 double segmentPointWidth = mWedgeWidth;
1221 segmentPointWidth = context.
convertToPainterUnits( segmentPointWidth, mWedgeWidthUnit, mWedgeWidthScale );
1231 double left = mMargins.
left();
1232 double right = mMargins.
right();
1233 double top = mMargins.
top();
1234 double bottom = mMargins.
bottom();
1239 if ( !value.isNull() )
1241 if ( value.type() == QVariant::List )
1243 const QVariantList list = value.toList();
1244 if ( list.size() == 4 )
1247 bool rightOk =
false;
1248 bool bottomOk =
false;
1249 bool leftOk =
false;
1250 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1251 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1252 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1253 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1254 if ( topOk && rightOk && bottomOk && leftOk )
1256 left = evaluatedLeft;
1258 right = evaluatedRight;
1259 bottom = evaluatedBottom;
1265 const QStringList list = value.toString().trimmed().split(
',' );
1266 if ( list.count() == 4 )
1269 bool rightOk =
false;
1270 bool bottomOk =
false;
1271 bool leftOk =
false;
1272 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1273 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1274 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1275 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1276 if ( topOk && rightOk && bottomOk && leftOk )
1278 left = evaluatedLeft;
1280 right = evaluatedRight;
1281 bottom = evaluatedBottom;
1293 const QRectF expandedRect = rect.height() < 0 ?
1294 QRectF( rect.left() - marginLeft, rect.top() + marginBottom,
1295 rect.width() + marginLeft + marginRight,
1296 rect.height() - marginTop - marginBottom ) :
1297 QRectF( rect.left() - marginLeft, rect.top() - marginTop,
1298 rect.width() + marginLeft + marginRight,
1299 rect.height() + marginTop + marginBottom );
1303 if ( expandedRect.width() <= 0 || ( rect.height() < 0 && expandedRect.height() >= 0 ) || ( rect.height() > 0 && expandedRect.height() <= 0 ) )
1307 const QTransform t = QTransform::fromScale( 100, 100 );
1308 const QTransform ti = t.inverted();
1309 const QPolygonF poly = path.toFillPolygon( t );
1310 return ti.map( poly );
double bottom() const
Returns the bottom margin.
Abstract base class for curved geometry type.
~QgsBalloonCallout() override
@ LabelPointOnExterior
The point on the label's boundary closest to the feature.
QgsLineSymbol * lineSymbol()
Returns the line symbol used to render the callout line.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
@ Clockwise
Curve lines in a clockwise direction.
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 QPainter::CompositionMode decodeBlendMode(const QString &s)
@ BlendMode
Callout blend mode (since QGIS 3.20)
@ OffsetFromAnchor
Distance to offset lines from anchor points.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
double top() const
Returns the top margin.
double offsetFromAnchor() const
Returns the offset distance from the anchor point at which to start the line.
QgsCoordinateReferenceSystem originalFeatureCrs
Contains the CRS of the original feature associated with this callout.
~QgsSimpleLineCallout() override
QgsExpressionContext & expressionContext()
Gets the expression context.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
AnchorPoint
Feature's anchor point position.
The class is used as a container of context for various read/write operations on other objects.
double distance(double x, double y) const SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
Abstract base class for callout renderers.
@ CornerRadius
Balloon callout corner radius (since QGIS 3.20)
@ Curvature
Curvature of curved line callouts (since QGIS 3.20)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Point geometry type, with support for z-dimension and m-values.
QgsGeometry shortestLine(const QgsGeometry &other, QString *errorMsg=nullptr) const
Returns the shortest line joining this geometry to the other geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
@ DataTypeString
Property requires a string value.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
@ WedgeWidth
Balloon callout wedge width (since QGIS 3.20)
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in callouts.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
Contains information about the context of a rendering operation.
@ OriginY
Y-coordinate of callout origin (label anchor) (since QGIS 3.20)
QPointF toQPointF() const
Converts a point to a QPointF.
@ Double
Double value (including negative values)
AnchorPoint anchorPoint() const
Returns the feature's anchor point position.
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,...
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
@ LabelCentroid
The labe's centroid.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the callout line.
@ PoleOfInaccessibility
The surface's pole of inaccessibility used as anchor for polygon geometries.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsSimpleLineCallout, using the settings serialized in the properties map (correspondin...
@ LabelBottomMiddle
Bottom middle of the label's boundary.
QgsManhattanLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
Line string geometry type, with support for z-dimension and m-values.
@ Margins
Margin from text (since QGIS 3.20)
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
QgsSimpleLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsCurvedLineCallout, using the settings serialized in the properties map (correspondin...
QgsManhattanLineCallout()
virtual QString type() const =0
Returns a unique string representing the callout type.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing callouts.
@ CounterClockwise
Curve lines in a counter-clockwise direction.
QString type() const override
Returns a unique string representing the callout type.
QString type() const override
Returns a unique string representing the callout type.
@ AnchorPointPosition
Feature's anchor point position.
@ PointOnExterior
A point on the surface's outline closest to the label is used as anchor for polygon geometries.
@ LabelMiddleRight
Middle right of the label's boundary.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
QSet< QString > referencedFields(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the callout.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
@ LabelTopLeft
Top left corner of the label's boundary.
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.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
void startRender(QgsRenderContext &context) override
Prepares the callout for rendering on the specified render context.
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
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...
void setDestination(const QPointF &destination)
Sets the destination of the callout line, in map coordinates.
virtual void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
double left() const
Returns the left margin.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
record about vertex coordinates and index of anchor to which it is snapped
QgsGeometry poleOfInaccessibility(double precision, double *distanceToBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
virtual void restoreProperties(const QDomElement &element, const QgsReadWriteContext &context)
Restores the callout's properties from a DOM element.
double offsetFromLabel() const
Returns the offset distance from label area at which to end the line.
QgsCoordinateTransform originalFeatureToMapTransform(const QgsRenderContext &renderContext) const
Returns the coordinate transform to convert from the original layer associated with the callout to th...
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
Custom exception class for Coordinate Reference System related exceptions.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
QString toString() const
Returns the margins encoded to a string.
Circular string geometry type.
double cornerRadius() const
Returns the corner radius of the balloon shapes.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
@ DestinationX
X-coordinate of callout destination (feature anchor) (since QGIS 3.20)
@ LabelAnchorPointPosition
Label's anchor point position.
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 QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Represents the calculated placement of a map label callout line.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
Does vector analysis using the geos library and handles import, export, exception handling*.
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.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
LabelAnchorPoint labelAnchorPoint() const
Returns the label's anchor point position.
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.
A line symbol type, for rendering LineString and MultiLineString geometries.
@ DrawCalloutToAllParts
Whether callout lines should be drawn to all feature parts.
static QString encodeLabelAnchorPoint(LabelAnchorPoint anchor)
Encodes a label anchor point to its string representation.
virtual DrawOrder drawOrder() const
Returns the desired drawing order (stacking) to use while rendering this callout.
Definition for a property.
@ Centroid
The surface's centroid is used as anchor for polygon geometries.
double length() const
Returns the planar, 2-dimensional length of geometry.
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.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
double right() const
Returns the right margin.
A simple direct line callout style.
QgsCallout()
Constructor for QgsCallout.
void setDestinationIsPinned(bool pinned)
Sets whether the destination of the callout has pinned (manually placed).
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const override
Returns the set of any fields referenced by the active properties from the collection.
QVariantMap properties(const QgsReadWriteContext &context) const override
Returns the properties describing the callout encoded in a string format.
QgsGeometry pointOnSurface() const
Returns a point guaranteed to lie on the surface of a geometry.
QgsFillSymbol * fillSymbol()
Returns the fill symbol used to render the callout.
QgsBalloonCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
void setEnabled(bool enabled)
Sets whether the callout is enabled.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
void addCalloutPosition(const QgsCalloutPosition &position)
Adds a rendered callout position.
static QString encodeAnchorPoint(AnchorPoint anchor)
Encodes an anchor point to its string representation.
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 ...
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.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
@ OriginX
X-coordinate of callout origin (label anchor) (since QGIS 3.20)
Abstract base class for all geometries.
void setOrigin(const QPointF &origin)
Sets the origin of the callout line, in map coordinates.
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...
void render(QgsRenderContext &context, const QRectF &rect, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext)
Renders the callout onto the specified render context.
Orientation orientation() const
Returns the callout line's curve orientation.
@ Orientation
Orientation of curved line callouts (since QGIS 3.20)
DrawOrder
Options for draw order (stacking) of callouts.
A class to represent a 2D point.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
virtual QVariantMap properties(const QgsReadWriteContext &context) const
Returns the properties describing the callout encoded in a string format.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
@ LabelBottomLeft
Bottom left corner of the label's boundary.
void startRender(QgsRenderContext &context) override
Prepares the callout for rendering on the specified render context.
QString type() const override
Returns a unique string representing the callout type.
void stopRender(QgsRenderContext &context) override
Finalises the callout after a set of rendering operations on the specified render context.
Draws straight (right angled) lines as callouts.
static QPolygonF createBalloon(const QgsPointXY &origin, const QRectF &rect, double wedgeWidth)
Generates a "balloon"/"talking bubble" style shape (as a QPolygonF).
QgsCurvedLineCallout * clone() const override
Duplicates a callout by creating a deep copy of the callout.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
void 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.
A geometry is the spatial representation of a feature.
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.
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.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
Draws curved lines as callouts.
QList< QgsSymbolLayer * > QgsSymbolLayerList
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,...
virtual QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns the set of attributes referenced by the callout.
void setOrientation(Orientation orientation)
Sets the callout line's curve orientation.
A cartoon talking bubble callout style.
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 ...
@ MinimumCalloutLength
Minimum length of callouts.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
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...
@ LabelMiddleLeft
Middle left of the label's boundary.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
@ LabelBottomRight
Bottom right corner of the label's boundary.
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.
@ DestinationY
Y-coordinate of callout destination (feature anchor) (since QGIS 3.20)
bool containsAdvancedEffects() const
Returns true if the callout requires advanced effects such as blend modes, which require output in ra...
Contains additional contextual information about the context in which a callout is being rendered.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
@ LabelTopMiddle
Top middle of the label's boundary.
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.
QString type() const override
Returns a unique string representing the callout type.
virtual void startRender(QgsRenderContext &context)
Prepares the callout for rendering on the specified render context.
virtual void stopRender(QgsRenderContext &context)
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 curvature() const
Returns the callout line's curvature.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const
Saves the current state of the callout to a DOM element.
QPainter * painter()
Returns the destination QPainter for the render operation.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsManhattanLineCallout, using the settings serialized in the properties map (correspon...
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsBalloonCallout, using the settings serialized in the properties map (corresponding t...
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
void stopRender(QgsRenderContext &context) override
Finalises the callout after a set of rendering operations on the specified render context.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
bool intersects(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const override
Checks if geom intersects this.
@ OrderBelowAllLabels
Render callouts below all labels.
virtual QgsCallout * clone() const =0
Duplicates a callout by creating a deep copy of the callout.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setCurvature(double curvature)
Sets the callout line's curvature.
LabelAnchorPoint
Label's anchor point position.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the callout.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
@ OffsetFromLabel
Distance to offset lines from label area.
double offsetFromAnchor() const
Returns the offset distance from the anchor point at which to start the line.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the callout's property collection, used for data defined overrides.
bool enabled() const
Returns true if the the callout is enabled.
@ PointOnSurface
A point guaranteed to be on the surface is used as anchor for polygon geometries.
Orientation
Curve orientation.
@ LabelTopRight
Top right corner of the label's boundary.
@ Automatic
Automatically choose most cartographically pleasing orientation based on label and callout arrangemen...
@ DoublePositive
Positive double value (including 0)
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.
void setOriginIsPinned(bool pinned)
Sets whether the origin of the callout has pinned (manually placed).