QGIS API Documentation  2.99.0-Master (0a63d1f)
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 #include "qgis_gui.h"
25 
26 class QDomDocument;
27 class QDomElement;
28 class QDialog;
29 class QgsVectorLayer;
30 class QgsMarkerSymbol;
31 
36 class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem, public QgsAnnotation
37 {
38  public:
40  {
51  ResizeFrameRightDown
52  };
53 
54  QgsAnnotationItem( QgsMapCanvas* mapCanvas );
55  virtual ~QgsAnnotationItem();
56 
57  void updatePosition() override;
58 
59  QRectF boundingRect() const override;
60 
61  virtual QSizeF minimumFrameSize() const;
62 
65  QgsAnnotationItem::MouseMoveAction moveActionForPosition( QPointF pos ) const;
67  Qt::CursorShape cursorShapeForAction( MouseMoveAction moveAction ) const;
68 
69  //setters and getters
70  void setMapPositionFixed( bool fixed );
71  bool hasFixedMapPosition() const override { return mMapPositionFixed; }
72 
73  virtual void setMapPosition( const QgsPoint& pos );
74  QgsPoint mapPosition() const override { return mMapPosition; }
75  virtual QPointF relativePosition() const override;
76  virtual double scaleFactor() const override;
77  virtual bool showItem() const override { return isVisible(); }
78 
82  virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
83  QgsCoordinateReferenceSystem mapPositionCrs() const override { return mMapPositionCrs; }
84 
85  void setFrameSize( QSizeF size );
86  QSizeF frameSize() const { return mFrameSize; }
87 
88  void setOffsetFromReferencePoint( QPointF offset );
89  QPointF offsetFromReferencePoint() const { return mOffsetFromReferencePoint; }
90 
92  void setMarkerSymbol( QgsMarkerSymbol* symbol );
93  const QgsMarkerSymbol* markerSymbol() const {return mMarkerSymbol;}
94 
95  void setFrameBorderWidth( double w ) { mFrameBorderWidth = w; }
96  double frameBorderWidth() const { return mFrameBorderWidth; }
97 
98  void setFrameColor( const QColor& c ) { mFrameColor = c; }
99  QColor frameColor() const { return mFrameColor; }
100 
101  void setFrameBackgroundColor( const QColor& c ) { mFrameBackgroundColor = c; }
102  QColor frameBackgroundColor() const { return mFrameBackgroundColor; }
103 
108  virtual void writeXml( QDomDocument& doc ) const = 0;
109 
114  virtual void readXml( const QDomDocument& doc, const QDomElement& itemElem ) = 0;
115 
120  void _writeXml( QDomDocument& doc, QDomElement& itemElem ) const;
121 
126  void _readXml( const QDomDocument& doc, const QDomElement& annotationElem );
127 
128  virtual void setItemData( int role, const QVariant& value ) override;
129 
130  virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override;
131 
132  void paint( QPainter* painter ) override;
133 
134  protected:
141 
144 
146  QSizeF mFrameSize;
149 
155  QColor mFrameColor;
157 
164 
165  void updateBoundingRect();
167  void updateBalloon();
168 
170  void drawFrame( QPainter* p ) const;
171 
173  void drawMarkerSymbol( QPainter* p ) const;
174 
176  void drawSelectionBoxes( QPainter* p ) const;
177 
179  //double scaledFrameWidth( QPainter* p) const;
181  QLineF segment( int index ) const;
183  QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance ) const;
185  double scaledSymbolSize() const;
186 };
187 
188 #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
const QgsMarkerSymbol * markerSymbol() const
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:74
An interface for annotation items which are drawn over a map.
Definition: qgsannotation.h:41
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
QPointF mBalloonSegmentPoint1
First segment point for drawing the connection (ccw direction)
void setFrameBorderWidth(double w)
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. -1 if no balloon needed (e...
QgsCoordinateReferenceSystem mapPositionCrs() const override
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
A class to represent a point.
Definition: qgspoint.h:143
QgsCoordinateReferenceSystem mMapPositionCrs
CRS of the map position.
An annotation item can be either placed either on screen corrdinates or on map coordinates.
bool hasFixedMapPosition() const override
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
QColor mFrameColor
Frame / balloon color.
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
This class represents a coordinate reference system (CRS).
QgsMarkerSymbol * mMarkerSymbol
Point symbol that is to be drawn at the map reference location.
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)