QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsannotationitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotationitem.h
3  ------------------------
4  begin : February 9, 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco dot hugentobler at hugis dot net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSANNOTATIONITEM_H
19 #define QGSANNOTATIONITEM_H
20 
21 #include "qgsmapcanvasitem.h"
23 #include "qgsannotation.h"
24 
25 class QDomDocument;
26 class QDomElement;
27 class QDialog;
28 class QgsVectorLayer;
29 class QgsMarkerSymbolV2;
30 
35 class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem, public QgsAnnotation
36 {
37  public:
39  {
50  ResizeFrameRightDown
51  };
52 
53  QgsAnnotationItem( QgsMapCanvas* mapCanvas );
54  virtual ~QgsAnnotationItem();
55 
56  void updatePosition() override;
57 
58  QRectF boundingRect() const override;
59 
60  virtual QSizeF minimumFrameSize() const;
61 
64  QgsAnnotationItem::MouseMoveAction moveActionForPosition( QPointF pos ) const;
66  Qt::CursorShape cursorShapeForAction( MouseMoveAction moveAction ) const;
67 
68  //setters and getters
69  void setMapPositionFixed( bool fixed );
70  bool mapPositionFixed() const override { return mMapPositionFixed; }
71 
72  virtual void setMapPosition( const QgsPoint& pos );
73  QgsPoint mapPosition() const override { return mMapPosition; }
74 
75  virtual QPointF relativePosition() const override;
76 
77  virtual double scaleFactor() const override;
78 
79  virtual bool showItem() const override { return isVisible(); }
80 
83  virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
85  QgsCoordinateReferenceSystem mapPositionCrs() const override { return mMapPositionCrs; }
86 
87  void setFrameSize( QSizeF size );
88  QSizeF frameSize() const { return mFrameSize; }
89 
90  void setOffsetFromReferencePoint( QPointF offset );
91  QPointF offsetFromReferencePoint() const { return mOffsetFromReferencePoint; }
92 
94  void setMarkerSymbol( QgsMarkerSymbolV2* symbol );
95  const QgsMarkerSymbolV2* markerSymbol() const {return mMarkerSymbol;}
96 
97  void setFrameBorderWidth( double w ) { mFrameBorderWidth = w; }
98  double frameBorderWidth() const { return mFrameBorderWidth; }
99 
100  void setFrameColor( const QColor& c ) { mFrameColor = c; }
101  QColor frameColor() const { return mFrameColor; }
102 
103  void setFrameBackgroundColor( const QColor& c ) { mFrameBackgroundColor = c; }
104  QColor frameBackgroundColor() const { return mFrameBackgroundColor; }
105 
106  virtual void writeXML( QDomDocument& doc ) const = 0;
107  virtual void readXML( const QDomDocument& doc, const QDomElement& itemElem ) = 0;
108 
109  void _writeXML( QDomDocument& doc, QDomElement& itemElem ) const;
110  void _readXML( const QDomDocument& doc, const QDomElement& annotationElem );
111 
112  virtual void setItemData( int role, const QVariant& value ) override;
113 
114  virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override;
115 
116  void paint( QPainter* painter ) override;
117 
118  protected:
125 
128 
133 
141 
148 
149  void updateBoundingRect();
151  void updateBalloon();
152 
154  void drawFrame( QPainter* p ) const;
155 
157  void drawMarkerSymbol( QPainter* p ) const;
158 
160  void drawSelectionBoxes( QPainter* p ) const;
161 
163  //double scaledFrameWidth( QPainter* p) const;
165  QLineF segment( int index ) const;
167  QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance ) const;
169  double scaledSymbolSize() const;
170 };
171 
172 #endif // QGSANNOTATIONITEM_H
QgsPoint mapPosition() const override
Returns the map position of the annotation, if it is attached to a fixed map position.
static unsigned index
QgsMarkerSymbolV2 * mMarkerSymbol
Point symbol that is to be drawn at the map reference location.
QColor frameColor() const
double mFrameBorderWidth
Width of the frame.
virtual void setItemData(int role, const QVariant &value)=0
deprecated - do not use
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
An abstract class for items that can be placed on the map canvas.
QSizeF frameSize() const
virtual double scaleFactor() const =0
Returns a scaling factor which should be applied to painters before rendering the item...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
An interface for annotation items which are drawn over a map.
Definition: qgsannotation.h:40
void setFrameColor(const QColor &c)
QRectF mBoundingRect
Bounding rect (including item frame and balloon)
virtual bool showItem() const override
Returns true if the annotation should be shown.
virtual QRectF boundingRect() const override
default implementation for canvas items
QPointF mBalloonSegmentPoint1
First segment point for drawing the connection (ccw direction)
void setFrameBorderWidth(double w)
const QgsMarkerSymbolV2 * markerSymbol() const
virtual QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Definition: qgsannotation.h:73
int mBalloonSegment
Segment number where the connection to the map point is attached.
QgsCoordinateReferenceSystem mapPositionCrs() const override
Returns the CRS of the map position.
A class to represent a point.
Definition: qgspoint.h:117
bool mapPositionFixed() const override
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
QgsCoordinateReferenceSystem mMapPositionCrs
CRS of the map position.
An annotation item can be either placed either on screen corrdinates or on map coordinates.
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
QColor mFrameColor
Frame / balloon color.
bool isVisible() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)=0
Paint the annotation to a destination painter.
QColor frameBackgroundColor() const
double frameBorderWidth() const
Class for storing a coordinate reference system (CRS)
QPointF mBalloonSegmentPoint2
Second segment point for drawing the balloon connection (ccw direction)
QPointF offsetFromReferencePoint() const
Represents a vector layer which manages a vector based data sets.
QgsPoint mMapPosition
Map position (in case mMapPositionFixed is true)
virtual void updatePosition()
called on changed extent or resize event to update position of the item
QSizeF mFrameSize
Size of the frame (without balloon)
void setFrameBackgroundColor(const QColor &c)