QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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.h"
22#include "qgis_core.h"
24#include "qgsfeature.h"
25#include "qgsmaplayer.h"
26#include "qgsmargins.h"
27#include "qgspointxy.h"
28
29#include <QPointer>
30
32class QgsMarkerSymbol;
33class QgsFillSymbol;
34
51
52class CORE_EXPORT QgsAnnotation : public QObject
53{
54#ifdef SIP_RUN
56 if ( dynamic_cast< QgsTextAnnotation * >( sipCpp ) )
57 sipType = sipType_QgsTextAnnotation;
58 else if ( dynamic_cast< QgsSvgAnnotation * >( sipCpp ) )
59 sipType = sipType_QgsSvgAnnotation;
60 else if ( dynamic_cast< QgsHtmlAnnotation * >( sipCpp ) )
61 sipType = sipType_QgsHtmlAnnotation;
62 else
63 sipType = NULL;
65#endif
66
67
68 Q_OBJECT
69 Q_PROPERTY( bool visible READ isVisible WRITE setVisible )
72 Q_PROPERTY( QSizeF frameSize READ frameSize WRITE setFrameSize )
73
74 public:
78 QgsAnnotation( QObject *parent SIP_TRANSFERTHIS = nullptr );
79
80 ~QgsAnnotation() override;
81
86 virtual QgsAnnotation *clone() const = 0 SIP_FACTORY;
87
92 bool isVisible() const { return mVisible; }
93
98 void setVisible( bool visible );
99
108 bool hasFixedMapPosition() const { return mHasFixedMapPosition; }
109
115 void setHasFixedMapPosition( bool fixed );
116
124 QgsPointXY mapPosition() const { return mMapPosition; }
125
131 void setMapPosition( const QgsPointXY &position );
132
138 QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
139
144 void setMapPositionCrs( const QgsCoordinateReferenceSystem &crs );
145
152 QPointF relativePosition() const { return mRelativePosition; }
153
160 void setRelativePosition( QPointF position );
161
167 Q_DECL_DEPRECATED void setFrameOffsetFromReferencePoint( QPointF offset ) SIP_DEPRECATED;
168
174 Q_DECL_DEPRECATED QPointF frameOffsetFromReferencePoint() const SIP_DEPRECATED;
175
181 void setFrameOffsetFromReferencePointMm( QPointF offset );
182
188 QPointF frameOffsetFromReferencePointMm() const { return mOffsetFromReferencePoint; }
189
196 Q_DECL_DEPRECATED void setFrameSize( QSizeF size ) SIP_DEPRECATED;
197
204 Q_DECL_DEPRECATED QSizeF frameSize() const SIP_DEPRECATED;
205
212 void setFrameSizeMm( QSizeF size );
213
220 QSizeF frameSizeMm() const { return mFrameSize; }
221
227 void setContentsMargin( const QgsMargins &margins );
228
234 QgsMargins contentsMargin() const { return mContentsMargins; }
235
241 void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
242
247 QgsFillSymbol *fillSymbol() const;
248
252 void render( QgsRenderContext &context ) const;
253
260 virtual void writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
261
268 virtual void readXml( const QDomElement &itemElem, const QgsReadWriteContext &context ) = 0;
269
276
281 QgsMarkerSymbol *markerSymbol() const { return mMarkerSymbol.get(); }
282
289 QgsMapLayer *mapLayer() const { return mMapLayer.data(); }
290
297 void setMapLayer( QgsMapLayer *layer );
298
304 QgsFeature associatedFeature() const { return mFeature; }
305
310 virtual void setAssociatedFeature( const QgsFeature &feature );
311
321 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
322
323 signals:
324
327
332 void moved();
333
338
339 protected:
344 virtual void renderAnnotation( QgsRenderContext &context, QSizeF size ) const = 0;
345
350 virtual QSizeF minimumFrameSize() const;
351
358 void _writeXml( QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context ) const;
359
366 void _readXml( const QDomElement &annotationElem, const QgsReadWriteContext &context );
367
374 void copyCommonProperties( QgsAnnotation *target ) const;
375
376 private:
378 void drawFrame( QgsRenderContext &context ) const;
379
381 void drawMarkerSymbol( QgsRenderContext &context ) const;
382
383 bool mVisible = true;
384
386 bool mHasFixedMapPosition = true;
387
389 QgsPointXY mMapPosition;
390
392 QgsCoordinateReferenceSystem mMapPositionCrs;
393
395 QPointF mRelativePosition;
396
398 QPointF mOffsetFromReferencePoint = QPointF( 13, -13 );
399
401 QSizeF mFrameSize;
402
404 std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
405
406 QgsMargins mContentsMargins;
407
409 std::unique_ptr<QgsFillSymbol> mFillSymbol;
410
412 QgsWeakMapLayerPointer mMapLayer;
413
415 QgsFeature mFeature;
416
418 double mSegmentPointWidthMm = 2.64;
419};
420
421#endif // QGSANNOTATION_H
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
Q_DECL_DEPRECATED void setFrameSize(QSizeF size)
Sets the size (in pixels) of the annotation's frame (the main area in which the annotation's content ...
bool hasFixedMapPosition
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...
QPointF frameOffsetFromReferencePointMm() const
Returns the annotation's frame's offset (in millimeters) from the mapPosition() reference point.
virtual void renderAnnotation(QgsRenderContext &context, QSizeF size) const =0
Renders the annotation's contents to a target /a context at the specified /a size.
void setMapPosition(const QgsPointXY &position)
Sets the map position of the annotation, if it is attached to a fixed map position.
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.
void _writeXml(QDomElement &itemElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes common annotation properties to a DOM element.
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.
void _readXml(const QDomElement &annotationElem, const QgsReadWriteContext &context)
Reads common annotation properties from a DOM element.
void copyCommonProperties(QgsAnnotation *target) const
Copies common annotation properties to the targe annotation.
QgsPointXY mapPosition
virtual QSizeF minimumFrameSize() const
Returns the minimum frame size for the annotation.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
virtual void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context)=0
Restores the annotation's state from a DOM element.
void setHasFixedMapPosition(bool fixed)
Sets whether the annotation is attached to a fixed map position, or uses a position relative to the c...
QgsAnnotation(QObject *parent=nullptr)
Constructor for QgsAnnotation.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the symbol that is drawn at the annotation's map position.
void setVisible(bool visible)
Sets whether the annotation is visible and should be rendered.
QSizeF frameSizeMm() const
Returns the size (in millimeters) of the annotation's frame (the main area in which the annotation's ...
virtual QgsAnnotation * clone() const =0
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current sta...
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.
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:60
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:83
Defines the four margins of a rectangle.
Definition qgsmargins.h:40
A marker symbol type, for rendering Point and MultiPoint geometries.
Represents a 2D point.
Definition qgspointxy.h:62
A container for the context for various read/write operations on 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:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.