40 new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::BrushStyle::SolidPattern, QColor( 0, 0, 0 ), Qt::PenStyle::NoPen )
43 borderSymbol->setPenJoinStyle( Qt::MiterJoin );
44 mFrameSymbol = std::make_unique< QgsFillSymbol >(
QgsSymbolLayerList{ borderSymbol } );
51 switch ( mPlacementMode )
81 switch ( mPlacementMode )
102 double x = anchorPoint.x();
103 double y = anchorPoint.y();
106 anchorPoint = QPointF( x, y );
111 painterBounds = QRectF( anchorPoint.x() + calloutOffsetWidthPixels,
112 anchorPoint.y() + calloutOffsetHeightPixels, widthPixels, heightPixels );
119 painterBounds = QRectF( center.x() - widthPixels * 0.5,
120 center.y() - heightPixels * 0.5,
121 widthPixels, heightPixels );
135 painterBounds = QRectF( center.x() - widthPixels * 0.5,
136 center.y() - heightPixels * 0.5,
137 widthPixels, heightPixels );
142 if ( painterBounds.width() < 1 || painterBounds.height() < 1 )
145 if ( mDrawBackground && mBackgroundSymbol )
147 mBackgroundSymbol->startRender( context );
148 mBackgroundSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
149 mBackgroundSymbol->stopRender( context );
155 renderCallout( context, painterBounds, 0, calloutContext, feedback );
160 if ( mDrawFrame && mFrameSymbol )
162 mFrameSymbol->startRender( context );
163 mFrameSymbol->renderPolygon( painterBounds,
nullptr,
nullptr, context );
164 mFrameSymbol->stopRender( context );
170 QList<QgsAnnotationItemNode> res;
171 switch ( mPlacementMode )
190 calloutNodePoint = mBounds.
center();
232 switch ( operation->
type() )
239 switch ( mPlacementMode )
247 moveOperation->
after().
y(),
253 moveOperation->
after().
y(),
254 moveOperation->
after().
x(),
260 moveOperation->
after().
x(),
261 moveOperation->
after().
y() );
267 moveOperation->
after().
y() );
308 switch ( mPlacementMode )
357 switch ( operation->
type() )
364 switch ( mPlacementMode )
418 switch ( mPlacementMode )
440 QPointF anchorPoint = anchor.
asQPointF();
443 double x = anchorPoint.x();
444 double y = anchorPoint.y();
447 anchorPoint = QPointF( x, y );
452 const double textOriginXPixels = anchorPoint.x() + calloutOffsetWidthPixels;
453 const double textOriginYPixels = anchorPoint.y() + calloutOffsetHeightPixels;
459 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels ),
460 QgsPointXY( textOriginXPixels + widthPixels, textOriginYPixels + heightPixels ),
461 QgsPointXY( textOriginXPixels, textOriginYPixels + heightPixels ),
462 QgsPointXY( textOriginXPixels, textOriginYPixels )
500 switch ( mPlacementMode )
534 switch ( mPlacementMode )
544 QRectF boundsInPixels;
552 QPointF anchorPoint = anchor.
asQPointF();
555 double x = anchorPoint.x();
556 double y = anchorPoint.y();
559 anchorPoint = QPointF( x, y );
564 QgsRectangle textRect( anchorPoint.x() + calloutOffsetWidthPixels,
565 anchorPoint.y() + calloutOffsetHeightPixels,
566 anchorPoint.x() + calloutOffsetWidthPixels + widthPixels,
567 anchorPoint.y() + calloutOffsetHeightPixels + heightPixels );
568 QgsRectangle anchorRect( anchorPoint.x(), anchorPoint.y(), anchorPoint.x(), anchorPoint.y() );
571 boundsInPixels = anchorRect.
toRectF();
578 double x = center.x();
579 double y = center.y();
582 center = QPointF( x, y );
586 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
587 center.y() - heightPixels * 0.5,
588 widthPixels, heightPixels );
605 QRectF boundsInPixels;
609 QPointF center( centerMapX, centerMapY );
612 double x = centerMapX;
613 double y = centerMapY;
616 center = QPointF( x, y );
620 boundsInPixels = QRectF( center.x() - widthPixels * 0.5,
621 center.y() - heightPixels * 0.5,
622 widthPixels, heightPixels );
644 return mBackgroundSymbol.get();
649 mBackgroundSymbol.reset( symbol );
654 return mFrameSymbol.get();
659 mFrameSymbol.reset( symbol );
671 if ( otherRect->mBackgroundSymbol )
675 if ( otherRect->mFrameSymbol )
688 element.setAttribute( QStringLiteral(
"sizeMode" ),
qgsEnumValueToKey( mPlacementMode ) );
689 element.setAttribute( QStringLiteral(
"fixedWidth" ),
qgsDoubleToString( mFixedSize.width() ) );
690 element.setAttribute( QStringLiteral(
"fixedHeight" ),
qgsDoubleToString( mFixedSize.height() ) );
693 element.setAttribute( QStringLiteral(
"backgroundEnabled" ), mDrawBackground ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
694 if ( mBackgroundSymbol )
696 QDomElement backgroundElement = document.createElement( QStringLiteral(
"backgroundSymbol" ) );
698 element.appendChild( backgroundElement );
701 element.setAttribute( QStringLiteral(
"frameEnabled" ), mDrawFrame ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
704 QDomElement frameElement = document.createElement( QStringLiteral(
"frameSymbol" ) );
706 element.appendChild( frameElement );
714 mBounds.
setXMinimum( element.attribute( QStringLiteral(
"xMin" ) ).toDouble() );
715 mBounds.
setXMaximum( element.attribute( QStringLiteral(
"xMax" ) ).toDouble() );
716 mBounds.
setYMinimum( element.attribute( QStringLiteral(
"yMin" ) ).toDouble() );
717 mBounds.
setYMaximum( element.attribute( QStringLiteral(
"yMax" ) ).toDouble() );
722 element.attribute( QStringLiteral(
"fixedWidth" ) ).toDouble(),
723 element.attribute( QStringLiteral(
"fixedHeight" ) ).toDouble()
727 mDrawBackground = element.attribute( QStringLiteral(
"backgroundEnabled" ), QStringLiteral(
"0" ) ).toInt();
728 const QDomElement backgroundSymbolElem = element.firstChildElement( QStringLiteral(
"backgroundSymbol" ) ).firstChildElement();
729 if ( !backgroundSymbolElem.isNull() )
731 setBackgroundSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( backgroundSymbolElem, context ) );
734 mDrawFrame = element.attribute( QStringLiteral(
"frameEnabled" ), QStringLiteral(
"0" ) ).toInt();
735 const QDomElement frameSymbolElem = element.firstChildElement( QStringLiteral(
"frameSymbol" ) ).firstChildElement();
736 if ( !frameSymbolElem.isNull() )
738 setFrameSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( frameSymbolElem, context ) );
756 return mFixedSizeUnit;
761 mFixedSizeUnit = unit;
766 return mPlacementMode;
771 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.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
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.
Abstract base class for annotation items which render annotations in a rectangular shape.
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.
A class to represent a 2D point.
QPointF toQPointF() const
Converts a point to a QPointF.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
double width() const
Returns the width of the rectangle.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
QgsPointXY center() const
Returns the center point of the rectangle.
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.
double height() const
Returns the height of the rectangle.
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 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.
A class to represent a 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.