QGIS API Documentation  2.99.0-Master (c558d51)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsAnnotationItem Class Referenceabstract

An annotation item can be either placed either on screen corrdinates or on map coordinates. More...

#include <qgsannotationitem.h>

Inheritance diagram for QgsAnnotationItem:
Inheritance graph
[legend]

Public Types

enum  MouseMoveAction {
  NoAction, MoveMapPosition, MoveFramePosition, ResizeFrameUp,
  ResizeFrameDown, ResizeFrameLeft, ResizeFrameRight, ResizeFrameLeftUp,
  ResizeFrameRightUp, ResizeFrameLeftDown, ResizeFrameRightDown
}
 

Public Member Functions

 QgsAnnotationItem (QgsMapCanvas *mapCanvas)
 
virtual ~QgsAnnotationItem ()
 
void _readXml (const QDomDocument &doc, const QDomElement &annotationElem)
 Deserialize from XML. More...
 
void _writeXml (QDomDocument &doc, QDomElement &itemElem) const
 Serialize to XML. More...
 
QRectF boundingRect () const override
 default implementation for canvas items More...
 
Qt::CursorShape cursorShapeForAction (MouseMoveAction moveAction) const
 Returns suitable cursor shape for mouse move action. More...
 
QColor frameBackgroundColor () const
 
double frameBorderWidth () const
 
QColor frameColor () const
 
QSizeF frameSize () const
 
bool hasFixedMapPosition () const override
 Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a position relative to the current map extent. More...
 
QgsPoint mapPosition () const override
 Returns the map position of the annotation, if it is attached to a fixed map position. More...
 
QgsCoordinateReferenceSystem mapPositionCrs () const override
 Returns the CRS of the map position. More...
 
const QgsMarkerSymbolmarkerSymbol () const
 
virtual QSizeF minimumFrameSize () const
 
QgsAnnotationItem::MouseMoveAction moveActionForPosition (QPointF pos) const
 Returns the mouse move behaviour for a given position. More...
 
QPointF offsetFromReferencePoint () const
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
 Paint the annotation to a destination painter. More...
 
void paint (QPainter *painter) override
 function to be implemented by derived classes More...
 
virtual void readXml (const QDomDocument &doc, const QDomElement &itemElem)=0
 Deserialize from XML. More...
 
virtual QPointF relativePosition () const override
 Returns the relative position of the annotation, if it is not attached to a fixed map position. More...
 
virtual double scaleFactor () const override
 Returns a scaling factor which should be applied to painters before rendering the item. More...
 
void setFrameBackgroundColor (const QColor &c)
 
void setFrameBorderWidth (double w)
 
void setFrameColor (const QColor &c)
 
void setFrameSize (QSizeF size)
 
virtual void setItemData (int role, const QVariant &value) override
 deprecated - do not use More...
 
virtual void setMapPosition (const QgsPoint &pos)
 
virtual void setMapPositionCrs (const QgsCoordinateReferenceSystem &crs)
 Sets the CRS of the map position. More...
 
void setMapPositionFixed (bool fixed)
 
void setMarkerSymbol (QgsMarkerSymbol *symbol)
 Set symbol that is drawn on map position. Takes ownership. More...
 
void setOffsetFromReferencePoint (QPointF offset)
 
virtual bool showItem () const override
 Returns true if the annotation should be shown. More...
 
void updatePosition () override
 called on changed extent or resize event to update position of the item More...
 
virtual void writeXml (QDomDocument &doc) const =0
 Serialize to XML. More...
 
- Public Member Functions inherited from QgsMapCanvasItem
QgsRectangle rect () const
 returns canvas item rectangle in map units More...
 
void setRect (const QgsRectangle &r, bool resetRotation=true)
 sets canvas item rectangle in map units More...
 
QPointF toCanvasCoordinates (const QgsPoint &point) const
 transformation from map coordinates to screen coordinates More...
 
QgsPoint toMapCoordinates (QPoint point) const
 transformation from screen coordinates to map coordinates More...
 

Protected Member Functions

void drawFrame (QPainter *p) const
 Draws the annotation frame to a destination painter. More...
 
void drawMarkerSymbol (QPainter *p) const
 Draws the map position marker symbol to a destination painter. More...
 
void drawSelectionBoxes (QPainter *p) const
 Draws selection handles around the item. More...
 
QPointF pointOnLineWithDistance (QPointF startPoint, QPointF directionPoint, double distance) const
 Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point. More...
 
double scaledSymbolSize () const
 Returns the symbol size scaled in (mapcanvas) pixels. Used for the counding rect calculation. More...
 
QLineF segment (int index) const
 Returns frame width in painter units. More...
 
void updateBalloon ()
 Check where to attach the balloon connection between frame and map point. More...
 
void updateBoundingRect ()
 
- Protected Member Functions inherited from QgsMapCanvasItem
 QgsMapCanvasItem (QgsMapCanvas *mapCanvas)
 protected constructor: cannot be constructed directly More...
 
virtual ~QgsMapCanvasItem ()
 
bool setRenderContextVariables (QPainter *p, QgsRenderContext &context) const
 Sets render context parameters. More...
 
void updateCanvas ()
 schedules map canvas for repaint More...
 

Protected Attributes

int mBalloonSegment
 Segment number where the connection to the map point is attached. -1 if no balloon needed (e.g. if point is contained in frame) More...
 
QPointF mBalloonSegmentPoint1
 First segment point for drawing the connection (ccw direction) More...
 
QPointF mBalloonSegmentPoint2
 Second segment point for drawing the balloon connection (ccw direction) More...
 
QRectF mBoundingRect
 Bounding rect (including item frame and balloon) More...
 
QColor mFrameBackgroundColor
 
double mFrameBorderWidth
 Width of the frame. More...
 
QColor mFrameColor
 Frame / balloon color. More...
 
QSizeF mFrameSize
 Size of the frame (without balloon) More...
 
QgsPoint mMapPosition
 Map position (in case mMapPositionFixed is true) More...
 
QgsCoordinateReferenceSystem mMapPositionCrs
 CRS of the map position. More...
 
bool mMapPositionFixed
 True: the item stays at the same map position, False: the item stays on same screen position. More...
 
QgsMarkerSymbolmMarkerSymbol
 Point symbol that is to be drawn at the map reference location. More...
 
QPointF mOffsetFromReferencePoint
 Describes the shift of the item content box to the reference point. More...
 
- Protected Attributes inherited from QgsMapCanvasItem
QSizeF mItemSize
 cached size of the item (to return in boundingRect()) More...
 
QgsMapCanvasmMapCanvas
 pointer to map canvas More...
 
QgsRectangle mRect
 cached canvas item rectangle in map coordinates encodes position (xmin,ymax) and size (width/height) used to re-position and re-size the item on zoom/pan while waiting for the renderer to complete. More...
 
double mRectRotation
 

Detailed Description

An annotation item can be either placed either on screen corrdinates or on map coordinates.

It may reference a feature and displays that associatiation with a balloon like appearance

Definition at line 35 of file qgsannotationitem.h.

Member Enumeration Documentation

Enumerator
NoAction 
MoveMapPosition 
MoveFramePosition 
ResizeFrameUp 
ResizeFrameDown 
ResizeFrameLeft 
ResizeFrameRight 
ResizeFrameLeftUp 
ResizeFrameRightUp 
ResizeFrameLeftDown 
ResizeFrameRightDown 

Definition at line 38 of file qgsannotationitem.h.

Constructor & Destructor Documentation

QgsAnnotationItem::QgsAnnotationItem ( QgsMapCanvas mapCanvas)

Definition at line 26 of file qgsannotationitem.cpp.

QgsAnnotationItem::~QgsAnnotationItem ( )
virtual

Definition at line 41 of file qgsannotationitem.cpp.

Member Function Documentation

void QgsAnnotationItem::_readXml ( const QDomDocument &  doc,
const QDomElement &  annotationElem 
)

Deserialize from XML.

The itemElem is used as source for the information. Should be called from subclasses in their readXml method.

Definition at line 445 of file qgsannotationitem.cpp.

void QgsAnnotationItem::_writeXml ( QDomDocument &  doc,
QDomElement &  itemElem 
) const

Serialize to XML.

The doc is used to generate new nodes. Should be called by subclasses in their writeXml method.

Definition at line 409 of file qgsannotationitem.cpp.

QRectF QgsAnnotationItem::boundingRect ( ) const
overridevirtual

default implementation for canvas items

Reimplemented from QgsMapCanvasItem.

Definition at line 117 of file qgsannotationitem.cpp.

Qt::CursorShape QgsAnnotationItem::cursorShapeForAction ( MouseMoveAction  moveAction) const

Returns suitable cursor shape for mouse move action.

Definition at line 367 of file qgsannotationitem.cpp.

void QgsAnnotationItem::drawFrame ( QPainter *  p) const
protected

Draws the annotation frame to a destination painter.

Definition at line 201 of file qgsannotationitem.cpp.

void QgsAnnotationItem::drawMarkerSymbol ( QPainter *  p) const
protected

Draws the map position marker symbol to a destination painter.

Definition at line 235 of file qgsannotationitem.cpp.

void QgsAnnotationItem::drawSelectionBoxes ( QPainter *  p) const
protected

Draws selection handles around the item.

Definition at line 256 of file qgsannotationitem.cpp.

QColor QgsAnnotationItem::frameBackgroundColor ( ) const
inline

Definition at line 104 of file qgsannotationitem.h.

double QgsAnnotationItem::frameBorderWidth ( ) const
inline

Definition at line 98 of file qgsannotationitem.h.

QColor QgsAnnotationItem::frameColor ( ) const
inline

Definition at line 101 of file qgsannotationitem.h.

QSizeF QgsAnnotationItem::frameSize ( ) const
inline

Definition at line 88 of file qgsannotationitem.h.

bool QgsAnnotationItem::hasFixedMapPosition ( ) const
inlineoverridevirtual

Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a position relative to the current map extent.

See also
mapPosition()
relativePositon()

Implements QgsAnnotation.

Definition at line 70 of file qgsannotationitem.h.

QgsPoint QgsAnnotationItem::mapPosition ( ) const
inlineoverridevirtual

Returns the map position of the annotation, if it is attached to a fixed map position.

See also
mapPositionFixed()
mapPositionCrs()

Reimplemented from QgsAnnotation.

Definition at line 73 of file qgsannotationitem.h.

QgsCoordinateReferenceSystem QgsAnnotationItem::mapPositionCrs ( ) const
inlineoverridevirtual

Returns the CRS of the map position.

Reimplemented from QgsAnnotation.

Definition at line 85 of file qgsannotationitem.h.

const QgsMarkerSymbol* QgsAnnotationItem::markerSymbol ( ) const
inline

Definition at line 95 of file qgsannotationitem.h.

QSizeF QgsAnnotationItem::minimumFrameSize ( ) const
virtual

Reimplemented in QgsHtmlAnnotationItem, and QgsFormAnnotationItem.

Definition at line 122 of file qgsannotationitem.cpp.

QgsAnnotationItem::MouseMoveAction QgsAnnotationItem::moveActionForPosition ( QPointF  pos) const

Returns the mouse move behaviour for a given position.

Parameters
posthe position in scene coordinates

Definition at line 308 of file qgsannotationitem.cpp.

QPointF QgsAnnotationItem::offsetFromReferencePoint ( ) const
inline

Definition at line 91 of file qgsannotationitem.h.

void QgsAnnotationItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget = nullptr 
)
overridevirtual

Paint the annotation to a destination painter.

Implements QgsAnnotation.

Reimplemented in QgsHtmlAnnotationItem, and QgsFormAnnotationItem.

Definition at line 499 of file qgsannotationitem.cpp.

void QgsAnnotationItem::paint ( QPainter *  painter)
overridevirtual

function to be implemented by derived classes

Implements QgsMapCanvasItem.

Reimplemented in QgsTextAnnotationItem, QgsHtmlAnnotationItem, QgsSvgAnnotationItem, and QgsFormAnnotationItem.

Definition at line 505 of file qgsannotationitem.cpp.

QPointF QgsAnnotationItem::pointOnLineWithDistance ( QPointF  startPoint,
QPointF  directionPoint,
double  distance 
) const
protected

Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point.

Definition at line 299 of file qgsannotationitem.cpp.

virtual void QgsAnnotationItem::readXml ( const QDomDocument &  doc,
const QDomElement &  itemElem 
)
pure virtual

Deserialize from XML.

The itemElem is used as source for the information. Needs to be reimplemented by subclasses

Implemented in QgsFormAnnotationItem, QgsHtmlAnnotationItem, QgsTextAnnotationItem, and QgsSvgAnnotationItem.

QPointF QgsAnnotationItem::relativePosition ( ) const
overridevirtual

Returns the relative position of the annotation, if it is not attached to a fixed map position.

The coordinates in the return point should be between 0 and 1, and represent the relative percentage for the position compared to the map width and height.

See also
mapPositionFixed()

Reimplemented from QgsAnnotation.

Definition at line 61 of file qgsannotationitem.cpp.

double QgsAnnotationItem::scaledSymbolSize ( ) const
protected

Returns the symbol size scaled in (mapcanvas) pixels. Used for the counding rect calculation.

Definition at line 393 of file qgsannotationitem.cpp.

double QgsAnnotationItem::scaleFactor ( ) const
overridevirtual

Returns a scaling factor which should be applied to painters before rendering the item.

Implements QgsAnnotation.

Definition at line 68 of file qgsannotationitem.cpp.

QLineF QgsAnnotationItem::segment ( int  index) const
protected

Returns frame width in painter units.

Gets the frame line (0 is the top line, 1 right, 2 bottom, 3 left)

Definition at line 278 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setFrameBackgroundColor ( const QColor &  c)
inline

Definition at line 103 of file qgsannotationitem.h.

void QgsAnnotationItem::setFrameBorderWidth ( double  w)
inline

Definition at line 97 of file qgsannotationitem.h.

void QgsAnnotationItem::setFrameColor ( const QColor &  c)
inline

Definition at line 100 of file qgsannotationitem.h.

void QgsAnnotationItem::setFrameSize ( QSizeF  size)

Definition at line 227 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setItemData ( int  role,
const QVariant &  value 
)
overridevirtual

deprecated - do not use

Implements QgsAnnotation.

Definition at line 494 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setMapPosition ( const QgsPoint pos)
virtual

Reimplemented in QgsFormAnnotationItem, and QgsHtmlAnnotationItem.

Definition at line 53 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setMapPositionCrs ( const QgsCoordinateReferenceSystem crs)
virtual

Sets the CRS of the map position.

Parameters
crsthe CRS to set

Definition at line 73 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setMapPositionFixed ( bool  fixed)

Definition at line 85 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setMarkerSymbol ( QgsMarkerSymbol symbol)

Set symbol that is drawn on map position. Takes ownership.

Definition at line 46 of file qgsannotationitem.cpp.

void QgsAnnotationItem::setOffsetFromReferencePoint ( QPointF  offset)

Definition at line 78 of file qgsannotationitem.cpp.

virtual bool QgsAnnotationItem::showItem ( ) const
inlineoverridevirtual

Returns true if the annotation should be shown.

Implements QgsAnnotation.

Definition at line 79 of file qgsannotationitem.h.

void QgsAnnotationItem::updateBalloon ( )
protected

Check where to attach the balloon connection between frame and map point.

Definition at line 143 of file qgsannotationitem.cpp.

void QgsAnnotationItem::updateBoundingRect ( )
protected

Definition at line 127 of file qgsannotationitem.cpp.

void QgsAnnotationItem::updatePosition ( )
overridevirtual

called on changed extent or resize event to update position of the item

Reimplemented from QgsMapCanvasItem.

Definition at line 104 of file qgsannotationitem.cpp.

virtual void QgsAnnotationItem::writeXml ( QDomDocument &  doc) const
pure virtual

Serialize to XML.

The doc is used to generate new nodes. Needs to be reimplemented by subclasses.

Implemented in QgsFormAnnotationItem, QgsHtmlAnnotationItem, QgsTextAnnotationItem, and QgsSvgAnnotationItem.

Member Data Documentation

int QgsAnnotationItem::mBalloonSegment
protected

Segment number where the connection to the map point is attached. -1 if no balloon needed (e.g. if point is contained in frame)

Definition at line 161 of file qgsannotationitem.h.

QPointF QgsAnnotationItem::mBalloonSegmentPoint1
protected

First segment point for drawing the connection (ccw direction)

Definition at line 163 of file qgsannotationitem.h.

QPointF QgsAnnotationItem::mBalloonSegmentPoint2
protected

Second segment point for drawing the balloon connection (ccw direction)

Definition at line 165 of file qgsannotationitem.h.

QRectF QgsAnnotationItem::mBoundingRect
protected

Bounding rect (including item frame and balloon)

Definition at line 150 of file qgsannotationitem.h.

QColor QgsAnnotationItem::mFrameBackgroundColor
protected

Definition at line 158 of file qgsannotationitem.h.

double QgsAnnotationItem::mFrameBorderWidth
protected

Width of the frame.

Definition at line 155 of file qgsannotationitem.h.

QColor QgsAnnotationItem::mFrameColor
protected

Frame / balloon color.

Definition at line 157 of file qgsannotationitem.h.

QSizeF QgsAnnotationItem::mFrameSize
protected

Size of the frame (without balloon)

Definition at line 148 of file qgsannotationitem.h.

QgsPoint QgsAnnotationItem::mMapPosition
protected

Map position (in case mMapPositionFixed is true)

Definition at line 140 of file qgsannotationitem.h.

QgsCoordinateReferenceSystem QgsAnnotationItem::mMapPositionCrs
protected

CRS of the map position.

Definition at line 142 of file qgsannotationitem.h.

bool QgsAnnotationItem::mMapPositionFixed
protected

True: the item stays at the same map position, False: the item stays on same screen position.

Definition at line 138 of file qgsannotationitem.h.

QgsMarkerSymbol* QgsAnnotationItem::mMarkerSymbol
protected

Point symbol that is to be drawn at the map reference location.

Definition at line 153 of file qgsannotationitem.h.

QPointF QgsAnnotationItem::mOffsetFromReferencePoint
protected

Describes the shift of the item content box to the reference point.

Definition at line 145 of file qgsannotationitem.h.


The documentation for this class was generated from the following files: