QGIS API Documentation 3.39.0-Master (bca3cdb6021)
Loading...
Searching...
No Matches
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
32class QgsMarkerSymbol;
33class QgsFillSymbol;
34
52class CORE_EXPORT QgsAnnotation : public QObject
53{
54
55#ifdef SIP_RUN
57 if ( dynamic_cast< QgsTextAnnotation * >( sipCpp ) )
58 sipType = sipType_QgsTextAnnotation;
59 else if ( dynamic_cast< QgsSvgAnnotation * >( sipCpp ) )
60 sipType = sipType_QgsSvgAnnotation;
61 else if ( dynamic_cast< QgsHtmlAnnotation * >( sipCpp ) )
62 sipType = sipType_QgsHtmlAnnotation;
63 else
64 sipType = NULL;
66#endif
67
68
69 Q_OBJECT
70 Q_PROPERTY( bool visible READ isVisible WRITE setVisible )
71 Q_PROPERTY( bool hasFixedMapPosition READ hasFixedMapPosition WRITE setHasFixedMapPosition )
72 Q_PROPERTY( QgsPointXY mapPosition READ mapPosition WRITE setMapPosition )
73 Q_PROPERTY( QSizeF frameSize READ frameSize WRITE setFrameSize )
74
75 public:
76
80 QgsAnnotation( QObject *parent SIP_TRANSFERTHIS = nullptr );
81
82 ~QgsAnnotation() override;
83
88 virtual QgsAnnotation *clone() const = 0 SIP_FACTORY;
89
94 bool isVisible() const { return mVisible; }
95
100 void setVisible( bool visible );
101
110 bool hasFixedMapPosition() const { return mHasFixedMapPosition; }
111
117 void setHasFixedMapPosition( bool fixed );
118
126 QgsPointXY mapPosition() const { return mMapPosition; }
127
133 void setMapPosition( const QgsPointXY &position );
134
140 QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
141
146 void setMapPositionCrs( const QgsCoordinateReferenceSystem &crs );
147
154 QPointF relativePosition() const { return mRelativePosition; }
155
162 void setRelativePosition( QPointF position );
163
169 Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint( QPointF offset ) SIP_DEPRECATED;
170
176 Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const SIP_DEPRECATED;
177
183 void setFrameOffsetFromReferencePointMm( QPointF offset );
184
190 QPointF frameOffsetFromReferencePointMm() const { return mOffsetFromReferencePoint; }
191
198 Q_DECL_DEPRECATED void setFrameSize( QSizeF size ) SIP_DEPRECATED;
199
206 Q_DECL_DEPRECATED QSizeF frameSize() const SIP_DEPRECATED;
207
214 void setFrameSizeMm( QSizeF size );
215
222 QSizeF frameSizeMm() const { return mFrameSize; }
223
229 void setContentsMargin( const QgsMargins &margins );
230
236 QgsMargins contentsMargin() const { return mContentsMargins; }
237
243 void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
244
249 QgsFillSymbol *fillSymbol() const;
250
254 void render( QgsRenderContext &context ) const;
255
262 virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
263
270 virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) = 0;
271
277 void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
278
283 QgsMarkerSymbol *markerSymbol() const { return mMarkerSymbol.get(); }
284
291 QgsMapLayer *mapLayer() const { return mMapLayer.data(); }
292
299 void setMapLayer( QgsMapLayer *layer );
300
306 QgsFeature associatedFeature() const { return mFeature; }
307
312 virtual void setAssociatedFeature( const QgsFeature &feature );
313
323 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
324
325 signals:
326
329
334 void moved();
335
340
341 protected:
342
347 virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
348
353 virtual QSizeF minimumFrameSize() const;
354
361 void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
362
369 void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
370
377 void copyCommonProperties( QgsAnnotation *target ) const;
378
379 private:
380
382 void drawFrame( QgsRenderContext &context ) const;
383
385 void drawMarkerSymbol( QgsRenderContext &context ) const;
386
387 bool mVisible = true;
388
390 bool mHasFixedMapPosition = true;
391
393 QgsPointXY mMapPosition;
394
396 QgsCoordinateReferenceSystem mMapPositionCrs;
397
399 QPointF mRelativePosition;
400
402 QPointF mOffsetFromReferencePoint = QPointF( 13, -13 );
403
405 QSizeF mFrameSize;
406
408 std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
409
410 QgsMargins mContentsMargins;
411
413 std::unique_ptr<QgsFillSymbol> mFillSymbol;
414
416 QgsWeakMapLayerPointer mMapLayer;
417
419 QgsFeature mFeature;
420
422 double mSegmentPointWidthMm = 2.64;
423
424};
425
426#endif // QGSANNOTATION_H
427
Abstract base class for annotation items which are drawn over a map.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
QgsMargins contentsMargin() const
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
virtual void renderAnnotation(QgsRenderContext &context, QSizeF size) const =0
Renders the annotation's contents to a target /a context at the specified /a size.
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
void moved()
Emitted when the annotation's position has changed and items need to be moved to reflect this.
QgsPointXY mapPosition() const
Returns the map position of the annotation, if it is attached to a fixed map position.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
bool hasFixedMapPosition() const
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
QgsFeature associatedFeature() const
Returns the feature associated with the annotation, or an invalid feature if none has been set.
virtual void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context)=0
Restores the annotation's state from a DOM element.
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position.
virtual void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const =0
Writes the annotation state to a DOM element.
void mapLayerChanged()
Emitted when the map layer associated with the annotation changes.
This class represents a coordinate reference system (CRS).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
An annotation item that embeds HTML content.
Base class for all map layer types.
Definition qgsmaplayer.h:76
The QgsMargins class defines the four margins of a rectangle.
Definition qgsmargins.h:37
A marker symbol type, for rendering Point and MultiPoint geometries.
A class to represent a 2D point.
Definition qgspointxy.h:60
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
An annotation which renders the contents of an SVG file.
An annotation item that displays formatted text from a QTextDocument document.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
const QgsCoordinateReferenceSystem & crs