QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 "qgssymbol.h"
26 #include "qgsmargins.h"
27 #include "qgsmaplayer.h"
28 
29 class QgsRenderContext;
30 
49 class CORE_EXPORT QgsAnnotation : public QObject
50 {
51 
52 #ifdef SIP_RUN
54  if ( dynamic_cast< QgsTextAnnotation * >( sipCpp ) )
55  sipType = sipType_QgsTextAnnotation;
56  else if ( dynamic_cast< QgsSvgAnnotation * >( sipCpp ) )
57  sipType = sipType_QgsSvgAnnotation;
58  else if ( dynamic_cast< QgsHtmlAnnotation * >( sipCpp ) )
59  sipType = sipType_QgsHtmlAnnotation;
60  else
61  sipType = NULL;
62  SIP_END
63 #endif
64 
65 
66  Q_OBJECT
67  Q_PROPERTY( bool visible READ isVisible WRITE setVisible )
68  Q_PROPERTY( bool hasFixedMapPosition READ hasFixedMapPosition WRITE setHasFixedMapPosition )
69  Q_PROPERTY( QgsPointXY mapPosition READ mapPosition WRITE setMapPosition )
70  Q_PROPERTY( QSizeF frameSize READ frameSize WRITE setFrameSize )
71 
72  public:
73 
77  QgsAnnotation( QObject *parent SIP_TRANSFERTHIS = nullptr );
78 
83  virtual QgsAnnotation *clone() const = 0 SIP_FACTORY;
84 
89  bool isVisible() const { return mVisible; }
90 
95  void setVisible( bool visible );
96 
105  bool hasFixedMapPosition() const { return mHasFixedMapPosition; }
106 
112  void setHasFixedMapPosition( bool fixed );
113 
121  QgsPointXY mapPosition() const { return mMapPosition; }
122 
128  void setMapPosition( const QgsPointXY &position );
129 
135  QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
136 
141  void setMapPositionCrs( const QgsCoordinateReferenceSystem &crs );
142 
149  QPointF relativePosition() const { return mRelativePosition; }
150 
157  void setRelativePosition( QPointF position );
158 
164  Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint( QPointF offset ) SIP_DEPRECATED;
165 
171  Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const SIP_DEPRECATED;
172 
178  void setFrameOffsetFromReferencePointMm( QPointF offset );
179 
185  QPointF frameOffsetFromReferencePointMm() const { return mOffsetFromReferencePoint; }
186 
193  Q_DECL_DEPRECATED void setFrameSize( QSizeF size ) SIP_DEPRECATED;
194 
201  Q_DECL_DEPRECATED QSizeF frameSize() const SIP_DEPRECATED;
202 
209  void setFrameSizeMm( QSizeF size );
210 
217  QSizeF frameSizeMm() const { return mFrameSize; }
218 
224  void setContentsMargin( const QgsMargins &margins );
225 
231  QgsMargins contentsMargin() const { return mContentsMargins; }
232 
238  void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
239 
244  QgsFillSymbol *fillSymbol() const { return mFillSymbol.get(); }
245 
249  void render( QgsRenderContext &context ) const;
250 
257  virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
258 
265  virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) = 0;
266 
272  void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
273 
278  QgsMarkerSymbol *markerSymbol() const { return mMarkerSymbol.get(); }
279 
286  QgsMapLayer *mapLayer() const { return mMapLayer.data(); }
287 
294  void setMapLayer( QgsMapLayer *layer );
295 
301  QgsFeature associatedFeature() const { return mFeature; }
302 
307  virtual void setAssociatedFeature( const QgsFeature &feature );
308 
309  signals:
310 
312  void appearanceChanged();
313 
318  void moved();
319 
323  void mapLayerChanged();
324 
325  protected:
326 
331  virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
332 
337  virtual QSizeF minimumFrameSize() const;
338 
345  void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
346 
353  void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
354 
361  void copyCommonProperties( QgsAnnotation *target ) const;
362 
363  private:
364 
366  void updateBalloon();
367 
369  QLineF segment( int index, QgsRenderContext *context ) const;
370 
372  void drawFrame( QgsRenderContext &context ) const;
373 
375  void drawMarkerSymbol( QgsRenderContext &context ) const;
376 
377  bool mVisible = true;
378 
380  bool mHasFixedMapPosition = true;
381 
383  QgsPointXY mMapPosition;
384 
386  QgsCoordinateReferenceSystem mMapPositionCrs;
387 
389  QPointF mRelativePosition;
390 
392  QPointF mOffsetFromReferencePoint = QPointF( 13, -13 );
393 
395  QSizeF mFrameSize;
396 
398  std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
399 
400  QgsMargins mContentsMargins;
401 
403  std::unique_ptr<QgsFillSymbol> mFillSymbol;
404 
406  int mBalloonSegment = -1;
407 
409  QPointF mBalloonSegmentPoint1;
410 
412  QPointF mBalloonSegmentPoint2;
413 
415  QgsWeakMapLayerPointer mMapLayer;
416 
418  QgsFeature mFeature;
419 
421  double mSegmentPointWidthMm = 2.64;
422 
423 };
424 
425 #endif // QGSANNOTATION_H
426 
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:78
#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:1576
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:766
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Abstract base class for annotation items which are drawn over a map.
Definition: qgsannotation.h:49
QgsPointXY mapPosition() const
Returns the map position of the annotation, if it is attached to a fixed map position.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content...
QPointF frameOffsetFromReferencePointMm() const
Returns the annotation&#39;s frame&#39;s offset (in millimeters) from the mapPosition() reference point...
#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
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation&#39;s map position.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
Contains information about the context of a rendering operation.
This class represents a coordinate reference system (CRS).
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
QSizeF frameSizeMm() const
Returns the size (in millimeters) of the annotation&#39;s frame (the main area in which the annotation&#39;s ...
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set...
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1061
bool hasFixedMapPosition() const
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37