QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
318  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
319 
320  signals:
321 
323  void appearanceChanged();
324 
329  void moved();
330 
334  void mapLayerChanged();
335 
336  protected:
337 
342  virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
343 
348  virtual QSizeF minimumFrameSize() const;
349 
356  void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
357 
364  void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
365 
372  void copyCommonProperties( QgsAnnotation *target ) const;
373 
374  private:
375 
377  void updateBalloon();
378 
380  QLineF segment( int index, QgsRenderContext *context ) const;
381 
383  void drawFrame( QgsRenderContext &context ) const;
384 
386  void drawMarkerSymbol( QgsRenderContext &context ) const;
387 
388  bool mVisible = true;
389 
391  bool mHasFixedMapPosition = true;
392 
394  QgsPointXY mMapPosition;
395 
397  QgsCoordinateReferenceSystem mMapPositionCrs;
398 
400  QPointF mRelativePosition;
401 
403  QPointF mOffsetFromReferencePoint = QPointF( 13, -13 );
404 
406  QSizeF mFrameSize;
407 
409  std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
410 
411  QgsMargins mContentsMargins;
412 
414  std::unique_ptr<QgsFillSymbol> mFillSymbol;
415 
417  int mBalloonSegment = -1;
418 
420  QPointF mBalloonSegmentPoint1;
421 
423  QPointF mBalloonSegmentPoint2;
424 
426  QgsWeakMapLayerPointer mMapLayer;
427 
429  QgsFeature mFeature;
430 
432  double mSegmentPointWidthMm = 2.64;
433 
434 };
435 
436 #endif // QGSANNOTATION_H
437 
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:79
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
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
An interface for classes which can visit style entity (e.g.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1632
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:860
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:189
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
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:172
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:1155
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