39   props.insert( QStringLiteral( 
"color" ), QStringLiteral( 
"white" ) );
 
   40   props.insert( QStringLiteral( 
"style" ), QStringLiteral( 
"solid" ) );
 
   41   props.insert( QStringLiteral( 
"style_border" ), QStringLiteral( 
"solid" ) );
 
   42   props.insert( QStringLiteral( 
"color_border" ), QStringLiteral( 
"black" ) );
 
   43   props.insert( QStringLiteral( 
"width_border" ), QStringLiteral( 
"0.3" ) );
 
   44   props.insert( QStringLiteral( 
"joinstyle" ), QStringLiteral( 
"miter" ) );
 
   61   if ( mHasFixedMapPosition == fixed )
 
   64   mHasFixedMapPosition = fixed;
 
   70   mMapPosition = position;
 
   76   mMapPositionCrs = 
crs;
 
   82   mRelativePosition = position;
 
   94   return mOffsetFromReferencePoint / 3.7795275;
 
   99   mOffsetFromReferencePoint = offset;
 
  113   return mFrameSize / 3.7795275;
 
  126   mContentsMargins = margins;
 
  132   mFillSymbol.reset( symbol );
 
  138   return mFillSymbol.get();
 
  143   QPainter *painter = context.
painter();
 
  152   drawFrame( context );
 
  153   if ( mHasFixedMapPosition )
 
  155     drawMarkerSymbol( context );
 
  157   if ( mHasFixedMapPosition )
 
  179   mMarkerSymbol.reset( symbol );
 
  222   return QSizeF( 0, 0 );
 
  230   auto scaleSize = [&context]( 
double size )->
double 
  235   const QRectF frameRect( mHasFixedMapPosition ? scaleSize( mOffsetFromReferencePoint.x() ) : 0,
 
  236                           mHasFixedMapPosition ? scaleSize( mOffsetFromReferencePoint.y() ) : 0,
 
  237                           scaleSize( mFrameSize.width() ),
 
  238                           scaleSize( mFrameSize.height() ) );
 
  243   mFillSymbol->startRender( context );
 
  244   QVector<QPolygonF> rings; 
 
  245   mFillSymbol->renderPolygon( poly, &rings, 
nullptr, context );
 
  246   mFillSymbol->stopRender( context );
 
  258     mMarkerSymbol->startRender( context );
 
  259     mMarkerSymbol->renderPoint( QPointF( 0, 0 ), 
nullptr, context );
 
  260     mMarkerSymbol->stopRender( context );
 
  266   if ( itemElem.isNull() )
 
  270   QDomElement annotationElem = doc.createElement( QStringLiteral( 
"AnnotationItem" ) );
 
  271   annotationElem.setAttribute( QStringLiteral( 
"mapPositionFixed" ), mHasFixedMapPosition );
 
  272   annotationElem.setAttribute( QStringLiteral( 
"mapPosX" ), 
qgsDoubleToString( mMapPosition.
x() ) );
 
  273   annotationElem.setAttribute( QStringLiteral( 
"mapPosY" ), 
qgsDoubleToString( mMapPosition.
y() ) );
 
  274   if ( mMapPositionCrs.
isValid() )
 
  275     mMapPositionCrs.
writeXml( annotationElem, doc );
 
  276   annotationElem.setAttribute( QStringLiteral( 
"offsetXMM" ), 
qgsDoubleToString( mOffsetFromReferencePoint.x() ) );
 
  277   annotationElem.setAttribute( QStringLiteral( 
"offsetYMM" ), 
qgsDoubleToString( mOffsetFromReferencePoint.y() ) );
 
  278   annotationElem.setAttribute( QStringLiteral( 
"frameWidthMM" ), 
qgsDoubleToString( mFrameSize.width() ) );
 
  279   annotationElem.setAttribute( QStringLiteral( 
"frameHeightMM" ), 
qgsDoubleToString( mFrameSize.height() ) );
 
  280   annotationElem.setAttribute( QStringLiteral( 
"canvasPosX" ), 
qgsDoubleToString( mRelativePosition.x() ) );
 
  281   annotationElem.setAttribute( QStringLiteral( 
"canvasPosY" ), 
qgsDoubleToString( mRelativePosition.y() ) );
 
  282   annotationElem.setAttribute( QStringLiteral( 
"contentsMargin" ), mContentsMargins.
toString() );
 
  283   annotationElem.setAttribute( QStringLiteral( 
"visible" ), 
isVisible() );
 
  286     annotationElem.setAttribute( QStringLiteral( 
"mapLayer" ), mMapLayer->id() );
 
  291     if ( !symbolElem.isNull() )
 
  293       annotationElem.appendChild( symbolElem );
 
  298     QDomElement fillElem = doc.createElement( QStringLiteral( 
"fillSymbol" ) );
 
  300     if ( !symbolElem.isNull() )
 
  302       fillElem.appendChild( symbolElem );
 
  303       annotationElem.appendChild( fillElem );
 
  306   itemElem.appendChild( annotationElem );
 
  311   if ( annotationElem.isNull() )
 
  316   pos.setX( annotationElem.attribute( QStringLiteral( 
"canvasPosX" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  317   pos.setY( annotationElem.attribute( QStringLiteral( 
"canvasPosY" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  318   if ( pos.x() >= 1 || pos.x() < 0 || pos.y() < 0 || pos.y() >= 1 )
 
  319     mRelativePosition = QPointF();
 
  321     mRelativePosition = pos;
 
  323   mapPos.
setX( annotationElem.attribute( QStringLiteral( 
"mapPosX" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  324   mapPos.
setY( annotationElem.attribute( QStringLiteral( 
"mapPosY" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  325   mMapPosition = mapPos;
 
  327   if ( !mMapPositionCrs.
readXml( annotationElem ) )
 
  332   mContentsMargins = 
QgsMargins::fromString( annotationElem.attribute( QStringLiteral( 
"contentsMargin" ) ) );
 
  334   if ( annotationElem.hasAttribute( QStringLiteral( 
"frameWidthMM" ) ) )
 
  335     mFrameSize.setWidth( annotationElem.attribute( QStringLiteral( 
"frameWidthMM" ), QStringLiteral( 
"5" ) ).toDouble() );
 
  337     mFrameSize.setWidth( dpiScale * annotationElem.attribute( QStringLiteral( 
"frameWidth" ), QStringLiteral( 
"50" ) ).toDouble() );
 
  338   if ( annotationElem.hasAttribute( QStringLiteral( 
"frameHeightMM" ) ) )
 
  339     mFrameSize.setHeight( annotationElem.attribute( QStringLiteral( 
"frameHeightMM" ), QStringLiteral( 
"3" ) ).toDouble() );
 
  341     mFrameSize.setHeight( dpiScale * annotationElem.attribute( QStringLiteral( 
"frameHeight" ), QStringLiteral( 
"50" ) ).toDouble() );
 
  343   if ( annotationElem.hasAttribute( QStringLiteral( 
"offsetXMM" ) ) )
 
  344     mOffsetFromReferencePoint.setX( annotationElem.attribute( QStringLiteral( 
"offsetXMM" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  346     mOffsetFromReferencePoint.setX( dpiScale * annotationElem.attribute( QStringLiteral( 
"offsetX" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  347   if ( annotationElem.hasAttribute( QStringLiteral( 
"offsetYMM" ) ) )
 
  348     mOffsetFromReferencePoint.setY( annotationElem.attribute( QStringLiteral( 
"offsetYMM" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  350     mOffsetFromReferencePoint.setY( dpiScale * annotationElem.attribute( QStringLiteral( 
"offsetY" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  352   mHasFixedMapPosition = annotationElem.attribute( QStringLiteral( 
"mapPositionFixed" ), QStringLiteral( 
"1" ) ).toInt();
 
  353   mVisible = annotationElem.attribute( QStringLiteral( 
"visible" ), QStringLiteral( 
"1" ) ).toInt();
 
  354   if ( annotationElem.hasAttribute( QStringLiteral( 
"mapLayer" ) ) )
 
  361     QDomElement symbolElem = annotationElem.firstChildElement( QStringLiteral( 
"symbol" ) );
 
  362     if ( !symbolElem.isNull() )
 
  364       QgsMarkerSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context );
 
  367         mMarkerSymbol.reset( symbol );
 
  372   mFillSymbol.reset( 
nullptr );
 
  373   QDomElement fillElem = annotationElem.firstChildElement( QStringLiteral( 
"fillSymbol" ) );
 
  374   if ( !fillElem.isNull() )
 
  376     QDomElement symbolElem = fillElem.firstChildElement( QStringLiteral( 
"symbol" ) );
 
  377     if ( !symbolElem.isNull() )
 
  379       QgsFillSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context );
 
  382         mFillSymbol.reset( symbol );
 
  389     frameColor.setNamedColor( annotationElem.attribute( QStringLiteral( 
"frameColor" ), QStringLiteral( 
"#000000" ) ) );
 
  390     frameColor.setAlpha( annotationElem.attribute( QStringLiteral( 
"frameColorAlpha" ), QStringLiteral( 
"255" ) ).toInt() );
 
  391     QColor frameBackgroundColor;
 
  392     frameBackgroundColor.setNamedColor( annotationElem.attribute( QStringLiteral( 
"frameBackgroundColor" ) ) );
 
  393     frameBackgroundColor.setAlpha( annotationElem.attribute( QStringLiteral( 
"frameBackgroundColorAlpha" ), QStringLiteral( 
"255" ) ).toInt() );
 
  394     double frameBorderWidth = annotationElem.attribute( QStringLiteral( 
"frameBorderWidth" ), QStringLiteral( 
"0.5" ) ).toDouble();
 
  396     frameBorderWidth = frameBorderWidth * 25.4 / 96.0;
 
  398     props.insert( QStringLiteral( 
"color" ), frameBackgroundColor.name() );
 
  399     props.insert( QStringLiteral( 
"style" ), QStringLiteral( 
"solid" ) );
 
  400     props.insert( QStringLiteral( 
"style_border" ), QStringLiteral( 
"solid" ) );
 
  401     props.insert( QStringLiteral( 
"color_border" ), frameColor.name() );
 
  402     props.insert( QStringLiteral( 
"width_border" ), QString::number( frameBorderWidth ) );
 
  403     props.insert( QStringLiteral( 
"joinstyle" ), QStringLiteral( 
"miter" ) );
 
  412   target->mVisible = mVisible;
 
  413   target->mHasFixedMapPosition = mHasFixedMapPosition;
 
  414   target->mMapPosition = mMapPosition;
 
  415   target->mMapPositionCrs = mMapPositionCrs;
 
  416   target->mRelativePosition = mRelativePosition;
 
  417   target->mOffsetFromReferencePoint = mOffsetFromReferencePoint;
 
  418   target->mFrameSize = mFrameSize;
 
  419   target->mMarkerSymbol.reset( mMarkerSymbol ? mMarkerSymbol->clone() : 
nullptr );
 
  420   target->mContentsMargins = mContentsMargins;
 
  421   target->mFillSymbol.reset( mFillSymbol ? mFillSymbol->clone() : 
nullptr );
 
  422   target->mSegmentPointWidthMm = mSegmentPointWidthMm;
 
  423   target->mMapLayer = mMapLayer;
 
  424   target->mFeature = mFeature;
 
Abstract base class for annotation items which are drawn over a map.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
Q_DECL_DEPRECATED void setFrameSize(QSizeF size)
Sets the size (in pixels) of the annotation's frame (the main area in which the annotation's content ...
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for rendering the annotation frame.
Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint(QPointF offset)
Sets the annotation's frame's offset (in pixels) from the mapPosition() reference point.
void setRelativePosition(QPointF position)
Sets the relative position of the annotation, if it is not attached to a fixed map position.
virtual void renderAnnotation(QgsRenderContext &context, QSizeF size) const =0
Renders the annotation's contents to a target /a context at the specified /a size.
void setMapPosition(const QgsPointXY &position)
Sets the map position of the annotation, if it is attached to a fixed map position.
void moved()
Emitted when the annotation's position has changed and items need to be moved to reflect this.
Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const
Returns the annotation's frame's offset (in pixels) from the mapPosition() reference point.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated within ...
void setContentsMargin(const QgsMargins &margins)
Sets the margins (in millimeters) between the outside of the frame and the annotation content.
void setFrameSizeMm(QSizeF size)
Sets the size (in millimeters) of the annotation's frame (the main area in which the annotation's con...
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
void setFrameOffsetFromReferencePointMm(QPointF offset)
Sets the annotation's frame's offset (in millimeters) from the mapPosition() reference point.
void setMapPositionCrs(const QgsCoordinateReferenceSystem &crs)
Sets the CRS of the map position.
~QgsAnnotation() override
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
void render(QgsRenderContext &context) const
Renders the annotation to a target render context.
virtual QSizeF minimumFrameSize() const
Returns the minimum frame size for the annotation.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
void setHasFixedMapPosition(bool fixed)
Sets whether the annotation is attached to a fixed map position, or uses a position relative to the c...
QgsAnnotation(QObject *parent=nullptr)
Constructor for QgsAnnotation.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the symbol that is drawn at the annotation's map position.
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
void setVisible(bool visible)
Sets whether the annotation is visible and should be rendered.
void mapLayerChanged()
Emitted when the map layer associated with the annotation changes.
void setMapLayer(QgsMapLayer *layer)
Sets the map layer associated with the annotation.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
Base class for all map layer types.
The QgsMargins class defines the four margins of a rectangle.
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.
A marker symbol type, for rendering Point and MultiPoint geometries.
A class to represent a 2D point.
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Scoped object for saving and restoring a QPainter object's state.
static QPolygonF createBalloon(const QgsPointXY &origin, const QRectF &rect, double wedgeWidth)
Generates a "balloon"/"talking bubble" style shape (as a QPolygonF).
An interface for classes which can visit style entity (e.g.
@ Annotation
An individual annotation.
virtual bool visitExit(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor stops visiting a node.
virtual bool visitEnter(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor starts visiting a node.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A symbol entity for QgsStyle databases.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
@ RenderMillimeters
Millimeters.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Q_GUI_EXPORT int qt_defaultDpiX()
const QgsCoordinateReferenceSystem & crs
Contains information relating to a node (i.e.
Contains information relating to the style entity currently being visited.