QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
QgsAnnotation::contentsMargin
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
Definition: qgsannotation.h:231
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgis.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsAnnotation::mapLayer
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
Definition: qgsannotation.h:286
QgsSvgAnnotation
Definition: qgssvgannotation.h:31
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QgsAnnotation
Abstract base class for annotation items which are drawn over a map.
Definition: qgsannotation.h:49
QgsAnnotation::fillSymbol
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
Definition: qgsannotation.h:244
QgsMarkerSymbol
Definition: qgssymbol.h:917
QgsAnnotation::associatedFeature
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set.
Definition: qgsannotation.h:301
qgsmaplayer.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMargins
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
QgsWeakMapLayerPointer
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1670
QgsHtmlAnnotation
Definition: qgshtmlannotation.h:35
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsPointXY
Definition: qgspointxy.h:43
QgsAnnotation::markerSymbol
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
Definition: qgsannotation.h:278
QgsTextAnnotation
Definition: qgstextannotation.h:31
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsFillSymbol
Definition: qgssymbol.h:1212
QgsAnnotation::relativePosition
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position.
Definition: qgsannotation.h:149
QgsAnnotation::hasFixedMapPosition
bool hasFixedMapPosition() const
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
Definition: qgsannotation.h:105
QgsAnnotation::mapPositionCrs
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
Definition: qgsannotation.h:135
QgsFeature
Definition: qgsfeature.h:55
QgsAnnotation::mapPosition
QgsPointXY mapPosition() const
Returns the map position of the annotation, if it is attached to a fixed map position.
Definition: qgsannotation.h:121
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
qgssymbol.h
qgspointxy.h
qgsmargins.h