41 new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::BrushStyle::SolidPattern, QColor( 0, 0, 0 ), Qt::PenStyle::NoPen )
44 borderSymbol->setPenJoinStyle( Qt::MiterJoin );
45 mFrameSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList{ borderSymbol } );
52 switch ( mPlacementMode )
82 switch ( mPlacementMode )
100 QPointF anchorPoint = anchor.
asQPointF();
103 double x = anchorPoint.x();
104 double y = anchorPoint.y();
107 anchorPoint = QPointF( x, y );
112 painterBounds = QRectF( anchorPoint.x() + calloutOffsetWidthPixels,
113 anchorPoint.y() + calloutOffsetHeightPixels, widthPixels, heightPixels );
117 QPointF center =
bounds.center().toQPointF();
120 painterBounds = QRectF( center.x() - widthPixels * 0.5,
121 center.y() - heightPixels * 0.5,
122 widthPixels, heightPixels );
132 QPointF center =
bounds.center().toQPointF();
136 painterBounds = QRectF( center.x() - widthPixels * 0.5,
137 center.y() - heightPixels * 0.5,
138 widthPixels, heightPixels );
143 if ( painterBounds.width() < 1 || painterBounds.height() < 1 )
146 if ( mDrawBackground && mBackgroundSymbol )
148 mBackgroundSymbol->startRender( context );
149 mBackgroundSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
150 mBackgroundSymbol->stopRender( context );
156 renderCallout( context, painterBounds, 0, calloutContext, feedback );
161 if ( mDrawFrame && mFrameSymbol )
163 mFrameSymbol->startRender( context );
164 mFrameSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
165 mFrameSymbol->stopRender( context );
171 QList<QgsAnnotationItemNode> res;
172 switch ( mPlacementMode )
191 calloutNodePoint = mBounds.center();
233 switch ( operation->
type() )
240 switch ( mPlacementMode )
248 moveOperation->
after().
y(),
250 mBounds.yMaximum() );
254 moveOperation->
after().
y(),
255 moveOperation->
after().
x(),
256 mBounds.yMaximum() );
261 moveOperation->
after().
x(),
262 moveOperation->
after().
y() );
268 moveOperation->
after().
y() );
289 mBounds.width(), mBounds.height() );
309 switch ( mPlacementMode )
342 mBounds.width(), mBounds.height() );
358 switch ( operation->
type() )
365 switch ( mPlacementMode )
419 switch ( mPlacementMode )
441 QPointF anchorPoint = anchor.
asQPointF();
444 double x = anchorPoint.x();
445 double y = anchorPoint.y();
448 anchorPoint = QPointF( x, y );
453 const double textOriginXPixels = anchorPoint.x() + calloutOffsetWidthPixels;
454 const double textOriginYPixels = anchorPoint.y() + calloutOffsetHeightPixels;
460 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels ),
461 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels + heightPixels ),
462 QgsPointXY( textOriginXPixels, textOriginYPixels + heightPixels ),
463 QgsPointXY( textOriginXPixels, textOriginYPixels )
501 switch ( mPlacementMode )
535 switch ( mPlacementMode )
545 QRectF boundsInPixels;
553 QPointF anchorPoint = anchor.
asQPointF();
556 double x = anchorPoint.x();
557 double y = anchorPoint.y();
560 anchorPoint = QPointF( x, y );
565 QgsRectangle textRect( anchorPoint.x() + calloutOffsetWidthPixels,
566 anchorPoint.y() + calloutOffsetHeightPixels,
567 anchorPoint.x() + calloutOffsetWidthPixels + widthPixels,
568 anchorPoint.y() + calloutOffsetHeightPixels + heightPixels );
569 QgsRectangle anchorRect( anchorPoint.x(), anchorPoint.y(), anchorPoint.x(), anchorPoint.y() );
572 boundsInPixels = anchorRect.
toRectF();
576 QPointF center = mBounds.center().toQPointF();
579 double x = center.x();
580 double y = center.y();
583 center = QPointF( x, y );
587 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
588 center.y() - heightPixels * 0.5,
589 widthPixels, heightPixels );
606 QRectF boundsInPixels;
610 QPointF center( centerMapX, centerMapY );
613 double x = centerMapX;
614 double y = centerMapY;
617 center = QPointF( x, y );
621 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
622 center.y() - heightPixels * 0.5,
623 widthPixels, heightPixels );
645 return mBackgroundSymbol.get();
650 mBackgroundSymbol.reset( symbol );
655 return mFrameSymbol.get();
660 mFrameSymbol.reset( symbol );
672 if ( otherRect->mBackgroundSymbol )
676 if ( otherRect->mFrameSymbol )
685 element.setAttribute( QStringLiteral(
"xMin" ),
qgsDoubleToString( mBounds.xMinimum() ) );
686 element.setAttribute( QStringLiteral(
"xMax" ),
qgsDoubleToString( mBounds.xMaximum() ) );
687 element.setAttribute( QStringLiteral(
"yMin" ),
qgsDoubleToString( mBounds.yMinimum() ) );
688 element.setAttribute( QStringLiteral(
"yMax" ),
qgsDoubleToString( mBounds.yMaximum() ) );
689 element.setAttribute( QStringLiteral(
"sizeMode" ),
qgsEnumValueToKey( mPlacementMode ) );
690 element.setAttribute( QStringLiteral(
"fixedWidth" ),
qgsDoubleToString( mFixedSize.width() ) );
691 element.setAttribute( QStringLiteral(
"fixedHeight" ),
qgsDoubleToString( mFixedSize.height() ) );
694 element.setAttribute( QStringLiteral(
"backgroundEnabled" ), mDrawBackground ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
695 if ( mBackgroundSymbol )
697 QDomElement backgroundElement = document.createElement( QStringLiteral(
"backgroundSymbol" ) );
699 element.appendChild( backgroundElement );
702 element.setAttribute( QStringLiteral(
"frameEnabled" ), mDrawFrame ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
705 QDomElement frameElement = document.createElement( QStringLiteral(
"frameSymbol" ) );
707 element.appendChild( frameElement );
715 mBounds.setXMinimum( element.attribute( QStringLiteral(
"xMin" ) ).toDouble() );
716 mBounds.setXMaximum( element.attribute( QStringLiteral(
"xMax" ) ).toDouble() );
717 mBounds.setYMinimum( element.attribute( QStringLiteral(
"yMin" ) ).toDouble() );
718 mBounds.setYMaximum( element.attribute( QStringLiteral(
"yMax" ) ).toDouble() );
723 element.attribute( QStringLiteral(
"fixedWidth" ) ).toDouble(),
724 element.attribute( QStringLiteral(
"fixedHeight" ) ).toDouble()
728 mDrawBackground = element.attribute( QStringLiteral(
"backgroundEnabled" ), QStringLiteral(
"0" ) ).toInt();
729 const QDomElement backgroundSymbolElem = element.firstChildElement( QStringLiteral(
"backgroundSymbol" ) ).firstChildElement();
730 if ( !backgroundSymbolElem.isNull() )
735 mDrawFrame = element.attribute( QStringLiteral(
"frameEnabled" ), QStringLiteral(
"0" ) ).toInt();
736 const QDomElement frameSymbolElem = element.firstChildElement( QStringLiteral(
"frameSymbol" ) ).firstChildElement();
737 if ( !frameSymbolElem.isNull() )
757 return mFixedSizeUnit;
762 mFixedSizeUnit = unit;
767 return mPlacementMode;
772 mPlacementMode = mode;
@ VertexHandle
Node is a handle for manipulating vertices.
@ CalloutHandle
Node is a handle for manipulating callouts.
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
@ SupportsCallouts
Item supports callouts.
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
@ Invalid
Operation has invalid parameters for the item, no change occurred.
@ Success
Item was modified successfully.
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
RenderUnit
Rendering size units.
AnnotationPlacementMode
Annotation item placement modes.
@ SpatialBounds
Item is rendered inside fixed spatial bounds, and size will depend on map scale.
@ FixedSize
Item is rendered at a fixed size, regardless of map scale. Item's location is georeferenced to a spat...
@ RelativeToMapFrame
Items size and placement is relative to the map's frame, and the item will always be rendered in the ...
@ Reverse
Reverse/inverse transform (from destination to source).
Abstract base class for annotation item edit operations.
@ DeleteNode
Delete a node.
@ TranslateItem
Translate (move) an item.
virtual Type type() const =0
Returns the operation type.
Encapsulates the context for an annotation item edit operation.
QgsRectangle currentItemBounds() const
Returns the current rendered bounds of the item, in the annotation layer's CRS.
QgsRenderContext renderContext() const
Returns the render context associated with the edit operation.
Annotation item edit operation consisting of moving a node.
double translationYPixels() const
Returns the y-axis translation, in pixels.
QgsPoint before() const
Returns the node position before the move occurred (in layer coordinates).
QgsPoint after() const
Returns the node position after the move occurred (in layer coordinates).
double translationXPixels() const
Returns the x-axis translation, in pixels.
QgsVertexId nodeId() const
Returns the associated node ID.
Encapsulates the transient results of an in-progress annotation edit operation.
Annotation item edit operation consisting of translating (moving) an item.
double translationY() const
Returns the y-axis translation, in layer units.
double translationX() const
Returns the x-axis translation, in layer units.
double translationYPixels() const
Returns the y-axis translation, in pixels.
double translationXPixels() const
Returns the x-axis translation, in pixels.
Contains information about a node used for editing an annotation item.
virtual bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
void setCallout(QgsCallout *callout)
Sets the item's callout renderer, responsible for drawing item callouts.
void setOffsetFromCallout(const QSizeF &offset)
Sets the offset of the annotation item from the calloutAnchor().
QgsGeometry calloutAnchor() const
Returns the callout's anchor geometry.
Qgis::RenderUnit offsetFromCalloutUnit() const
Returns the units for the offsetFromCallout().
virtual void copyCommonProperties(const QgsAnnotationItem *other)
Copies common properties from the base class from an other item.
void setCalloutAnchor(const QgsGeometry &anchor)
Sets the callout's anchor geometry.
QSizeF offsetFromCallout() const
Returns the (optional) offset of the annotation item from the calloutAnchor().
QgsCallout * callout() const
Returns the item's callout renderer, responsible for drawing item callouts.
virtual bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
void renderCallout(QgsRenderContext &context, const QRectF &rect, double angle, QgsCallout::QgsCalloutContext &calloutContext, QgsFeedback *feedback)
Renders the item's callout.
virtual void renderInBounds(QgsRenderContext &context, const QRectF &painterRect, QgsFeedback *feedback)=0
Renders the item to the specified render context.
Qgis::AnnotationItemFlags flags() const override
Returns item flags.
void copyCommonProperties(const QgsAnnotationItem *other) override
Copies common properties from the base class from an other item.
QgsRectangle bounds() const
Returns the bounds of the item.
void render(QgsRenderContext &context, QgsFeedback *feedback) override
Renders the item to the specified render context.
QgsAnnotationItemEditOperationTransientResults * transientEditResultsV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Retrieves the results of a transient (in progress) edit operation on the item.
Qgis::AnnotationItemEditOperationResult applyEditV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context) override
Applies an edit operation to the item.
~QgsAnnotationRectItem() override
bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context) override
Reads common properties from the base class from the given DOM element.
Qgis::RenderUnit fixedSizeUnit() const
Returns the units to use for fixed item sizes, when the placementMode() is Qgis::AnnotationPlacementM...
QSizeF fixedSize() const
Returns the fixed size to use for the item, when the placementMode() is Qgis::AnnotationPlacementMode...
void setFixedSizeUnit(Qgis::RenderUnit unit)
Sets the unit to use for fixed item sizes, when the placementMode() is Qgis::AnnotationPlacementMode:...
QgsAnnotationRectItem(const QgsRectangle &bounds)
Constructor for QgsAnnotationRectItem, rendering the annotation within the specified bounds geometry.
void setBackgroundSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the item's background.
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the item's frame.
void setBounds(const QgsRectangle &bounds)
Sets the bounds of the item.
void setPlacementMode(Qgis::AnnotationPlacementMode mode)
Sets the placement mode for the item.
bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes common properties from the base class into an XML element.
const QgsFillSymbol * frameSymbol() const
Returns the symbol used to render the item's frame.
void setBackgroundEnabled(bool enabled)
Sets whether the item's background should be rendered.
QList< QgsAnnotationItemNode > nodesV2(const QgsAnnotationItemEditContext &context) const override
Returns the nodes for the item, used for editing the item.
void setFrameEnabled(bool enabled)
Sets whether the item's frame should be rendered.
QgsRectangle boundingBox() const override
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
void setFixedSize(const QSizeF &size)
Sets the fixed size to use for the item, when the placementMode() is Qgis::AnnotationPlacementMode::F...
Qgis::AnnotationPlacementMode placementMode() const
Returns the placement mode for the item.
const QgsFillSymbol * backgroundSymbol() const
Returns the symbol used to render the item's background.
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
Contains additional contextual information about the context in which a callout is being rendered.
Custom exception class for Coordinate Reference System related exceptions.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
QPointF asQPointF() const
Returns contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPoint...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
static QgsGeometry fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
Line string geometry type, with support for z-dimension and m-values.
QRectF transformBounds(const QRectF &bounds) const
Transforms a bounding box from map coordinates to device coordinates.
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.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
Contains information about the context of a rendering operation.
double convertFromPainterUnits(double size, Qgis::RenderUnit unit) const
Converts a size from painter units (pixels) to the specified render unit.
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).
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
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.
Renders polygons using a single fill and stroke color.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
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.
Represent a 2-dimensional vector.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define BUILTIN_UNREACHABLE
QList< QgsSymbolLayer * > QgsSymbolLayerList
Utility class for identifying a unique vertex within a geometry.