QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsannotation.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotation.h
3  ---------------
4  begin : January 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 QGSANNOTATION_H
19 #define QGSANNOTATION_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgspointxy.h"
25 #include "qgsrendercontext.h"
26 #include "qgssymbol.h"
27 #include "qgsmargins.h"
28 #include "qgsmaplayer.h"
29 
48 class CORE_EXPORT QgsAnnotation : public QObject
49 {
50 
51 #ifdef SIP_RUN
53  if ( dynamic_cast< QgsTextAnnotation * >( sipCpp ) )
54  sipType = sipType_QgsTextAnnotation;
55  else if ( dynamic_cast< QgsSvgAnnotation * >( sipCpp ) )
56  sipType = sipType_QgsSvgAnnotation;
57  else if ( dynamic_cast< QgsHtmlAnnotation * >( sipCpp ) )
58  sipType = sipType_QgsHtmlAnnotation;
59  else
60  sipType = NULL;
61  SIP_END
62 #endif
63 
64 
65  Q_OBJECT
66  Q_PROPERTY( bool visible READ isVisible WRITE setVisible )
67  Q_PROPERTY( bool hasFixedMapPosition READ hasFixedMapPosition WRITE setHasFixedMapPosition )
68  Q_PROPERTY( QgsPointXY mapPosition READ mapPosition WRITE setMapPosition )
69  Q_PROPERTY( QSizeF frameSize READ frameSize WRITE setFrameSize )
70 
71  public:
72 
76  QgsAnnotation( QObject *parent SIP_TRANSFERTHIS = nullptr );
77 
82  virtual QgsAnnotation *clone() const = 0 SIP_FACTORY;
83 
88  bool isVisible() const { return mVisible; }
89 
94  void setVisible( bool visible );
95 
104  bool hasFixedMapPosition() const { return mHasFixedMapPosition; }
105 
111  void setHasFixedMapPosition( bool fixed );
112 
120  QgsPointXY mapPosition() const { return mMapPosition; }
121 
127  void setMapPosition( const QgsPointXY &position );
128 
134  QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
135 
140  void setMapPositionCrs( const QgsCoordinateReferenceSystem &crs );
141 
148  QPointF relativePosition() const { return mRelativePosition; }
149 
156  void setRelativePosition( QPointF position );
157 
163  Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint( QPointF offset ) SIP_DEPRECATED;
164 
170  Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const SIP_DEPRECATED;
171 
177  void setFrameOffsetFromReferencePointMm( QPointF offset );
178 
184  QPointF frameOffsetFromReferencePointMm() const { return mOffsetFromReferencePoint; }
185 
192  Q_DECL_DEPRECATED void setFrameSize( QSizeF size ) SIP_DEPRECATED;
193 
200  Q_DECL_DEPRECATED QSizeF frameSize() const SIP_DEPRECATED;
201 
208  void setFrameSizeMm( QSizeF size );
209 
216  QSizeF frameSizeMm() const { return mFrameSize; }
217 
223  void setContentsMargin( const QgsMargins &margins );
224 
230  QgsMargins contentsMargin() const { return mContentsMargins; }
231 
237  void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
238 
243  QgsFillSymbol *fillSymbol() const { return mFillSymbol.get(); }
244 
248  void render( QgsRenderContext &context ) const;
249 
256  virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
257 
264  virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) = 0;
265 
271  void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
272 
277  QgsMarkerSymbol *markerSymbol() const { return mMarkerSymbol.get(); }
278 
285  QgsMapLayer *mapLayer() const { return mMapLayer.data(); }
286 
293  void setMapLayer( QgsMapLayer *layer );
294 
300  QgsFeature associatedFeature() const { return mFeature; }
301 
306  virtual void setAssociatedFeature( const QgsFeature &feature );
307 
308  signals:
309 
311  void appearanceChanged();
312 
317  void moved();
318 
322  void mapLayerChanged();
323 
324  protected:
325 
330  virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
331 
336  virtual QSizeF minimumFrameSize() const;
337 
344  void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
345 
352  void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
353 
360  void copyCommonProperties( QgsAnnotation *target ) const;
361 
362  private:
363 
365  void updateBalloon();
366 
368  QLineF segment( int index, QgsRenderContext *context ) const;
369 
371  void drawFrame( QgsRenderContext &context ) const;
372 
374  void drawMarkerSymbol( QgsRenderContext &context ) const;
375 
376  bool mVisible = true;
377 
379  bool mHasFixedMapPosition = true;
380 
382  QgsPointXY mMapPosition;
383 
385  QgsCoordinateReferenceSystem mMapPositionCrs;
386 
388  QPointF mRelativePosition;
389 
391  QPointF mOffsetFromReferencePoint = QPointF( 13, -13 );
392 
394  QSizeF mFrameSize;
395 
397  std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
398 
399  QgsMargins mContentsMargins;
400 
402  std::unique_ptr<QgsFillSymbol> mFillSymbol;
403 
405  int mBalloonSegment = -1;
406 
408  QPointF mBalloonSegmentPoint1;
409 
411  QPointF mBalloonSegmentPoint2;
412 
414  QgsWeakMapLayerPointer mMapLayer;
415 
417  QgsFeature mFeature;
418 
420  double mSegmentPointWidthMm = 2.64;
421 
422 };
423 
424 #endif // QGSANNOTATION_H
425 
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Definition: qgsmaplayer.h:63
QPointF frameOffsetFromReferencePointMm() const
Returns the annotation&#39;s frame&#39;s offset (in millimeters) from the mapPosition() reference point...
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A class to represent a 2D point.
Definition: qgspointxy.h:43
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1482
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:732
Abstract base class for annotation items which are drawn over a map.
Definition: qgsannotation.h:48
QgsPointXY mapPosition() const
Returns the map position of the annotation, if it is attached to a fixed map position.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
#define SIP_FACTORY
Definition: qgis_sip.h:69
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Contains information about the context of a rendering operation.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content...
This class represents a coordinate reference system (CRS).
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation&#39;s map position.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1003
bool hasFixedMapPosition() const
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
QSizeF frameSizeMm() const
Returns the size (in millimeters) of the annotation&#39;s frame (the main area in which the annotation&#39;s ...