QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsmargins.h"
26 #include "qgsmaplayer.h"
27 #include "qgsfeature.h"
28 
29 #include <QPointer>
30 
31 class QgsRenderContext;
32 class QgsMarkerSymbol;
33 class QgsFillSymbol;
34 
53 class CORE_EXPORT QgsAnnotation : public QObject
54 {
55 
56 #ifdef SIP_RUN
58  if ( dynamic_cast< QgsTextAnnotation * >( sipCpp ) )
59  sipType = sipType_QgsTextAnnotation;
60  else if ( dynamic_cast< QgsSvgAnnotation * >( sipCpp ) )
61  sipType = sipType_QgsSvgAnnotation;
62  else if ( dynamic_cast< QgsHtmlAnnotation * >( sipCpp ) )
63  sipType = sipType_QgsHtmlAnnotation;
64  else
65  sipType = NULL;
66  SIP_END
67 #endif
68 
69 
70  Q_OBJECT
71  Q_PROPERTY( bool visible READ isVisible WRITE setVisible )
72  Q_PROPERTY( bool hasFixedMapPosition READ hasFixedMapPosition WRITE setHasFixedMapPosition )
73  Q_PROPERTY( QgsPointXY mapPosition READ mapPosition WRITE setMapPosition )
74  Q_PROPERTY( QSizeF frameSize READ frameSize WRITE setFrameSize )
75 
76  public:
77 
81  QgsAnnotation( QObject *parent SIP_TRANSFERTHIS = nullptr );
82 
83  ~QgsAnnotation() override;
84 
89  virtual QgsAnnotation *clone() const = 0 SIP_FACTORY;
90 
95  bool isVisible() const { return mVisible; }
96 
101  void setVisible( bool visible );
102 
111  bool hasFixedMapPosition() const { return mHasFixedMapPosition; }
112 
118  void setHasFixedMapPosition( bool fixed );
119 
127  QgsPointXY mapPosition() const { return mMapPosition; }
128 
134  void setMapPosition( const QgsPointXY &position );
135 
141  QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
142 
147  void setMapPositionCrs( const QgsCoordinateReferenceSystem &crs );
148 
155  QPointF relativePosition() const { return mRelativePosition; }
156 
163  void setRelativePosition( QPointF position );
164 
170  Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint( QPointF offset ) SIP_DEPRECATED;
171 
177  Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const SIP_DEPRECATED;
178 
184  void setFrameOffsetFromReferencePointMm( QPointF offset );
185 
191  QPointF frameOffsetFromReferencePointMm() const { return mOffsetFromReferencePoint; }
192 
199  Q_DECL_DEPRECATED void setFrameSize( QSizeF size ) SIP_DEPRECATED;
200 
207  Q_DECL_DEPRECATED QSizeF frameSize() const SIP_DEPRECATED;
208 
215  void setFrameSizeMm( QSizeF size );
216 
223  QSizeF frameSizeMm() const { return mFrameSize; }
224 
230  void setContentsMargin( const QgsMargins &margins );
231 
237  QgsMargins contentsMargin() const { return mContentsMargins; }
238 
244  void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
245 
250  QgsFillSymbol *fillSymbol() const;
251 
255  void render( QgsRenderContext &context ) const;
256 
263  virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
264 
271  virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) = 0;
272 
278  void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
279 
284  QgsMarkerSymbol *markerSymbol() const { return mMarkerSymbol.get(); }
285 
292  QgsMapLayer *mapLayer() const { return mMapLayer.data(); }
293 
300  void setMapLayer( QgsMapLayer *layer );
301 
307  QgsFeature associatedFeature() const { return mFeature; }
308 
313  virtual void setAssociatedFeature( const QgsFeature &feature );
314 
324  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
325 
326  signals:
327 
329  void appearanceChanged();
330 
335  void moved();
336 
340  void mapLayerChanged();
341 
342  protected:
343 
348  virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
349 
354  virtual QSizeF minimumFrameSize() const;
355 
362  void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
363 
370  void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
371 
378  void copyCommonProperties( QgsAnnotation *target ) const;
379 
380  private:
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  QgsWeakMapLayerPointer mMapLayer;
418 
420  QgsFeature mFeature;
421 
423  double mSegmentPointWidthMm = 2.64;
424 
425 };
426 
427 #endif // QGSANNOTATION_H
428 
QgsAnnotation::contentsMargin
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
Definition: qgsannotation.h:237
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgsfeature.h
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsAnnotation::mapLayer
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
Definition: qgsannotation.h:292
QgsSvgAnnotation
An annotation which renders the contents of an SVG file.
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:186
QgsAnnotation
Abstract base class for annotation items which are drawn over a map.
Definition: qgsannotation.h:53
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsAnnotation::associatedFeature
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set.
Definition: qgsannotation.h:307
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:2146
QgsHtmlAnnotation
An annotation item that embeds HTML content.
Definition: qgshtmlannotation.h:35
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsAnnotation::markerSymbol
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
Definition: qgsannotation.h:284
QgsTextAnnotation
An annotation item that displays formatted text from a QTextDocument document.
Definition: qgstextannotation.h:31
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
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:155
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:111
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:141
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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:127
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
qgspointxy.h
qgsmargins.h