QGIS API Documentation  2.99.0-Master (c42dad3)
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 QgsMarkerSymbol;
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 hasFixedMapPosition() 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( QgsMarkerSymbol* symbol );
95  const QgsMarkerSymbol* 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 
110  virtual void writeXml( QDomDocument& doc ) const = 0;
111 
116  virtual void readXml( const QDomDocument& doc, const QDomElement& itemElem ) = 0;
117 
122  void _writeXml( QDomDocument& doc, QDomElement& itemElem ) const;
123 
128  void _readXml( const QDomDocument& doc, const QDomElement& annotationElem );
129 
130  virtual void setItemData( int role, const QVariant& value ) override;
131 
132  virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override;
133 
134  void paint( QPainter* painter ) override;
135 
136  protected:
143 
146 
148  QSizeF mFrameSize;
151 
157  QColor mFrameColor;
159 
166 
167  void updateBoundingRect();
169  void updateBalloon();
170 
172  void drawFrame( QPainter* p ) const;
173 
175  void drawMarkerSymbol( QPainter* p ) const;
176 
178  void drawSelectionBoxes( QPainter* p ) const;
179 
181  //double scaledFrameWidth( QPainter* p) const;
183  QLineF segment( int index ) const;
185  QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance ) const;
187  double scaledSymbolSize() const;
188 };
189 
190 #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:106
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)
virtual QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Definition: qgsannotation.h:72
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.
A class to represent a point.
Definition: qgspoint.h:111
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)