40void QgsCallout::initPropertyDefinitions()
42 const QString origin = QStringLiteral(
"callouts" );
53 "<b>TR</b>=Top right|<br>"
54 "<b>L</b>=Left|<b>R</b>=Right|<br>"
55 "<b>BL</b>=Bottom left|<b>B</b>=Bottom middle|"
56 "<b>BR</b>=Bottom right]", origin )
67 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>" ) )
83 props.insert( QStringLiteral(
"enabled" ), mEnabled ?
"1" :
"0" );
84 props.insert( QStringLiteral(
"anchorPoint" ),
encodeAnchorPoint( mAnchorPoint ) );
93 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt();
94 mAnchorPoint =
decodeAnchorPoint( props.value( QStringLiteral(
"anchorPoint" ), QString() ).toString() );
95 mLabelAnchorPoint =
decodeLabelAnchorPoint( props.value( QStringLiteral(
"labelAnchorPoint" ), QString() ).toString() );
97 static_cast< Qgis::BlendMode >( props.value( QStringLiteral(
"blendMode" ), QString::number(
static_cast< int >( Qgis::BlendMode::Normal ) ) ).toUInt() ) );
103 if ( element.isNull() )
110 QDomElement calloutElement = doc.createElement( QStringLiteral(
"callout" ) );
111 calloutElement.setAttribute( QStringLiteral(
"type" ),
type() );
112 calloutElement.appendChild( calloutPropsElement );
114 element.appendChild( calloutElement );
151 QPainter *painter = context.
painter();
155 const QPainter::CompositionMode
blendMode = mBlendMode;
162 painter->setCompositionMode(
blendMode );
167 painter->setRenderHint( QPainter::Antialiasing,
false );
168 painter->translate( rect.center() );
169 painter->rotate( -
angle );
171 painter->setBrush( QColor( 255, 0, 0, 100 ) );
172 painter->setPen( QColor( 255, 0, 0, 150 ) );
174 painter->drawRect( rect.width() * -0.5, rect.height() * -0.5, rect.width(), rect.height() );
177 painter->setBrush( QColor( 0, 255, 0, 100 ) );
178 painter->setPen( QColor( 0, 255, 0, 150 ) );
183 draw( context, rect,
angle, anchor, calloutContext );
185 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
195 static std::once_flag initialized;
196 std::call_once( initialized, [ = ]( )
198 initPropertyDefinitions();
200 return sPropertyDefinitions;
207 const QString cleaned = name.toLower().trimmed();
209 if ( cleaned == QLatin1String(
"pole_of_inaccessibility" ) )
211 else if ( cleaned == QLatin1String(
"point_on_exterior" ) )
213 else if ( cleaned == QLatin1String(
"point_on_surface" ) )
215 else if ( cleaned == QLatin1String(
"centroid" ) )
228 return QStringLiteral(
"pole_of_inaccessibility" );
230 return QStringLiteral(
"point_on_exterior" );
232 return QStringLiteral(
"point_on_surface" );
234 return QStringLiteral(
"centroid" );
244 return QStringLiteral(
"point_on_exterior" );
246 return QStringLiteral(
"centroid" );
248 return QStringLiteral(
"tl" );
250 return QStringLiteral(
"t" );
252 return QStringLiteral(
"tr" );
254 return QStringLiteral(
"l" );
256 return QStringLiteral(
"r" );
258 return QStringLiteral(
"bl" );
260 return QStringLiteral(
"b" );
262 return QStringLiteral(
"br" );
272 const QString cleaned = name.toLower().trimmed();
274 if ( cleaned == QLatin1String(
"point_on_exterior" ) )
276 else if ( cleaned == QLatin1String(
"centroid" ) )
278 else if ( cleaned == QLatin1String(
"tl" ) )
280 else if ( cleaned == QLatin1String(
"t" ) )
282 else if ( cleaned == QLatin1String(
"tr" ) )
284 else if ( cleaned == QLatin1String(
"l" ) )
286 else if ( cleaned == QLatin1String(
"r" ) )
288 else if ( cleaned == QLatin1String(
"bl" ) )
290 else if ( cleaned == QLatin1String(
"b" ) )
292 else if ( cleaned == QLatin1String(
"br" ) )
432 std::unique_ptr< QgsAbstractGeometry > tempPartAnchor;
445 evaluatedPartAnchor = tempPartAnchor.get();
453 evaluatedPartAnchor = partGeometry;
471 case Qgis::GeometryType::Point:
472 case Qgis::GeometryType::Line:
478 case Qgis::GeometryType::Polygon:
480 if ( labelGeos.
intersects( evaluatedPartAnchor ) )
504 case Qgis::GeometryType::Null:
505 case Qgis::GeometryType::Unknown:
517 if ( !mOriginalFeatureToMapTransform.
isValid() )
522 return mOriginalFeatureToMapTransform;
540 , mLineSymbol( other.mLineSymbol ? other.mLineSymbol->
clone() : nullptr )
541 , mMinCalloutLength( other.mMinCalloutLength )
542 , mMinCalloutLengthUnit( other.mMinCalloutLengthUnit )
543 , mMinCalloutLengthScale( other.mMinCalloutLengthScale )
544 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
545 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
546 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
547 , mOffsetFromLabelDistance( other.mOffsetFromLabelDistance )
548 , mOffsetFromLabelUnit( other.mOffsetFromLabelUnit )
549 , mOffsetFromLabelScale( other.mOffsetFromLabelScale )
550 , mDrawCalloutToAllParts( other.mDrawCalloutToAllParts )
557 std::unique_ptr< QgsSimpleLineCallout > callout = std::make_unique< QgsSimpleLineCallout >();
558 callout->readProperties(
properties, context );
559 return callout.release();
564 return QStringLiteral(
"simple" );
580 props[ QStringLiteral(
"minLength" ) ] = mMinCalloutLength;
584 props[ QStringLiteral(
"offsetFromAnchor" ) ] = mOffsetFromAnchorDistance;
587 props[ QStringLiteral(
"offsetFromLabel" ) ] = mOffsetFromLabelDistance;
591 props[ QStringLiteral(
"drawToAllParts" ) ] = mDrawCalloutToAllParts;
600 const QString lineSymbolDef = props.value( QStringLiteral(
"lineSymbol" ) ).toString();
601 QDomDocument doc( QStringLiteral(
"symbol" ) );
602 doc.setContent( lineSymbolDef );
603 const QDomElement symbolElem = doc.firstChildElement( QStringLiteral(
"symbol" ) );
604 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol< QgsLineSymbol >( symbolElem, context ) );
608 mMinCalloutLength = props.value( QStringLiteral(
"minLength" ), 0 ).toDouble();
612 mOffsetFromAnchorDistance = props.value( QStringLiteral(
"offsetFromAnchor" ), 0 ).toDouble();
615 mOffsetFromLabelDistance = props.value( QStringLiteral(
"offsetFromLabel" ), 0 ).toDouble();
619 mDrawCalloutToAllParts = props.value( QStringLiteral(
"drawToAllParts" ),
false ).toBool();
626 mLineSymbol->startRender( context );
633 mLineSymbol->stopRender( context );
640 fields.unite( mLineSymbol->usedAttributes( context ) );
646 return mLineSymbol.get();
651 mLineSymbol.reset( symbol );
664 bool originPinned =
false;
669 auto drawCalloutLine = [
this, &context, &calloutContext, &label, &rect,
angle, &anchor, originPinned](
const QgsAbstractGeometry * partAnchor )
671 bool destinationPinned =
false;
676 const double lineLength = line.
length();
680 double minLength = mMinCalloutLength;
686 const double minLengthPixels = context.
convertToPainterUnits( minLength, mMinCalloutLengthUnit, mMinCalloutLengthScale );
687 if ( minLengthPixels > 0 && lineLength < minLengthPixels )
690 std::unique_ptr< QgsCurve > calloutCurve(
createCalloutLine( qgsgeometry_cast< const QgsLineString * >( line.
constGet() )->startPoint(),
691 qgsgeometry_cast< const QgsLineString * >( line.
constGet() )->endPoint(), context, rect,
angle, anchor, calloutContext ) );
708 if ( offsetFromAnchorPixels > 0 || offsetFromLabelPixels > 0 )
710 calloutCurve.reset( calloutCurve->curveSubstring( offsetFromLabelPixels, calloutCurve->length() - offsetFromAnchorPixels ) );
713 const QPolygonF points = calloutCurve->asQPolygonF();
715 if ( points.empty() )
725 mLineSymbol->renderPolyline( points,
nullptr, context );
728 bool toAllParts = mDrawCalloutToAllParts;
736 drawCalloutLine( anchor.
constGet() );
740 drawCalloutLine( *it );
766 std::unique_ptr< QgsManhattanLineCallout > callout = std::make_unique< QgsManhattanLineCallout >();
767 callout->readProperties(
properties, context );
768 return callout.release();
773 return QStringLiteral(
"manhattan" );
784 return new QgsLineString( QVector< QgsPoint >() << start << mid1 << end );
798 , mOrientation( other.mOrientation )
799 , mCurvature( other.mCurvature )
806 std::unique_ptr< QgsCurvedLineCallout > callout = std::make_unique< QgsCurvedLineCallout >();
807 callout->readProperties(
properties, context );
809 callout->setCurvature(
properties.value( QStringLiteral(
"curvature" ), 0.1 ).toDouble() );
810 callout->setOrientation( decodeOrientation(
properties.value( QStringLiteral(
"orientation" ), QStringLiteral(
"auto" ) ).toString() ) );
812 return callout.release();
817 return QStringLiteral(
"curved" );
828 props.insert( QStringLiteral(
"curvature" ), mCurvature );
829 props.insert( QStringLiteral(
"orientation" ), encodeOrientation( mOrientation ) );
849 orientation = decodeOrientation( orientationString );
864 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
869 else if ( end.
x() > start.
x() )
877 if ( end.
x() < start.
x() )
879 else if ( end.
y() < start.
y() )
881 else if ( end.
x() - start.
x() < end.
y() - start.
y() )
892 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
897 else if ( end.
y() < start.
y() )
905 if ( end.
x() < start.
x() )
907 else if ( end.
y() > start.
y() )
909 else if ( end.
x() - start.
x() < start.
y() - end.
y() )
920 if ( start.
x() < ( rect.left() + 0.5 * rect.width() ) )
925 else if ( end.
x() < start.
x() )
933 if ( end.
x() > start.
x() )
935 else if ( end.
y() > start.
y() )
937 else if ( start.
x() - end.
x() < start.
y() - end.
y() )
948 if ( start.
y() < ( rect.top() + 0.5 * rect.height() ) )
953 else if ( end.
y() > start.
y() )
961 if ( end.
x() > start.
x() )
963 else if ( end.
y() < start.
y() )
965 else if ( start.
x() - end.
x() < end.
y() - start.
y() )
985 const QString cleaned =
string.toLower().trimmed();
986 if ( cleaned == QLatin1String(
"auto" ) )
988 if ( cleaned == QLatin1String(
"clockwise" ) )
990 if ( cleaned == QLatin1String(
"counterclockwise" ) )
1000 return QStringLiteral(
"auto" );
1002 return QStringLiteral(
"clockwise" );
1004 return QStringLiteral(
"counterclockwise" );
1011 return mOrientation;
1044 , mFillSymbol( other.mFillSymbol ? other.mFillSymbol->clone() : nullptr )
1045 , mOffsetFromAnchorDistance( other.mOffsetFromAnchorDistance )
1046 , mOffsetFromAnchorUnit( other.mOffsetFromAnchorUnit )
1047 , mOffsetFromAnchorScale( other.mOffsetFromAnchorScale )
1048 , mMargins( other.mMargins )
1049 , mMarginUnit( other.mMarginUnit )
1050 , mWedgeWidth( other.mWedgeWidth )
1051 , mWedgeWidthUnit( other.mWedgeWidthUnit )
1052 , mWedgeWidthScale( other.mWedgeWidthScale )
1053 , mCornerRadius( other.mCornerRadius )
1054 , mCornerRadiusUnit( other.mCornerRadiusUnit )
1055 , mCornerRadiusScale( other.mCornerRadiusScale )
1062 std::unique_ptr< QgsBalloonCallout > callout = std::make_unique< QgsBalloonCallout >();
1063 callout->readProperties(
properties, context );
1064 return callout.release();
1069 return QStringLiteral(
"balloon" );
1086 props[ QStringLiteral(
"offsetFromAnchor" ) ] = mOffsetFromAnchorDistance;
1090 props[ QStringLiteral(
"margins" ) ] = mMargins.
toString();
1093 props[ QStringLiteral(
"wedgeWidth" ) ] = mWedgeWidth;
1097 props[ QStringLiteral(
"cornerRadius" ) ] = mCornerRadius;
1108 const QString fillSymbolDef = props.value( QStringLiteral(
"fillSymbol" ) ).toString();
1109 QDomDocument doc( QStringLiteral(
"symbol" ) );
1110 doc.setContent( fillSymbolDef );
1111 const QDomElement symbolElem = doc.firstChildElement( QStringLiteral(
"symbol" ) );
1112 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElem, context ) );
1116 mOffsetFromAnchorDistance = props.value( QStringLiteral(
"offsetFromAnchor" ), 0 ).toDouble();
1123 mWedgeWidth = props.value( QStringLiteral(
"wedgeWidth" ), 2.64 ).toDouble();
1127 mCornerRadius = props.value( QStringLiteral(
"cornerRadius" ), 0 ).toDouble();
1136 mFillSymbol->startRender( context );
1143 mFillSymbol->stopRender( context );
1150 fields.unite( mFillSymbol->usedAttributes( context ) );
1156 return mFillSymbol.get();
1161 mFillSymbol.reset( symbol );
1166 bool destinationIsPinned =
false;
1177 if ( offsetFromAnchorPixels > 0 )
1181 line =
QgsGeometry( ls->curveSubstring( 0, ls->length() - offsetFromAnchorPixels ) );
1189 origin = ls->startPoint();
1190 destination = ls->endPoint();
1197 const QPolygonF points = getPoints( context, destination, rect );
1198 if ( points.empty() )
1211 mFillSymbol->renderPolygon( points,
nullptr,
nullptr, context );
1216 double segmentPointWidth = mWedgeWidth;
1222 segmentPointWidth = context.
convertToPainterUnits( segmentPointWidth, mWedgeWidthUnit, mWedgeWidthScale );
1232 double left = mMargins.
left();
1233 double right = mMargins.
right();
1234 double top = mMargins.
top();
1235 double bottom = mMargins.
bottom();
1242 if ( value.type() == QVariant::List )
1244 const QVariantList list = value.toList();
1245 if ( list.size() == 4 )
1248 bool rightOk =
false;
1249 bool bottomOk =
false;
1250 bool leftOk =
false;
1251 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1252 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1253 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1254 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1255 if ( topOk && rightOk && bottomOk && leftOk )
1257 left = evaluatedLeft;
1259 right = evaluatedRight;
1260 bottom = evaluatedBottom;
1266 const QStringList list = value.toString().trimmed().split(
',' );
1267 if ( list.count() == 4 )
1270 bool rightOk =
false;
1271 bool bottomOk =
false;
1272 bool leftOk =
false;
1273 const double evaluatedTop = list.at( 0 ).toDouble( &topOk );
1274 const double evaluatedRight = list.at( 1 ).toDouble( &rightOk );
1275 const double evaluatedBottom = list.at( 2 ).toDouble( &bottomOk );
1276 const double evaluatedLeft = list.at( 3 ).toDouble( &leftOk );
1277 if ( topOk && rightOk && bottomOk && leftOk )
1279 left = evaluatedLeft;
1281 right = evaluatedRight;
1282 bottom = evaluatedBottom;
1294 const QRectF expandedRect = rect.height() < 0 ?
1295 QRectF( rect.left() - marginLeft, rect.top() + marginBottom,
1296 rect.width() + marginLeft + marginRight,
1297 rect.height() - marginTop - marginBottom ) :
1298 QRectF( rect.left() - marginLeft, rect.top() - marginTop,
1299 rect.width() + marginLeft + marginRight,
1300 rect.height() + marginTop + marginBottom );
1304 if ( expandedRect.width() <= 0 || ( rect.height() < 0 && expandedRect.height() >= 0 ) || ( rect.height() > 0 && expandedRect.height() <= 0 ) )
1308 const QTransform t = QTransform::fromScale( 100, 100 );
1309 const QTransform ti = t.inverted();
1310 const QPolygonF poly = path.toFillPolygon( t );
1311 return ti.map( poly );
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Abstract base class for all geometries.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
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.
Qgis::WkbType wkbType() const SIP_HOLDGIL
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.
A cartoon talking bubble callout style.
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.
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.
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.
~QgsBalloonCallout() override
QgsBalloonCallout * 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 QgsBalloonCallout, using the settings serialized in the properties map (corresponding t...
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.
Abstract base class for callout renderers.
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.
virtual QgsCallout * clone() const =0
Duplicates a callout by creating a deep copy of the callout.
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.
@ DestinationX
X-coordinate of callout destination (feature anchor) (since QGIS 3.20)
@ Curvature
Curvature of curved line callouts (since QGIS 3.20)
@ BlendMode
Callout blend mode (since QGIS 3.20)
@ DestinationY
Y-coordinate of callout destination (feature anchor) (since QGIS 3.20)
@ CornerRadius
Balloon callout corner radius (since QGIS 3.20)
@ AnchorPointPosition
Feature's anchor point position.
@ LabelAnchorPointPosition
Label's anchor point position.
@ DrawCalloutToAllParts
Whether callout lines should be drawn to all feature parts.
@ OffsetFromAnchor
Distance to offset lines from anchor points.
@ WedgeWidth
Balloon callout wedge width (since QGIS 3.20)
@ OriginY
Y-coordinate of callout origin (label anchor) (since QGIS 3.20)
@ OffsetFromLabel
Distance to offset lines from label area.
@ Orientation
Orientation of curved line callouts (since QGIS 3.20)
@ OriginX
X-coordinate of callout origin (label anchor) (since QGIS 3.20)
@ MinimumCalloutLength
Minimum length of callouts.
@ Margins
Margin from text (since QGIS 3.20)
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 the callout is enabled.
Circular string geometry type.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Draws curved lines as callouts.
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.
void setCurvature(double curvature)
Sets the callout line's curvature.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsCurvedLineCallout, using the settings serialized in the properties map (correspondin...
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 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,...
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,...
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
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.
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, exception handling*.
QgsGeometry shortestLine(const QgsGeometry &other, QString *errorMsg=nullptr) const
Returns the shortest line joining this geometry to the other geometry.
bool intersects(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const override
Checks if geom intersects this.
Line string geometry type, with support for z-dimension and m-values.
A line symbol type, for rendering LineString and MultiLineString geometries.
Draws straight (right angled) lines as callouts.
QgsManhattanLineCallout()
QString type() const override
Returns a unique string representing the callout type.
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.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsManhattanLineCallout, using the settings serialized in the properties map (correspon...
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.
double top() const
Returns the top margin.
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...
double right() const
Returns the right margin.
double bottom() const
Returns the bottom margin.
QString toString() const
Returns the margins encoded to a string.
double left() const
Returns the left margin.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
A class to represent a 2D point.
bool isEmpty() const SIP_HOLDGIL
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 SIP_HOLDGIL
Returns the Cartesian 2D distance between this point and a specified x, y coordinate.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
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.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Definition for a property.
@ 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.
The class is used as a container of context for various read/write operations on other objects.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
Contains information about the context of a rendering operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
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...
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).
A simple direct line callout style.
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 ...
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.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsSimpleLineCallout, using the settings serialized in the properties map (correspondin...
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 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)
Returns true if the specified variant should be considered a NULL value.
static Qgis::GeometryType geometryType(Qgis::WkbType type) SIP_HOLDGIL
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.
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)
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList
record about vertex coordinates and index of anchor to which it is snapped