37using namespace Qt::StringLiterals;
45 new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::BrushStyle::SolidPattern, QColor( 0, 0, 0 ), Qt::PenStyle::NoPen )
48 borderSymbol->setPenJoinStyle( Qt::MiterJoin );
49 mFrameSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList{ borderSymbol } );
56 switch ( mPlacementMode )
86 switch ( mPlacementMode )
104 QPointF anchorPoint = anchor.
asQPointF();
107 double x = anchorPoint.x();
108 double y = anchorPoint.y();
111 anchorPoint = QPointF( x, y );
116 painterBounds = QRectF( anchorPoint.x() + calloutOffsetWidthPixels,
117 anchorPoint.y() + calloutOffsetHeightPixels, widthPixels, heightPixels );
121 QPointF center =
bounds.center().toQPointF();
124 painterBounds = QRectF( center.x() - widthPixels * 0.5,
125 center.y() - heightPixels * 0.5,
126 widthPixels, heightPixels );
136 QPointF center =
bounds.center().toQPointF();
140 painterBounds = QRectF( center.x() - widthPixels * 0.5,
141 center.y() - heightPixels * 0.5,
142 widthPixels, heightPixels );
147 if ( painterBounds.width() < 1 || painterBounds.height() < 1 )
150 if ( mDrawBackground && mBackgroundSymbol )
152 mBackgroundSymbol->startRender( context );
153 mBackgroundSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
154 mBackgroundSymbol->stopRender( context );
160 renderCallout( context, painterBounds, 0, calloutContext, feedback );
165 if ( mDrawFrame && mFrameSymbol )
167 mFrameSymbol->startRender( context );
168 mFrameSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
169 mFrameSymbol->stopRender( context );
175 QList<QgsAnnotationItemNode> res;
176 switch ( mPlacementMode )
195 calloutNodePoint = mBounds.center();
237 switch ( operation->
type() )
244 switch ( mPlacementMode )
252 moveOperation->
after().
y(),
254 mBounds.yMaximum() );
258 moveOperation->
after().
y(),
259 moveOperation->
after().
x(),
260 mBounds.yMaximum() );
265 moveOperation->
after().
x(),
266 moveOperation->
after().
y() );
272 moveOperation->
after().
y() );
293 mBounds.width(), mBounds.height() );
313 switch ( mPlacementMode )
346 mBounds.width(), mBounds.height() );
363 switch ( operation->
type() )
370 switch ( mPlacementMode )
424 switch ( mPlacementMode )
446 QPointF anchorPoint = anchor.
asQPointF();
449 double x = anchorPoint.x();
450 double y = anchorPoint.y();
453 anchorPoint = QPointF( x, y );
458 const double textOriginXPixels = anchorPoint.x() + calloutOffsetWidthPixels;
459 const double textOriginYPixels = anchorPoint.y() + calloutOffsetHeightPixels;
465 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels ),
466 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels + heightPixels ),
467 QgsPointXY( textOriginXPixels, textOriginYPixels + heightPixels ),
468 QgsPointXY( textOriginXPixels, textOriginYPixels )
507 switch ( mPlacementMode )
541 switch ( mPlacementMode )
551 QRectF boundsInPixels;
559 QPointF anchorPoint = anchor.
asQPointF();
562 double x = anchorPoint.x();
563 double y = anchorPoint.y();
566 anchorPoint = QPointF( x, y );
571 QgsRectangle textRect( anchorPoint.x() + calloutOffsetWidthPixels,
572 anchorPoint.y() + calloutOffsetHeightPixels,
573 anchorPoint.x() + calloutOffsetWidthPixels + widthPixels,
574 anchorPoint.y() + calloutOffsetHeightPixels + heightPixels );
575 QgsRectangle anchorRect( anchorPoint.x(), anchorPoint.y(), anchorPoint.x(), anchorPoint.y() );
578 boundsInPixels = anchorRect.
toRectF();
582 QPointF center = mBounds.center().toQPointF();
585 double x = center.x();
586 double y = center.y();
589 center = QPointF( x, y );
593 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
594 center.y() - heightPixels * 0.5,
595 widthPixels, heightPixels );
612 QRectF boundsInPixels;
616 QPointF center( centerMapX, centerMapY );
619 double x = centerMapX;
620 double y = centerMapY;
623 center = QPointF( x, y );
627 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
628 center.y() - heightPixels * 0.5,
629 widthPixels, heightPixels );
651 return mBackgroundSymbol.get();
656 mBackgroundSymbol.reset( symbol );
661 return mFrameSymbol.get();
666 mFrameSymbol.reset( symbol );
678 if ( otherRect->mBackgroundSymbol )
682 if ( otherRect->mFrameSymbol )
696 element.setAttribute( u
"fixedWidth"_s,
qgsDoubleToString( mFixedSize.width() ) );
697 element.setAttribute( u
"fixedHeight"_s,
qgsDoubleToString( mFixedSize.height() ) );
700 element.setAttribute( u
"backgroundEnabled"_s, mDrawBackground ? u
"1"_s : u
"0"_s );
701 if ( mBackgroundSymbol )
703 QDomElement backgroundElement = document.createElement( u
"backgroundSymbol"_s );
705 element.appendChild( backgroundElement );
708 element.setAttribute( u
"frameEnabled"_s, mDrawFrame ? u
"1"_s : u
"0"_s );
711 QDomElement frameElement = document.createElement( u
"frameSymbol"_s );
713 element.appendChild( frameElement );
721 mBounds.setXMinimum( element.attribute( u
"xMin"_s ).toDouble() );
722 mBounds.setXMaximum( element.attribute( u
"xMax"_s ).toDouble() );
723 mBounds.setYMinimum( element.attribute( u
"yMin"_s ).toDouble() );
724 mBounds.setYMaximum( element.attribute( u
"yMax"_s ).toDouble() );
729 element.attribute( u
"fixedWidth"_s ).toDouble(),
730 element.attribute( u
"fixedHeight"_s ).toDouble()
734 mDrawBackground = element.attribute( u
"backgroundEnabled"_s, u
"0"_s ).toInt();
735 const QDomElement backgroundSymbolElem = element.firstChildElement( u
"backgroundSymbol"_s ).firstChildElement();
736 if ( !backgroundSymbolElem.isNull() )
741 mDrawFrame = element.attribute( u
"frameEnabled"_s, u
"0"_s ).toInt();
742 const QDomElement frameSymbolElem = element.firstChildElement( u
"frameSymbol"_s ).firstChildElement();
743 if ( !frameSymbolElem.isNull() )
763 return mFixedSizeUnit;
768 mFixedSizeUnit = unit;
773 return mPlacementMode;
778 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.
@ RotateItem
Rotate an item.
@ 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.